Get the inverse of a Hermitian operator for measurement in qiskit

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?

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)
• Thanks! That helps a lot. Jul 6 '21 at 13:54
• The resulting output is a SummedOp object. Is there a way to transform it t a PauliSumOp object? Jul 6 '21 at 15:51
• I updated the answer to show how to get PauliSumOp. Jul 6 '21 at 16:46
• Thanks for the update. Jul 7 '21 at 3:25