47 min read

Every chapter since Part II has worked around noise. Chapter 12 measured a 288× spread in two-qubit

Prerequisites

  • 11
  • 13
  • 15

Learning Objectives

  • Build the three-qubit bit-flip and phase-flip codes and measure syndromes.
  • Measure the logical error rate against the physical error rate and find the break-even point.
  • Identify the states and errors a given code is blind to, and prove it by measurement.
  • Explain why syndrome extraction is not free and what it costs in qubits and time.
  • Connect small codes to the surface code and to Chapter 15's overhead figures.

Chapter 25: Quantum Error Correction in Code

Every chapter since Part II has worked around noise. Chapter 12 measured a 288× spread in two-qubit gate error across a single chip and chose layouts to dodge the worst of it. Chapter 13 mitigated errors after the fact, recovering 79% with the right ordering. Chapter 10 counted the routing overhead that noise makes expensive. Chapter 24 found that even with all of it, the shot budget alone defeats chemical accuracy.

Every one of those is a way of living with noise. This chapter is about removing it — and about the precise, measurable conditions under which that works. Which turn out to be conditions current hardware does not meet.

Part IV closes here because error correction is the hinge. Chapter 23's Shor implementation needs about 3,368 gates to factor 15 and roughly 20 million to factor a 2048-bit key. Chapter 15's estimator put that at millions of physical qubits. Both numbers assume error correction works. This chapter shows what "works" costs.

We will build the codes, run them, and — as usual — let the measurements correct the narrative. They did so three times while this chapter was being written, and all three corrections are in here.


25.1 You cannot copy a qubit

Classical error correction is easy to state: send each bit three times, take a majority vote. A single flipped bit is outvoted.

The obvious quantum translation is illegal. The no-cloning theorem says no unitary can map $|\psi\rangle|0\rangle|0\rangle \to |\psi\rangle|\psi\rangle|\psi\rangle$ for arbitrary $|\psi\rangle$. You cannot make three copies of an unknown qubit.

There is a second problem, and it is worse. Even if you had three copies, measuring them to compare would destroy the superposition. Chapter 3's measurement postulate is not negotiable: looking at a qubit collapses it.

So quantum error correction has to do something that sounds impossible — detect and fix errors on a state without ever learning what the state is.

The resolution is the central idea of the field, and it is worth stating precisely before any code:

⚛️ The Physics Underneath: entangle, don't copy.

The map $|0\rangle \to |000\rangle$, $|1\rangle \to |111\rangle$ is linear, so it extends to $\alpha|0\rangle + \beta|1\rangle \to \alpha|000\rangle + \beta|111\rangle$.

That is not three copies of $|\psi\rangle$. Each individual qubit, on its own, is in a completely mixed state and carries no information about $\alpha$ or $\beta$. The information lives in the correlations. No-cloning is untouched.

And now the trick: you can measure whether two qubits agree without measuring what they are. The parity $Z_0Z_1$ is a different observable from $Z_0$ and $Z_1$ individually. It returns one bit — "same" or "different" — and leaves $\alpha$ and $\beta$ entirely alone.

Redundancy without copying; comparison without inspection. Everything in this chapter is an elaboration of those two sentences.

What a single encoded qubit actually looks like

The claim that the individual qubits carry nothing is worth making exactly, because the loose version is slightly too strong and the exact version is the one no-cloning needs.

Trace out two of the three qubits of $\alpha|000\rangle + \beta|111\rangle$ with qiskit.quantum_info.partial_trace:

   |alpha|^2   rho_0 diagonal    off-diagonal   purity
      0.50     0.5000, 0.5000          0.0000   0.5000
      0.90     0.9000, 0.1000          0.0000   0.8200
      0.10     0.1000, 0.9000          0.0000   0.8200

The off-diagonal entries are exactly zero and the diagonal entries are not. A single physical qubit does retain the populations $|\alpha|^2$ and $|\beta|^2$ — you could estimate them by measuring one qubit in the $Z$ basis many times. What it has lost completely is the relative phase, and with it any possibility of being a copy.

A copy of $|\psi\rangle$ would have purity 1. At $|\alpha|^2 = 0.9$ the reduced state has purity 0.82, and at $|\alpha|^2 = 0.5$ it is 0.5 — maximally mixed. The encoder produced three qubits, none of which is $|\psi\rangle$, which is precisely what a theorem forbidding copies requires.

📐 Math Aside: where the phase went.

Expand the encoded density matrix:

$$\rho = |\alpha|^2|000\rangle\langle000| + \alpha\beta^*|000\rangle\langle111| + > \alpha^*\beta|111\rangle\langle000| + |\beta|^2|111\rangle\langle111|$$

Tracing over qubits 1 and 2 keeps a term only when the traced indices agree on both sides. The cross terms carry $\langle 00|$ against $|11\rangle$ there — orthogonal — so they vanish, and the diagonal terms survive with their coefficients. That is exactly the measured $\rho_0$.

The cross terms are the phase, and they are the part the traced-out qubits were holding. They are not destroyed. They are delocalized: bring all three qubits back together and they return in full.

That is the difference between an encoded qubit and a decohered one, and it is the mechanism behind the entire chapter. The information is somewhere, but nowhere local — so a noise process that acts locally, on one qubit at a time, cannot reach it.


25.2 The three-qubit bit-flip code

Encoding is two CNOTs:

qc.cx(d[0], d[1])
qc.cx(d[0], d[2])

Syndrome extraction uses two ancillas to compute the two parities $Z_0Z_1$ and $Z_1Z_2$:

qc.cx(d[0], a[0]); qc.cx(d[1], a[0])    # a0 = d0 XOR d1
qc.cx(d[1], a[1]); qc.cx(d[2], a[1])    # a1 = d1 XOR d2

Two bits, four syndromes, and the mapping is a lookup table:

   (a0,a1)   diagnosis        correction
    (0,0)    no error         none
    (1,0)    d0 flipped       X on d0
    (1,1)    d1 flipped       X on d1
    (0,1)    d2 flipped       X on d2

The ancillas never learn $\alpha$ or $\beta$. They learn only which qubit disagrees with the others. That is the whole design.

First, verify the noise is actually in the circuit

Before any number below can be trusted, one thing has to be checked. This is the third of the chapter's three corrections, and it happened before the other two, during setup.

Aer attaches noise to gates. These circuits mark their noise locations with identity gates, and the noise model attaches an $X$ error to id on each data qubit. But an identity gate is by construction removable, and the transpiler removes it:

   optimization_level=0:   id gates surviving = 3    <- noise attaches here
   optimization_level=1:   id gates surviving = 0    <- NOISE SLOTS DELETED
   optimization_level=2:   id gates surviving = 0
   optimization_level=3:   id gates surviving = 0

Only level 0 preserves them, and level 0 is not the default. Calling transpile(qc, sim) produces a circuit with nowhere for the noise to go, and the simulator then faithfully executes a noiseless one:

     p     unencoded    level=0    default
  0.01        0.0100     0.0002     0.0000
  0.05        0.0500     0.0075     0.0000
  0.10        0.1000     0.0283     0.0000
  0.20        0.2000     0.1011     0.0000
  0.50        0.5000     0.5003     0.0000
  0.60        0.6000     0.6494     0.0000

Perfect correction at $p = 0.60$, where a three-qubit code cannot correct anything at all. Case Study 1 works through the full diagnosis. The fix is one argument plus one assertion:

t = transpile(qc, sim, optimization_level=0)
assert t.count_ops().get("id", 0) == 3, f"noise slots optimized away: {dict(t.count_ops())}"

⚙️ Under the Transpiler: "noise goes here" and "do nothing" are the same gate.

The transpiler did nothing wrong. Removing identity gates is correct, documented, desirable behaviour — Chapter 10 presents it as a feature. The problem is that id carries two meanings and only one of them survives optimization.

Nothing warns you. There is no exception, no changed gate count in the object you built, no difference in the returned counts format. The circuit you constructed and the circuit that ran are different objects, and the only place the difference is visible is count_ops() on the transpiled circuit.

So assert on the transpiled circuit, not the source one. vqelab.errorcorrection raises rather than asserts, so the check survives python -O. It is not defensive programming — it is the experiment's control, and without it a noise study has no evidence that it contained any noise.

Run it under X noise applied independently to each data qubit with probability $p$:

     p     unencoded    encoded   3p^2-2p^3
  0.01        0.0100     0.0002      0.0003
  0.02        0.0200     0.0010      0.0012
  0.05        0.0500     0.0075      0.0073
  0.10        0.1000     0.0283      0.0280
  0.20        0.2000     0.1011      0.1040
  0.30        0.3000     0.2145      0.2160
  0.40        0.4000     0.3549      0.3520
  0.45        0.4500     0.4254      0.4253
  0.50        0.5000     0.5003      0.5000     <-- crossover
  0.55        0.5500     0.5763      0.5748
  0.60        0.6000     0.6494      0.6480

The encoded rate tracks $3p^2 - 2p^3$ — the probability that two or more of three qubits flip — to within shot noise at every point. Error correction works, and it works for the reason the theory says.

And notice the last two rows. At $p > 0.5$ the encoded state is worse than the unencoded one: 0.6494 against 0.6000. Above the crossover, adding error correction adds error. That is not a quirk of this code; it is the first appearance of the most important concept in the chapter, and §25.8 will make it general.

Solving $3p^2 - 2p^3 = p$ gives $2p^2 - 3p + 1 = 0$, with roots $p = \tfrac12$ and $p = 1$. The crossover is exactly one half, and the measurement puts it there.

Reading a syndrome as a distribution

§25.1 claimed the ancillas learn nothing about $\alpha$ and $\beta$. That is directly testable: prepare several different states, encode, inject identical noise, and look at the syndrome rather than the data. At $p = 0.10$, 40,000 shots:

   stored           s=00     s=01     s=10     s=11
   |0>            0.7287   0.0912   0.0885   0.0916
   |1>            0.7287   0.0912   0.0885   0.0916
   |+>            0.7287   0.0912   0.0885   0.0916
   |i>            0.7287   0.0912   0.0885   0.0916
   0.9|0>+0.44|1> 0.7287   0.0912   0.0885   0.0916
   random         0.7287   0.0912   0.0885   0.0916
   SPREAD         0.0000   0.0000   0.0000   0.0000

Not close — identical to every digit, across six encoded states, two of them with complex amplitudes. The syndrome distribution does not move at all.

And it is the distribution the error model predicts:

$$P(00) = (1-p)^3 + p^3 = 0.730, \qquad P(01)=P(10)=P(11) = p(1-p)^2 + p^2(1-p) = p(1-p) = 0.090$$

against measured 0.7287, 0.0912, 0.0885, 0.0916. At 40,000 shots the standard error is about 0.0022 on the first and 0.0014 on the others, so every entry sits within 1.2 standard errors of theory.

📊 What the Numbers Say: the trivial syndrome does not mean "no error".

Look at where the $p^3$ went. $P(00) = (1-p)^3 + p^3$ — the syndrome $(0,0)$ means "nothing happened" or "all three qubits flipped", because both leave every parity even.

The second case is a logical failure that the syndrome reports as clean. That is not a defect in the extraction circuit; it is what distance 3 means. A $d=3$ code corrects one error, detects two, and is silently defeated by three.

A syndrome is not a diagnosis. It is a coset label. It names which class of errors occurred, and the decoder then guesses the lightest member of that class. When the true error is a heavier member, the "correction" completes the logical error instead of undoing it. Every logical failure in this chapter's tables is that guess going the wrong way — never a failure to detect, always a failure to choose.


25.3 The blind spot

Here is the first measurement that corrected this chapter.

The obvious next test is the phase-flip code — the same construction conjugated by Hadamards, so that $Z$ errors become $X$ errors in the rotated frame. It was written, run against $Z$ noise, and produced this:

     p     unencoded    encoded
  0.01        0.0100     0.0000
  0.05        0.0500     0.0000
  0.10        0.1000     0.0000
  0.50        0.5000     0.0000
  0.60        0.6000     0.0000     <-- at p=0.6 correction is IMPOSSIBLE

A logical error rate of exactly zero at $p = 0.6$, where the majority vote should fail 65% of the time. The code was not that good. Something was wrong.

The diagnosis: the test stored $|+\rangle$ in the code. Conjugating a physical $Z$ error backwards through the decoder shows what it becomes:

   physical ZII after encoding  ==  IIX  before it
   physical IZI after encoding  ==  IXX  before it
   physical IIZ after encoding  ==  XIX  before it

The decoded logical error is an $X$. And $X|+\rangle = |+\rangle$. The stored state was an eigenstate of the very error the experiment was trying to detect. The measurement was correct, reproducible, and completely uninformative.

Re-run storing $|0_L\rangle$ instead, and the code behaves:

     p     unencoded  uncorrected  corrected   3p^2-2p^3
  0.01        0.0100       0.0109     0.0003      0.0003
  0.05        0.0500       0.0517     0.0076      0.0073
  0.10        0.1000       0.1018     0.0293      0.0280
  0.20        0.2000       0.2029     0.1050      0.1040
  0.50        0.5000       0.5048     0.5048      0.5000
  0.60        0.6000       0.6044     0.6527      0.6480

Same theory curve, same crossover at one half.

⚠️ Common Pitfall: a QEC test must store BOTH logical basis states.

A code protects an arbitrary state. A test that stores one basis state probes one failure mode, and there are two independent ways such a test can be unable to fail:

  1. The stored state is an eigenstate of the physical error. $|000\rangle$ cannot be harmed by $Z$; $|{+}{+}{+}\rangle$ cannot be harmed by $X$.
  2. The residual logical error stabilizes the stored state. This is the case above: two errors defeat the majority vote and produce a logical $X$, which $|+_L\rangle$ absorbs.

Test $|0_L\rangle$ and $|+_L\rangle$, against $X$, $Z$, and $Y$, and report the worst. Anything less will show you zeros and let you believe them.

And note that blindness depends on the code, not just the stored state — the phase-flip code is blind exactly where the bit-flip code sees. The project module encodes all four blind cells and checks the rule against the simulator in all twelve, because the first version of that rule was written without the code argument and was wrong for half the table.

This is the same failure as Chapter 24 §24.3's exact simulator hiding shot noise, and Chapter 19's oracle that "worked" in the computational basis: an experiment that cannot fail is not evidence.

★ An impossible result is a gift

Both of this chapter's blind measurements were caught by the same move, and it is worth separating the move from the luck.

Neither was found by reading the code. Both were found by looking at one row — $p = 0.6$ — where the correct answer is loudly non-zero and the reported answer was exactly zero:

     p     correct    reported    difference
  0.01      0.0003      0.0000    invisible
  0.60      0.6480      0.0000    unmissable

At low $p$ a broken measurement is indistinguishable from a working one. "Very small" and "zero" look alike, and the low-$p$ rows are the ones a reader scans first, because they are the rows that flatter the code. At $p = 0.6$ there is nowhere to hide.

So: an impossible result is a gift, because it announces itself. A merely wrong result does not. The book now has one of each, and the contrast is the point:

  • Chapter 27's false-failure rate came out as 1.0%, from 2 failures in 200 runs. It is wrong — the true rate at 2,000 runs is 0.150% — but 1.0% is a plausible number. Nothing about it demands investigation. Catching it took ten times the sample.
  • §25.3's phase-flip code came out as 0.0000 at $p = 0.6$. That is not a plausible number. It is arithmetically impossible, and catching it took one row.

The bug that produced a ridiculous number was cheaper to find than the bug that produced a reasonable one, and the difference was not skill. It was that one of the two experiments contained a regime where the answer was known in advance.

🧪 Run It: put an impossible row in every sweep.

Take a noise sweep you already have and add one parameter value where you can state the correct answer from theory before running it — usually the maximally noisy end, where the answer is "as bad as it can possibly get."

For this chapter that row is $p = 0.6$, where a majority vote over three qubits must fail $3p^2 - 2p^3 = 0.648$ of the time. For a Grover circuit it is an oracle that marks every item, where amplification has nothing to amplify. For a mitigation study it is zero noise, where mitigated and unmitigated must agree exactly. For a QEC test it is any $p$ above the code's crossover.

The row costs one extra simulation, and it is the only row in the table capable of failing loudly. Sweeping only the regime you care about means sweeping only the regime where you cannot check yourself.


25.4 One code is never enough

With both logical states tested, the honest picture appears. Logical error rate at $p = 0.05$, against an unencoded baseline of 0.0500:

   code        stored     X noise  Z noise  Y noise      WORST
   bit-flip    |0_L>       0.0079   0.0000   0.0079
   bit-flip    |+_L>       0.0000   0.1346   0.1345     0.1346  WORSE THAN NOTHING
   phase-flip  |0_L>       0.0000   0.0079   0.0079
   phase-flip  |+_L>       0.1346   0.0000   0.1345     0.1346  WORSE THAN NOTHING

Read the bit-flip row for $Z$ noise on $|+_L\rangle$: 0.1346 against an unencoded 0.0500. The code made the error rate 2.7× worse.

The reason is arithmetic. An unencoded qubit has one chance to suffer a $Z$ error: probability $p$. An encoded one has three qubits, and a $Z$ on any single one of them flips the logical phase: $1 - (1-p)^3 = 0.1426$ at $p = 0.05$, which is what the measurement finds.

🔬 Honest Assessment: a code that fixes one error type amplifies the other.

The bit-flip code does not merely fail to correct phase errors — it triples your exposure to them. Three qubits, three chances. Encoding is not a neutral act.

The zeros in that table are blind spots, not successes. Only the worst-case column is a claim about the code.

Hence the Shor nine-qubit code: concatenate the two. Encode a qubit in the phase-flip code, then encode each of its three qubits in the bit-flip code. Nine physical qubits, one logical qubit, and — the standard claim — it corrects any single-qubit error.

That claim is exactly checkable. Inject every single-qubit Pauli on every qubit, for both logical basis states, and compute the exact output state:

   stored |0_L>:  27 injections (X, Y, Z on each of 9 qubits) -> P(logical error) = 0.000000
   stored |+_L>:  27 injections                               -> P(logical error) = 0.000000
   TOTAL FAILURES across 54 injections: 0

Fifty-four out of fifty-four, exactly zero. The code does precisely what it claims.

What nine qubits bought

Put the codes side by side as rates — logical qubits per physical qubit — because that is the number that multiplies into every resource estimate in Chapter 15:

   code                     [[n,k,d]]     rate k/n   corrects
   unencoded                [[1,1,1]]        1.000   nothing
   3-qubit bit-flip         [[3,1,3]]        0.333   one X
   3-qubit phase-flip       [[3,1,3]]        0.333   one Z
   Steane                   [[7,1,3]]        0.143   any single-qubit Pauli
   Shor                     [[9,1,3]]        0.111   any single-qubit Pauli
   surface, distance d   [[~2d^2,1,d]]    1/(2d^2)   up to (d-1)/2

Steane's row is the interesting one. It reaches the same distance as Shor with two fewer qubits — a 22% saving on a resource Chapter 15 counts in millions — and nothing about the nine-qubit construction suggests it exists. Shor's code was built by concatenating two codes you can picture. Steane's was found by searching the space the stabilizer formalism defines, which is §25.6.

The last row is where the argument goes. A distance-3 code costs 7 or 9 qubits, once, and then stops improving. The surface code's cost is quadratic in distance and its benefit, as §25.8 will show, is exponential in it. That trade is what makes the enterprise viable, and Chapter 15's estimator turned it into a concrete price: 450 physical qubits become 2,882 to support a single $T$ gate, a 6.4× cliff paid for one operation.

📉 Noise Report: the verdict survives a realistic channel.

§25.4's grid injects one Pauli type at a time, which is a deliberately clean model. Real decoherence is closer to depolarizing — under Qiskit's depolarizing_error(lam, 1), $X$, $Y$ and $Z$ each with probability $\lambda/4$. Re-run the bit-flip code under that instead:

text lambda unencoded |0_L> |+_L> predicted |+_L> 0.02 0.0100 0.0003 0.0301 0.0294 0.05 0.0250 0.0020 0.0722 0.0713 0.10 0.0500 0.0079 0.1371 0.1355 0.20 0.1000 0.0267 0.2429 0.2440

At $\lambda = 0.10$: 0.0079 against an unencoded 0.0500 storing $|0_L\rangle$, and 0.1371 storing $|+_L\rangle$ — the same 2.7× penalty as the single-Pauli grid, arrived at through a completely different channel.

The prediction is exact and explains why. Two of the three Paulis, $Z$ and $Y$, flip the logical phase, so the effective phase-error rate is $q = \lambda/2$, and an odd number of flips across three qubits has probability $\tfrac12\big(1-(1-2q)^3\big)$. Changing the noise model changed the numbers and not the verdict, which is what you want from a conclusion — and is worth checking rather than assuming.


25.5 Correcting any single error is not the same as helping

And now the second measurement that corrected this chapter.

"Corrects any single-qubit error" is a statement about one error. Real noise is independent and per-qubit: with nine qubits each failing with probability $p$, multi-qubit errors are common. Run the Shor code under independent $Z$ noise:

        p  unencoded   measured  predicted   verdict
    0.005     0.0050     0.0007     0.0007    HELPS
    0.010     0.0100     0.0026     0.0026    HELPS
    0.020     0.0200     0.0093     0.0100    HELPS
    0.030     0.0300     0.0196     0.0215    HELPS
    0.037     0.0370     0.0293     0.0319    HELPS
    0.050     0.0500     0.0518     0.0552    HURTS
    0.080     0.0800     0.1089     0.1253    HURTS

The nine-qubit code stops helping at $p \approx 0.037$ — far below the three-qubit code's 0.5. More qubits bought a worse crossover.

The prediction column explains it. A block of three suffers a phase flip if any of its three qubits gets a $Z$: $q = 3p - 3p^2 + p^3 \approx 3p$. The outer code then fails at $3q^2 - 2q^3$. So the logical error is roughly $3(3p)^2 = 27p^2$, and breakeven is at

$$27p^2 = p \quad\Longrightarrow\quad p = \tfrac{1}{27} \approx 0.0370$$

which is where the measurement puts it. The inner layer concentrates phase errors by a factor of three before the outer layer gets to correct them.

The $X$ direction is different again:

        p  unencoded   measured  predicted   verdict
    0.010     0.0100     0.0008     0.0009    HELPS
    0.050     0.0500     0.0212     0.0218    HELPS
    0.100     0.1000     0.0817     0.0840    HELPS

Here the inner code corrects, failing only on two-in-a-block at $3p^2 - 2p^3$, and three blocks each get a chance: $9p^2$, breakeven at $p = 1/9 \approx 0.111$. Three times better than the $Z$ direction.

🔬 Honest Assessment: "corrects any single-qubit error" is a distance claim, not a performance claim.

It tells you the code distance is 3. It does not tell you the code helps at your noise rate, and it does not tell you the code is symmetric. The Shor code's $Z$ breakeven (1/27) is three times worse than its $X$ breakeven (1/9), and both are far worse than the three-qubit code's 1/2.

Adding qubits does not monotonically improve anything. It improves the distance, which pays off only below the crossover — and the crossover moves as you add structure.

Two chapters, two versions of the same error: Chapter 21's Grover benchmarked against a strawman, and now a code benchmarked by its distance instead of its performance. Ask what the number is a claim about.


25.6 The stabilizer formalism

Writing lookup tables by hand does not scale to a code with 8 generators, let alone thousands. The field's actual language is the stabilizer formalism.

A stabilizer code is defined by a set of commuting Pauli operators. The codespace is their simultaneous $+1$ eigenspace:

$$S_i |\psi\rangle = +|\psi\rangle \quad \text{for every generator } S_i$$

   code                 n  generators   k   all generators commute?
   3-qubit bit-flip     3      2        1        True     ZZI, IZZ
   3-qubit phase-flip   3      2        1        True     XXI, IXX
   Shor [[9,1,3]]       9      8        1        True
   Steane [[7,1,3]]     7      6        1        True

$n$ qubits with $n-k$ independent commuting generators leaves a $2^k$-dimensional codespace — the $[[n,k,d]]$ notation, with $d$ the distance.

Commuting is the requirement that makes the whole thing work. Because the generators commute with each other, they can all be measured simultaneously. Because an error either commutes or anticommutes with each generator, the measurement outcomes form a classical bit string. And because the generators act trivially on the codespace, that bit string depends only on the error, never on the encoded state:

⚛️ The Physics Underneath: the syndrome is information about the error and nothing else.

$S_i$ fixes every codeword. So measuring $S_i$ on an uncorrupted codeword always returns $+1$ and disturbs nothing. On a corrupted one it returns $-1$ exactly when the error anticommutes with $S_i$.

The measurement extracts $n-k$ bits, and every one of them is about the error. Zero bits about $\alpha$ and $\beta$. That is why measuring a syndrome is safe and measuring a qubit is not, and it is the formal version of §25.1's "comparison without inspection."

The Steane $[[7,1,3]]$ code above is worth noticing: 7 qubits for distance 3, against Shor's 9. Both correct any single-qubit error. The stabilizer formalism is what lets you search for codes like that systematically instead of inventing them.

It also connects back to Chapter 11. Stabilizer circuits are Clifford circuits, and Clifford circuits are classically simulable in polynomial time by the Gottesman–Knill theorem. Every measurement of a repetition code in this chapter used Aer's stabilizer method for exactly that reason — it is why simulating a distance-9 code at 40,000 shots is instant.

★★ Why measuring a stabilizer does not collapse the logical state

The box above states the result. The derivation is three lines, and it is the single most important calculation in the field.

Let $|\psi\rangle$ be any codeword and $E$ any Pauli error. Every pair of Paulis either commutes or anticommutes, so for each generator there is a sign $\sigma_i \in \{+1,-1\}$ with $S_i E = \sigma_i E S_i$. Then

$$S_i\big(E|\psi\rangle\big) \;=\; \sigma_i\,E\,S_i|\psi\rangle \;=\; \sigma_i\,E|\psi\rangle$$

using $S_i|\psi\rangle = |\psi\rangle$ at the last step.

So $E|\psi\rangle$ is already an eigenvector of $S_i$, with eigenvalue $\sigma_i$. Three consequences follow immediately, and together they are the entire design:

  1. The measurement is deterministic. Measuring $S_i$ on $E|\psi\rangle$ returns $\sigma_i$ with probability 1. There is no randomness to average away and no shot noise in the syndrome itself.
  2. The measurement does not disturb. A projective measurement leaves an eigenstate of the measured observable untouched. The post-measurement state is $E|\psi\rangle$ — exactly what went in.
  3. The outcome depends on $E$ alone. $\sigma_i$ is fixed by the commutation relation between $S_i$ and $E$. $|\psi\rangle$ does not appear in it. Two different codewords corrupted by the same error give the same syndrome — which is §25.2's six identical rows, derived rather than measured.

📐 Math Aside: the syndrome measurement is coarse on purpose.

Why does a measurement that returns real information not collapse anything? Count dimensions.

Each generator is a Pauli with eigenvalues $\pm1$, so on $n$ qubits its $+1$ and $-1$ eigenspaces are each $2^{n-1}$-dimensional. Measuring it projects onto half the Hilbert space, not onto a ray. With $n-k$ generators the joint measurement lands in a $2^k$-dimensional subspace — for $k=1$, a subspace still containing a full qubit's worth of state.

Compare measuring the qubit itself: that projects onto a one-dimensional ray and destroys everything.

The syndrome measurement is deliberately blunt — sharp enough to name the error's coset, blunt enough never to reach inside it. Pauli errors on $n$ qubits carry $2n$ bits of information; the syndrome extracts $n-k$ of them and leaves the rest, which is where the logical information lives.

And the bluntness buys something the chapter has not yet used: it discretizes continuous errors. A real physical error is not a Pauli. It is some $E = c_0I + c_xX + c_yY + c_zZ$ — an over-rotation, a slow drift, a partial decay — and applied to a codeword it gives a superposition of differently corrupted states.

The syndrome measurement projects that superposition onto one syndrome subspace, collapsing $E|\psi\rangle$ onto a single Pauli-corrupted branch with probability $|c_j|^2$. The error becomes a Pauli because you measured the syndrome. This is why a code that handles $X$, $Y$ and $Z$ handles every single-qubit error including the continuum of small ones — and it is why §25.4's 54-injection test, which uses only Paulis, is a complete test rather than a sample of one.

Logical operators, and blindness by construction

The formalism also explains §25.3's blind spots — not as an experimental accident but as a structural fact readable straight off the generators.

A logical operator is a Pauli that commutes with every stabilizer but is not itself in the stabilizer group. It maps codewords to codewords, so the syndrome cannot see it; it changes the encoded state, so it matters. Check the candidates against the bit-flip code's generators $\{ZZI, IZZ\}$:

   operator   commutes with both   weight   status
     XII             False              1    detectable error
     XXX             True               3    logical X_L
     ZII             True               1    logical Z_L
     IZI             True               1    logical Z_L
     IIZ             True               1    logical Z_L
     ZZZ             True               3    logical Z_L
     YYY             True               3    logical Y_L

$X_L$ has weight 3. $Z_L$ has weight 1.

That single asymmetry is the whole of §25.4. A single $Z$ on any data qubit is already a logical operator: it commutes with both stabilizers, so the syndrome reads $(0,0)$, so the decoder applies no correction, so the logical phase flips and nothing anywhere in the circuit noticed. The code is not failing to correct a $Z$ error. It is failing to have one — in its own bookkeeping, a $Z$ on one qubit is not an error at all, it is a different codeword.

⚠️ Common Pitfall: the $d$ in $[[3,1,3]]$ is not the distance against everything.

Distance is defined as the minimum weight of a logical operator. For the bit-flip code that minimum is 1, achieved by $ZII$ — so the honest unrestricted label is $[[3,1,1]]$.

$[[3,1,3]]$ is the distance restricted to $X$ errors, the only channel the code was built for. It is a promise about one noise model, quoted without the noise model.

This is not pedantry. It is the gap between "corrects one error" and §25.4's measured 0.1346 against an unencoded 0.0500, and the arithmetic is visible in the table above: three weight-1 $Z_L$ operators means three independent chances per encoded qubit, hence $1-(1-p)^3 = 0.1426$.

Blindness is by construction, and it is mirrored. Conjugate the whole argument by Hadamards and the phase-flip code's $X_L$ has weight 1 while its $Z_L$ has weight 3 — which is why §25.3's grid is symmetric, and why the project module's blindness rule needs the code as an argument.

🔀 In Another Framework: stabilizer simulation elsewhere.

Every repetition-code measurement here runs on Aer's stabilizer method, Qiskit's Gottesman–Knill backend. The equivalents in this book's other frameworks, checked against the installed versions:

text Qiskit 2.5.1 AerSimulator(method="stabilizer") Cirq 1.7.0 cirq.CliffordSimulator, cirq.StabilizerSampler PennyLane 0.45.1 qml.device("default.clifford", wires=n)

All three exploit the same theorem for the same reason: a QEC circuit is Clifford, so its cost is polynomial rather than exponential in qubit count.

The field's own tools are neither. Stim is the standard simulator for large-scale QEC and PyMatching the standard minimum-weight-perfect-matching decoder; distance-25 surface codes at millions of shots are routine there and infeasible in a general-purpose simulator. Neither is installed in this book's environment, and nothing here was measured with them. If you are going past distance 9, or writing a decoder rather than a lookup table, that is where to go next.


25.7 Mid-circuit measurement and feedforward

The circuits so far corrected errors unitarily — Toffolis conditioned on ancilla states. Real hardware measures the syndrome and applies a classically-conditioned fix:

qc.measure(a[0], s[0]); qc.measure(a[1], s[1])    # MID-CIRCUIT
with qc.if_test((s, 0b01)): qc.x(d[0])            # FEEDFORWARD
with qc.if_test((s, 0b11)): qc.x(d[1])
with qc.if_test((s, 0b10)): qc.x(d[2])

The two approaches agree exactly:

      p   unitary correction   measure+feedforward   3p^2-2p^3
   0.01               0.0004                0.0004      0.0003
   0.05               0.0076                0.0076      0.0073
   0.10               0.0279                0.0279      0.0280
   0.20               0.1055                0.1055      0.1040

They are physically very different, though. Feedforward requires mid-circuit measurement and classical control fast enough to act inside the coherence time — read out an ancilla, decode, and apply a gate, all in microseconds, repeatedly, for the entire duration of the computation.

That control loop is a large part of why error correction is hard engineering and not only hard physics. It is also why the syndrome must be extracted repeatedly, not once: errors keep arriving, so the correction cycle runs continuously, and each cycle is itself an opportunity to introduce errors. Which is §25.9.

🗝️ Version Note: c_if is gone; if_test is the way.

Classically-conditioned gates used to be written by attaching a condition to a single instruction:

python qc.x(d[0]).c_if(s, 0b01) # removed in Qiskit 2.0

InstructionSet.c_if was removed in Qiskit 2.0. On the version everything here was measured with it is simply absent:

text qiskit 2.5.1 InstructionSet.c_if present: False QuantumCircuit.if_test present: True import qiskit.pulse: ModuleNotFoundError

The replacement is the if_test context manager used above, and it is strictly more capable: it takes blocks rather than single instructions, it nests, and it has an else branch. The same release removed qiskit.pulse entirely along with add_calibration, .calibrations, backend.defaults and instruction_schedule_map — Chapter 31 covers what replaced them.

QEC code written before 2024 will use c_if, and it will not run. This is the most common reason a published error-correction notebook fails on a current install.

Syndrome extraction is not free

Count what the correction machinery adds to a circuit whose only job is to hold a qubit still. Encode, wait, decode — against encode, wait, extract, correct, decode:

                          qubits   raw gate counts                     depth
   encode + decode             3   cx 4,  id 3                             6
   + syndrome + correct        5   cx 8,  x 4,  ccx 3,  id 3              16

and after decomposition into the one- and two-qubit gates hardware actually executes:

                          two-qubit gates   one-qubit gates   depth
   encode + decode                      4                 3       6
   + syndrome + correct                26                34      41

Protecting the qubit costs 22 extra two-qubit gates and multiplies the depth by nearly seven — 41 against 6. The Toffolis dominate: three ccx account for 18 of those 26 CNOTs, which is why exercise 25.33 asks what replacing them with feedforward does to the breakeven.

And note the qubit column. The $[[3,1,3]]$ label says $n = 3$, and §25.4's rate table uses that. The circuit needs five qubits at once — three data, two ancillas — because the syndrome has to be written somewhere. Ancillas can be reset and reused between rounds, which is why the rate convention counts only data qubits; but at any given instant the hardware is holding five, and a machine sized from a rate table will be short.

Every one of those 26 two-qubit gates has an error rate. That is §25.9.


25.8 The threshold

Now the concept the whole chapter builds toward. Extend the repetition code to distance $d$ and sweep the physical error rate:

        p        d=1        d=3        d=5        d=7        d=9
     0.01     0.0101     0.0004     0.0000     0.0000     0.0000
     0.05     0.0502     0.0076     0.0011     0.0003     0.0001
     0.10     0.0999     0.0279     0.0089     0.0027     0.0010
     0.20     0.2013     0.1055     0.0581     0.0337     0.0190
     0.30     0.3004     0.2191     0.1637     0.1265     0.0993
     0.40     0.3993     0.3568     0.3222     0.2939     0.2711
     0.45     0.4504     0.4293     0.4097     0.3953     0.3822
     0.50     0.4997     0.5046     0.5038     0.5018     0.5019   <-- THRESHOLD
     0.55     0.5499     0.5789     0.5972     0.6121     0.6241
     0.60     0.6005     0.6508     0.6867     0.7144     0.7377
     0.70     0.6986     0.7844     0.8408     0.8759     0.9033

Read it as a fan. Below $p = 0.5$ the curves fan downward — more qubits, lower logical error, and the gap widens as you add distance. Above $p = 0.5$ they fan upward — more qubits, higher logical error, and the gap widens the other way. At $p = 0.5$ every distance gives 0.5 and the curves cross.

That crossing point is the threshold, and it is the single most important number in fault tolerance:

⚛️ The Physics Underneath: the threshold theorem.

Below threshold, increasing the code distance suppresses the logical error rate exponentially, at a cost in qubits that is only polynomial. Any desired logical error rate is reachable by building a bigger code.

Above threshold, increasing the distance makes things worse. There is no size of code that helps. You are not slightly short of fault tolerance — you are on the wrong side of a phase transition, and no amount of engineering effort on code size will move you.

This is a threshold, not a slope. The question "is our hardware good enough for error correction?" has a yes-or-no answer, and it is the only question that matters.

The exponential suppression is visible directly. Define $\Lambda = P_L(d) / P_L(d+2)$, the factor by which two extra units of distance divide the logical error:

   p=0.01  Lambda(3->5)=  30.25   (5->7)=  28.83   (7->9)=  28.04
   p=0.05  Lambda(3->5)=   6.26   (5->7)=   5.98   (7->9)=   5.83
   p=0.10  Lambda(3->5)=   3.27   (5->7)=   3.14   (7->9)=   3.06
   p=0.20  Lambda(3->5)=   1.80   (5->7)=   1.74   (7->9)=   1.70

$\Lambda$ is roughly constant down each column. Every two units of distance divides the error by the same factor — which is what exponential suppression means, and it is the property that makes large-scale quantum computing conceivable at all.

Notice also that $\Lambda$ depends strongly on how far below threshold you are: 28× at $p = 0.01$, but only 1.7× at $p = 0.2$. Being barely below threshold is nearly as bad as being above it, because you need enormous distance to buy anything. Chapter 15's millions of physical qubits are the price of operating close to threshold rather than far below it.

Why the crossing is at exactly one half, for every distance at once

The fan does not merely cross near one half. Every curve passes through the same point, for a reason worth seeing.

📐 Math Aside: the binomial symmetry that fixes the threshold at 1/2.

A distance-$d$ repetition code fails when a majority of its $d$ qubits flip:

$$P_L(d,p) \;=\; \sum_{k>d/2}\binom{d}{k}p^k(1-p)^{d-k}$$

Set $p = \tfrac12$. Every term's $p^k(1-p)^{d-k}$ collapses to $2^{-d}$, so

$$P_L\!\left(d,\tfrac12\right) \;=\; 2^{-d}\sum_{k>d/2}\binom{d}{k}$$

For odd $d$ there is no central term, and $\binom{d}{k} = \binom{d}{d-k}$ splits the total $2^d$ into two equal halves:

$$\sum_{k>d/2}\binom{d}{k} = 2^{d-1} \quad\Longrightarrow\quad P_L\!\left(d,\tfrac12\right) = > \frac{2^{d-1}}{2^{d}} = \frac12 \quad\text{independently of } d$$

Evaluated exactly:

text d P_L(1/2) 1 0.500000 3 0.500000 5 0.500000 7 0.500000 9 0.500000 21 0.500000

Every curve passes through the point $(0.5, 0.5)$ — which is the measured row 0.4997 / 0.5046 / 0.5038 / 0.5018 / 0.5019, to within shot noise at 40,000 shots.

And the mechanism is worth naming, because it is what a threshold is. At $p = 1/2$ the error pattern is a uniformly random bit string, and a majority vote over uniformly random bits is a fair coin however many bits you take. Redundancy is worthless against noise that carries no signal. The threshold is the point where the syndrome stops containing information, and adding qubits past it only adds places for the noise to enter.

What Λ costs, in qubits

$\Lambda$ is a slope. What an engineer needs is a distance, and what a procurement decision needs is a qubit count. Both follow by arithmetic.

Each two units of distance divides the logical error by $\Lambda$, so reaching a target $P_L^\star$ from a starting point $P_L(d_0)$ takes

$$\Delta d \;=\; 2\,\frac{\log_{10}\!\big(P_L(d_0)/P_L^{\star}\big)}{\log_{10}\Lambda}$$

Work it against a concrete target. A computation of $10^{12}$ logical operations needs a logical error rate near $10^{-12}$ for the whole thing to survive, and Chapter 23's 2048-bit factoring is in that territory. Take a distance-7 patch reaching $10^{-3}$ as the starting point — nine orders of magnitude to find — and apply $2d^2$ physical qubits per logical qubit:

   Lambda   steps of +2   delta_d   final d   2d^2 physical qubits per logical
        2         29.90     59.79        67                            8,978
       10          9.00     18.00        25                            1,250

$\Lambda = 2$ costs 8,978 physical qubits per logical qubit. $\Lambda = 10$ costs 1,250 — 7.2× fewer. Same target, same code, same nine orders of magnitude. The only thing that changed is how far below threshold the hardware sits.

The first row is where Google's reported $\Lambda \approx 2$ puts us. The second is what a factor-of-a-few improvement in gate fidelity would buy. This is why hardware groups chase gate error rather than qubit count: qubit count is what you pay, and gate error is what sets the price. The starting point $10^{-3}$ at $d=7$ is an assumption, not a measurement — but the ratio between the two rows does not depend on it, because both rows travel the same nine orders of magnitude.

💰 Cost and Queue: fault tolerance is a session, not a job.

The 8,978-qubit figure is a static count. The dynamic cost is worse, and Chapter 39 measured the numbers that set it.

Syndrome extraction runs continuously for the whole duration of the computation — §25.7's control loop, closed once per round, forever. A round is a shallow layer of two-qubit gates plus a measurement, and Chapter 39's measured cz durations of 68–184 ns with measure at 1,560 ns put a round in the microsecond range. A one-second computation is therefore of order a million rounds, each emitting $d^2-1$ syndrome bits that must be decoded before the next few rounds elapse.

Chapter 39's other measurement is the one that stings. Submitting work as jobs rather than inside a session turned 120 VQE iterations from 5 minutes into 10 hours, and put device utilization at $2.31\times10^{-5}$ — a wall-clock overhead of 43,340× at a 5-minute queue.

A fault-tolerant computation cannot be a sequence of jobs. There is no point in the schedule where the state can sit in a queue, because it decays while it waits. Everything in this chapter presumes a machine held open and driven in real time — an operational requirement as demanding as the gate fidelity, and one that no pricing model in Chapter 39 is currently shaped for.


25.9 The threshold you actually face

Everything in §25.8 assumes perfect syndrome extraction — that the CNOTs and Toffolis measuring the syndrome are themselves noiseless. They are not. Those gates are made of the same hardware as everything else.

Give the syndrome-extraction gates a depolarizing error rate and hold the data error at $p = 0.01$:

   syndrome gate error   logical error   verdict
              0.0000            0.0002    HELPS
              0.0005            0.0016    HELPS
              0.0010            0.0034    HELPS
              0.0015            0.0047    HELPS
              0.0020            0.0058    HELPS
              0.0025            0.0080    HELPS
              0.0030            0.0092    HELPS
              0.0040            0.0122    HURTS
              0.0050            0.0159    HURTS
              0.0078            0.0238    HURTS

Breakeven is at a syndrome gate error of roughly 0.0035.

And now put Chapter 12's measurement beside it. The median two-qubit gate error measured on real IBM hardware was 0.0078 — the last row of that table. At that gate quality, the three-qubit code takes a physical error rate of 0.01 and produces a logical error rate of 0.0238.

🔬 Honest Assessment: with real measured gate errors, this code makes things 2.4× worse.

Not marginally worse. Not "close to breakeven." More than twice the error you started with, using three times the qubits.

The circuitry that fixes errors is made of the same gates that cause them. This is the entire reason quantum error correction is not deployed today, and it is why threshold numbers quoted for real codes (around $10^{-2}$ for the surface code, under favourable noise assumptions) are so much more demanding than §25.8's naive 0.5.

The three-qubit repetition code is a teaching device, not a candidate — it corrects one error type and §25.4 showed it amplifies the other. But the structure of the result is general: the real threshold is set by the quality of the syndrome-extraction circuit, and every real threshold calculation is a calculation about that circuit.

This is the sharpest form of a pattern running through the whole book. Chapter 13: mitigation costs shots, and can lose. Chapter 19: an ancilla that isn't uncomputed looks like decoherence. Chapter 24: mitigation at a fixed budget can make a variational result worse. The machinery you add to fix a problem is made of the same imperfect parts as the problem.

The shape of the break-even calculation

The number 0.0035 is specific to this code and this noise model. The shape of the calculation is not, and it is the calculation every real threshold estimate performs.

The benefit and the cost have different exponents.

  • Benefit is quadratic in the data error. The residual with perfect extraction is $3p_{\text{data}}^2 - 2p_{\text{data}}^3$. You have to lose two qubits to lose the qubit.
  • Cost is linear in the gate error. The correction block is 26 two-qubit gates run once, and a single one of them failing can produce a logical error directly. Nothing votes on the machinery.

So $P_L \approx 3p_{\text{data}}^2 + \kappa\,p_{\text{gate}}$, and break-even — $P_L = p_{\text{data}}$ — sits at

$$p_{\text{gate}}^{\star} \;=\; \frac{p_{\text{data}} - 3p_{\text{data}}^2}{\kappa}$$

$\kappa$ is recoverable from §25.9's own table. A least-squares fit to its ten rows gives

   logical error = 0.00014 + 3.054 * p_gate          (fit to the table above)
   break-even at logical = 0.0100:  p_gate = 0.00323

which sits inside the grid's bracket of $[0.0030,\,0.0040]$ and sharpens the midpoint quoted above — the grid could not resolve better than $\pm0.0005$. The slope is 3: about three of the correction block's gate failures per unit error rate reach the data qubits in a way the code cannot undo.

The formula then makes a prediction. For small $p_{\text{data}}$ the $3p^2$ term is negligible, so $p_{\text{gate}}^{\star} \approx p_{\text{data}}/\kappa$ — the gate quality you need scales linearly with the data error, at roughly one third of it. Measured by bisection across two decades:

     p_data   break-even p_gate   ratio
     0.0010             0.00027   0.274
     0.0050             0.00163   0.327
     0.0100             0.00325   0.325
     0.0200             0.00608   0.304
     0.0500             0.01397   0.279

The ratio holds between 0.27 and 0.33 across a fiftyfold range. The prediction survives.

And now the uncomfortable reading. Improving the qubits' idle error does not move you toward break-even — it moves the target down by the same factor. Halve $p_{\text{data}}$ and the gate error you need also halves. Crossing requires improving the ratio of gate error to idle error, which means improving gates specifically, not the device generally. That is a much narrower engineering instruction than "make the qubits better," and it is the actionable form of the result.

🔬 Honest Assessment: this is a property of this circuit, not a law.

The linear scaling above is measured for one code, one decoder, one noise model, one extraction circuit. What generalizes is the structure — benefit quadratic, cost linear — not the constant 0.3.

Published threshold calculations for the surface code run the same computation with a circuit-level noise model, a matching decoder, and many rounds, and land near $10^{-2}$. That number is better than this one not because the surface code corrects more cleverly, but because its extraction circuit is far cheaper per stabilizer: weight-4 and local, against this code's three Toffolis and depth 41. The threshold is a property of the extraction circuit, which is why §25.10's "weight-4 and local" is the surface code's real selling point and its threshold value is a consequence.

★ Where this conclusion flips: many rounds

§25.9's headline — 2.4× worse at measured gate quality — is a single-round result. One noise exposure, one extraction, one correction. Real error correction runs the loop continuously, and the accounting changes when it does.

Run $r$ rounds of (noise, extract, correct) with the ancillas reset between rounds, against an unencoded qubit exposed to the same per-round noise $r$ times. Data error 0.01, syndrome gate error 0.0078 — Chapter 12's measured median — at 40,000 shots:

   rounds   unencoded   encoded     delta   verdict
        1      0.0100    0.0238   +0.0137   HURTS
        2      0.0198    0.0310   +0.0112   HURTS
        3      0.0294    0.0389   +0.0095   HURTS
        4      0.0388    0.0457   +0.0069   HURTS
        5      0.0480    0.0529   +0.0049   HURTS
        6      0.0571    0.0597   +0.0027   HURTS
        7      0.0659    0.0668   +0.0009   HURTS
        8      0.0746    0.0730   -0.0017   HELPS
       10      0.0915    0.0866   -0.0048   HELPS
       12      0.1076    0.1002   -0.0074   HELPS

The code crosses over to helping between round 7 and round 8 — at exactly the gate error §25.9 just used to call it 2.4× worse.

The mechanism is a constant against a slope. Encoding pays a fixed entry cost: the first round's syndrome circuit contributes 0.0238 where the unencoded qubit has accumulated only 0.0100. After that the per-round increments differ:

   encoded, per additional round      about 0.0068
   unencoded, per additional round    about 0.0098, falling as it saturates

0.0068 against 0.0098. The code starts 0.0138 behind and gains about 0.0030 per round, so it recovers in roughly $0.0138/0.0030 \approx 4.6$ rounds past the first — which is where the measurement puts the crossing.

Two cautions, both load-bearing.

The crossing is at the edge of the shot noise. At 40,000 shots the standard error on a rate near 0.07 is about 0.0013, so round 7's $+0.0009$ and round 8's $-0.0017$ are each under 1.5 standard errors from zero. What is unambiguous is the trend: the gap marches monotonically from $+0.0137$ to $-0.0074$ across twelve rounds, which shot noise does not produce by accident. The crossing is real; the round number is bracketed at 7–8, not pinned.

And this is still the bit-flip code, in the direction it protects. §25.4's verdict is untouched — for an arbitrary state this code is worse than nothing at any number of rounds, because $Z_L$ has weight 1 and no quantity of correction rounds repairs a code that cannot see the error. The model also idealizes the ancilla reset as noiseless and gives the ancillas no idle error, both of which favour the encoded side.

⚠️ Common Pitfall: comparing a one-round encoded circuit against a one-round unencoded one.

The encoded circuit pays for its syndrome extraction immediately and then keeps paying per round; the unencoded circuit pays nothing up front and then accumulates. A single-round comparison measures the entry fee and reports it as the price.

The honest comparison fixes the duration of the storage rather than the number of rounds, and asks which arrangement holds the qubit better over that duration. The result above is a demonstration that the comparison is time-dependent — not a claim about any specific device.

The same trap runs the other way for a large code, where the entry fee is enormous and the amortization window is the whole computation. "Does encoding help?" is not answerable without saying for how long.


25.10 The surface code, and where the field actually is

The surface code is the leading candidate, and the reasons are practical rather than elegant:

  • It needs only nearest-neighbour connectivity on a 2D grid — which is exactly what Chapter 29's heavy-hex and grid topologies provide. A code requiring all-to-all connectivity would be unbuildable on current hardware regardless of its threshold.
  • Its threshold is around $10^{-2}$ under standard circuit-level noise models — high enough that current gate fidelities are in the neighbourhood, which is not true of most alternatives.
  • Its stabilizers are weight-4 and local, so syndrome extraction is a short, shallow, repeatable circuit — which §25.9 just showed is the thing that actually sets the threshold.

The cost is the part Chapter 15 measured: a distance-$d$ surface code uses roughly $2d^2$ physical qubits per logical qubit, so the qubit count scales as $d^2$ while the error suppression scales as $\Lambda^{d/2}$. That trade — polynomial cost, exponential benefit — is favourable, and it is still expensive enough to produce Chapter 15's estimates of millions of physical qubits for a useful computation.

Where 2d² comes from, and why weight-4 is the whole argument

The $2d^2$ figure is not an empirical fit. It falls out of the layout.

A rotated distance-$d$ surface code patch holds $d^2$ data qubits on a $d\times d$ grid, encoding $k=1$ logical qubit, so it needs $n-k = d^2-1$ stabilizer generators — and each generator needs its own measurement ancilla:

   d^2        data qubits
   d^2 - 1    weight-4 stabilizer generators, alternating X-type and Z-type
   d^2 - 1    measurement ancillas, one per generator
   ---------------------------------------------------
   2d^2 - 1   physical qubits, for k = 1

The factor of two is the ancillas. Half the chip is measurement apparatus. That is the surface code's version of §25.7's five-qubits-for-a-three-qubit-code, and it is why "an $n$-qubit machine" and "an $n$-data-qubit code" are different claims. At the distances §25.8's arithmetic produced:

   Lambda   distance   data qubits   ancillas   total 2d^2 - 1
        2         67         4,489      4,488          8,977
       10         25           625        624          1,249

Now the part that actually decides it. Each weight-4 stabilizer is measured by four CNOTs onto its ancilla, so a full round is $4(d^2-1)$ CNOTs — but every data qubit touches at most four plaquettes, so the round schedules into a constant number of layers regardless of $d$. The depth of a syndrome round does not grow with the code.

Compare what §25.7 measured for the three-qubit code: depth 41 in a decomposed basis, dominated by three Toffolis. The surface code has no Toffolis at all. Its decoding is classical post-processing on the accumulated syndrome record; the quantum circuit per round is CNOTs and measurements only. Shor's code, by contrast, has weight-6 $X$-type generators ($XXXXXXIII$) needing six CNOTs each and a longer schedule.

That is the surface code's real selling point, and §25.9 is why it is the selling point. The threshold is set by the extraction circuit. The surface code's threshold is high not because it corrects cleverly but because it asks for less — the shortest, shallowest, most local extraction circuit anyone has found that still admits a growing distance.

And the surface code is where Chapter 15's other finding bites. It supports Clifford gates naturally but not $T$ gates, which must be supplied by magic state distillation — the reason Chapter 15's resource estimates were dominated by $T$ count and why Chapter 22's rotationCount and rotationDepth mattered so much. The code that makes fault tolerance possible is also the code that makes $T$ gates expensive.

The factory share inverts with scale

Chapter 15 measured something about distillation that is easy to read backwards:

   small circuit:   T factories are 93% of the qubits
   large circuit:   T factories are  3% of the qubits

The factory share falls as the computation grows, and not because factories get cheaper. A factory is a fixed-size apparatus producing magic states at some rate, and it is reusable — one factory feeds $T$ gate after $T$ gate down a long circuit. A small computation needs a factory and few logical qubits, so the factory is everything. A large one needs a comparable number of factories against a data region that grows with the algorithm.

The consequence is a trap in resource estimation. A prototype-scale estimate is dominated by a term that will not dominate at scale, and a full-scale estimate is dominated by a term the prototype never showed you. Chapter 15's 450 → 2,882 cliff for one $T$ gate is the small-circuit regime: a 6.4× multiplier that is almost entirely factory. Reading it as the general cost of fault tolerance would be wrong in both directions at once.

📌 Version Note. Google reported below-threshold operation of a surface code in 2024 — a distance-7 logical qubit with a lower error rate than its best physical qubit, and a $\Lambda$ of roughly 2. That is a genuine landmark: it is the first demonstration that the fan in §25.8's table points downward on real hardware.

It is also $\Lambda \approx 2$, not 28. Compare §25.8's table: $\Lambda = 2$ corresponds to operating close to threshold, where each two units of distance buys a factor of two and reaching useful logical error rates requires very large $d$. Below threshold is the necessary condition, not the sufficient one. Check the current state of the art before quoting any of this — it is the fastest-moving number in the field.


25.11 What Part IV adds up to

Seven chapters of algorithms, and error correction is the load-bearing assumption under most of them.

Chapter 21's Grover offers a quadratic speedup. Chapter 21 §21.7 found the crossover is astronomically far away, and error correction is why: every logical operation costs thousands of physical ones, so a quadratic advantage has an enormous constant to overcome.

Chapter 23's Shor is the one algorithm in this book with a proven exponential advantage over the best known classical method. It needs about 20 million gates for a 2048-bit key, executed with a logical error rate low enough that they all succeed. §25.8 says that is achievable if the hardware is below threshold. §25.9 says it is not yet.

Chapter 24's VQE and QAOA exist precisely because error correction is not available. They are the answer to "what can you run on a machine with no error correction?" — and Chapter 24 found the answer includes a shot budget that defeats chemical accuracy before noise is even considered.

So the two halves of Part IV are the two halves of the field:

   ALGORITHMS THAT NEED FAULT TOLERANCE      ALGORITHMS THAT DO NOT
   Shor, phase estimation, Grover            VQE, QAOA
   proven advantage (Shor)                   no proven advantage
   need error correction to work             work now, on real hardware
   blocked on THIS CHAPTER                   blocked on the shot budget

Neither column has produced a useful computation that a classical computer could not do. The left column has the stronger theory and is waiting on hardware; the right column has the hardware and is waiting on theory. This chapter is about what the left column is waiting for, and it is a threshold — a yes-or-no condition, currently answered nearly.

What would have to be true

"Error correction is not ready" is a conclusion, not a plan. The measurements here make the conditions specific enough to check, so here they are as a list, each with the number that has to move.

   1. BELOW THRESHOLD, NOT NEAR IT
      Sec 25.8: Lambda = 28 at p=0.01 but 1.7 at p=0.2.
      Google's reported surface-code Lambda is about 2.
      NEEDED: Lambda around 5-10. Sec 25.8's arithmetic prices the gap --
      Lambda 2 -> 8,978 physical qubits per logical qubit; Lambda 10 -> 1,250.
      A 7.2x saving bought entirely with gate quality.

   2. SYNDROME EXTRACTION CHEAPER THAN THE ERRORS IT FINDS
      Sec 25.9: break-even at a gate error of 0.00323 for p_data = 0.01.
      Chapter 12 measured a median of 0.0078.
      NEEDED: a factor of about 2.4 in two-qubit gate error -- and the target
      moves down as idle error improves, so what must improve is the RATIO.

   3. A CONTROL LOOP THAT CLOSES INSIDE THE COHERENCE TIME
      Sec 25.7: measure, decode, condition, apply -- every round, forever.
      Chapter 39 measured measure = 1,560 ns and reset = 1,600-1,848 ns
      against T1 = 15.2-483.0 us.
      NEEDED: decoding faster than syndrome generation, at d^2-1 bits per
      round, sustained for the whole computation.

   4. QUBITS IN THE MILLIONS
      Sec 25.10: 2d^2 - 1 physical qubits per logical qubit.
      Chapter 15: one T gate takes 450 -> 2,882 physical qubits.
      Chapter 23: about 20 million gates to factor a 2048-bit key.
      NEEDED: the product of those, on one machine, held coherent and driven
      in real time -- Sec 25.8's session, not a queue of jobs.

   5. UNIFORMITY, WHICH NOBODY QUOTES
      Chapter 30 measured a factor of 9.6 between the best and worst two-qubit
      error on ONE chip (0.00750 to 0.07205). Chapter 39 found cz error
      running from 1.79e-03 to 1.00 -- dead links.
      NEEDED: a good median AND a tail that is not catastrophic.

Item 5 is the one this chapter can add that the others cannot, and it follows from §25.6. A code is limited by its weakest path, not its median one, because a logical operator only has to find a single low-weight route through the lattice. Every estimate above uses median gate errors; Chapter 30's factor of 9.6 across one chip and Chapter 39's dead links say the median is not the number a code experiences.

🔬 Honest Assessment: what this chapter does and does not establish.

It establishes, by measurement: that a repetition code follows $3p^2-2p^3$ to four decimal places; that the crossover is exactly $1/2$ for every odd distance, by binomial symmetry; that logical error falls exponentially in distance with a constant $\Lambda$; that a code correcting one error type amplifies the other by exactly the factor its weight-1 logical operators predict; that the Shor code corrects all 54 single-qubit Paulis and still has a worse break-even than a three-qubit code; and that with extraction gates at Chapter 12's measured quality this code is 2.4× worse than nothing in one round, crossing to better somewhere past round 7.

It does not establish anything about the surface code by measurement. Every surface-code number here — the $10^{-2}$ threshold, $2d^2$, $\Lambda \approx 2$ — is quoted from the literature or derived from the layout. None was run. Nothing in this book's environment can simulate a distance-25 circuit-level-noise experiment; that is what Stim exists for, and it is not installed here.

And it does not establish that error correction will not work. Every measurement says the same narrower thing: the conditions are specific, they are numbers, and today's hardware does not meet them. That is a claim about 2026 — and the fastest-moving number on the list is the one Google already moved.

Part V turns to the engineering that the last four chapters kept demanding and never got: debugging programs whose intermediate states you cannot inspect, testing them so that a run which cannot fail is caught before it reaches a slide deck, optimizing circuits, writing hardware-aware code, benchmarking honestly, and — at the bottom of the stack — controlling the pulses the gates are made of. Which is where §25.9's syndrome-extraction fidelity is ultimately won.


What we measured

  • The three-qubit bit-flip code follows $3p^2 - 2p^3$ exactly, with a crossover at $p = 0.5$. Above it, the code adds error: 0.6494 against 0.6000 at $p = 0.6$.
  • A phase-flip test storing $|+\rangle$ reported 0.0000 logical error at every noise rate including 0.6, because the decoded logical error is an $X$ and $X|+\rangle = |+\rangle$. A QEC test must store both logical basis states.
  • Each three-qubit code is worse than no encoding for arbitrary states: worst case 0.1346 against an unencoded 0.0500 at $p = 0.05$, because three qubits give three chances at the error type the code does not correct.
  • The Shor code corrects 54 of 54 single-qubit Pauli injections exactly. But under independent noise its breakeven is $1/27 \approx 0.037$ for $Z$ and $1/9 \approx 0.111$ for $X$ — worse than the three-qubit code's 0.5, and asymmetric.
  • Repetition codes at $d = 1,3,5,7,9$ fan downward below $p = 0.5$ and upward above it, crossing at the threshold. Below it, $\Lambda = P_L(d)/P_L(d{+}2)$ is constant: 28× at $p=0.01$, 1.7× at $p=0.2$.
  • With noisy syndrome extraction at $p_{\text{data}} = 0.01$, breakeven is a gate error of about 0.0035. At Chapter 12's measured median of 0.0078, the code produces 0.02382.4× worse than doing nothing.
  • Mid-circuit measurement with feedforward and unitary correction agree to four decimal places.
  • The transpiler deletes the id noise slots at every optimization level above 0, and the default is not 0. The resulting circuit reports 0.0000 logical error at every $p$ including 0.60 — a perfectly reproducible measurement of a noiseless circuit.
  • The syndrome distribution is identical to four decimal places across six different encoded states (spread 0.0000), and matches $P(00) = (1-p)^3+p^3 = 0.730$, $P(\text{each other}) = p(1-p) = 0.090$. Syndrome $(0,0)$ means "no error OR all three" — the trivial syndrome is not a clean bill.
  • Tracing out two qubits of $\alpha|000\rangle+\beta|111\rangle$ leaves zero coherence and non-zero populations: purity 0.82 at $|\alpha|^2 = 0.9$, 0.50 at $|\alpha|^2 = 0.5$. Not a copy.
  • The bit-flip code's $Z_L$ has weight 1 and its $X_L$ weight 3, so its unrestricted distance is 1, not 3 — the structural reason for the 0.1346.
  • Under a depolarizing channel rather than a single Pauli, the verdict is unchanged: at $\lambda=0.10$, 0.0079 for $|0_L\rangle$ and 0.1371 for $|+_L\rangle$ against an unencoded 0.0500, matching $\tfrac12(1-(1-\lambda)^3)$ to within shot noise.
  • Syndrome extraction costs 22 extra two-qubit gates (4 → 26), depth 6 → 41, and five qubits not three.
  • The break-even gate error scales linearly with the data error at a ratio of 0.27–0.33 across a fiftyfold range; a least-squares fit gives $P_L = 0.00014 + 3.054\,p_{\text{gate}}$ and a break-even of 0.00323 at $p_{\text{data}} = 0.01$.
  • ★ Over repeated rounds at Chapter 12's measured gate error, the same code crosses over from hurting to helping between round 7 and round 8 — the single-round verdict measures the entry fee, not the price.
  • $P_L(d, 1/2) = 1/2$ exactly, for every odd $d$, by binomial symmetry — so all five curves pass through one point rather than merely crossing near it.
  • At $\Lambda = 2$, reaching $10^{-12}$ from $10^{-3}$ needs distance 67 and 8,978 physical qubits per logical qubit; at $\Lambda = 10$, distance 25 and 1,250 — a 7.2× saving bought with gate quality alone.

The theme: the machinery that fixes errors is built from the same imperfect parts that cause them — and a code's distance is a claim about one error, not about your noise.