qib.operator.pauli_operator.PauliString

class qib.operator.pauli_operator.PauliString(z, x, q)[source]

Bases: AbstractOperator

Pauli string (sequence of identity and Pauli matrices X, Y, Z), together with a global phase factor.

Using check matrix representation (similar to Qiskit convention) by storing binary arrays z and x. The logical Pauli string is

\[(-i)^q \otimes_{k=0}^{n-1} (-i)^{z_k x_k} Z^{z_k} X^{x_k}\]

Using convention that Pauli matrix at site 0 corresponds to slowest varying index.

Methods

as_matrix

Generate the sparse matrix representation of the Pauli string.

commutes_with

Test whether the Pauli string commutes with another Pauli string.

fields

List of fields the Pauli string acts on.

from_single_paulis

Construct a Pauli string from a list of single Pauli matrices, like ('Y', 1), ('X', 4), ('Z', 5).

from_string

Construct a Pauli string from a literal string representation, like "iYZXZ".

get_pauli

Get the Pauli matrix at index i as string 'I', 'X', 'Y' or 'Z'.

identity

Construct the Pauli string representation of the identity operation.

is_hermitian

Whether the operator is Hermitian.

is_unitary

Whether the operator is unitary.

refactor_phase

"Refactor" the Pauli string by setting q to 0 and returning the corresponding overall phase factor.

refactor_sign

"Refactor" the Pauli string by forcing q to be 0 or 1 and returning the corresponding overall sign factor.

set_field

Set a field which the Pauli string acts on (such that it can be used like a Hamiltonian).

set_pauli

Set an individual Pauli matrix at index i.

Attributes

num_qubits

Number of qubits, i.e., length of Pauli string, including identities.

as_matrix()[source]

Generate the sparse matrix representation of the Pauli string.

commutes_with(other)[source]

Test whether the Pauli string commutes with another Pauli string.

fields()[source]

List of fields the Pauli string acts on.

classmethod from_single_paulis(nqubits: int, *args, **kwargs)[source]

Construct a Pauli string from a list of single Pauli matrices, like (‘Y’, 1), (‘X’, 4), (‘Z’, 5).

classmethod from_string(s: str)[source]

Construct a Pauli string from a literal string representation, like “iYZXZ”.

get_pauli(i: int)[source]

Get the Pauli matrix at index i as string ‘I’, ‘X’, ‘Y’ or ‘Z’.

classmethod identity(nqubits: int)[source]

Construct the Pauli string representation of the identity operation.

is_hermitian()[source]

Whether the operator is Hermitian.

is_unitary()[source]

Whether the operator is unitary.

property num_qubits

Number of qubits, i.e., length of Pauli string, including identities.

refactor_phase()[source]

“Refactor” the Pauli string by setting q to 0 and returning the corresponding overall phase factor.

refactor_sign()[source]

“Refactor” the Pauli string by forcing q to be 0 or 1 and returning the corresponding overall sign factor.

set_field(field: Field)[source]

Set a field which the Pauli string acts on (such that it can be used like a Hamiltonian).

set_pauli(s: str, i: int)[source]

Set an individual Pauli matrix at index i.