class mentpy.PauliOp

Class for representing Pauli operators as matrices and strings.

Parameters:
op : Union[np.ndarray, str, List[str]]

The Pauli operator to be represented. Can be a matrix, a string, or a list of strings.

Examples

Create a Pauli operator from a matrix

In [1]: op = mp.PauliOp(np.array([[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 0, 1], [0, 0, 1, 0]]))

In [2]: print(op)
XI
IX
IZ
ZI

Create a Pauli operator from a string

In [3]: op = mp.PauliOp('XIZ;ZII;IIZ;IZI')

In [4]: print(op)
XIZ
ZII
IIZ
IZI

Create a Pauli operator from a list of strings

In [5]: op = mp.PauliOp(['XIZ', 'ZII', 'IIZ', 'IZI'])

In [6]: print(op)
XIZ
ZII
IIZ
IZI

Constructors

PauliOp(op: ndarray | str | List[str])

Initialize a PauliOp object.

String representation

__repr__()

Return repr(self).

Special methods

__eq__(other: PauliOp)

Return self==value.

__getitem__(key)
__hash__()

Return hash(self).

__mul__(other: PauliOp)

Returns the product of two Pauli operators.

Methods

append(other)

Appends a Pauli operator to the end of another Pauli operator.

commutator(other) PauliOp

Returns the commutator of two Pauli operators.

get_subset(indices)

Returns a subset of the Pauli operator.

symplectic_prod(other)

Returns the symplectic product of two Pauli operators.

Properties

property number_of_qubits

Returns the number of qubits in the Pauli operator.