pub struct CssCode {
pub id: String,
pub n: usize,
pub checks: Vec<Vec<usize>>,
pub stabs: Vec<Vec<usize>>,
pub k: usize,
/* private fields */
}Expand description
A CSS code prepared for decoding one error sector. checks are the parity
checks whose syndrome we decode (rows as sorted qubit lists); stab_basis is
the GF(2) row space of the complementary stabilizers, against which a residual
error is tested for logical triviality.
Fields§
§id: String§n: usize§checks: Vec<Vec<usize>>Parity checks (syndrome producers), each a sorted list of qubit indices.
stabs: Vec<Vec<usize>>The complementary stabilizer family, kept so callers can inspect the code (a CSS code is defined by both families, not just the one that produces the syndrome being decoded).
k: usizeNumber of encoded logical qubits, k = n − rank(checks) − rank(stab).
Implementations§
Source§impl CssCode
impl CssCode
Sourcepub fn check_matrix_bytes(&self) -> Vec<u8> ⓘ
pub fn check_matrix_bytes(&self) -> Vec<u8> ⓘ
Canonical bytes of the check matrix (content-addresses the code).
Sourcepub fn is_trivial(&self, residual_cols: &[usize]) -> bool
pub fn is_trivial(&self, residual_cols: &[usize]) -> bool
A residual error (as its 1-qubits) is logically trivial iff it lies in the stabilizer row space.
Sourcepub fn toric(l: usize) -> CssCode
pub fn toric(l: usize) -> CssCode
The L×L toric code: n = 2L² qubits on edges, L² star (X) checks and
L² plaquette (Z) checks, k = 2. We decode X-errors: checks = Z
(plaquettes), triviality against the X-stabilizers (stars).
Sourcepub fn surface(d: usize) -> CssCode
pub fn surface(d: usize) -> CssCode
The distance-d rotated surface code, [[d², 1, d]] (d odd).
The toric code above is this code’s periodic-boundary cousin: elegant, but
it needs a torus. The rotated surface code is the planar one — nearest-
neighbour on a d × d patch with open boundaries — and it is what
essentially every hardware roadmap actually targets.
Data qubit (r, c) is index r·d + c. Bulk plaquettes cover each 2×2
square and alternate in a checkerboard; the boundaries carry weight-2
stabilizers, X along the top and bottom, Z along the left and right. The
parities are the ones that make the two families commute — the neighbouring
choice does not, which the css_commutation test would catch.
Examples found in repository?
11fn main() {
12 let trials = 4000;
13 println!("rotated surface code, union-find decoder, {trials} shots per point\n");
14
15 let codes: Vec<CssCode> = [3usize, 5, 7].iter().map(|&d| CssCode::surface(d)).collect();
16 for c in &codes {
17 // the distance is computed, not taken on faith from the constructor's name
18 let d = x_distance(c, 6).map(|d| d.to_string()).unwrap_or_else(|| ">5".into());
19 println!(" {} : n={} k={} d={}", c.id, c.n, c.k, d);
20 }
21
22 println!("\n p d=3 d=5 d=7");
23 for p in [0.01f64, 0.02, 0.05, 0.08, 0.12, 0.16] {
24 print!(" {p:<8}");
25 for c in &codes {
26 let (t, f) = benchmark_uf(c, p, trials, 11);
27 print!(" {:>10.4}", f as f64 / t as f64);
28 }
29 println!();
30 }
31 println!("\n Read down each column: at low p a larger code wins. Read across the\n bottom rows: past threshold that reverses, and more qubits buy less.");
32}Sourcepub fn color_steane() -> CssCode
pub fn color_steane() -> CssCode
The [[7,1,3]] Steane code — the smallest 2D colour code.
Its three checks are the rows of the Hamming [7,4,3] parity-check matrix,
used for both the X and the Z family. That coincidence is the whole point
of a colour code: the two stabilizer families sit on the same supports, so
the code is self-dual as a CSS code.
The payoff is CssCode::has_transversal_hadamard. A surface code has to
implement a logical Hadamard with lattice surgery or code deformation; a
colour code gets it by applying H to every physical qubit, one round, no
ancillas. The trade is a lower threshold — this buys gates, not noise
tolerance.
Sourcepub fn is_self_dual(&self) -> bool
pub fn is_self_dual(&self) -> bool
Whether the X and Z stabilizer families generate the same group.
This is the algebraic content of “colour code”. H⊗n exchanges X-type and
Z-type Paulis, so it maps the stabilizer group to itself exactly when the
two families coincide — and a map that preserves the stabilizer group
preserves the code space.
Sourcepub fn has_transversal_hadamard(&self) -> bool
pub fn has_transversal_hadamard(&self) -> bool
Whether applying H to every physical qubit is a logical operation.
True exactly for a self-dual CSS code. Stated as its own question because it is the property people actually want from a colour code.
Sourcepub fn encode_zero_circuit(&self) -> Circuit
pub fn encode_zero_circuit(&self) -> Circuit
A circuit preparing the logical |0⟩ of this CSS code from |0…0⟩.
|0⟩_L is the uniform superposition over the row space of the X-stabilizer
matrix. Reduce that matrix to fully reduced row-echelon form, put an H
on each pivot qubit, and fan a CNOT out to the rest of its row: each row
then contributes an independent branch, which is exactly that superposition.
The full reduction matters — with pivots shared between rows the fan-out would interfere with itself and prepare something else.
Needs the quantum feature: the decoding layer above is deliberately
independent of the simulator, and this is the one place that borrows it.
Sourcepub fn bivariate_bicycle(
l: usize,
m: usize,
a: &[(usize, usize)],
b: &[(usize, usize)],
) -> CssCode
pub fn bivariate_bicycle( l: usize, m: usize, a: &[(usize, usize)], b: &[(usize, usize)], ) -> CssCode
A bivariate-bicycle code on Z_l × Z_m. a and b are lists of monomials
(px, py); A = Σ x^px y^py, B likewise (mod-2 sums of shift matrices).
H_X = [A | B], H_Z = [Bᵀ | Aᵀ], n = 2·l·m. We decode X-errors:
checks = H_Z, triviality against H_X.