peropq.pauli#

Module Contents#

Classes#

Pauli

Enum class for Pauli gates.

PauliString

Class representing a Pauli string multiplied by a complex coefficient.

Functions#

_pauli_string_mult(pauli_string1, pauli_string2)

class peropq.pauli.Pauli#

Bases: enum.Enum

Enum class for Pauli gates.

I = 'I'#
X = 'X'#
Y = 'Y'#
Z = 'Z'#
__mul__(other)#

Multiply two Paulis.

Parameters:

other (Pauli) –

Return type:

tuple[complex, Pauli]

commutes_with(other)#

Return whether this Pauli commutes with given Pauli.

:param other The right side of the Commutator

Returns:

True if PauliStrings commute, False otherwise

Parameters:

other (Pauli) –

Return type:

bool

class peropq.pauli.PauliString#

Class representing a Pauli string multiplied by a complex coefficient.

qubit_pauli_map: dict[int, Pauli]#
coefficient: complex = 1#
classmethod from_pauli_sequence(paulis, coeff=1, start_qubit=0)#

Create from a sequence of Paulis.

The Paulis will be placed sequentially on qubits starting from qubit index <start_qubit>

:param paulis a list/tuple of Paulis :param coeff coefficient of the tensor :param start_qubit which qubit to place first Pauli on

Parameters:
  • paulis (collections.abc.Sequence[Pauli]) –

  • coeff (complex) –

  • start_qubit (int) –

Return type:

PauliString

__post_init__()#

Special dataclass method that runs directly after initialization.

Return type:

None

prune()#

Remove any Identities from the string.

Return type:

PauliString

__eq__(other)#

Equality for PauliStrings.

Two PauliStrings are equal if their coefficients are equal and if their Paulis are equal on all qubits. The underlying qubit_pauli_maps may differ (in the number of Identities).

Parameters:

other (object) –

Return type:

bool

get_pauli(qubit)#

Return the pauli at a given qubit.

:param qubit the qubit index to retrieve the Pauli from

Returns:

the pauli at qubit index <qubit> otherwise, the identity Pauli.I

Parameters:

qubit (int) –

Return type:

Pauli

update(update_qubit_pauli_map, coeff=None)#

Update the PauliString.

Parameters:
  • update_qubit_pauli_map (dict[int, Pauli]) –

  • coeff (complex | None) –

Return type:

PauliString

__mul__(other)#

Multiply PauliString with a complex number or PauliString.

Parameters:

other (PauliString | complex) –

Return type:

PauliString

__rmul__(other)#

Multiply PauliString with a complex number or PauliString.

Parameters:

other (complex) –

Return type:

PauliString

commutes_with(other)#

Return whether this PauliString commutes with given PauliString.

:param other The right side of the Commutator

Returns:

True if PauliStrings commute, False otherwise

Parameters:

other (PauliString) –

Return type:

bool

normalized_trace()#

Returns 2^(-n)*Tr(self).

The trace is just the coefficient times the product of the traces of the Paulis over all n qubits (including any identities on qubits not explicitly contained in the qubit_pauli_map). Since Tr(Pauli.I) == 2, and Tr(Pauli.X) == Tr(Pauli.Y) == Tr(Pauli.Z) == 0, the result will either be 0 (if any of the Paulis is not the Identity) or self.coefficient (if all paulis are the identity).

Return type:

complex

peropq.pauli._pauli_string_mult(pauli_string1, pauli_string2)#
Parameters:
Return type:

PauliString