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 , a billion of them would almost surely fail somewhere, and the answer would be noise. No foreseeable improvement in hardware closes a gap of six or more orders of magnitude. Quantum error correction (QEC) closes it differently: it spends many noisy physical qubits to build one logical qubit whose error rate falls exponentially as the code grows, as long as the physical error rate is below a threshold.

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 per round of error correction. Each step up in code distance, from 3 to 5 to 7, divided the logical error rate by (PUBLISHED; Nature 638, 920 (2025), arXiv 2408.13687). Getting there took years of work on codes, circuits, noise models and decoders. Almost all of that work was done first in simulation, with one loop run over and over: build a code, write its circuit, add noise, sample, decode, count failures.

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 physical qubits, chosen so that a set of commuting Pauli operators, the stabilizers, all equal on every encoded state. Measuring a stabilizer does not disturb the encoded information, but it does project any error onto a definite Pauli error, and it reports a bit: if the error commutes with that stabilizer, if it anticommutes. The list of these bits is the syndrome. Lecture 1 builds this from scratch; for now, two consequences matter.

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 of a code is the smallest number of single-qubit errors that can change the logical state without changing any stabilizer. A code of distance corrects any errors, and the probability that noise beats it falls roughly like when the physical error rate is small. That exponent is the reason to build bigger codes.

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 (how much each step in distance helps), and error budgets (which physical error to fix first). Lecture 6 covers all three.

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.

code RotatedPlanarCode(3, 3) qubits, stabilisers, logical operators circuit css_code_memory_circuit(...) noiseless Circuit with detectors noisy circuit QPU(...).compile_and_add_noise_... native gates plus noise channels decoder PyMatchingDecoder.construct_... a decoder and the circuit it expects samples compile_detector_sampler(seed=...) detection events: shots x detectors statistics decode_batch_to_logical_flip(dets) fails / shots, then LEP and error bar dashed: StimDecoderManager(seed=...) runs both steps in one call

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:

packageimport aswhat it gives you
deltakit-circuitdeltakit.circuitcircuits, gates, noise channels, conversion to and from Stim
deltakit-coredeltakit.coreshared data formats; decoding graphs built from detector error models
deltakit-decodedeltakit.decodedecoders, the sampling-and-decoding loop, decoding statistics
deltakit-explorerdeltakit.explorercode families, memory and stability circuits, QPU and noise models, analysis and plots
deltakit-stimdeltakit_stima fork of the Stim simulator with leakage and adaptive detector error models
deltakit-compiledeltakit_compilea 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).

PyMatchingDecoder runs on your machine. The other decoder classes in deltakit.decode (MWPMDecoder, CCDecoder, BeliefMatchingDecoder, BPOSDecoder, ACDecoder, LCDecoder) send the problem to Riverlane’s cloud service and raise NotImplementedError when you construct them without a client holding 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 -basis memory experiment, compiles it for a QPU with SI1000 noise at (a standard superconducting-style model, Lecture 4), builds a matching decoder, and runs 100,000 shots.

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 shots

That is a logical error probability of about for the whole three-round experiment. Read the code against the figure: each line is one box. Three details in it are easy to get wrong, and each has a card in the field map.

  • The decoder hands you a circuit. construct_decoder_and_stim_circuit returns 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 Python frozenset, whose order follows Python’s string-hash seed. The pages of this primer were built with PYTHONHASHSEED=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_circuit takes no seed and prints a progress bar. It is convenient for exploring, but every number quoted in this primer comes from a seeded StimDecoderManager or a seeded sampler.

The notebook then repeats the experiment for distances 3, 5 and 7 at four noise strengths. At each step in distance divides the failures by about four. Near the three curves meet: that is roughly the threshold of this code, noise model and decoder.

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 JupyterLab

The 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.
#lectureDeltakit you meet
1Stabilizer codes in one sittingnone: the theory, fast
2Clifford simulation and Stimdeltakit.circuit, deltakit_stim
3Surface codes and syndrome extractioncode families, schedules, memory circuits
4Noise, detectors and detector error modelsQPU, noise models, decoding graphs
5DecodingPyMatchingDecoder, the sampling loop, what the cloud decoders do
6Measuring performanceLEP, LEP per round, , error budgets, QuOps
7qLDPC and bivariate bicycle codesBivariateBicycleCode, why matching fails
8Fault-tolerant compilationdeltakit_compile, logical assembly, lattice surgery
9The ecosystem and open problemsrepositories, 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_rounds from 3 to 9 and predict, before running, roughly how the failure count changes.
  • In the first-run code above, replace SI1000Noise(p=1e-3) by SI1000Noise(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.