Running a Surface Code Cycle on a Simulator
> Prerequisites: posts 055 (surface code board and threshold), 054 (stabilizers — checking for damage, not content), 051 (error rates), 091 (simulator workflow). > Next up: 096, "Measurement Also Lies: Readout Error Mitigation."
A robot vacuum patrols every day: sweep → spot dirt → clean → return to dock → repeat. The surface code's error-correction cycle is the same patrol routine: read the sentinels → compare for anomalies → infer the error → apply the fix — then start over immediately, forever.
Post 055 drew the board, post 054 explained the sentinel principle — this post assembles both into a patrol machine you can run yourself: on a simulator, the minimal d=3 board (9 data qubits + 8 stabilizer sentinels) runs one complete cycle, followed by three experiments.
The Four Steps of a Cycle
Step 1: Run the business. The logical qubit does its job (in these experiments, simply "quietly holding a memory state" — the plainest workload).
Step 2: Read the sentinels. Each of the 8 stabilizers is measured via an ancilla qubit (post 054's "check for injury, not content" — parity is measured, logical information is never touched). This reads out an 8-bit string of 0/1s — the syndrome: the board's anomaly report.
Step 3: Decode. Syndrome → error locations. Post 055 said errors form "chains" and stabilizers alarm at the chain's two ends. The decoder's plain-language job: find the shortest chain that explains all the alarms (like locating a sound by ear: both ears ring, so the source is in the middle). A minimum-weight matching decoder does exactly this.
Step 4: Apply the fix. Apply a correction at the inferred error locations — in practice this is often software bookkeeping (a note in the "frame," cancelled out at later readout), without physically touching the qubits.
The four steps run back-to-back, then start over from the top — the patrol is continuous; a single round would miss paired errors spanning rounds.
Experiment 1: A Clean Board
No noise, one cycle: all-zero syndrome — all 8 sentinel lights green. Baseline established.
Experiment 2: Inject One Error
Manually inject an X error on one data qubit (post 020's switch), then run one round: exactly two adjacent stabilizers alarm (two 1s in the syndrome string) — post 055's "one error lights two lamps" live: a chain has two endpoints, and each sentinel sees half. Move the injected error to the center of the board, and the two lit lamps shift accordingly — the pattern of lit sentinels is the location information, and that's precisely what the decoder consumes.
(The same experiment with a Z error: a different set of sentinels alarms — X-type and Z-type stabilizers each mind their own turf, post 055's "two patrols" in action.)
Experiment 3: Continuous Patrol and the Threshold, Live
The final experiment puts the whole series' promise on the table:
Setup: run 1000 cycles, injecting random errors each round at some physical error rate (simulating a real machine); measure the logical error rate (fraction of rounds where the logical qubit is still wrong after the patrol).
Result 1 (benefit below threshold): at a 0.5% physical error rate, the d=3 logical error rate is below the physical value — the patrol pays off; raising d to 5 drops the logical error rate by another order of magnitude — post 055's "bigger code gets better," live.
Result 2 (worsening above threshold): push the physical error rate past threshold (~1%), and larger d makes things worse — the sentinels themselves generate errors, and the bigger the board, the more overwhelmed the patrol — post 055's "threshold theorem" turned from formula into a visible curve kink.
Result 3 (the speed requirement): on real hardware each cycle must finish in microseconds (post 051: errors arise on microsecond timescales) — the patrol must outrun contamination for the board to stay clean (the same logic as post 083's "drainage must exceed inflow"). In a simulator, decoding can take its time; on real hardware the decoder is dedicated real-time hardware — one of the limits of "simulator first."
Tearing Down the Analogy
Where the robot vacuum analogy breaks:
- Disanalogy 1: a vacuum "sees" the dirt itself (optical imaging); a surface code sees only traces of the dirt (parity anomalies) — sentinels never report "which qubit is wrong," only "which two lamps are lit." Decoding is inference, not observation — position is inferred from traces, always mediated by the decoder's judgment (which can also guess wrong).
- Disanalogy 2: one vacuum pass means one pass of cleanliness; a surface code's "clean" holds only while patrol speed > contamination speed — cleanliness is not a state but a dynamically enforced equilibrium.
What to Take Away
1. The four-step cycle: read sentinels → compare anomalies (syndrome) → infer (shortest-chain decoding) → fix (often software bookkeeping) — then loop forever; clean is a dynamic equilibrium, not a one-shot state. 2. Two-lamp localization: one error lights adjacent sentinels — the syndrome's "lighting pattern" is all the decoder's raw material; X and Z each have their own sentinel groups. 3. The threshold, live (experiment-class perspective, Nov 2026): below threshold, bigger codes win; above, they lose — post 055's formulas can be plotted by hand in a simulator overnight; real-machine patrols need microsecond cycles with dedicated decoding hardware.
Hook for the next stop: the patrol is done, but there's a subtler lie — measurement itself lies: what fraction of read-out 0s are actually 1s? Measuring, modeling, and mitigating readout error in 096, "Measurement Also Lies: Readout Error Mitigation."
*(Hashtags in original: quantum computing / from coins to error correction / surface code / error correction in practice.)*