0
$\begingroup$

I am using qiksit to measure the Hamiltonian H, which isbasically sum of Pauli strings, say something like 2*X^X+0.5*Z^Y. For one variable, I need to get the analytically form of the inverse of H. It seems that there is no easy way to directly get the inverse observable. So, I am wondering that how can I get this done by using qiskit?

$\endgroup$
4
$\begingroup$

It seems that Qiskit does not have this feature. However, you can get the matrix, inverse it using numpy.linalg.inv(), then convert it to operator object again:

from qiskit.opflow import X, Y, Z
from qiskit.opflow.primitive_ops import MatrixOp
import numpy as np

op = 2*(X^X)+0.5*(Z^Y)
inv_matrix = np.linalg.inv(op.to_matrix())
operator = MatrixOp(inv_matrix)

print(operator.to_pauli_op())

And to get a PauliSumOp:

pauli_list = [(p.primitive.to_label(), p.coeff) for p in operator.to_pauli_op().oplist]

pauli_sum_op = PauliSumOp.from_list(pauli_list)
$\endgroup$
4
  • $\begingroup$ Thanks! That helps a lot. $\endgroup$ – ironmanaudi Jul 6 at 13:54
  • $\begingroup$ The resulting output is a SummedOp object. Is there a way to transform it t a PauliSumOp object? $\endgroup$ – ironmanaudi Jul 6 at 15:51
  • $\begingroup$ I updated the answer to show how to get PauliSumOp. $\endgroup$ – Egretta.Thula Jul 6 at 16:46
  • $\begingroup$ Thanks for the update. $\endgroup$ – ironmanaudi Jul 7 at 3:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.