Codes & Circuits paulicert.codes paulicert.circuits
Load built-in stabilizer and qLDPC presets, construct custom codes, apply local Clifford deformations, and synthesize physical-order Qiskit circuits. For algebraic definitions, see Foundations.
StabilizerCode & Presets
class StabilizerCode
Frozen dataclass storing parity-check matrices (h_x, h_z, h_sym), code parameters (n, k, d, r, t), standard form, and physical-order logical operators (x_bar, z_bar).
| Method | Returns | Description |
|---|---|---|
from_pauli_list(...) | StabilizerCode | Classmethod constructing a validated code from Pauli strings or a Qiskit PauliList (qiskit_order=False for textbook left-to-right strings). |
to_pauli_list() | PauliList | Stabilizer generators in Qiskit qubit order (rightmost character = qubit 0). |
logical_x_paulis() | PauliList | Logical X operators as a Qiskit PauliList. |
logical_z_paulis() | PauliList | Logical Z operators as a Qiskit PauliList. |
to_stabilizer_state() | StabilizerState | Encoded logical zero state in Qiskit tableau form. |
to_encoder_clifford() | Clifford | Physical-order encoding circuit as a Qiskit Clifford. |
def get_preset_code(preset_id: str) → StabilizerCode
Returns one of the nine built-in codes listed in PRESETS.
preset_id | [[n, k, d]] | Family | Description |
|---|---|---|---|
"3-1-1-bitflip" | [[3, 1, 1]] | Repetition | 3-qubit bit-flip code (ZZI, IZZ). |
"5-1-3-perfect" | [[5, 1, 3]] | Non-CSS | Smallest single-error-correcting quantum code. |
"7-1-3-steane" | [[7, 1, 3]] | CSS | Self-dual Steane code from the [7,4,3] Hamming code. |
"8-3-3-gottesman" | [[8, 3, 3]] | Non-CSS | 3-logical-qubit Gottesman code. |
"9-1-3-shor" | [[9, 1, 3]] | CSS | Concatenated 9-qubit Shor code. |
"58-16-3-hgp" | [[58, 16, 3]] | HGP qLDPC | Hypergraph product of the [7,4,3] Hamming code. |
"72-12-6-bb" | [[72, 12, 6]] | BB qLDPC | Bivariate bicycle code (ell=6, m=6). |
"90-8-10-bb" | [[90, 8, 10]] | BB qLDPC | Bivariate bicycle code (ell=15, m=3). |
"144-12-12-bb" | [[144, 12, 12]] | BB qLDPC | Gross bivariate bicycle code (ell=12, m=6). |
Custom Constructors & Deformations
def build_stabilizer_code(h_x: ArrayLike | str | None = None, h_z: ArrayLike | str | None = None, *, h_gf4: ArrayLike | str | None = None, code_type: str = "non-css", d: int | None = None, name: str | None = None) → StabilizerCode
Validates commutativity and builds a StabilizerCode from binary h_x / h_z matrices or a GF(4) matrix h_gf4 (entries in 0..3 for I, X, Z, Y).
def from_pauli_list(stabilizers: PauliList | Sequence[str], *, d: int | None = None, name: str | None = None, qiskit_order: bool = True) → StabilizerCode
Builds a validated StabilizerCode directly from Pauli generator strings or a Qiskit PauliList (qiskit_order=True puts qubit 0 on the right; pass qiskit_order=False for left-to-right textbook strings).
def deform_stabilizer_code(code: StabilizerCode, qubit_ops: str | Sequence[str] | Mapping[int, str] = "xzzx", *, name: str | None = None) → StabilizerCode
Applies single-qubit Clifford Pauli-axis permutations (such as "xzzx", "xy_code", a per-qubit gate list, or a mapping {q: "H"}) to rotate +1 stabilizers while preserving [[n, k, d]] (canonicalizing redundant generators via RREF if local Clifford phases frustrate a dependent row).
qLDPC Constructors
def build_hypergraph_product_code(h1: ArrayLike | str, h2: ArrayLike | str | None = None, *, d: int | None = None, name: str | None = None) → StabilizerCode
Builds a hypergraph-product CSS code from one or two classical binary parity-check matrices.
def build_bivariate_bicycle_code(ell: int, m: int, a_terms: Sequence[tuple[int, int]], b_terms: Sequence[tuple[int, int]], *, d: int | None = None, name: str | None = None) → StabilizerCode
Builds a bivariate bicycle CSS code of blocklength 2 * ell * m from sparse shift exponent pairs (a, b) representing polynomial terms x^a y^b in a_terms and b_terms.
import paulicert as pc
hgp = pc.build_hypergraph_product_code("1 1 0\n0 1 1", d=3)
bb72 = pc.build_bivariate_bicycle_code(
6, 6, [(3, 0), (0, 1), (0, 2)], [(0, 3), (1, 0), (2, 0)], d=6
)
print(f"HGP : n={hgp.n}, k={hgp.k}, d={hgp.d}") # HGP : n=13, k=1, d=3
print(f"BB72: n={bb72.n}, k={bb72.k}, d={bb72.d}") # BB72: n=72, k=12, d=6
Qiskit Circuits paulicert.circuits
def encoding_circuit(code: StabilizerCode) → QuantumCircuit
Synthesizes an n-qubit Clifford encoding circuit in physical qubit order. The wire indices carrying unencoded logical inputs are stored in circuit.metadata["logical_inputs"].
def syndrome_circuit(code: StabilizerCode) → QuantumCircuit
Builds an (n + r)-qubit circuit measuring r independent stabilizer generators into classical register syn.
[[4, 2, 2]] code, apply an XZZX Clifford deformation, and synthesize physical-order circuits.import paulicert as pc
code422 = pc.from_pauli_list(["XXXX", "ZZZZ"], d=2, name="[[4, 2, 2]]")
xzzx = pc.deform_stabilizer_code(code422, "xzzx")
enc = pc.encoding_circuit(code422)
syn = pc.syndrome_circuit(code422)
print(f"[[{code422.n}, {code422.k}, {code422.d}]] | XZZX checks: {xzzx.to_pauli_list().to_labels()}")
# [[4, 2, 2]] | XZZX checks: ['ZXZX', 'XZXZ']
print(f"Encoder qubits={enc.num_qubits} (logical_inputs={enc.metadata['logical_inputs']}) | Syndrome qubits={syn.num_qubits}")
# Encoder qubits=4 (logical_inputs=[2, 3]) | Syndrome qubits=6
Note on Qiskit qubit order: Qiskit strings start q0 on the right (q3 q2 q1 q0), so applying "xzzx" (Hadamard on odd qubits q1, q3) maps "XXXX" to "ZXZX".