1
$\begingroup$

I am using Qiskit 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$

1 Answer 1

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$ Jul 6, 2021 at 13:54
  • $\begingroup$ The resulting output is a SummedOp object. Is there a way to transform it t a PauliSumOp object? $\endgroup$ Jul 6, 2021 at 15:51
  • $\begingroup$ I updated the answer to show how to get PauliSumOp. $\endgroup$ Jul 6, 2021 at 16:46
  • $\begingroup$ Thanks for the update. $\endgroup$ Jul 7, 2021 at 3:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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