stabilizer_qec
A quantum error-correction simulator and decoder: circuits and detector error models in Stim's
formats, a bit-parallel sampler, exact and correlated matching, belief-matching, BP and BP+OSD,
window decoding, IBM's bivariate bicycle codes and lattice surgery. It is the engine behind the
stabilizer-qec Python package and the
interactive explainer, and it agrees with Stim, PyMatching,
ldpc and beliefmatching on every check in its test suite.
use ;
// A distance-5 surface-code memory under circuit noise, sampled and decoded.
let circuit = memory_circuit?;
let samples = circuit.detector_sampler?.sample; // 0 threads: every core
let dem = circuit.detector_error_model?;
let predictions = with_correlations?.decode_batch?;
let failures = .filter.count;
assert!;
# Ok::
- Circuits: [
Circuit] reads Stim's circuit language (every Clifford gate, all three bases, Pauli products, every noise channel, measurement feedback,REPEAT, tags, Pauli observables) and prints it back, or is built in code ([Circuit::append] with [Target]s,+,*); [Circuit::detector_error_model] builds the error model Stim's analyzer builds, fault for fault, its loops folded as Stim folds them (a d = 11 memory of 10,000 rounds in a tenth of a second); [DetectorSampler] samples 64 shots to a word, reproducibly from a seed on any number of threads; [MeasurementConverter] turns raw records into detection events. - Decoders on an error model: [
Matching] (exact, sparse blossom; plain or correlated, as fast as PyMatching), [BeliefMatching], [BpOsd], [WindowMatching]. On a check matrix: [BpDecoder] and [BpOsdDecoder], equal toldpc's. AllSend + Sync. - Beyond Clifford, and beyond the CPU (2.0): [
Circuit::stabilizer_rank_sampler] runs Clifford+T circuits (I[T], tagged rotations) exactly, [Circuit::coherent_sampler] and the joint sampler reweight the Pauli twirl of coherent errors (I_ERROR[R_Z(theta=…)]) by the interference it leaves out, with the exact gates kept exact; thegpufeature runs the frame sampler and min-sum BP as wgpu compute shaders, bit for bit the CPU lane sampler's and the f32 decoder's results; thehighsfeature adds the ILP circuit distance. - Codes: [
memory_circuit] (rotated and XZZX surface codes), [stream_memory] and [stream_circuit] (a million rounds of a memory, or of any circuit with a loop, window-decoded as they stream), [BivariateBicycleCode] (the gross code, its automorphisms' logical action, and the gauging measurement of its logicals), [lattice_surgery] (Z⊗Z and X⊗X merges, a logical CNOT).
Shots are [BitTable]s, bit-packed as Stim's b8 format. Every fallible call returns
[Error]; none panics on bad input.
Stability
Semantic versioning from 1.0: the items in this documentation keep compiling, with the same
meaning, through every 2.x release (checked by cargo-semver-checks in CI). The engine's own
modules are public so the Python bindings, the site and the tools can reach them, but they are
hidden from this documentation and carry no such promise. The Python bindings sit behind the
python feature, off by default. The minimum supported Rust is 1.87.