qldpc.experimental.surgery.gadget
L=1 gadget construction (Webster, Smith, Cohen arXiv:2511.15989 §II A).
The construction restricts complementary checks to the logical support, computes a gauge basis for
that incidence matrix, and assembles the resulting merged CSS checks. The paper writes the number
of gauge-fixing checks as |S_L| - wt(L) + 1; the general form is |S_L| - rank(F), and the
two agree whenever dim ker(F) = 1, as they do for the paper’s four codes.
Notation (used throughout the surgery package; the symbols follow Webster/Cohen/Cross, not Cain). For a logical measured on support V_0:
V_0 — logical support (measured qubits) → ``support``
C_0 — data-code checks touching V_0 → rows of ``incidence``
F — restriction (incidence) matrix on (C_0, V_0) → ``incidence``
κ — gadget ancilla qubits (one per row of F)
χ — added meas-basis checks (one per support qubit)
G — a basis of ker(F^T); the gadget gauge checks → ``gauge``
Copyright 2026 The qLDPC Authors
Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Classes
An L=1 surgery gadget for measuring one logical operator of a CSS code. |
Functions
|
Webster §II A L=1 gadget: restriction, gauge fix, assembly. Deterministic in its arguments. |
Module Contents
- class qldpc.experimental.surgery.gadget.GadgetLayout[source]
An L=1 surgery gadget for measuring one logical operator of a CSS code.
Built by
build_gadget. The field names map onto Webster, Smith, Cohen arXiv:2511.15989 §II A as V_0 → support, F → incidence, G → gauge.incidencecarries one row per κ ancilla qubit, and the κ qubits occupy the merged-code qubit indices fromcode.num_quditsonward, soincidence.shape[0]is the κ count. A boosted gadget appends one row per added κ qubit; those rows belong to no check of the data code, soincidenceis then not a plain restriction of the complementary check matrix.- with_added_ancillas(incidence_rows: numpy.ndarray) GadgetLayout[source]
Return a layout with additional weight-2 ancilla rows, preserving existing additions.
- HX_merged: numpy.ndarray
- HZ_merged: numpy.ndarray
- property added_ancilla_incidence: numpy.ndarray
Rows added after the data-code restriction, in their current order.
- basis: qldpc.objects.PauliXZ
- gauge: numpy.ndarray
- incidence: numpy.ndarray
- property is_augmented: bool
Whether this layout contains ancillas beyond the data-code restriction.
- support: tuple[int, ...]
- x: numpy.ndarray
- qldpc.experimental.surgery.gadget.build_gadget(code: qldpc.codes.common.CSSCode, x: numpy.ndarray, *, basis: qldpc.objects.PauliXZ) GadgetLayout[source]
Webster §II A L=1 gadget: restriction, gauge fix, assembly. Deterministic in its arguments.
gadget notation: κ qubits → rows of incidence; G → gauge.
basis=Pauli.X: measures a logical X (PPM of X̄). Validates H_Z @ x == 0. basis=Pauli.Z: measures a logical Z (PPM of Z̄). Validates H_X @ x == 0.
- Raises:
ValueError – code is a subsystem code or is not over GF(2); x has an entry outside {0, 1}; basis is neither Pauli.X nor Pauli.Z; x fails the complementary check equation (H_Z @ x == 0 for basis=X, H_X @ x == 0 for basis=Z); x is the zero vector; or x lies in the row space of the measured basis’s check matrix, making it a stabilizer rather than a logical operator.