From failure counts to claims
A memory simulation returns a count: logical failures in shots. Turning that count into a statement others can rely on takes three more steps. We must say what unit the rate refers to (one shot of rounds, or one round), how uncertain it is, and, when comparing code sizes, what the comparison does and does not establish. Most mistakes in published and unpublished QEC benchmarks happen in exactly these steps, not in the simulation. This lesson develops the tools and applies them to a small threshold sweep that you run yourself.
Throughout, "uniform circuit-level noise with parameter " means Stim's
rotated surface-code generator with after_clifford_depolarization,
before_round_data_depolarization, before_measure_flip_probability and
after_reset_flip_probability all equal to (see the Stim lesson), a
-basis memory with rounds, decoded by PyMatching
(Higgott 2022) from the decomposed detector
error model produced by Stim (Gidney 2021).
Per shot and per round
The natural estimate is the per-shot logical error rate : the probability that one complete experiment of rounds ends with the wrong logical value. It depends on , so it cannot be compared across experiments with different numbers of rounds, and in a sweep with the larger code is penalised simply for running longer.
The per-round rate removes that dependence under a model. Assume that each round independently flips the logical value with the same probability . As for the repetition-code memory, the experiment fails when an odd number of rounds failed:
For this is close to , and the exact form matters as grows: it saturates at , where the conversion breaks down. Worked example. over rounds gives , slightly more than .
The assumptions are real assumptions. The first and last rounds of a memory experiment differ from the middle ones (the time boundaries), so the per-round rate of a short experiment is biased; experiments therefore often fit over several instead of converting a single point. In this course we convert single points and say so.
How uncertain is ?
If every shot fails independently with probability , is binomially distributed, with standard error . The textbook "Wald" interval plugs in the estimate. It is badly behaved exactly where QEC lives, at small : for it has zero width, claiming certainty that the rate is 0, and for small its actual coverage is well below 95%.
The Wilson score interval (Wilson 1927) instead asks which values of are consistent with the observation at the stated level. With for 95%,
Worked examples (computed by the snippet below and by your exercise code):
- , : , Wilson interval . Note the asymmetry: the interval extends further up than down.
- , : the interval is , the upper
end being . Zero observed failures is an upper bound, never a
rate of zero. The KetQat SDK products report such results with an explicit
is_upper_bound_onlyflag.
import math
from scipy.stats import binomtest
def wilson(k, n, z=1.959963984540054):
centre = (k + z * z / 2) / (n + z * z)
half = z / (n + z * z) * math.sqrt(k * (n - k) / n + z * z / 4)
return max(0.0, centre - half), min(1.0, centre + half)
for k, n in [(7, 1000), (0, 10_000)]:
ref = binomtest(k, n).proportion_ci(confidence_level=0.95, method="wilson")
print(k, n, [round(x, 6) for x in wilson(k, n)], [round(float(ref.low), 6), round(float(ref.high), 6)])
This prints [0.003395, 0.014378] and [0.0, 0.000384] for both
implementations; SciPy is an independent check of the formula, and the
exercise uses it the same way.
How many shots?
To estimate with relative standard error you need , that is
Since is the expected number of failures, this says: you need about failures, roughly 100 for 10% relative precision, whatever is. At that is 99,900 shots; at , . This is why simulations of very low logical error rates rely on extrapolation from higher or on specialised rare-event methods, and why such numbers must be labelled as extrapolations.
Thresholds
For a code family, a noise model and a decoder, the threshold is the physical error rate below which the logical error rate goes to zero as the code distance grows, and above which it does not. For the surface code under independent noise, Dennis et al. related it to a phase transition in a statistical-mechanics model (Dennis et al. 2002); for general fault-tolerance schemes its existence is a theorem (Aharonov and Ben-Or 1999). Its value is not a theorem: it is estimated numerically.
In practice one plots against for several distances. Below threshold the larger code is better, above it worse, so the curves cross. The crossing of curves for increasing approaches the threshold. Three effects keep a crossing of small codes from being the threshold:
- Finite-size drift. The crossing of and generally differs from that of and , and so on. Only the limit is the threshold; serious estimates use several distances and fit a scaling form.
- The metric moves it. Per-shot and per-round curves cross at different places when the number of rounds grows with (computed below).
- Statistics. Near the crossing the two curves are close by definition, so their difference is the hardest quantity in the sweep to measure.
Below threshold, the useful quantity is often the suppression factor , the factor gained per step of 2 in distance. Far below threshold is large; at threshold it is 1.
Your sweep
The exercise runs at
with 40,000 shots per point and seed
2026 (point seeds derived with numpy.random.SeedSequence). The reference
solution gives (failures, per-shot rate with 95% Wilson interval, per-round
rate):
| failures | [95% CI] | failures | [95% CI] | |||
|---|---|---|---|---|---|---|
| 0.004 | 410 | 0.01025 [0.00931, 0.01129] | 0.00344 | 306 | 0.00765 [0.00684, 0.00855] | 0.00154 |
| 0.006 | 997 | 0.02492 [0.02344, 0.02650] | 0.00845 | 957 | 0.02392 [0.02247, 0.02547] | 0.00488 |
| 0.008 | 1621 | 0.04052 [0.03864, 0.04250] | 0.01389 | 1917 | 0.04793 [0.04587, 0.05006] | 0.00998 |
| 0.010 | 2359 | 0.05897 [0.05671, 0.06133] | 0.02049 | 3358 | 0.08395 [0.08127, 0.08671] | 0.01805 |
| 0.012 | 3226 | 0.08065 [0.07802, 0.08336] | 0.02847 | 4981 | 0.12452 [0.12133, 0.12780] | 0.02784 |
| 0.014 | 4108 | 0.10270 [0.09976, 0.10571] | 0.03689 | 6886 | 0.17215 [0.16848, 0.17588] | 0.04047 |
Log-log interpolation between neighbouring points puts the per-shot crossing at and the per-round crossing at . A parametric bootstrap (redraw every count from a binomial at its observed rate, recompute the crossing, 2,000 times) gives 95% ranges of about and :
import math
import numpy as np
ps = [0.004, 0.006, 0.008, 0.010, 0.012, 0.014]
shots = 40_000
failures = {3: [410, 997, 1621, 2359, 3226, 4108], # from the exercise sweep, seed 2026
5: [306, 957, 1917, 3358, 4981, 6886]}
def per_round(p_shot, rounds):
return (1 - (1 - 2 * p_shot) ** (1 / rounds)) / 2
def crossing(ps, small, large):
g = [math.log(b) - math.log(a) for a, b in zip(small, large)]
for i in range(len(ps) - 1):
if g[i] < 0 <= g[i + 1]:
t = -g[i] / (g[i + 1] - g[i])
return math.exp(math.log(ps[i]) + t * (math.log(ps[i + 1]) - math.log(ps[i])))
return None
def estimate(counts, per_round_rates):
rates = {d: [k / shots for k in counts[d]] for d in counts}
if per_round_rates:
rates = {d: [per_round(r, d) for r in rates[d]] for d in rates}
return crossing(ps, rates[3], rates[5])
print("per shot :", round(estimate(failures, False), 5))
print("per round:", round(estimate(failures, True), 5))
# Parametric bootstrap: redraw every count from a binomial at its observed rate.
rng = np.random.default_rng(1)
for per_round_rates in (False, True):
values = []
for _ in range(2000):
counts = {d: [rng.binomial(shots, k / shots) for k in failures[d]] for d in failures}
x = estimate(counts, per_round_rates)
if x is not None:
values.append(x)
lo, hi = np.percentile(values, [2.5, 97.5])
print("per round" if per_round_rates else "per shot ", len(values), round(lo, 5), round(hi, 5))
How to read this honestly:
- These are crossing estimates for versus , for this noise model, this decoder, memory in the basis with rounds, and the stated metric. They are not "the threshold of the surface code".
- The metric changes the answer by a factor of two. With , the experiment runs 5 rounds against 3, so per shot it looks worse earlier. Per round removes that penalty, but its crossing lies where for exceeds 0.1 and the independent-rounds model is strained. Neither number is wrong; each answers a different question, which must be stated.
- The bootstrap range is statistical only. It says nothing about finite-size drift, which you would see by adding , or about the interpolation model.
- Look at the neighbouring points. At the per-shot intervals of and overlap; that is what "near the crossing" looks like. At and they are cleanly separated, which is what the exercise's tests check instead of hard-coded numbers.
- Seeds fix numbers, not truths. Running the same sweep with another seed moves every count by about a standard error or two. Try it: rerun one point with eight different seeds and look at the spread. Conclusions should survive that.
Published results, labelled as such
The following are published values. They were obtained under the stated conditions; we have not reproduced them, and they are not comparable with the crossings above without accounting for every difference in model, decoder and metric.
- Circuit-level threshold near 1%. Wang, Fowler and Hollenberg (2011) simulated the surface code on a nearest-neighbour square lattice with two-qubit depolarizing noise of probability after two-qubit gates, single-qubit depolarizing noise of probability on idle (identity) steps, and measurements reporting the wrong result with probability , decoded by minimum-weight perfect matching with edge weights derived from the error model. They reported a threshold of about 1.1% per operation for that model (distances 3 to 9, estimated from the average number of rounds before a logical failure), and 1.2% and 1.4% for two variants with different idle and measurement error ratios. Our uniform model also has reset errors and data depolarization before every round, our decoder uses Stim's error model directly, and our crossing compares only and , so our 0.6% (per shot) and 1.2% (per round) are not comparable with their 1.1%: different model, metric and distances, not a contradiction.
- Scaling a logical qubit (2023). Google Quantum AI reported that, on their superconducting processor, a distance-5 surface code logical qubit had a logical error per cycle of , compared with averaged over distance-3 codes, over 25 cycles, decoded with an approximate maximum-likelihood (tensor-network) decoder; the faster belief-matching decoder gave and (Google Quantum AI 2023): a modest improvement with distance on real hardware noise.
- Below threshold (2024/2025). Google Quantum AI reported surface-code memories with a suppression factor per increase of the distance by two with their neural-network decoder ( with ensembled matching synthesis), a distance-7 code (101 qubits) with error per cycle of error correction, and, in repetition-code experiments up to distance 29, logical performance limited by rare correlated error events (Google Quantum AI and Collaborators 2025). These are per-cycle rates on a specific device with its own noise and decoders.
Note the units: "per cycle" in these papers corresponds to per round here.
Common mistakes
- Quoting with no unit. Per shot of how many rounds? Per round under which conversion?
- Reporting zero failures as zero. It is an upper bound, about at 95% (two-sided Wilson).
- Using the Wald interval at small . It undercovers, and at it collapses to a point.
- Calling a two-distance crossing "the threshold". It is a finite-size estimate for a stated model, decoder and metric, with a statistical uncertainty that you should report.
- Comparing with published thresholds across models. Different noise models, decoders and metrics give different numbers by design.
- Sharing seeds across sweep points. Identical seeds make neighbouring points correlated; derive one seed per point.
- Too few failures. Fewer than about 100 failures per point gives more than 10% relative uncertainty.
Summary
- Per-shot and per-round rates are related by under independent rounds.
- Use Wilson intervals; zero failures gives an upper bound .
- About failures are needed for relative precision .
- Thresholds are limits over increasing ; a crossing of and is an estimate whose value depends on the metric and carries statistical and finite-size uncertainty. In our sweep the per-shot and per-round crossings differ by a factor of two.
- Published thresholds and hardware results must be cited with their noise model, decoder, distances, rounds and units.
Exercise
You implement Wilson intervals (checked against SciPy and by a coverage simulation), the per-round conversion (checked against an explicit composition of rounds), the shot budget, the seeded sweep and the crossing estimator. Tests check statistical consistency: the pipeline must reproduce the exact repetition-code rate within a 99.99% interval, and the sweep must show better than at and worse at with non-overlapping intervals. The quiz asks for the crossing estimates of the reference sweep, which your implementation reproduces exactly with the stated seed.