mqt.qecc.codes.core.pauli

Class for working with representations of Pauli operators.

Exceptions

InvalidPauliError

Exception raised when an invalid Pauli operator is encountered.

Classes

Pauli

Class representing an n-qubit Pauli operator.

StabilizerTableau

Class representing a stabilizer tableau.

CheckMatrix

Type alias for CSS check matrices.

Functions

complete_stabilizer_tableau_with_destabilizers(...)

Given a tableau of stabilizers, complete it to a full tableau by adding destabilizers.

is_pauli_string(→ bool)

Check if a string is a valid Pauli string.

Module Contents

class Pauli(symplectic: SymplecticVector, phase: int = 0)[source]

Class representing an n-qubit Pauli operator.

classmethod from_pauli_string(p: str) Pauli[source]

Create a new Pauli operator from a Pauli string.

classmethod from_stim(p: stim.PauliString) Pauli[source]

Create a new Pauli operator from Stim representation.

commute(other: Pauli) bool[source]

Check if this Pauli operator commutes with another Pauli operator.

anticommute(other: Pauli) bool[source]

Check if this Pauli operator anticommutes with another Pauli operator.

as_vector() numpy.typing.NDArray[numpy.int8][source]

Convert the Pauli operator to a binary vector.

x_part() numpy.typing.NDArray[numpy.int8][source]

Return the X part of the Pauli operator.

z_part() numpy.typing.NDArray[numpy.int8][source]

Return the Z part of the Pauli operator.

class StabilizerTableau(tableau: SymplecticMatrix | numpy.typing.NDArray[numpy.int8], phase: numpy.typing.NDArray[numpy.int8] | None = None)[source]

Class representing a stabilizer tableau.

classmethod from_stim_circuit(circ: stim.Circuit) StabilizerTableau[source]

Create a StabilizerTableau from a stim.Circuit.

Parameters:

circ – A stim.Circuit object.

Returns:

A StabilizerTableau instance.

classmethod from_stim_tableau(stim_tableau: stim.Tableau) StabilizerTableau[source]

Create a StabilizerTableau from a stim.Tableau.

Parameters:

stim_tableau – A stim.Tableau object.

Returns:

A StabilizerTableau instance.

classmethod from_pauli_strings(pauli_strings: Sequence[str]) StabilizerTableau[source]

Create a new stabilizer tableau from a list of Pauli strings.

classmethod from_paulis(paulis: Sequence[Pauli]) StabilizerTableau[source]

Create a new stabilizer tableau from a list of Pauli operators.

classmethod empty(n: int) StabilizerTableau[source]

Create a new empty stabilizer tableau.

classmethod identity(n: int) StabilizerTableau[source]

Create a new identity stabilizer tableau.

classmethod from_matrix(matrix: numpy.typing.NDArray[numpy.int8]) StabilizerTableau[source]

Create a StabilizerTableau from a symplectic matrix.

Parameters:

matrix – A 2n x 2n symplectic matrix representing the stabilizer tableau.

Returns:

A StabilizerTableau instance.

classmethod from_check_matrix(check_matrix: CheckMatrix) StabilizerTableau[source]

Create a StabilizerTableau from a CSS check matrix.

Parameters:

check_matrix – A CheckMatrix object representing the CSS check matrix.

Returns:

A StabilizerTableau instance.

all_commute(other: StabilizerTableau) bool[source]

Check if all Pauli operators in this stabilizer tableau commute with all Pauli operators in another stabilizer tableau.

as_matrix() numpy.typing.NDArray[numpy.int8][source]

Convert the stabilizer tableau to a binary matrix.

apply_h(qubit: int) None[source]

Apply the Hadamard gate to the stabilizer tableau.

Parameters:

qubit – The index of the qubit to apply the Hadamard gate to.

apply_cx(ctrl: int, tar: int) None[source]

Apply the CNOT gate to the stabilizer tableau.

Parameters:
  • ctrl – The index of the control qubit.

  • tar – The index of the target qubit.

apply_cz(ctrl: int, tar: int) None[source]

Apply the CZ gate to the stabilizer tableau.

Parameters:
  • ctrl – The index of the control qubit.

  • tar – The index of the target qubit.

apply_swap(q1: int, q2: int) None[source]

Apply the SWAP gate to the stabilizer tableau.

Parameters:
  • q1 – The index of the first qubit.

  • q2 – The index of the second qubit.

apply_s(qubit: int) None[source]

Apply the S gate to the stabilizer tableau.

Parameters:

qubit – The index of the qubit to apply the S gate to.

apply_sdg(qubit: int) None[source]

Apply the S† gate to the stabilizer tableau.

apply_x(qubit: int) None[source]

Apply the X gate to the stabilizer tableau.

apply_z(qubit: int) None[source]

Apply the Z gate to the stabilizer tableau.

apply_y(qubit: int) None[source]

Apply the Y gate to the stabilizer tableau.

copy() StabilizerTableau[source]

Return a copy of the stabilizer tableau.

to_pauli_list() list[Pauli][source]

Return the tableau as a list of Paulis.

to_numpy() numpy.typing.NDArray[numpy.int8][source]

Convert the stabilizer tableau to a NumPy array.

Returns:

A NumPy array where the first 2n columns represent the symplectic matrix and the last column represents the phase vector.

is_css() bool[source]

Check if the stabilizer tableau is in CSS form.

to_css() tuple[CheckMatrix, CheckMatrix][source]

Convert the stabilizer tableau to CSS check matrices.

Returns:

A tuple containing the X and Z check matrices.

get_x_part() numpy.typing.NDArray[numpy.int8][source]

Get the X part of the stabilizer tableau.

get_z_part() numpy.typing.NDArray[numpy.int8][source]

Get the Z part of the stabilizer tableau.

symplectic_submatrix(q: int) numpy.typing.NDArray[numpy.int8][source]

Get the 2x2 symplectic submatrix for a given qubit.

Parameters:

q – The index of the qubit.

Returns:

A 2x2 NumPy array representing the symplectic submatrix for the given qubit.

is_identity() bool[source]

Check if the stabilizer tableau is the identity.

Returns:

True if the stabilizer tableau is the identity, False otherwise.

num_rows() int[source]

Return the number of rows in the stabilizer tableau.

is_row(pauli: Pauli) bool[source]

Check if a given Pauli operator is a stabilizer of the tableau.

Parameters:

pauli – A Pauli operator to check.

Returns:

True if the Pauli operator is a stabilizer, False otherwise.

complete_stabilizer_tableau_with_destabilizers(stabilizers: StabilizerTableau, stab_rows: list[int] | None = None) StabilizerTableau[source]

Given a tableau of stabilizers, complete it to a full tableau by adding destabilizers.

Destabilizer d_i anticommutes with stabilizer s_i but commutes with all other stabilizers, destabilizers, and logical operators.

Parameters:
  • stabilizers – A tableau representing the stabilizers (and possibly some logical operators) of the code.

  • stab_rows – List of row indices that are stabilizers. If None, assumes all rows are stabilizers. Destabilizers will be added for each row specified in stab_rows.

Returns:

logical X, destabilizers, logical Z, stabilizers.

Return type:

A tableau ordered as

Note

This function assumes that all rows not specified in stab_rows are logical operators. These rows are split by position: the first half are treated as logical X operators, and the second half as logical Z operators. Any pre-existing destabilizers in the input tableau that are not identified in stab_rows will be treated as logical operators and may be reordered or reinterpreted according to this convention.

Raises:

ValueError – If any row index in stab_rows is out of bounds or if valid destabilizers cannot be found.

is_pauli_string(p: str) bool[source]

Check if a string is a valid Pauli string.

exception InvalidPauliError(message: str)[source]

Bases: ValueError

Exception raised when an invalid Pauli operator is encountered.

class CheckMatrix(matrix: numpy.typing.NDArray[numpy.int8], pauli_type: str)[source]

Type alias for CSS check matrices.

is_x_type() bool[source]

Check if the check matrix is of type ‘X’.

is_z_type() bool[source]

Check if the check matrix is of type ‘Z’.

copy() CheckMatrix[source]

Create a copy of the check matrix.

is_identity() bool[source]

Check if the check matrix is an identity matrix.

num_qubits() int[source]

Get the number of qubits represented by the check matrix.

num_rows() int[source]

Get the number of rows in the check matrix.

equ_span(other: CheckMatrix | numpy.typing.NDArray[numpy.int8]) bool[source]

Check if the row spans of this check matrix and another check matrix are equal.