The project
You will implement a decoder, benchmark it honestly against a strong baseline, and write it up so that someone else can reproduce every number. This is what decoder papers, internal evaluations and hiring portfolios in quantum error correction actually look like, and doing it well is mostly a matter of discipline: a stated model, paired data, intervals on every rate, and a report that separates what was measured from what was assumed.
Concretely, you will:
- Construct an error model. A Stim memory circuit (repetition code by default, rotated surface code as an extension) with a stated circuit-level noise model.
- Generate syndrome data with Stim. Via the circuit's detector error model, sampled with a seeded, platform-independent recipe.
- Implement and configure decoders. Your own union-find decoder (scaffold provided) and PyMatching as the baseline, plus the trivial decoder as a floor.
- Evaluate logical error probabilities with Wilson score intervals.
- Compare settings and algorithms across decoders, distances and noise strengths, using paired tests on identical samples.
- Write a reproducible technical report from the template in the exercise: model, method, parameters, seeds, environment versions, results with uncertainty, limitations.
- Export code and results to a portfolio: a deterministic JSON summary with parameters, seeds, package versions, per-point counts and rates, and the SHA-256 of the results. It is written to a local file; nothing is uploaded.
The exercise's automated checks cover the core of items 1–5 and 7. The report and the quality of the comparison are assessed with the published capstone rubric.
Step 1: an error model you can state in one paragraph
Decoder results are meaningless without the model that produced the syndromes. Three levels of model are common:
- Code capacity: independent Pauli errors on data qubits, perfect syndrome measurement. Simple and useful for understanding a code, but it ignores measurement errors entirely.
- Phenomenological: data errors plus independent flips of each syndrome bit in each round. It introduces the time dimension.
- Circuit level: every gate, idle step, reset and measurement can fail. This captures hook errors and correlations, and it is what the default configuration uses.
Our circuit-level model applies, with one parameter , a two-qubit depolarizing
channel after each CNOT, single-qubit depolarizing noise on data qubits before
each round, and bit flips after resets and before measurements. In Stim's
generated circuits these are the arguments after_clifford_depolarization,
before_round_data_depolarization, after_reset_flip_probability and
before_measure_flip_probability, all set to (Gidney, Stim).
Note what is: a probability per operation, not per round and not a measured
hardware figure.
The repetition code's syndrome extraction for measures and with two ancillas, every round:
Stim compares each ancilla outcome with the previous round's to form detectors, and the final data readout gives one more layer of detectors and the logical observable. A -round memory of the distance- repetition code has detectors. Before decoding anything, check the model: the detector count is what you expect, the noiseless circuit produces no detection events, all error probabilities in the detector error model lie in , and the detection-event rate grows with . The exercise automates these checks; your report should mention that you ran them.
Step 2: data you can regenerate anywhere
Stim converts the circuit into a detector error model (DEM): a list of independent mechanisms, each with a probability and the detectors and observables it flips. Sampling the DEM is equivalent to sampling the circuit for detection events and observable flips, and the exercise checks this statistically against Stim's own sampler.
Why not just use Stim's sampler? It is much faster, but its documentation is explicit that seeded results may differ between Stim versions and between machines with different SIMD instruction widths. For a benchmark whose numbers you want others to reproduce bit for bit, the exercise therefore samples the DEM with NumPy's PCG64 generator following an exact recipe: draw a uniform number per (shot, mechanism) and fire mechanism when it is below . Each benchmark point gets its own seed, derived by hashing the base seed together with the code, distance, rounds and , so adding a point never changes the data of another.
All decoders at a point are evaluated on the same shots. This paired design removes sampling noise from the comparison: a difference between decoders cannot come from one of them having been handed easier syndromes.
Step 3: decoders
The trivial decoder: a floor
The trivial decoder always predicts "no logical flip". Its failure rate is the probability that the observable flipped at all. Any decoder worth reporting must beat it by a wide margin; the exercise requires your decoder to fail on at most half as many shots as the trivial decoder at , .
Union-find
The union-find decoder of Delfosse and Nickerson grows clusters around detection events until every cluster can be neutralised internally, then picks a correction inside the grown region by peeling a spanning forest (Delfosse and Nickerson). They prove it corrects every error of weight up to in their setting, and its running time is almost linear in the number of qubits. The version you implement is the simplest: unweighted, with half-edge growth.
Worked example. Take a distance-5 repetition code with perfect measurements (code capacity): data qubits , detectors for , and one boundary node that stands for "beyond either end". The matching graph is a path , where the edge between and is qubit , joins to and joins to . Let errors hit and . Then fires (because of ), sees both and stays silent, and fires (because of ).
- Round 1. The clusters and are odd. Each adds half an edge on both of its incident edges: for and for . Nothing is fully grown yet.
- Round 2. Both clusters are still odd and grow again. Now are fully grown. Merging along them joins into one cluster that contains the boundary, so growth stops.
- Peeling. Root the spanning tree at : (edges to ). Leaf has no event: drop it. has an event: add its parent edge to the correction and toggle , which now carries an event. : add and toggle , whose event is cancelled. is clear, so is not used.
The correction equals the error, so there is no logical failure.
With circuit-level noise the graph comes from the DEM: nodes are detectors, edges
are graphlike error mechanisms (Stim's decompose_errors=True splits the rest),
and each edge carries a bit mask of the observables it flips. The decoder's output
is the XOR of the masks along the correction.
The baseline: minimum-weight perfect matching
PyMatching, configured with Matching.from_detector_error_model(dem), finds a
minimum-weight correction with edge weights , using the sparse
blossom algorithm (Higgott and Gidney).
Matching-based decoding of the surface code goes back to Dennis, Kitaev, Landahl
and Preskill (Dennis et al.). Because your
union-find decoder ignores the edge weights, expect it to be somewhat worse at the
same distance. How much worse, and whether the gap is resolved by your data, is
the question your report answers.
Verify before you benchmark
A decoder that is wrong on simple inputs produces plausible-looking curves. Before any statistics, check that it corrects every single fault of the DEM (for a code of distance at least 3 this is required) and that the empty syndrome gives no flip. The exercise runs exactly this check for both your decoder and PyMatching, on the repetition code and on the surface code.
Step 4: statistics you can defend
Intervals for every rate
With failures in shots, report together with a 95% Wilson score interval (Wilson),
Brown, Cai and DasGupta compare binomial intervals and recommend the Wilson interval over the textbook normal ("Wald") interval, whose coverage is poor for small or extreme (Brown, Cai and DasGupta), which is exactly the regime of logical error rates.
Worked example. , , so and . The centre is and the half-width is , giving . The interval is not symmetric around , and it is wide: seven failures pin the rate down only to within a factor of about four.
With zero failures the interval is , about . Report such a point as an upper bound, never as a rate of zero.
from scipy.stats import binomtest
for k, n in [(7, 10_000), (0, 10_000)]:
ci = binomtest(k, n).proportion_ci(confidence_level=0.95, method="wilson")
print(f"{k}/{n}: [{ci.low:.3e}, {ci.high:.3e}]")
This prints 7/10000: [3.391e-04, 1.444e-03] and 0/10000: [0.000e+00, 3.840e-04].
The exercise asks you to implement the formula and checks it against SciPy and,
if installed, the KetQat SDK.
Paired comparisons
Because both decoders saw the same shots, the informative quantities are the discordant counts: shots where only decoder A failed () and shots where only B failed (). Under the null hypothesis that the decoders are equally good, each discordant shot is equally likely to go either way, so the exact two-sided McNemar test uses .
The reference implementation on the default configuration illustrates this. At , , 20,000 shots and the seed derived from base seed 20261123, the union-find decoder failed 134 times and PyMatching 84 times; 75 shots failed only for union-find and 25 only for PyMatching, and the exact test gives . The gap is resolved. At , , union-find failed 12 times and PyMatching 11 times, with 5 and 4 discordant shots, and : these data cannot distinguish the decoders at that point, and the report must say so rather than rank them. (These numbers come from the reference implementation; yours may differ slightly where implementations break ties differently, but the PyMatching and trivial counts are fixed by the seed.)
Planning shots
The relative standard error of is roughly . To know a rate to about ±20% (one standard error) you need about 25 failures; to ±10%, about 100. At that means shots per point. Decide the shot counts (or a stopping rule such as "until 100 failures or shots") before looking at results, and report the rule. Choosing to stop when a comparison looks favourable biases it.
Step 5: comparisons that mean something
Comparisons are only meaningful between runs that share the code, distance, rounds, noise model and unit of rate. Within that constraint, useful questions include: how the ratio of union-find to PyMatching failure rates changes with and ; whether union-find's rate still falls with distance at a given ; and roughly where curves for different distances cross. Be careful with that last one. A crossing of two distances is not a threshold estimate; threshold claims need at least three distances, enough shots near the crossing and a finite-size analysis, as discussed in the earlier lesson on logical error rates and thresholds. Per-shot rates of experiments with different numbers of rounds are not comparable without converting to per-round rates.
Step 6: the report and the portfolio summary
The exercise README contains the report template. Its required sections are:
summary; model; method; parameters; seeds and reproducibility; environment
versions; results with uncertainty; comparison; limitations; conclusions;
references. Two sections deserve emphasis. Seeds and reproducibility must give
the exact commands that regenerate every number, and the results_sha256 of your
exported JSON. Limitations must list what the study does not show: other noise
models, larger distances, decoder speed (you have not measured it in a comparable
way), and implementation simplifications such as unweighted growth.
export_portfolio writes the JSON summary with sorted keys, fixed separators and
a trailing newline, so two runs with the same inputs produce byte-identical files.
The hash covers the per-point results only (not the environment), so the same
results on different machines produce the same hash, while the environment block
records what produced them.
Common pitfalls
- Benchmarking an unverified decoder. Always check single faults and simple syndromes first.
- Unpaired comparisons. Evaluating decoders on different samples adds noise that hides or invents differences.
- Rates without intervals, or zero reported as zero. Every rate needs an interval; zero failures give an upper bound.
- Overlapping intervals read as "no difference". Overlap of two marginal intervals is a weak test; use the paired test on discordant shots.
- Trusting seeds across machines. Stim's own seeded sampler is reproducible only with the same Stim version and the same SIMD width. Say which sampler you used.
- Tuning on the test data. If you adjust your decoder after looking at results, regenerate the reported data with fresh seeds.
- Mixing units. Per-shot rates of -round experiments are not per-round rates.
- Overclaiming. No threshold from two distances, no hardware conclusions from a uniform depolarizing model, no speed claims without a fair timing study.
How the capstone is assessed
The automated checks in the exercise must pass. The report is then assessed with the published rubric on six criteria: correctness, statistical rigour, reproducibility, comparison quality, report clarity, and honesty about limitations. Passing the capstone is an educational record of work you completed in this course; it is not a professional certification or a verified skill claim. The code, results and report are yours. You decide whether and where to publish them, and KetQat does not publish or reuse them without your explicit permission.
Summary
- A decoder benchmark is a model, data, decoders, statistics and a report, and each must be stated precisely enough to be reproduced.
- Sample the detector error model with a portable seeded recipe; give each point its own derived seed; evaluate all decoders on the same shots.
- Verify your decoder on every single fault before benchmarking it, and keep the trivial decoder as a floor and PyMatching as a baseline.
- Report Wilson intervals, treat zero failures as upper bounds, compare decoders with an exact paired test, and plan shot counts in advance.
- Publish a report with seeds, versions and limitations, and a hash-verified JSON summary that lets anyone check your numbers.