From memory to computation
A quantum memory only has to keep a state alive. A computer has to change the state while keeping it alive, and every operation it applies is itself noisy. Two new dangers appear. First, gates move errors around: a single fault on one qubit can become correlated errors on several qubits after a two-qubit gate. Second, no code lets you apply every gate in a simple, error-contained way, so at least one ingredient of a universal gate set has to be produced by another route.
This lesson treats both. We make "fault tolerant" precise, compute exactly how faults spread through a syndrome-extraction circuit, repair the circuit with a flag qubit, and then build a universal gate set from Clifford operations plus distilled magic states. The exercise turns each claim into an exhaustive or exact computation.
What fault tolerance means
Faults, locations and the single-fault model
A circuit has locations: preparations, gates, idle steps and measurements. A fault at a location replaces the ideal operation by the ideal operation followed by an arbitrary Pauli on the qubits it touches (for a stochastic Pauli noise model this loses no generality; general noise is reduced to it by standard arguments (Gottesman)). For a distance-3 code the relevant question is what one fault can do.
Definition (single-fault tolerance, distance-3 codes). A gadget, for example a syndrome-extraction round or an encoded gate, is fault tolerant if any single fault inside it leaves each output code block with an error that an ideal subsequent round of error correction removes, and if, without faults, it implements the intended operation. Rigorous versions, with separate conditions for preparation, gates, error correction and measurement and with faults for distance , are given by Aliferis, Gottesman and Preskill (AGP). The single-fault version is enough to see every phenomenon in this lesson.
How Paulis travel through Clifford gates
A Pauli error that occurs before a Clifford is equivalent to the error after it. In the binary symplectic form of the previous lesson, three rules cover the gates we need:
| Gate | Effect on |
|---|---|
| on | swap and |
| on | (so ) |
| and |
So X errors flow forward from control to target, and Z errors flow backward from
target to control. Stim implements the same conjugation as
PauliString.after(circuit) (Gidney, Stim), which the
exercise uses as an independent check of your own propagation code.
Hook errors: a worked example
The Steane code (Steane) on qubits has X- and Z-type stabilizers given by the rows of the Hamming parity check matrix, whose column is in binary. One X stabilizer is . The obvious way to measure it uses one ancilla, qubit 7, prepared in , four CNOTs from the ancilla to the data, and an X-basis readout.
Now suppose the second CNOT fails and leaves an on the ancilla. By the CNOT rule, that is copied onto by the third CNOT and onto by the fourth. One fault has produced the weight-two data error . This is a hook error.
Is a weight-two error a problem? For the Steane code it is fatal. A weight-two X error has the same Hamming syndrome as some weight-one error (the syndrome of is in binary, the syndrome of ), so ideal correction applies and leaves . That has zero syndrome and odd weight, which for the Steane code means it is a logical operator. The decoder is not to blame: a distance-3 code can only guarantee to correct one error.
Enumerating every single fault exactly confirms the picture. With the fault model "any non-identity Pauli on the qubits of one operation, right after it", the bare circuit has single faults. Running the reference solution of the exercise, 8 of them lead to a logical failure after ideal correction, and every one of them leaves the X error on the data (sometimes with a harmless single Z). Four are faults on the second CNOT that put an X or Y on the ancilla and no X-type error on ; the other four are faults on the third CNOT that put an X on both the ancilla and , so the ancilla's X still reaches . Reordering the CNOTs only changes which pair is hit, and since every weight-two error is uncorrectable for this code, the count of failing faults stays at 8 for every order the exercise tries.
You can reproduce the propagation step in two lines of Stim:
import stim
# Ancilla 7 has an X error after the CNOT to qubit 4; propagate it through the rest.
rest = stim.Circuit("CX 7 5\nCX 7 6")
error = stim.PauliString("_______X") # X on qubit 7
print(error.after(rest)) # +_____XXX: X on data 5 and 6, and on the ancilla
For the surface code the story is different. Its weight-four checks also produce
two-qubit hooks, but a distance- surface code can absorb some weight-two errors,
and the CNOT order can be chosen so that each hook lies across the direction of
the logical operator it could shorten (Dennis et al.)
(Fowler et al.). Stim's generated rotated
surface-code circuits use such an order: for circuit-level depolarizing noise,
len(circuit.shortest_graphlike_error()) returns 3, 5 and 7 for ,
so the hook errors do not reduce the circuit-level distance below (computed
with Stim 1.16 on surface_code:rotated_memory_x).
Flags: catching the dangerous faults
Chao and Reichardt showed that one extra qubit is enough to make such measurements fault tolerant for several distance-3 codes, including the Steane code (Chao and Reichardt). A flag qubit in receives a CNOT from the ancilla after the first data CNOT and again after the third:
An X error on the ancilla before the first flag CNOT reaches the flag twice, and the two copies cancel; one after the second flag CNOT never reaches it. Every ancilla X fault that would leave a data error of effective weight two or more (up to stabilizers) occurs between the two flag CNOTs, so the flag measurement reads 1; faults outside that window leave errors equivalent to weight at most one. When the flag fires, the decoder switches to a lookup table built for the small set of errors a single flagged fault can cause.
The exercise checks this exhaustively over the 96 single faults of the flagged circuit: no fault that leaves the flag at 0 causes a logical failure, and no two data errors that a flagged fault can produce share a syndrome while differing by a logical operator, so a flag-aware table corrects all of them. That is the single- fault definition of fault tolerance, verified rather than argued.
Transversal gates and the Eastin–Knill theorem
A transversal gate acts as across the qubits of a block (or as gates pairing qubit of one block with qubit of another). It never couples two qubits of the same block, so one fault stays one error per block. For the Steane code, CNOT, and are all transversal (the bitwise implements the logical , because the logical is a superposition of Hamming words of weights 3 and 7), so the whole Clifford group is available transversally.
Why not a universal transversal set? Eastin and Knill answered this.
Theorem (Eastin and Knill, 2009). If a quantum code can detect an arbitrary error on any single physical subsystem, then its transversal encoded gates do not form a universal set (Eastin and Knill).
Every code we care about detects single-qubit errors, so some gate must come from elsewhere. Codes differ in which gates they get for free: the Steane code has the Clifford group, while the 15-qubit quantum Reed–Muller code has a transversal but no transversal . The standard escape is to keep the Clifford group cheap and supply the missing gate through states.
Clifford + T and magic states
Clifford circuits alone can be simulated efficiently on a classical computer (the Gottesman–Knill theorem), and adding the single gate yields an approximately universal set (Nielsen and Chuang). Arbitrary single-qubit rotations then have to be synthesised from Clifford and gates; Ross and Selinger give an algorithm that, in the typical case, uses gates for a -rotation to precision (Ross and Selinger). The count is therefore the currency of fault-tolerant cost estimates.
Teleporting a T gate
Let and let the magic state be with . Apply with as control and as target:
Measure the second qubit in the Z basis. Outcome 0 leaves . Outcome 1 leaves , and applying gives . Every operation besides the magic state is Clifford, so a fault-tolerant Clifford layer plus a supply of good states gives a fault-tolerant .
15-to-1 distillation
Magic states can be prepared on a logical patch only with an error comparable to the physical error rate, far too high for a long computation. Bravyi and Kitaev showed how to purify them using only Clifford operations (Bravyi and Kitaev). In the 15-to-1 protocol, fifteen noisy copies are consumed to apply a transversal on the 15-qubit Reed–Muller code; measuring the code's four X-type stabilizers checks for errors, and the output is kept only if all four are trivial.
Model each input, after twirling, as having an independent error with probability , and assume the Clifford part is perfect. A -error pattern is undetected exactly when it is a codeword of the Hamming code (the X stabilizers form its parity-check matrix, with columns in binary). An undetected pattern of even weight is a Z stabilizer; one of odd weight is a logical error. With the number of Hamming codewords of weight ,
The smallest odd weight with is 3, and counts triples of distinct non-zero 4-bit vectors that sum to zero: . Hence , the leading-order result of Bravyi and Kitaev.
Worked example. Enumerating all patterns gives the full enumerator, and at the exact formulas give and :
import numpy as np
H = np.array([[(j + 1) >> b & 1 for j in range(15)] for b in range(4)])
words = (np.arange(2**15)[:, None] >> np.arange(15)) & 1
A = np.bincount(words[~((words @ H.T) % 2).any(axis=1)].sum(axis=1), minlength=16)
p = 1e-3
terms = A * p ** np.arange(16) * (1 - p) ** (15 - np.arange(16))
print(A[:4], f"p_out = {terms[1::2].sum() / terms.sum():.3e}", f"accept = {terms.sum():.4f}")
This prints [ 1 0 0 35] p_out = 3.511e-08 accept = 0.9851. Two levels in
sequence take to about and consume on average about
228 raw states per output (the exercise computes this as per
level, multiplied over levels). These numbers are exact for the stated model.
Real factories also suffer from errors in their own Clifford operations, which
depend on the code distance of the factory; Litinski's analysis shows that
careful layouts make distillation much cheaper than early estimates suggested
(Litinski, magic states). Above some
input error one level makes things worse; the exercise finds
exactly and compares it with the leading-order estimate .
Lattice surgery
Transversal two-qubit gates between surface-code patches would need long-range interactions. Lattice surgery instead acts on patch boundaries with nearest-neighbour operations only (Horsman et al.). Two patches placed side by side are merged by measuring, for rounds, the stabilizers of the combined patch along the seam. The product of the new seam stabilizers equals a joint logical operator such as , so its value is learned while the individual logical and are not. A split then measures the seam qubits individually and returns two patches. A merge costs about code cycles of time, because the seam's syndrome has to be repeated to be reliable against measurement errors.
Joint Pauli measurements are enough for Clifford logic. A CNOT from control to target with an ancilla patch in : measure (outcome ), then (), then (); apply if and if . The corrections are Pauli operators, so in practice they are tracked in software (the Pauli frame) rather than applied. The snippet checks all eight outcome combinations with state vectors:
import itertools
import numpy as np
I2, X, Z = np.eye(2), np.array([[0, 1], [1, 0]]), np.diag([1.0, -1.0])
kron = lambda *ms: np.kron(np.kron(ms[0], ms[1]), ms[2]) # order: c, a, t
proj = lambda P, m: (np.eye(8) + (-1) ** m * P) / 2
CX = np.eye(4)[[0, 1, 3, 2]]
rng = np.random.default_rng(1)
psi = rng.normal(size=4) + 1j * rng.normal(size=4)
psi /= np.linalg.norm(psi)
start = np.einsum("ct,a->cat", psi.reshape(2, 2), np.ones(2) / np.sqrt(2)).reshape(8)
for m1, m2, m3 in itertools.product((0, 1), repeat=3):
s = proj(kron(I2, Z, I2), m3) @ proj(kron(I2, X, X), m2) @ proj(kron(Z, Z, I2), m1) @ start
out = s.reshape(2, 2, 2)[:, m3, :].reshape(4)
out = np.kron(np.linalg.matrix_power(Z, m2), np.linalg.matrix_power(X, m1 ^ m3)) @ out
assert abs(abs(np.vdot(CX @ psi, out / np.linalg.norm(out))) - 1) < 1e-12
print("measurement-based CNOT verified for all 8 outcomes")
Litinski's "game of surface codes" turns this into a compilation framework: a computation becomes a sequence of multi-patch Pauli product measurements, each costing about cycles, with gates consumed from factories at the edge of the layout (Litinski, game of surface codes). The next lesson prices such layouts.
The threshold theorem
Theorem (threshold theorem; Aharonov and Ben-Or; Aliferis, Gottesman and Preskill, among others). Consider noise that is local and stochastic (each set of locations is faulty with probability at most ), and assume that operations can be applied in parallel, that fresh ancilla qubits can be supplied throughout, and that classical computation is fast and reliable. There is a constant such that, for , any ideal circuit of size can be simulated with failure probability at most by a noisy circuit of size (Aharonov and Ben-Or) (AGP).
For concatenated distance-3 codes the mechanism is visible in one line: if one level turns a fault rate into roughly , then levels give with , a doubly exponential suppression bought with an exponential (in ), hence polylogarithmic (in ), overhead. AGP proved for an adversarial independent stochastic noise model in their scheme; that is a rigorous lower bound, not an estimate of what real codes achieve.
Keep two kinds of "threshold" apart. The theorem's is a proven existence statement with conservative constants. The surface-code values near 1% (the published circuit-level estimates, and the distance-3 versus distance-5 crossings you computed in the lesson on logical error rates and thresholds, which are not themselves thresholds) are numerical observations for a specific code, noise model and decoder. Both are useful; neither substitutes for the other.
Common mistakes
- Counting physical weight instead of effective weight. An error is dangerous if its minimum weight over the stabilizer coset exceeds what the code corrects. An ancilla X error right after preparation spreads to all four data qubits, but that is the stabilizer itself and does no harm.
- Assuming a better decoder fixes hooks. For the Steane code every weight-two error is uncorrectable; the circuit must change (flags, cat states, or Steane- or Knill-style extraction), not the decoder.
- Applying Pauli corrections physically. Corrections from teleportation and lattice surgery are tracked in the Pauli frame. Only the Clifford correction in the gadget must be applied before the next non-Clifford gate.
- Quoting without its assumptions. It is the leading order for independent errors on the inputs and perfect Clifford operations. Clifford errors inside a real factory add terms that depend on the factory's code distance.
- Reading Eastin–Knill as "no fault-tolerant universal gate set". The theorem rules out transversal universality only. Magic states, code switching and other non-transversal techniques remain available.
- Confusing the threshold theorem with a surface-code threshold value. The theorem's assumptions (parallelism, fresh ancillas, fast classical control, weakly correlated noise) are part of its statement.
Summary
- A gadget is fault tolerant (for distance 3) when every single fault leaves an error that ideal correction removes. Checking this is a finite enumeration over fault locations and Paulis, propagated with the symplectic rules.
- A bare-ancilla measurement of a weight-four Steane stabilizer is not fault tolerant: 8 of its 63 single faults are hook errors that cause logical failures. A Chao–Reichardt flag catches all of them.
- Eastin–Knill forbids a universal transversal gate set. The usual answer is Clifford operations plus magic states, with applied by teleportation.
- 15-to-1 distillation suppresses errors from to at leading order. Its exact output error and cost follow from the Hamming code's weight enumerator.
- Lattice surgery implements Clifford logic as joint Pauli measurements on patch boundaries, each costing about code cycles.
- The threshold theorem is a proven statement with explicit assumptions; code thresholds from simulation are numerical observations.
What next
Resource estimation for fault-tolerant computers combines a fitted logical error model, lattice-surgery time steps and distillation costs into qubit counts and run times for a target computation.