Skip to content
Tushar Pandey

Step 2 of 8

Lesson 1: A surface code patch

Quantum Error Correction in Practice, part 1: Errors and decoding

Read

Nine physical qubits in a 3 by 3 grid hold one logical qubit. An encoder spreads |0⟩ over all nine, and eight checks (four X, four Z) watch for errors. Pick an error next to the Play button to see which checks fire.

Patches and gate layers

X check Z check fired undetermined gate XL, ZL = +1

What this lesson shows

The patch is nine data qubits in a 3 by 3 grid, watched by eight checks: four X and four Z. The encoder takes eight steps. Two CNOTs copy q0 along the top row, H makes q4, q5, q6 and q7 the sources of the X checks, and their CNOTs fan out until all eight checks hold and the patch is |0⟩⁠L.

An injected error strikes right after encoding. An X error fires the Z checks that share its qubit, a Z error fires the X checks, and a Y error fires both. The page looks the Z syndrome up in a table of single errors and applies X to the qubit it names. A Z error cannot change a Z readout, so here it is harmless.

Things to try

  • Pick X on q4 in the Inject an error menu and press Play. Two Z checks fire, and the table points back at q4.
  • Pick X on q6. Only one Z check fires and the table applies X to q3 instead; X on q3 and q6 is itself an X check, so nothing logical changes.
  • Pick Z on q4: two X checks fire and the Z readout stays correct.
  • Drag the slider, or click a block in the strip, to stop on any step.

The ideal logical circuit

Step by step

  1. encode A. CNOT q0 → q1 starts copying q0 along the top row. H on q4, q5, q6, q7 makes them the sources of the X checks.
  2. encode A. CNOT q0 → q2 finishes the copy. Had q0 been |1⟩, the top row would now carry X on all three qubits: that is X⁠L, the logical flip.
  3. encode A. The sources fan out: CNOT q4 → q0, q5 → q2.
  4. encode A. The sources fan out: CNOT q4 → q1, q7 → q0.
  5. encode A. The sources fan out: CNOT q4 → q3, q7 → q1.
  6. encode A. The sources fan out: CNOT q6 → q3, q7 → q2.
  7. encode A. The sources fan out: CNOT q7 → q3.
  8. encode A. CNOT q7 → q8 completes the fan-out: all eight checks hold and A is |0⟩⁠L. Whatever state q0 starts in, the encoder makes it the logical state.
  9. measure. Every qubit is measured in Z. Only the checks that are Z parities can still be read.

Results

How to read this table

Every shot ends with all data qubits measured, and the checks are worked out from those bits. Clean shots only gives the rate over the shots in which no check fired. Corrected by the code is the share of shots in which checks fired and a table of single errors named a qubit to flip back; After correction is the rate over all kept shots once that flip is made. Discarded by the checks is the share of shots whose fired checks are not in the table at all: those shots are dropped. No correction reads the raw bits of every shot. Bare qubits runs the same logical circuit with one unprotected qubit in place of each patch: no encoder and no checks. Each rate comes with one binomial standard error.

Why the code loses here: the noise in this simulation acts only on gates, as the line under the table says. The bare row reads a qubit left in |0⟩ with no gate acting on it, so no noise reaches it: it is a trivial control, not a fair rival. The patch goes through the twelve CNOTs of the encoder, and one faulty CNOT can leave errors on two qubits that the table of single errors then completes into a logical flip. The encoder is not fault tolerant: in the course's own stabilizer simulator, 44 of the 180 ways a single CNOT of the lesson 1 encoder can fail (each of its 12 CNOTs followed by one of the 15 two-qubit Pauli errors) end in a wrong logical readout after the table's correction.

Cite this lesson T. Pandey, "Lesson 1: A surface code patch", Quantum Error Correction in Practice (2026), https://pandey-tushar.com/qec-in-practice/lesson-1.html