Lecture 3 ended with noiseless circuits. A decoder needs two more things. It needs to know what can go wrong, and how often. And it needs to know which detectors each fault lights up. This lecture follows the chain that supplies both: a noise model turns a circuit into a noisy circuit, detectors turn each fault into a symptom, Stim lists every fault with its symptom in a detector error model, and the decoder works on a decoding graph built from that list.

Each link in the chain is a modelling choice, and the decoder inherits every one of them. The weights a matching decoder uses come from the noise model’s probabilities. If the model misjudges how often measurements fail, the decoder makes worse choices. The lecture ends with leakage, a kind of error that the model cannot express at all. You will see what it does to a decoder that does not know about it.

Notebook and field map

Notebook 4: Noise and detector error models compares the noise models at equal , plots detection events round by round, measures how the DEM grows with distance, checks a decoding graph against sampled data, switches leakage on and off, and runs true phenomenological noise. Field map: Circuit noise models, Leakage, Detectors and observables, Detector error models, From DEM to decoding graph.

Three levels of noise

Studies of QEC use three levels of noise, each more realistic and more pessimistic than the last.

  • Code capacity. Only the data qubits suffer errors, once, and the syndrome is read perfectly. This tests the code alone. It is what the playground of Lecture 3 simulates.
  • Phenomenological. Before each round of checks the data qubits suffer errors, and each check outcome is flipped with some probability. Measurements can now lie, so the decoder must reason over space and time. It still knows nothing about the circuit.
  • Circuit-level. Every operation of the actual extraction circuit can fail. This is the only level that sees hook errors (Lecture 3) and the correlated symptoms that gate faults create, such as the diagonal edges of the decoding graph below.
Definition 4.1 (Circuit-level noise model).

A circuit-level noise model is a rule that inserts a noise channel after (or before) each operation of a circuit, depending on the operation’s kind, its qubits and how long they sit idle. The channels are Pauli channels such as depolarizing noise, plus classical flips of measurement outcomes, so the noisy circuit can still be simulated by Stim.

Each level lowers the threshold of the surface code. With minimum-weight matching it is about 10.3% at code capacity (independent and flips) and about 2.9% for phenomenological noise (Wang, Harrington and Preskill, 2003). At circuit level it depends on the model. For SI1000 noise, Notebook 0 finds the curves of distances 3, 5 and 7 meeting near . A circuit-level noise model (Definition 4.1) also sets the cost of a code: the same means different things in different models.

Circuit noise models in Deltakit

A QPU holds a noise model. qpu.compile_and_add_noise_to_circuit(circ) first compiles the circuit into the QPU’s native gates (by default H, CX, R and M) and then inserts noise. Deltakit ships three one-parameter circuit models. SD6Noise puts the same everywhere. SI1000Noise, “superconducting-inspired”, weights the locations by how they fail in superconducting devices: measurements are bad, single-qubit gates are good. Both come from Gidney et al. (2021). ToyNoise is a gentler model for quick studies. Rather than trust the docstrings, read the rates off the compiled circuits. The , three-round memory circuit has 72 two-qubit gates and 33 measurements:

from collections import Counter
 
import numpy as np
from deltakit.circuit.gates import PauliBasis
from deltakit.explorer.codes import RotatedPlanarCode, css_code_memory_circuit
from deltakit.explorer.qpu import QPU, SD6Noise, SI1000Noise, ToyNoise
 
SEED = 2026
code = RotatedPlanarCode(3, 3)
circ = css_code_memory_circuit(
    code, num_rounds=3, logical_basis=PauliBasis.Z
)
NOISY = ("DEPOLARIZE1", "DEPOLARIZE2", "X_ERROR", "M", "MX")
 
 
def noise_table(noisy):
    """(instruction, probability) -> number of qubits or pairs hit."""
    table = Counter()
    for inst in noisy.as_stim_circuit().flattened():
        args = inst.gate_args_copy()
        if inst.name in NOISY and args:
            per = 2 if inst.name == "DEPOLARIZE2" else 1
            table[inst.name, args[0]] += len(inst.targets_copy()) // per
    return dict(sorted(table.items()))
 
 
models = {
    "SD6": SD6Noise(p=1e-3),
    "SI1000": SI1000Noise(p=1e-3),
    "Toy": ToyNoise(p=1e-3),
}
for name, model in models.items():
    qpu = QPU(code.qubits, noise_model=model)
    noisy = qpu.compile_and_add_noise_to_circuit(circ)
    print(name)
    for (gate, p), n in noise_table(noisy).items():
        print(f"  {gate:12s} p={p:<7g} x{n}")
SD6
  DEPOLARIZE1  p=0.001   x215
  DEPOLARIZE2  p=0.001   x72
  M            p=0.001   x33
  X_ERROR      p=0.001   x33
SI1000
  DEPOLARIZE1  p=0.0001  x215
  DEPOLARIZE1  p=0.002   x36
  DEPOLARIZE2  p=0.001   x72
  M            p=0.005   x33
  X_ERROR      p=0.002   x33
Toy
  DEPOLARIZE1  p=0.0001  x281
  DEPOLARIZE2  p=0.001   x72
  M            p=0.001   x33

Read with the source, the three models put errors here:

locationSD6Noise(p)SI1000Noise(p)ToyNoise(p)
after a two-qubit gateDEPOLARIZE2(p)DEPOLARIZE2(p)DEPOLARIZE2(p)
after a one-qubit gate, or idleDEPOLARIZE1(p)DEPOLARIZE1(p/10)DEPOLARIZE1(p/10)
idle while others are measured or resetDEPOLARIZE1(p)DEPOLARIZE1(2p), on top of the idle DEPOLARIZE1(p/10)DEPOLARIZE1(p/10)
after a resetX_ERROR(p)X_ERROR(2p)DEPOLARIZE1(p/10), also after a measurement
measurement result flipped (p_measurement_flip)

The 215 single-qubit channels at in SI1000 are where SD6 has 215 channels at . So at equal , SD6 is far harsher on gates and idles and SI1000 far harsher on measurements. Notebook 4 runs both at and , three rounds, with 200,000 shots each. SD6 gives 515 failures and SI1000 730. ToyNoise, with no reset flips and cheap single-qubit noise, gives 96.

PhenomenologicalNoise is the odd one out. It takes a function from a qubit to a noise channel and applies it at every explicit idle (I) gate. The memory circuit has exactly one such layer per round, on the data qubits (Lecture 3). Add a measurement flip and you have the phenomenological model, with one catch. The compiler removes I gates, even when I is a native gate and even with remove_paulis=False. So compile_and_add_noise_to_circuit silently drops the data noise and keeps only the measurement flips. The workaround is to skip compilation. A QPU with ExhaustiveGateSet() accepts the circuit’s own gates, and add_noise_to_circuit adds noise without compiling:

from deltakit.circuit import measurement_noise_profile
from deltakit.circuit.noise_channels import Depolarise1
from deltakit.explorer.qpu import ExhaustiveGateSet, PhenomenologicalNoise
 
phen = PhenomenologicalNoise(
    phenomenological_noise=lambda q: Depolarise1(q, 1e-3),
    measurement_flip=measurement_noise_profile(1e-3),
)
compiled = QPU(code.qubits, noise_model=phen)
compiled = compiled.compile_and_add_noise_to_circuit(circ)
direct = QPU(code.qubits, ExhaustiveGateSet(), noise_model=phen)
direct = direct.add_noise_to_circuit(circ)
print("compiled:", noise_table(compiled))
print("direct:  ", noise_table(direct))
compiled: {('M', 0.001): 33}
direct:   {('DEPOLARIZE1', 0.001): 27, ('M', 0.001): 9, ('MX', 0.001): 24}

The compiled circuit has no DEPOLARIZE1 at all. The direct one has 27, one per data qubit per round. Its symptoms are what the textbook phenomenological model promises.

Detectors turn faults into symptoms

A detector (Lecture 0) is a parity of measurements that is fixed without noise. Deltakit gives each detector the coordinates : the position of its check’s ancilla and the round. A fault flips some detectors and perhaps the observable.

Definition 4.2 (Symptom).

The symptom of a fault is the set of detectors it flips together with the set of logical observables it flips. Two faults with the same symptom look the same to every decoder.

In a surface-code memory, the symptoms (Definition 4.2) come in a few shapes. A data error between two rounds flips the two neighbouring checks of the matching type, in the same round. On the boundary there may be only one such check. A measurement error flips one outcome, so the detectors of that check in two consecutive rounds fire. A fault partway through a round, on a two-qubit gate, is caught by some checks in this round and others in the next. A error, or a two-qubit depolarizing fault, can flip and detectors at once: three or four detectors.

boundary t=0 t=1 t=2 t=3 1 2 3 4 checks along one row 1 data error between rounds same round, neighbouring checks 2 measurement error same check, consecutive rounds 3 data error on the edge one detector, plus the boundary 4 fault inside a round neighbouring checks, next round

The rate at which detectors fire is the first thing to look at in any experiment, simulated or real. Here it is round by round for a five-round, memory with SI1000 noise:

code5 = RotatedPlanarCode(5, 5)
circ5 = css_code_memory_circuit(
    code5, num_rounds=5, logical_basis=PauliBasis.Z
)
qpu5 = QPU(code5.qubits, noise_model=SI1000Noise(p=1e-3))
sc5 = qpu5.compile_and_add_noise_to_circuit(circ5).as_stim_circuit()
dets = sc5.compile_detector_sampler(seed=SEED).sample(100_000)
coords = sc5.get_detector_coordinates()
t = np.array([coords[i][2] for i in range(sc5.num_detectors)])
for r in np.unique(t):
    print(f"t={r:.0f}: {np.sum(t == r):2d} detectors,"
          f" fire rate {dets[:, t == r].mean():.4f}")
t=0: 12 detectors, fire rate 0.0180
t=1: 24 detectors, fire rate 0.0316
t=2: 24 detectors, fire rate 0.0320
t=3: 24 detectors, fire rate 0.0319
t=4: 24 detectors, fire rate 0.0322
t=5: 12 detectors, fire rate 0.0280

The first and last rows have half as many detectors: only the checks are deterministic at the start and readable at the end. They also fire less. A bulk detector compares two noisy ancilla measurements, each flipped with probability . A first-round detector compares one measurement with the known value of a fresh preparation. A last-round detector compares one with the data readout. A rate that stays flat in the bulk is a sign that nothing builds up over time; the last section shows a case where it does not stay flat.

Detector error models and the decoding graph

Stim condenses a noisy circuit into a detector error model (DEM): one row per independent error mechanism, with its probability and its symptom. Faults with the same symptom merge into one row. For two independent mechanisms, the merged probability is , the chance that exactly one of them happens. The Detector error models card works through a small example. For the , three-round SI1000 circuit, the raw DEM has 221 rows and 113 of them flip three or four detectors. A matching decoder needs every row to flip at most two. decompose_errors=True asks Stim to split each larger symptom into graphlike pieces, and the DEM grows to 290 rows.

Definition 4.3 (Decoding graph).

The decoding graph of a DEM whose rows flip at most two detectors has one node per detector plus a boundary node. Each row becomes an edge between the detectors it flips, or between its one detector and the boundary. Rows with the same endpoints merge into one edge. An edge with probability gets the weight , and it records which observables it flips.

With the weights of the decoding graph (Definition 4.3), the probability of a set of independent edges is proportional to . The most likely set of edges that explains the detection events is therefore the one of least total weight, which is what minimum-weight matching finds (Lecture 5). deltakit.core.decoding_graphs builds the graph from a DEM:

import math
 
from deltakit.core.decoding_graphs import dem_to_decoding_graph_and_logicals
 
qpu = QPU(code.qubits, noise_model=SI1000Noise(p=1e-3))
sc = qpu.compile_and_add_noise_to_circuit(circ).as_stim_circuit()
raw = sc.detector_error_model()
dem = sc.detector_error_model(decompose_errors=True)
print("DEM rows: raw", raw.num_errors, " decomposed", dem.num_errors)
graph, logicals = dem_to_decoding_graph_and_logicals(dem)
print("nodes", len(graph.nodes), " edges", len(graph.edges),
      " boundary", sorted(graph.boundaries))
recs = graph.detector_records
kinds = {"space": [], "time": [], "diagonal": [], "boundary": []}
for edge in graph.edges:
    u, v = tuple(edge)
    if graph.boundaries & {u, v}:
        kind = "boundary"
    elif recs[u].time == recs[v].time:
        kind = "space"
    elif recs[u].spatial_coord == recs[v].spatial_coord:
        kind = "time"
    else:
        kind = "diagonal"
    kinds[kind].append(graph.edge_records[edge].p_err)
for kind, ps in kinds.items():
    w = [math.log((1 - p) / p) for p in ps]
    print(f"{kind:8s} {len(ps):2d} edges  p {min(ps):.1e}..{max(ps):.1e}"
          f"  weight {min(w):.2f}..{max(w):.2f}")
print("edges that flip the observable:", len(logicals[0]))
DEM rows: raw 221  decomposed 290
nodes 25  edges 78  boundary [24]
space    18 edges  p 2.3e-03..6.1e-03  weight 5.09..6.06
time     16 edges  p 7.5e-03..7.6e-03  weight 4.87..4.88
diagonal 20 edges  p 2.7e-04..1.1e-03  weight 6.84..8.23
boundary 24 edges  p 2.7e-03..2.0e-02  weight 3.90..5.93
edges that flip the observable: 8

Every class of the figure is there. Among the bulk edges the time-like ones are the most likely, because a measurement flips with probability in SI1000. Their weight is the smallest, so the decoder readily explains a pair of firings in one check as a measurement error. The diagonal edges come from faults on two-qubit gates partway through a round, and they are the least likely. Some boundary edges are more likely still: every fault that lights a single detector merges into the boundary edge of that detector. The 8 edges that flip the observable all end on the boundary: a logical error is a chain of edges that runs from one boundary to the other. Pass the raw DEM instead and the graph builder refuses its hyperedges:

dem_to_decoding_graph_and_logicals(raw)

It raises ValueError: Edge of degree 3 cannot be converted to decoding edge.. Decoders that use hyperedges directly, such as belief propagation, appear in Lectures 5 and 7. The graph also grows fast with distance:

print(" d  detectors  DEM rows  graph edges")
for d in (3, 5, 7):
    c = css_code_memory_circuit(
        RotatedPlanarCode(d, d), num_rounds=d, logical_basis=PauliBasis.Z
    )
    q = QPU(c.qubits, noise_model=SI1000Noise(p=1e-3))
    s = q.compile_and_add_noise_to_circuit(c).as_stim_circuit()
    m = s.detector_error_model(decompose_errors=True)
    g, _ = dem_to_decoding_graph_and_logicals(m)
    print(f"{d:2d} {s.num_detectors:10d} {m.num_errors:9d}"
          f" {len(g.edges):12d}")
 d  detectors  DEM rows  graph edges
 3         24       290           78
 5        120      2233          502
 7        336      6920         1558

All three columns grow like for a -round experiment. This growth is why real-time decoding of large codes is hard (Lecture 5).

Leakage: an error the model cannot see

Physical qubits are not two-level systems. A transmon has a third level, , and a two-qubit gate or a reset sometimes leaves the qubit there.

Definition 4.4 (Leakage).

A qubit has leaked when its state has left the computational subspace spanned by and . A leaked qubit no longer responds to gates as a qubit. It corrupts the qubits it interacts with, and it reads out as a random bit, until it relaxes back or is reset.

Leakage (Definition 4.4) is not a Pauli error, so an ordinary Stim circuit cannot describe it. The deltakit_stim fork adds instructions for it, and SI1000Noise(p=…, pL=…) uses them. With it adds LEAKAGE(pL) after every two-qubit gate and every reset. It also adds RELAX channels, which bring a leaked qubit back, at rates , and in different places. The detector error model, however, is built from Pauli faults only:

qpu_l = QPU(code.qubits, noise_model=SI1000Noise(p=1e-3, pL=1e-4))
leaky = qpu_l.compile_and_add_noise_to_circuit(circ).as_stim_circuit()
names = {i.name for i in leaky.flattened()}
print("new instructions:", sorted(names - {i.name for i in sc.flattened()}))
print("DEM rows:", leaky.detector_error_model(decompose_errors=True).num_errors)
for pL in (0.0, 1e-3):
    q = QPU(code5.qubits, noise_model=SI1000Noise(p=1e-3, pL=pL))
    c10 = css_code_memory_circuit(
        code5, num_rounds=10, logical_basis=PauliBasis.Z
    )
    s = q.compile_and_add_noise_to_circuit(c10).as_stim_circuit()
    dets = s.compile_detector_sampler(seed=SEED).sample(50_000)
    co = s.get_detector_coordinates()
    t = np.array([co[i][2] for i in range(s.num_detectors)])
    rates = [dets[:, t == r].mean() for r in np.unique(t)]
    print(f"pL={pL:g}:", " ".join(f"{x:.3f}" for x in rates))
new instructions: ['LEAKAGE', 'RELAX']
DEM rows: 290
pL=0: 0.018 0.032 0.032 0.032 0.032 0.032 0.032 0.032 0.032 0.032 0.028
pL=0.001: 0.027 0.053 0.060 0.067 0.073 0.079 0.085 0.091 0.097 0.103 0.090

The DEM has the same 290 rows with leakage on as without it. The decoder built from it does not know that leakage exists. Yet the detectors know. Without leakage the bulk fire rate is flat. With it climbs round after round, because leaked qubits pile up faster than they relax and each one keeps randomising its neighbours. Notebook 4 measures the cost. At the memory fails 3910 times in 200,000 shots, against 3819 for . The bigger code has stopped helping. The remedies are hardware leakage-reduction units that pump back into the qubit subspace, and decoders that use heralds, measurements that flag a leaked qubit. Riverlane’s local clustering decoder adapts its weights to heralded leakage events, and its paper is the source of the leakage model in SI1000Noise (PUBLISHED; Nat. Commun. 16, 11048 (2025), arXiv 2411.10343).

In Deltakit

stepcallreturns
choose a modelSD6Noise(p=…), SI1000Noise(p=…, pL=…), ToyNoise(p=…, p_measurement_flip=…), PhenomenologicalNoise(phenomenological_noise=…, measurement_flip=…)a NoiseParameters dataclass (keyword-only)
compile and add noiseQPU(qubits, noise_model=…).compile_and_add_noise_to_circuit(circ)a noisy deltakit.circuit.Circuit
add noise onlyQPU(qubits, ExhaustiveGateSet(), noise_model=…).add_noise_to_circuit(circ)the same, with the circuit’s own gates and I layers kept
detector coordinatesstim_circ.get_detector_coordinates(){index: [x, y, t]}
DEMstim_circ.detector_error_model(decompose_errors=True)a deltakit_stim.DetectorErrorModel
decoding graphdem_to_decoding_graph_and_logicals(dem)(NXDecodingGraph, [set of edges per observable])
edge datagraph.edge_records[edge].p_err, .weight; graph.detector_records[i].time, .spatial_coordfloats and tuples; the boundary node has coordinates

Three traps:

  • PhenomenologicalNoise through compile_and_add_noise_to_circuit keeps only the measurement flips (above). Use add_noise_to_circuit with ExhaustiveGateSet().
  • Constructing a QPU with PhenomenologicalNoise adds I to the default native gate set that every later QPU() shares (a mutable default argument). In our tests later SD6, SI1000 and Toy circuits came out identical anyway, but pass NativeGateSetAndTimes() explicitly if you mix models in one process.
  • DecodingEdge objects cannot be sorted. Sort tuple(edge) instead.

Try this

  • Replace SI1000Noise by SD6Noise in the decoding-graph block. Which edge class changes its weight the most, and why?
  • Raise p_measurement_flip in ToyNoise from to and watch the time-like weights fall. Predict their new value from the merge rule first.
  • In the leakage block, raise pL to . How many rounds until the bulk fire rate doubles?
  • Run the phenomenological circuit (the direct one) at for with StimDecoderManager. Is above or below the phenomenological threshold?

Readings

  • C. Gidney, M. Newman, A. Fowler and M. Broughton, A fault-tolerant honeycomb memory, Quantum 5, 605 (2021). Defines the SD6 and SI1000 models (their Tables 1 and 2).
  • C. Wang, J. Harrington and J. Preskill, Confinement-Higgs transition in a disordered gauge theory and the accuracy threshold for quantum memory, Annals of Physics 303, 31 (2003). Code-capacity and phenomenological thresholds.
  • C. Gidney, Stim: a fast stabilizer circuit simulator, Quantum 5, 497 (2021), and the DEM file format.
  • M. McEwen et al., Removing leakage-induced correlated errors in superconducting quantum error correction, Nat. Commun. 12, 1761 (2021). Leakage in a real device, and leakage-reduction units.
  • A. B. Ziad et al., Local Clustering Decoder as a fast and adaptive hardware decoder for the surface code, Nat. Commun. 16, 11048 (2025). The leakage model behind SI1000Noise(pL=…).