Superfermion logo
Guides

Quantum Error Correction

10 stabilizer codes + 4 decoders for quantum error correction in Superfermion.

Superfermion provides a comprehensive QEC toolkit: 10 quantum error correction codes and 4 decoders, all backed by Rust performance.

Codes

All codes are in superfermion.qec:

from superfermion.qec import (
    RepetitionCode,
    ShorCode,
    SteaneCode,
    BaconShorCode,
    SurfaceCode2D,
    ToricCode2D,
    ColorCode,
    HoneycombCode,
    HypercubeCode4D,
    GenericCSSCode,
)
CodeQubitsTypeDescription
RepetitionCodeconfigurable1DBit-flip or phase-flip repetition
ShorCode9CSS9-qubit code concatenating 3-qubit bit/phase flip
SteaneCode7CSS7-qubit CSS code from Hamming [7,4,3]
BaconShorCodeconfigurableSubsystemSubsystem code, gauge qubits tolerate errors
SurfaceCode2DconfigurableTopologicalPlanar surface code on 2D grid
ToricCode2DconfigurableTopologicalToric code with periodic boundaries
ColorCodeconfigurableTopological2D color code with transversal T gate
HoneycombCodeconfigurableFloquetDynamical code with weight-2 checks
HypercubeCode4DconfigurableLDPC4D hypercube product code
GenericCSSCodeconfigurableCSSCustom CSS code from X/Z check matrices

Usage

import numpy as np
from superfermion.qec import SurfaceCode2D, MWPMDecoder

# Create a distance-3 surface code
code = SurfaceCode2D(distance=3)
print(f"Code parameters: data={code.n_data}, ancilla={code.n_ancilla}, distance={code.d}")

# Build the syndrome-extraction circuit (data + ancilla qubits)
syndrome_circuit = code.build()
print(f"Syndrome circuit qubits: {syndrome_circuit.n_qubits}")

# Decode errors: decoders need the data-qubit count and the map of which
# data qubits each syndrome (ancilla) qubit touches
syndrome_qubit_map = [[i, (i + 1) % code.n_data] for i in range(code.n_ancilla)]
decoder = MWPMDecoder(code.n_data, syndrome_qubit_map)

syndrome = np.zeros(code.n_ancilla, dtype=int)   # example syndrome (no error)
correction = decoder.decode(syndrome)
print(f"Correction: {correction}")

Repetition code

RepetitionCode supports any length n >= 2 and optional repeated syndrome-extraction rounds. Layout: n data qubits [0..n-1] plus n-1 ancillas, with check k measuring d_k (+) d_{k+1}.

from superfermion.qec import RepetitionCode, MWPMDecoder

rep = RepetitionCode(n=5)
print(rep.syndrome_map())            # [[0, 1], [1, 2], [2, 3], [3, 4]]
circuit = rep.build(rounds=3)        # 3 rounds; fresh classical bits per round

dec = MWPMDecoder.for_repetition(5)  # ML-optimal chain decoding

Decoders

DecoderAlgorithmBest For
MWPMDecoderMinimum-Weight Perfect MatchingSurface/Toric codes
UnionFindDecoderUnion-Find clusteringFast decoding with good threshold
BPOSD_DecoderBelief Propagation + Ordered Statistics DecodingLDPC codes, generic CSS
NeuralDecoderNeural network basedCustom training, noisy syndromes

Decoder Comparison

import numpy as np
from superfermion.qec import SurfaceCode2D, MWPMDecoder, UnionFindDecoder

code = SurfaceCode2D(distance=5)
syndrome_qubit_map = [[i, (i + 1) % code.n_data] for i in range(code.n_ancilla)]

# MWPM — accurate, moderate speed
mwpm = MWPMDecoder(code.n_data, syndrome_qubit_map)

# Union-Find — fast, slightly lower threshold
uf = UnionFindDecoder(code.n_data, syndrome_qubit_map)

# Both return a list of (qubit_index, pauli_type) corrections
syndrome = np.zeros(code.n_ancilla, dtype=int)
syndrome[[0, 3]] = 1                    # example syndrome bits
mwpm_correction = mwpm.decode(syndrome)
uf_correction = uf.decode(syndrome)
print(f"MWPM correction: {mwpm_correction}")
print(f"UF correction:   {uf_correction}")

QEC Manager

The QECManager orchestrates the full QEC pipeline:

from superfermion.qec import QECManager

manager = QECManager()

# Simulate the full logical-qubit lifecycle: encode → noise → syndrome → recovery
result = manager.run_logical_lifecycle("surface_2d")
print(f"Phase: {result['phase']}")
print(f"Logical state: {result['logical_state']}")
print(f"Syndrome detected: {result['syndrome_detected']}")
print(f"Error corrected: {result['error_corrected']}")

# Simulate a fault-tolerant workflow
workflow = manager.simulate_fault_tolerant_workflow("surface_2d")
print(f"Code: {workflow['code']}, qubits: {workflow['qubits']}")
print(f"Fidelity estimate: {workflow['fidelity_estimate']}")

Rust Backend

All QEC operations run in Rust (sf-qec crate). The Rust implementation:

  • Stabilizer tableau — word-packed representation for fast Clifford simulation
  • Syndrome extraction circuits — generated in Rust for each code
  • Decoder algorithms — MWPM (Blossom V), Union-Find (Delfosse-Nickerson), BP+OSD (Panteleev-Kalachev)
  • Performance — syndrome decoding at microsecond scale for distance < 10

On this page