A good superconducting or trapped-ion qubit today fails roughly once every thousand
operations. A useful quantum algorithm needs millions to billions of operations. If every
operation could fail with probability
That promise is now an experimental fact. In 2024 Google Quantum AI ran a distance-7 surface
code on 101 qubits and measured a logical error of
This primer teaches that loop and the theory behind it, using Deltakit, Riverlane’s open-source Python toolkit for QEC experiments. This lecture sets the scene. It explains the experiment the whole primer revolves around, how Deltakit’s packages divide the work, what runs on your laptop and what needs an account, and how the lectures, notebooks and field map fit together.
Notebook and field map
Notebook 0: A first memory experiment runs the whole pipeline on a distance-3 surface code, then on distances 5 and 7, and shows where a bigger code starts to help. Field map: The Deltakit package map, The memory-experiment pipeline, The deltakit-stim fork, Detector error models, The error-suppression factor Λ.
What error correction does, in one page
Quantum errors look continuous: a qubit can drift by any small angle. The first idea of QEC is
that measuring the right operators makes errors discrete. Encode one logical qubit in
First, the syndrome does not identify the error. Many different errors produce the same
syndrome, and the job of a decoder is to choose a correction that is probably right. Second,
the code protects only against errors that are small enough. The distance
In a real device the stabilizers are measured by circuits, with ancilla qubits, two-qubit gates and measurements that are themselves noisy. A measurement can lie. So one round of measurement is not enough: the circuit repeats the measurement round after round, and the decoder looks for changes in the results over space and time.
Definition 0.1 (Detector).A detector is a set of measurement outcomes in a circuit whose parity is deterministic when there is no noise. Typically it compares a stabilizer’s result in one round with its result in the previous round. A detector that comes out with the wrong parity fires, and the list of fired detectors in one run of the circuit is that run’s set of detection events.
Detectors (Definition 0.1) are what a decoder actually reads. Lecture 2 shows how Stim declares them, and Lecture 4 shows how they turn noise into a list of error mechanisms that a decoder can reason about.
The memory experiment
The simplest complete QEC experiment stores a logical qubit and checks that it survived. It is the “hello world” of the field, and almost every result in this primer is a variation on it.
Definition 0.2 (Memory experiment).Prepare a logical qubit in a known state of one basis (for example
), run rounds of stabilizer measurement, then measure every data qubit in that basis. The data measurements give one last syndrome and the value of the logical observable. A decoder reads all detection events and predicts whether the observable was flipped. The run fails if the prediction is wrong.
The memory experiment (Definition 0.2) tests everything at once: the code, the measurement circuit, the noise and the decoder. It produces one number per configuration.
Definition 0.3 (Logical error probability).Run the memory experiment
times (shots) and count failures. The logical error probability (LEP) is , with binomial standard error . Divided suitably by the number of rounds, it becomes the logical error per round, the number quoted in the Google result above.
Everything else in QEC benchmarking is built from Definition 0.3, namely thresholds (where a bigger code
stops helping), the suppression factor
The figure below shows the experiment as a software pipeline. Each box is a stage, and the text beside it is the Deltakit call that performs it and the object it passes on.
What Deltakit is
Deltakit is a Python toolkit for creating, simulating, decoding and analysing QEC experiments,
released by Riverlane under the Apache-2.0 licence
(repository,
documentation). The deltakit package you install is
a thin layer over several component packages, each in its own repository. You import them
through the deltakit namespace, apart from the last two:
| package | import as | what it gives you |
|---|---|---|
| deltakit-circuit | deltakit.circuit | circuits, gates, noise channels, conversion to and from Stim |
| deltakit-core | deltakit.core | shared data formats; decoding graphs built from detector error models |
| deltakit-decode | deltakit.decode | decoders, the sampling-and-decoding loop, decoding statistics |
| deltakit-explorer | deltakit.explorer | code families, memory and stability circuits, QPU and noise models, analysis and plots |
| deltakit-stim | deltakit_stim | a fork of the Stim simulator with leakage and adaptive detector error models |
| deltakit-compile | deltakit_compile | a compiler from logical programs on code patches down to Stim circuits |
Two facts about this table save time later.
The simulator is a fork. Stim is Craig Gidney’s stabilizer simulator
(Gidney 2021), and almost every QEC simulation today runs on
it. Deltakit ships its own fork, deltakit_stim, which adds gates for leakage: a qubit escaping
its two-level subspace, which ordinary Pauli noise models cannot describe (Lecture 4). In this
primer we always write import deltakit_stim as stim and never install upstream stim next to
it. Two copies of Stim in one environment give two different Circuit classes, and libraries
that check isinstance reject objects from the other copy. PyMatching, for example, refuses a
deltakit_stim detector error model in its main constructor.
Some decoders need an account. Deltakit’s decoder classes come in two kinds:
Remark 0.1 (What runs locally).
PyMatchingDecoderruns on your machine. The other decoder classes indeltakit.decode(MWPMDecoder,CCDecoder,BeliefMatchingDecoder,BPOSDecoder,ACDecoder,LCDecoder) send the problem to Riverlane’s cloud service and raiseNotImplementedErrorwhen you construct them without aclientholding an access token. Everything this primer runs is local. Lectures 5 and 7 explain what the cloud decoders do, and implement small versions of the ideas behind them in plain Python where that teaches something.
Because of Remark 0.1, the decoder for codes whose errors do not fit a matching graph, such as the bivariate bicycle codes of Lecture 7, is something you would have to bring yourself. That gap is one of the open problems Lecture 9 discusses.
A first run
Here is the whole pipeline from the figure, with a fixed seed. It builds a distance-3 rotated
surface code, writes a three-round
from deltakit.circuit.gates import PauliBasis
from deltakit.decode import PyMatchingDecoder
from deltakit.decode.analysis import StimDecoderManager
from deltakit.explorer.codes import RotatedPlanarCode, css_code_memory_circuit
from deltakit.explorer.qpu import QPU, SI1000Noise
SEED = 2026
code = RotatedPlanarCode(width=3, height=3)
circ = css_code_memory_circuit(code, num_rounds=3, logical_basis=PauliBasis.Z)
qpu = QPU(qubits=code.qubits, noise_model=SI1000Noise(p=1e-3))
noisy = qpu.compile_and_add_noise_to_circuit(circ)
dec, dec_circ = PyMatchingDecoder.construct_decoder_and_stim_circuit(noisy)
manager = StimDecoderManager(dec_circ, dec, seed=SEED, batch_size=100_000)
shots, fails = manager.run_batch_shots(100_000)
print(f"{fails} logical failures in {shots} shots")344 logical failures in 100000 shotsThat is a logical error probability of about
- The decoder hands you a circuit.
construct_decoder_and_stim_circuitreturns the decoder and a Stim circuit, and that circuit is not the one you built. It reorders the detectors and drops those the decoder does not need. Here 24 detectors become 16, because a matching decoder for a-basis observable uses only the -check detectors (the -check ones are linked to it only through errors, which matching ignores). Always sample from the returned circuit. Notebook 0 shows the error you get if you do not. - A seed is not quite enough.
StimDecoderManager(..., seed=SEED)fixes the random numbers. Which qubit receives each random number depends on the order of the targets in the circuit, and Deltakit builds one layer of the circuit from a Pythonfrozenset, whose order follows Python’s string-hash seed. The pages of this primer were built withPYTHONHASHSEED=0, and the course’s notebook kernel sets it too. With another hash seed you get, for example, 340 failures instead of 344. That is the same experiment statistically, but not the same bits. - Some calls hide the seed. Deltakit’s quick-start function
run_decoding_on_circuittakes no seed and prints a progress bar. It is convenient for exploring, but every number quoted in this primer comes from a seededStimDecoderManageror a seeded sampler.
The notebook then repeats the experiment for distances 3, 5 and 7 at four noise strengths. At
Setting up
The pages show every output, so you can read the primer without installing anything. To run the notebooks you need uv, which installs Python 3.12 and the exact package versions the pages were built with (from the lock file): Deltakit 0.10.2, deltakit-stim 0.2.7 and PyMatching 2.4.0, among others. From the course folder:
make lab # uv sync, build the notebooks, install the "Python (qecdk)" kernel, open JupyterLabThe first import deltakit in a fresh environment takes about 26 seconds while caches are built,
and about 2 seconds afterwards. Nothing in the notebooks touches the network or needs a Riverlane
account. The build scripts run every notebook under a memory watchdog (8 GiB per kernel), and no
notebook comes close: Notebook 0 peaks below 0.5 GiB. If you only have the website, each notebook
page has a download link for its .ipynb; run it in any environment with Deltakit 0.10.2. With
different package versions or another hash seed, the counts will differ slightly from the page.
How this primer works
The primer has three layers, and each lecture links to the other two.
- Lectures (this page and the nine that follow) explain the ideas, with derivations kept short and the tooling explained in detail.
- Notebooks run the ideas. Every output on a notebook page is exactly what the code printed when the site was built, and a second run reproduces it byte for byte.
- The field map (open it) is an interactive cheatsheet with one card per concept, grouped into five territories: Foundations, Simulation, Decoding, Performance and Toolchain. Each card opens into a short chapter that ends with an In Deltakit section: the exact import and a snippet that runs.
| # | lecture | Deltakit you meet |
|---|---|---|
| 1 | Stabilizer codes in one sitting | none: the theory, fast |
| 2 | Clifford simulation and Stim | deltakit.circuit, deltakit_stim |
| 3 | Surface codes and syndrome extraction | code families, schedules, memory circuits |
| 4 | Noise, detectors and detector error models | QPU, noise models, decoding graphs |
| 5 | Decoding | PyMatchingDecoder, the sampling loop, what the cloud decoders do |
| 6 | Measuring performance | LEP, LEP per round, |
| 7 | qLDPC and bivariate bicycle codes | BivariateBicycleCode, why matching fails |
| 8 | Fault-tolerant compilation | deltakit_compile, logical assembly, lattice surgery |
| 9 | The ecosystem and open problems | repositories, contributing, open issues |
Reading paths. If stabilizer codes are familiar, skim Lectures 1 and 2 and start at Lecture 3. If you already use Stim, skim Lecture 2 and read the Deltakit parts of Lectures 3 and 4. Lectures 6 to 8 assume the memory experiment of this lecture.
Homework. Four problem sets follow Lectures 2, 4, 6 and 8. Each mixes pen-and-paper problems with short Deltakit runs, and a script recomputes every numerical answer in the folded solutions.
Claims about recent work carry a status tag: PUBLISHED (peer-reviewed), PREPRINT (arXiv only) or VENDOR (a company announcement without a paper). The tag says how much checking a claim has had, not whether it is true.
Try this
- Run Notebook 0. Then change
num_roundsfrom 3 to 9 and predict, before running, roughly how the failure count changes. - In the first-run code above, replace
SI1000Noise(p=1e-3)bySI1000Noise(p=4e-3). Does decoding still help, that is, is the LEP still below the raw, undecoded rate that Notebook 0 prints? (A truly unprotected qubit, idling for the same three rounds, is a different baseline.) - Open the field map, filter to the Toolchain territory and
find the call that the figure on this page labels
compile_and_add_noise_....
Readings
- Google Quantum AI and collaborators, Quantum error correction below the surface code threshold, Nature 638, 920 (2025). The experiment this primer’s pipeline imitates in simulation.
- C. Gidney, Stim: a fast stabilizer circuit simulator, Quantum 5, 497 (2021). Sections 1 and 2 explain why stabilizer simulation is fast; Lecture 2 builds on them.
- The Deltakit documentation, especially the quick-start memory experiment, which this lecture’s first run rewrites with a seed.
- D. Gottesman, Stabilizer Codes and Quantum Error Correction, PhD thesis (1997). The reference for Lecture 1.