sfSuperfermion docs
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

from superfermion.qec import SurfaceCode2D, MWPMDecoder

# Create a distance-3 surface code
code = SurfaceCode2D(distance=3)

# Get stabilizer generators
stabilizers = code.stabilizers()
print(f"Code parameters: n={code.n_qubits}, k={code.n_logical}, d={code.distance}")

# Get the syndrome measurement circuit
syndrome_circuit = code.syndrome_circuit()

# Decode errors
decoder = MWPMDecoder(code)
syndrome = [1, 0, 0, 1, 0, 1, 0, 0]  # example syndrome
correction = decoder.decode(syndrome)
corrected_circuit = code.apply_correction(correction)

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

from superfermion.qec import SurfaceCode2D, MWPMDecoder, UnionFindDecoder

code = SurfaceCode2D(distance=5)

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

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

# Both return a correction operator
syndrome = code.random_error(p=0.01).syndrome()
mwpm_correction = mwpm.decode(syndrome)
uf_correction = uf.decode(syndrome)

QEC Manager

The QECManager orchestrates the full QEC pipeline:

from superfermion.qec import QECManager, SurfaceCode2D, MWPMDecoder

code = SurfaceCode2D(distance=3)
decoder = MWPMDecoder(code)
manager = QECManager(code, decoder)

# Simulate a noisy circuit with error correction
noisy_circuit = manager.protect(my_logical_circuit, noise_level=0.01)
result = manager.run(noisy_circuit, shots=1000)

# Analyze logical error rate
logical_errors = manager.logical_error_rate(num_rounds=100, p_phys=0.001)
print(f"Logical error rate: {logical_errors:.2e}")

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