mqt.qecc.codes.core.pauli¶
Class for working with representations of Pauli operators.
Exceptions¶
Exception raised when an invalid Pauli operator is encountered. |
Classes¶
Class representing an n-qubit Pauli operator. |
|
Class representing a stabilizer tableau. |
|
Type alias for CSS check matrices. |
Functions¶
Given a tableau of stabilizers, complete it to a full tableau by adding destabilizers. |
|
|
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.
- 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.
- copy() StabilizerTableau[source]¶
Return a copy of the stabilizer tableau.
- 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.
- to_css() tuple[CheckMatrix, CheckMatrix][source]¶
Convert the stabilizer tableau to CSS check matrices.
- Returns:
A tuple containing the X and Z check matrices.
- 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.
- 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.
- exception InvalidPauliError(message: str)[source]¶
Bases:
ValueErrorException 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.
- copy() CheckMatrix[source]¶
Create a copy of 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.