3
$\begingroup$

Suppose we have a PauliWeightedOperator object from Qiskit. Is there any built-in method to convert it to the matrix representation in the computational basis? My search in the docs was not successful.

$\endgroup$
1
$\begingroup$

I think this is what you are looking for:

from qiskit.aqua.operators import WeightedPauliOperator
import numpy as np

pauli_dict = {'paulis': [{"coeff": {"imag": -1.0, "real": 1.0 }, "label": "XX"}
                         ]}
operator = WeightedPauliOperator.from_dict(pauli_dict)

Op = operator.to_opflow()
MatrixOp = Op.to_matrix()
MatrixRepresentation = np.real(MatrixOp)
print(MatrixRepresentation)

The output would be:

array([[0., 0., 0., 1.],
       [0., 0., 1., 0.],
       [0., 1., 0., 0.],
       [1., 0., 0., 0.]])
$\endgroup$

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.