Why estimate resources
Asymptotic statements such as "polynomial in " decide whether an algorithm is interesting. They do not decide whether it is useful: for that you need to know how many qubits, how many hours and what hardware quality a concrete instance requires. A resource estimate answers that question for a stated machine model. Its value lies as much in the stated assumptions as in the final numbers, because the numbers move by orders of magnitude when the assumptions move.
This lesson builds a deliberately coarse estimator in two layers. The logical layer describes the algorithm as a fault-tolerant circuit. The physical layer turns logical operations into surface-code patches, rounds of error correction and magic-state factories. Every constant in the physical layer is an assumption, and the lesson labels each one.
The logical layer
On a surface-code computer the natural gate set is Clifford + T. Clifford operations (Paulis, , , CNOT) can be implemented fault-tolerantly by lattice surgery at a cost that scales with the code distance, but they do not need special resources. The gate does: it is implemented by consuming a magic state that has been prepared and purified separately. That makes the T-count, or equivalently the Toffoli count with dedicated factories, the headline cost of most fault-tolerant algorithms.
The gadget below shows how one magic state becomes a gate on a data qubit . After a CNOT from to the magic qubit , the state is (unnormalised) for . Measuring and finding 0 leaves ; finding 1 leaves up to a global phase, which the Clifford correction turns into . Only Clifford operations and a measurement act on the data, so the whole cost of the non-Clifford gate sits in preparing a clean .
The numbers that characterise an algorithm at this level are:
- logical qubits , including ancillas and workspace;
- T-count (or Toffoli count): one standard decomposition uses 7 gates per Toffoli (Nielsen and Chuang), and arbitrary-angle rotations, such as the controlled phases of the QFT, must each be approximated by a sequence of many and Clifford gates whose length grows as the required precision tightens;
- T-depth or reaction depth, which bounds how far the computation can be parallelised.
These are properties of the circuit, independent of hardware, and they are where algorithmic improvements show up: the approximate QFT from earlier in this course is a resource optimisation at the logical layer.
The physical layer
Surface-code patches
A logical qubit is a patch of rotated surface code of distance : data qubits and measurement qubits, so physical qubits (Fowler et al. 2012). Each round (or cycle) measures all stabilisers once and takes time ; a logical operation such as a lattice-surgery merge takes about rounds. Algorithms also need routing space between data patches. Lattice-surgery layouts trade space for speed, and published layouts use between roughly one and a half and a little over two patch-sized tiles per logical qubit (Litinski 2019, A Game of Surface Codes). The estimator uses a routing factor of 2 (an assumption).
How logical errors scale with distance
Below threshold, logical errors are suppressed exponentially in the distance. A common empirical ansatz, of the form used by Fowler and coauthors, is
per patch per round, where is the physical error rate, a threshold and a prefactor. Increasing by 2 multiplies by , so the suppression factor is . The ansatz is a fit, not a theorem: and depend on the noise model, the decoder and the syndrome-extraction circuit, and it is accurate only well below threshold. This lesson's estimator uses , and , so : all three are illustrative assumptions, and the calibration section below shows how a simulation pins down for one concrete noise model.
Choosing the distance
If patches must survive rounds and failures are rare and roughly independent, the union bound gives a failure probability of at most . Choose the smallest odd for which this is below the error budget :
itself depends on , because each logical step takes rounds, so the condition is solved by trying in turn. Because falls exponentially while grows only linearly in , the required distance grows only logarithmically with the size of the computation.
Magic-state factories
A distillation factory consumes many noisy magic states and outputs fewer, much cleaner ones; it occupies a block of tiles for the duration of each distillation round. Litinski showed that careful factory design makes this overhead considerably smaller than earlier estimates suggested (Litinski 2019, Magic State Distillation). At a coarse level a factory is described by two numbers: its footprint, in tiles, and the time it needs per output state. The estimator assumes a factory of 25 tiles that outputs one T state every rounds (both assumptions for illustration), and that the computation consumes one T state per logical step of rounds. Keeping up then requires factories running in parallel. The factories' own output error is assumed to meet its target, so only data patches count against the error budget.
Run time
With T gates consumed one per step, the run takes rounds and seconds. The cycle time is another assumption. Real schedules may be faster (several T gates per step, with more factories) or slower (waiting for the classical decoder to react before a measurement-dependent correction).
Worked example: a toy workload
Take an algorithm with logical qubits and T gates, and the assumptions collected in the table.
| assumption | value |
|---|---|
| physical error rate | |
| ansatz threshold and prefactor | and |
| round (cycle) time | |
| routing factor (tiles per logical qubit) | 2 |
| factory footprint and period | 25 tiles, one T state per rounds |
| error budget for the data patches |
The data region has tiles. For , rounds and , so the failure bound is , above budget. For , and , giving , within budget. So . Each tile holds physical qubits, there are tiles, and
The same search in a few lines of Python:
p, p_th, A, budget = 1e-3, 1e-2, 0.1, 1e-2 # assumptions, see the table
data_tiles, factory_tiles, t_count, tau = 200, 6 * 25, 1e8, 1e-6
d = 3
while data_tiles * t_count * d * A * (p / p_th) ** ((d + 1) / 2) > budget:
d += 2
print(d, (data_tiles + factory_tiles) * (2 * d * d - 1), t_count * d * tau)
It prints 25 437150 2500.0, and the estimator in the exercise reproduces the same numbers. Its sensitivity to the assumptions is the
real lesson:
| change | distance | physical qubits | run time |
|---|---|---|---|
| baseline | 25 | 437,150 | 2,500 s |
| () | 37 | 957,950 | 3,700 s |
| () | 19 | 252,350 | 1,900 s |
| , T gates | 31 | 4,130,150 | 310,000 s (3.6 days) |
Doubling the physical error rate roughly doubles the qubit count, because the distance needed at is much larger than at . Physical error rates, not logical qubit counts, dominate the footprint at this scale; and 150 of the baseline machine's 350 tiles, about 43%, are magic-state factories.
Calibrating the ansatz with a simulation
Where do and come from? From simulations or experiments of the actual code, noise
model and decoder. The KetQat SDK's surface-code-memory product runs a rotated surface-code memory
experiment with Stim and decodes it with PyMatching (KetQat SDK). Its noise model is
circuit-level depolarizing noise of strength after every Clifford gate, with no measurement, reset
or idle errors; the decoder is minimum-weight perfect matching with the matching noise model; the
reported rate is per experiment of the stated number of rounds.
A memory experiment of rounds fails with probability . If each round independently flips the logical qubit with probability , then , which inverts to the per-round rate . With , , rounds, memory in the Z basis, 50,000 shots per distance and seed 11 (Stim 1.16.0, PyMatching 2.4.0), the exercise's reference solution measures:
| distance | per-round logical error rate |
|---|---|
| 3 | |
| 5 | |
| 7 |
A least-squares fit of against gives and . With the illustrative , the ansatz would predict . So for this noise model the effective near is about . These are numerical results for one noise model at one physical error rate, with statistical uncertainty from the finite number of failures (the point rests on about 100 failures). They are not a threshold estimate, which requires sweeping and locating where curves for different distances cross, and they are not a hardware prediction: real devices add measurement errors, leakage and correlated noise, all of which lower the effective threshold.
Published estimates, with their assumptions
The most cited estimate in this area is for factoring a 2048-bit RSA modulus. Gidney and Ekerå estimated that it could be done in about 8 hours using 20 million noisy qubits, assuming a planar grid of qubits with nearest-neighbour connectivity, a physical gate error rate of , a surface-code cycle time of 1 s and a classical reaction time of 10 s (Gidney and Ekerå 2021, arXiv preprint 2019). In a 2025 preprint, Gidney estimated that under the same assumptions the same task could be done in less than a week with fewer than one million noisy qubits, trading a longer run time for far fewer qubits through approximate residue arithmetic, more compact storage of idle logical qubits, and cheaper magic-state preparation (Gidney 2025).
Read these the way this lesson reads its own toy estimate. They are estimates for a hypothetical machine whose stated properties no existing device has at that scale, not demonstrations; they assume a specific error rate, cycle time and connectivity; and the more than twentyfold change in qubit count between them came from algorithmic and architectural ideas, not from new hardware. Babbush and coauthors used the same kind of reasoning to argue that the slow logical clock of surface-code machines makes quadratic speed-ups hard to exploit (Babbush et al. 2021), the argument behind the crossover exercise in the complexity lesson.
What the toy model leaves out
The estimator ignores, among other things: the detailed layout and routing schedule; Clifford costs; the error budget of the factories; the synthesis cost of arbitrary rotations; decoder reaction time and its effect on the schedule; storage tricks for idle qubits; and noise beyond the simulated model (leakage, correlated errors, drift). Each of these can change the answer by a large factor. Use the toy model to understand which assumptions matter, and a dedicated estimation tool or a published analysis for any number that will inform a decision.
Exercise: a small resource estimator
In surface-code-resource-estimator you implement the scaling ansatz, the patch size, the distance
search, the full estimate, the per-round conversion of memory-experiment failure rates, the fit of
, and a calibration run against the SDK's [email protected] product. The checks verify
the factor per distance step, the patch size, the toy workload (with the chosen
distance checked independently: it meets the budget and does not), the direction of every
sensitivity, the round-trip of the per-round formula, recovery of known constants from synthetic data,
and that the simulated logical error rates decrease with distance with a plausible .
Common mistakes
- Quoting a number without its assumptions. "20 million qubits" means nothing without the error rate, cycle time, connectivity and reaction time.
- Using the ansatz near or above threshold. It is a below-threshold fit; at larger codes do not help.
- Mixing per-round and per-experiment rates. A memory experiment of rounds fails about times more often than a single round.
- Forgetting the factories. In the toy example they are about 43% of the machine.
- Treating a local fit as a threshold. at one is not .
- Ignoring that the distance depends on the run length. Longer computations need larger codes.
Summary
A resource estimate has a logical layer (logical qubits, T count, depth) and a physical layer (code distance, patches, factories, rounds). With the ansatz and a union bound, the distance is the smallest odd for which fits the error budget; physical qubits follow from per tile, and run time from rounds times cycle time. For a toy workload of 100 logical qubits and T gates under stated assumptions, this gives , about 437,000 physical qubits and 42 minutes, and the sensitivity table shows the physical error rate dominating. Simulation calibrates the ansatz for a specific noise model: for circuit-level depolarizing noise at with matching decoding, . Published estimates such as Gidney–Ekerå's must always be quoted with their assumptions. This completes the course: from Grover's rotation to the cost of running algorithms like it at scale, the recurring lesson is to state what is proven, what is assumed and what was measured.