Skip to main content

CssCode

Struct CssCode 

Source
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: usize

Number of encoded logical qubits, k = n − rank(checks) − rank(stab).

Implementations§

Source§

impl CssCode

Source

pub fn check_matrix_bytes(&self) -> Vec<u8> ⓘ

Canonical bytes of the check matrix (content-addresses the code).

Source

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.

Source

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).

Source

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?
examples/threshold.rs (line 15)
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}
Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn gross() -> CssCode

The [[72,12]] bivariate-bicycle preset (l=m=6, A=x³+y+y², B=y³+x+x²).

Trait Implementations§

Source§

impl Clone for CssCode

Source§

fn clone(&self) -> CssCode

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for CssCode

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.