mqt.qecc.codes.core.stabilizer_code¶
Class for representing general stabilizer codes.
Exceptions¶
Raised when the stabilizer code is invalid. |
Classes¶
A class for representing stabilizer codes. |
Module Contents¶
- class StabilizerCode(generators: PauliTableau | list[Pauli] | list[str], distance: int | None = None, z_logicals: PauliTableau | list[Pauli] | list[str] | None = None, x_logicals: PauliTableau | list[Pauli] | list[str] | None = None, n: int | None = None)[source]¶
A class for representing stabilizer codes.
- property symplectic: numpy.typing.NDArray[numpy.int8]¶
The binary symplectic matrix of the stabilizer generators.
- equal_stabilizer_group(other: StabilizerCode) bool[source]¶
Check if two stabilizer codes have the same signed stabilizer group.
The generators need not be independent; the comparison is over the generated groups, so redundant generators on either side do not affect the result.
- equal_logical_basis(other: StabilizerCode) bool[source]¶
Check if two stabilizer codes have the same logical basis.
- is_equivalent(other: StabilizerCode) bool[source]¶
Check if two stabilizer codes are equivalent.
Two codes are equivalent if they have the same stabilizer group and the same logical basis (up to stabilizer equivalence). This is a semantic comparison, unlike __eq__ which checks for exact matrix equality.
- is_z_logical(p: Pauli | str) bool[source]¶
Check if a given Pauli string is a logical Z operator of the code.
- is_x_logical(p: Pauli | str) bool[source]¶
Check if a given Pauli string is a logical X operator of the code.
- get_logical_mapping(other: StabilizerCode) list[int] | None[source]¶
Get a mapping of logical qubits from this code to another code, if it exists.
- Returns:
A list of integers where the i-th element is the index of the logical qubit in the other code that corresponds to the i-th logical qubit in this code. Returns None if no such mapping exists.
- is_logical(p: Pauli | str) bool[source]¶
Check if a given Pauli string is a logical operator of the code.
- get_syndrome(error: Pauli | str) numpy.typing.NDArray[numpy.int8][source]¶
Compute the syndrome of the error.
- Parameters:
error – The error as a pauli string or binary vector.
- stabilizer_equivalent(p1: Pauli | str, p2: Pauli | str) bool[source]¶
Check if two Pauli operators differ by an element of the signed stabilizer group.
- to_tableau() PauliTableau[source]¶
Convert the stabilizer code to a tableau with logicals and stabilizers.
- Returns:
- A tableau with rows ordered as:
X logical operators
Z logical operators
Stabilizer generators
- Return type:
- static get_generators(generators: PauliTableau | list[Pauli] | list[str], n: int | None = None) PauliTableau[source]¶
Get the stabilizer generators as a PauliTableau object.
- Parameters:
generators – The stabilizer generators as a PauliTableau object, a list of Pauli objects, or a list of Pauli strings.
n – The number of qubits in the code. Required if generators is an empty list.
- classmethod get_trivial_code(n: int) StabilizerCode[source]¶
Get the trivial stabilizer code.
- compute_logical_ops() tuple[PauliTableau, PauliTableau][source]¶
Compute logical Z/X operators from stabilizer generators.
Finds a basis of the centralizer modulo the stabilizers and canonicalizes it into k symplectic pairs (Z̄_i, X̄_i).
- Returns:
The tuple (L_x, L_z) of logical X and Z operators as PauliTableau objects, ordered such that rows i represent X̄_i and Z̄_i.
- classmethod from_file(file_path: str | Path) StabilizerCode[source]¶
Load a Stabilizer code from a file.
The file can contain either: 1. One line per stabilizer generator as a Pauli string (e.g., “IXXZZ”) 2. A binary symplectic matrix (2nxm) where m is the number of stabilizers
For the 5-qubit perfect code in Pauli string format: IXXZZ ZIXXZ ZZIXX XZZIX
For binary symplectic matrix format, any of these are accepted: - Space-separated: “1 0 0 0 0 …” - Comma-separated: “1,0,0,0,0,…” - List notation: “[[1,0,0,…],[0,1,0,…]]” - NumPy array notation: “[[1 0 0 …]n [0 1 0 …]]”
- Parameters:
file_path – The path to the file containing the code.
- Returns:
The stabilizer code.
- Return type:
- exception InvalidStabilizerCodeError[source]¶
Bases:
ValueErrorRaised when the stabilizer code is invalid.