Qiskit PauliWeightedOperator in the matrix representation?

2

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.

Ghostwriter

Posted 2020-12-29T21:10:25.133

Reputation: 45

Answers

1

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.]])

KAJ226

Posted 2020-12-29T21:10:25.133

Reputation: 6 322