Up to now a syndrome was a clean bit string: measure the checks and read off which ones are . In a real device the measurement itself is noisy. The ancilla can flip, the CNOTs that copy parities can fail, and a fault halfway through a round can spread (Module 8). A single syndrome snapshot can therefore lie. The remedy is to measure repeatedly and to look for changes in the outcomes.

This module turns that idea into the standard pipeline used in every modern QEC experiment and simulation. Noisy measurement records become detectors. Detectors and the noise model together give a detector error model. The detector error model is a graph (or hypergraph) that a decoder can work on. We build everything concretely for the repetition code in Stim, the fast stabilizer simulator from Module 6.

Learning goals. After this module you should be able to

  1. distinguish code-capacity, phenomenological and circuit-level noise, and write the corresponding Stim noise channels;
  2. explain why syndrome rounds are repeated, and tell data errors from measurement errors by their detector signature;
  3. define detectors and observables, and place them correctly in a memory experiment (first round, middle rounds, final readout);
  4. read a detector error model and draw its space-time decoding graph;
  5. run the full Stim workflow (circuit, sampling, DEM, matching decoder) for a repetition-code memory.

1. Three levels of noise

Definition 9.1 (Noise models).
  • Code capacity. Pauli errors hit the data qubits once. Syndrome measurement is perfect. This is the setting of Modules 1 to 7. (Module 8 previewed one circuit-level effect, hook errors.)
  • Phenomenological. In every round, data qubits suffer Pauli errors with probability , and each check outcome is flipped with probability (often ). The extraction circuit itself is not modelled.
  • Circuit-level. Every location of the actual circuit is noisy: each gate, idle step, reset and measurement. A typical “uniform depolarizing” model with strength applies a random non-identity Pauli after each one- or two-qubit gate (probability ), flips each reset and each measurement result with probability , and depolarizes idling qubits.
code capacity data errors only perfect checks phenomenological data errors + faulty outcomes circuit-level every gate, idle, reset, measurement more realistic, harder to decode, lower threshold

In Stim the circuit-level channels are explicit instructions:

instructionmeaning
X_ERROR(p) qapply to with probability (also used to flip a measurement or a reset)
DEPOLARIZE1(p) qapply , or , each with probability
DEPOLARIZE2(p) a bapply one of the 15 non-identity two-qubit Paulis, each with probability

The three models give very different numbers. For the toric code with independent X and Z noise and minimum-weight matching, the threshold is about under code-capacity noise and about under phenomenological noise (Wang, Harrington and Preskill, 2003). Under circuit-level noise it drops to roughly to , depending on the noise details. The more locations can fail, the less noise the code tolerates. Code-capacity numbers are a useful first sanity check, but only circuit-level numbers predict hardware performance.

The Pauli assumption is not as strong as it looks. Error digitization (Module 1) and randomized compiling (Pauli twirling) justify modelling noise as random Paulis. Such noise is exactly what a stabilizer simulator can sample efficiently, because Pauli faults just get pushed through Clifford circuits.

2. Why repeat the measurements?

Take one check of a repetition code and measure it in rounds . Without errors the outcomes are . Now consider two single faults:

  • a data error between rounds 1 and 2: from round 2 on, the check reads forever, giving ;
  • a measurement error in round 2: only that one outcome is wrong, giving .

A single snapshot at round 2 cannot tell these apart. The time series can. The useful quantity is the change between consecutive rounds, (with ). It is for the data error and for the measurement error.

t1 t1 t2 t2 t3 t3 t4 t4 outcomes mt detectors mt + mt-1 no error 0 0 0 0 0 0 0 0 data flip before round 2 0 0 1 1 1 0 1 0 measurement flip in round 2 0 0 1 1 0 1 0 0

A data error causes one change, at the moment it happens. A measurement error causes two consecutive changes, one when the wrong value appears and one when it disappears. (Both streams above were produced by a noiseless Stim simulation with the fault inserted by hand.) In a 2D layout this becomes a 3D picture. Data errors flip two neighbouring checks in the same round, giving a space-like pair. Measurement errors flip the same check in two consecutive rounds, giving a time-like pair. Decoding then means pairing up changes in space-time.

How many rounds? A measurement error looks like a pair of events one time step apart. For time-like errors to be as rare as space-like ones, the number of rounds must grow with the code. The standard benchmark uses rounds.

3. Detectors

Definition 9.2 (Detector and detection event).

A detector is a set of measurement outcomes whose parity is deterministic in the absence of noise. A detection event occurs when, in a noisy run, the detector’s parity differs from its noiseless value. Detection events are recorded as bits: means the detector fired.

A detector does not have to be a single stabilizer outcome. It is any parity that the noiseless circuit fixes. The typical choice is the XOR of the same check in two consecutive rounds, as in Section 2. Stim only needs to know which measurements to XOR. It checks determinism itself and computes the noiseless parity by simulation, so you never write down “expected value 0” or “expected value 1”.

Where do detectors go in a memory experiment? Take a memory in the rotated surface code (Module 8):

  1. First round. The data starts in , so every Z-check outcome is deterministic (). Each one is a detector by itself. The X-checks give random outcomes in the first round, so they get no first-round detector. Declaring one makes Stim refuse to build the error model, because the detector is non-deterministic.
  2. Rounds . Every check gets a detector: its outcome XOR its outcome in the previous round.
  3. Final readout. All data qubits are measured in the Z basis. For each Z-check, the parity of its data outcomes recomputes the check’s value. XORing that parity with the check’s last ancilla outcome gives one final detector per Z-check. Without this step, data errors in the last round would go unnoticed.
Proposition 9.1 (Counting detectors).

A memory experiment with rounds of the rotated surface code has

detectors. A distance- repetition-code memory with rounds has : checks per round plus final detectors.

The three terms match the three steps above. Stim’s built-in surface_code:rotated_memory_z circuits have detectors for and for , as predicted. Its repetition_code:memory circuit with , has .

Remark 9.1 (Detection regions).

Which faults does a given detector catch? Propagate the detector’s measurements backward through the circuit as Pauli operators (Heisenberg picture). The set of space-time locations where this back-propagated Pauli lives is the detector’s detection region. A fault anticommuting with it at some location flips the detector. For a “same check, consecutive rounds” detector, the region covers the data qubits of that check between the two measurements, plus the ancilla itself. Crumble (algassert.com/crumble) draws these regions interactively.

4. Observables

The decoder’s final job is not to explain every detection event. It is to decide whether the logical outcome was flipped.

Definition 9.3 (Logical observable).

An observable is a set of measurement outcomes whose parity is the value of a logical operator in the noiseless circuit. In a memory, the observable is the parity of the final data measurements along a string. The memory fails when the decoder’s prediction of the observable’s flip is wrong.

In Stim, observables are declared with OBSERVABLE_INCLUDE(k). For the repetition code with codewords and , a single data qubit already carries . For the surface code you need a whole row (Module 8).

5. Detector error models

Here is the key simplification. With Pauli noise and Clifford circuits, each independent fault has a fixed effect: it flips a fixed set of detectors and a fixed set of observables. What happens elsewhere in the circuit does not change this, so the full circuit can be compressed into a list.

Definition 9.4 (Detector error model).

A detector error model (DEM) is a list of independent error mechanisms. Mechanism has a probability , a set of detectors it flips, and a set of observables it flips. The detection events and observable flips of a shot are the XOR of the and over the mechanisms that fired. In Stim’s text format, a mechanism is written error(p) D0 D2 L0.

Different faults in the circuit often have identical symptoms. Stim merges them into one mechanism, combining their probabilities with the following rule.

Lemma 9.1 (Merging independent mechanisms).

If two independent mechanisms with probabilities have identical symptoms, their combined effect is a single mechanism with probability

the probability that an odd number of them fire. For example, .

Example 9.1 (DEM of a phenomenological repetition code).

Take the distance-3 repetition code with data qubits and ancillas (checks and ). Run 2 rounds, each with X_ERROR(0.01) on the data before the round and X_ERROR(0.02) on the ancillas before measurement, then a noiseless data readout. The observable is data qubit 4. The detectors are D0, D1 (round 1), D2, D3 (round 2) and D4, D5 (final). Stim produces:

error(0.01) D0          # data 0 flipped before round 1
error(0.01) D0 D1       # data 2 flipped before round 1 (space-like)
error(0.01) D1 L0       # data 4 flipped before round 1 (also flips the observable)
error(0.02) D0 D2       # ancilla 1 measurement error, round 1 (time-like)
error(0.02) D1 D3       # ancilla 3 measurement error, round 1
error(0.01) D2          # data 0 flipped before round 2
error(0.01) D2 D3       # data 2 flipped before round 2
error(0.01) D3 L0       # data 4 flipped before round 2
error(0.02) D2 D4       # ancilla 1 measurement error, round 2
error(0.02) D3 D5       # ancilla 3 measurement error, round 2

(The comments are ours.) That makes 10 mechanisms: data qubits 2 rounds plus ancillas 2 rounds. Every mechanism flips at most two detectors. Errors on an end qubit flip only one, a “boundary” mechanism.

Graphlike vs hyperedges. In the repetition code every mechanism flips one or two detectors. In the surface code a error on a bulk data qubit flips two X-check detectors and two Z-check detectors: four in total. Two-qubit depolarizing faults in the circuit can be similar. A mechanism flipping more than two detectors is a hyperedge. In Stim’s rotated memory with data depolarization only, the undecomposed DEM has 20 mechanisms with 1 detector, 23 with 2, 8 with 3 and 2 with 4. The call detector_error_model(decompose_errors=True) splits each hyperedge into graphlike pieces separated by ^, for example error(0.0101) D4 D6 ^ D5 L0. Each piece is then an ordinary edge, typically the X-part and the Z-part of a error. This is what lets matching decoders run on circuit noise.

6. The space-time decoding graph

Definition 9.5 (Decoding graph).

If every mechanism (after decomposition) flips one or two detectors, the DEM defines a graph. There is one node per detector plus a virtual boundary node. Each mechanism flipping detectors is an edge -, and each mechanism flipping a single detector is an edge from to the boundary. Each edge remembers its probability and whether it flips the observable. A shot’s detection events are the set of odd-degree nodes of the set of edges that fired.

Laying the nodes out by (position, round) gives a space-time lattice. Below is the graph Stim produces for the distance-3 repetition code under circuit-level noise with 2 rounds and a final readout. This is the circuit of Section 7 shortened to two rounds.

bdry bdry L0 cut D0 D1 D2 D3 D4 D5 t = 0 t = 1 t = 2 space: check Z0Z2 (left), Z2Z4 (right)

Four kinds of edge appear:

  • space-like (horizontal): a data error in the middle of the chain flips both checks of one round (D0-D1, D2-D3, D4-D5);
  • time-like (vertical): a measurement or reset error on one ancilla flips the same check in consecutive rounds (D0-D2, D2-D4, D1-D3, D3-D5);
  • boundary: an error on an end data qubit flips one check (D0, D2, D4 to the left boundary; D1, D3, D5 to the right). The right-hand ones cross the observable (data qubit 4);
  • diagonal (dashed): a data error between the two CNOT layers of a round is seen by one check in this round and by the other check only in the next round (D0-D3, D2-D5). Take an X on data qubit 2 after CX 2 3 but before CX 2 1 in round 1 (the first round; Stim code and detector indices count from 0). Ancilla 3 has already interacted with qubit 2, so it misses the error until the next round. Ancilla 1 interacts afterwards and sees it at once. The fault lies in the detection regions (Remark 9.1) of D0 and D3 only, and inserting it by hand in Stim fires exactly D0 and D3. In Stim’s DEM these have probability , about a quarter of a typical time-like edge (), because there are few such fault locations.

A decoder now solves a graph problem: find a likely set of edges whose odd-degree nodes are exactly the observed detection events, then report whether that set crosses an odd number of times. Using edge weights , the most likely such set is a minimum-weight perfect matching problem. That is Module 10.

7. The Stim workflow: a repetition-code memory

Here is a complete circuit-level repetition-code memory, transcribed from Google’s Introduction to Stim lecture (distance 3, data qubits , ancillas , noise strength , 6 rounds).

Example 9.2 (A noisy repetition-code memory in Stim).
R 0 1 2 3 4
X_ERROR(0.001) 0 1 2 3 4
TICK
CX 0 1 2 3
DEPOLARIZE2(0.001) 0 1 2 3
DEPOLARIZE1(0.001) 4
TICK
CX 2 1 4 3
DEPOLARIZE1(0.001) 0
DEPOLARIZE2(0.001) 2 1 4 3
TICK
X_ERROR(0.001) 1 3
M 1 3
DEPOLARIZE1(0.001) 0 2 4
DETECTOR(1, 0) rec[-2]
DETECTOR(3, 0) rec[-1]
REPEAT 5 {
    R 1 3
    X_ERROR(0.001) 1 3
    DEPOLARIZE1(0.001) 0 2 4
    TICK
    CX 0 1 2 3
    DEPOLARIZE2(0.001) 0 1 2 3
    DEPOLARIZE1(0.001) 4
    TICK
    CX 2 1 4 3
    DEPOLARIZE1(0.001) 0
    DEPOLARIZE2(0.001) 2 1 4 3
    TICK
    X_ERROR(0.001) 1 3
    M 1 3
    DEPOLARIZE1(0.001) 0 2 4
    SHIFT_COORDS(0, 1)
    DETECTOR(1, 0) rec[-2] rec[-4]
    DETECTOR(3, 0) rec[-1] rec[-3]
}
X_ERROR(0.001) 0 2 4
M 0 2 4
SHIFT_COORDS(0, 1)
DETECTOR(1, 0) rec[-2] rec[-3] rec[-5]
DETECTOR(3, 0) rec[-1] rec[-2] rec[-4]
OBSERVABLE_INCLUDE(0) rec[-1]

How to read it:

  • Noise placement. Every qubit gets a noise operation at every time step. There is X_ERROR after resets and before measurements, DEPOLARIZE2 after each CNOT pair, and DEPOLARIZE1 on whichever qubits idle in that layer. This “every qubit, every tick” rule makes the model honest. Dropping the idle noise makes the code look better than it is.
  • rec[-k] is the -th most recent measurement result. After M 1 3, rec[-2] is ancilla 1 and rec[-1] is ancilla 3. One round earlier they were rec[-4] and rec[-3]. So DETECTOR rec[-2] rec[-4] is “ancilla 1 now XOR ancilla 1 last round”, the time-difference detector of Section 3.
  • First-round detectors use a single measurement, because the data starts in and the checks are deterministic.
  • Final detectors. After M 0 2 4, the records are rec[-3], rec[-2], rec[-1] for data 0, 2, 4 and rec[-5], rec[-4] for the last ancilla outcomes. So rec[-2] rec[-3] rec[-5] is : the check recomputed from data, compared with its last measurement.
  • DETECTOR(x, t) coordinates are just labels, here (ancilla index, round). SHIFT_COORDS(0, 1) advances the round counter. They do not affect the simulation but make DEMs and plots readable.
  • The observable is data qubit 4. For the repetition code any single data qubit reveals vs .

The Python side is short:

import stim, pymatching, numpy as np
 
circuit = stim.Circuit(open("rep_code_d3.stim").read())   # the listing above
dem = circuit.detector_error_model(decompose_errors=True)
matcher = pymatching.Matching.from_detector_error_model(dem)
 
sampler = circuit.compile_detector_sampler()
det, obs = sampler.sample(1_000_000, separate_observables=True)
pred = matcher.decode_batch(det)
print("logical error rate per shot:", np.mean(pred[:, 0] != obs[:, 0]))
stim.Circuit gates + noise detector sampler detection events decoder PyMatching detector error model compare with observable flip predicted flip mismatch rate = logical error rate

Running this (our check script, shots) gives:

quantityvalue
detectors14 with ,
DEM mechanisms (after merging)69
len(circuit.shortest_graphlike_error()) (circuit distance)3
mean detection-event probability
observable flip rate without decoding
logical error rate per shot with matching (about between seeds)

Decoding cuts the failure rate by a factor of about 45 compared with ignoring the syndrome. On a laptop, sampling a million shots of this circuit took about 0.03 s and decoding them about 0.02 s. Stim’s frame simulator (Module 6) propagates only the Pauli faults, not the state.

The same pipeline for the surface code. Replace the circuit with stim.Circuit.generated("surface_code:rotated_memory_z", distance=d, rounds=d, ...) or with your own generator (Module 8). Nothing else changes. The DEM now has hyperedges, so decompose_errors=True matters. For hardware comparison: in Google’s Willow experiment, the fraction of bulk weight-4 detectors that fire per round was at . Detection events are common. The decoder’s job is to explain them all with as few, as likely, faults as possible.

Summary

  • Realistic noise acts on the extraction circuit itself (Definition 9.1). Thresholds drop from about (code capacity) to about (phenomenological) to about or less (circuit-level) for the toric/surface code with matching.
  • Repeating syndrome rounds and taking differences separates data errors (one event) from measurement errors (two consecutive events).
  • A detector is a parity of measurements that is deterministic without noise (Definition 9.2). In a memory: Z-checks only in round 1, all checks in later rounds, and a final data-based comparison. The surface-code count is (Proposition 9.1).
  • An observable records the logical value (Definition 9.3). A shot fails when the decoder mispredicts its flip.
  • A detector error model lists independent mechanisms with probabilities and symptoms (Definition 9.4, Lemma 9.1, Example 9.1). If every mechanism flips at most two detectors, it is a weighted space-time graph with space-like, time-like, boundary and diagonal edges (Definition 9.5). Hyperedges are decomposed for matching.
  • Stim turns a noisy circuit into samples and a DEM in a few lines (Example 9.2). Matching on the DEM is the subject of Module 10.

Further reading

  • C. Gidney, Stim: a fast stabilizer circuit simulator, Quantum 5, 497 (2021), arXiv:2103.02202. Also the Stim Getting Started notebook and the DEM file format documentation (github.com/quantumlib/Stim/tree/main/doc).
  • E. Dennis, A. Kitaev, A. Landahl, J. Preskill, Topological quantum memory, J. Math. Phys. 43, 4452 (2002), arXiv:quant-ph/0110143. Faulty measurements and the 3D space-time picture.
  • C. Wang, J. Harrington, J. Preskill, Confinement-Higgs transition in a disordered gauge theory and the accuracy threshold for quantum memory, Ann. Phys. 303, 31 (2003), arXiv:quant-ph/0207088. The 10.3% and 2.9% thresholds.
  • A. G. Fowler, M. Mariantoni, J. M. Martinis, A. N. Cleland, Surface codes: Towards practical large-scale quantum computation, Phys. Rev. A 86, 032324 (2012), arXiv:1208.0928.
  • Google Quantum AI / Coursera, Quantum error correction II (repeated detection, detectors) and Introduction to Stim slides, plus the Introduction to Stim lab.
  • A. Pesah, An interactive introduction to the surface code (2023), section on noise models.
  • Google Quantum AI, Quantum error correction below the surface code threshold, Nature 638, 920 (2025), arXiv:2408.13687.

Homework

Homework 9: Circuit Noise, Detectors and Detector Error Models