This quantum error correction tutorial gives you a practical path from a small repetition-code experiment to stabilizer and surface-code studies. You will compare code overhead, correctable errors, circuit depth, decoder needs, and simulator suitability, then define a repeatable test for whether encoding actually lowers the logical error rate.
Overview
Quantum error correction (QEC) protects a logical qubit by distributing its information across several physical qubits. Instead of measuring the logical state directly, a circuit measures syndromes: parity-like values that reveal which error pattern occurred without revealing the encoded information itself. A decoder uses those syndromes to choose a correction or estimate the most likely logical state.
The right first code depends on your goal. A repetition code is the clearest introduction to encoding, syndrome extraction, and majority-vote decoding. Bit-flip and phase-flip demonstrations isolate two important error types. Shor's code shows how a larger stabilizer construction can protect against an arbitrary single-qubit error, while a surface-code demonstration introduces local checks, increasing code distance, and a separate decoder workflow.
These examples should be treated as learning and benchmarking tools, not as production fault-tolerant implementations. Results depend heavily on the noise model, gate ordering, measurement errors, connectivity assumptions, decoder, number of shots, and simulator configuration. Always compare an encoded circuit with a carefully matched unencoded baseline.
| Code or workflow | Qubit overhead | Typical demonstration | Correctable errors | Circuit and decoder considerations |
|---|---|---|---|---|
| Three-qubit repetition | Three physical qubits for one logical qubit | Encode, extract two parity syndromes, apply majority vote | One bit-flip error in the ideal code model | Short circuit; decoder can be a lookup table or majority vote; suitable for basic state-vector and shot-based noise simulations |
| Bit-flip code | Three physical qubits | Protection against X-type errors | One bit flip, assuming at most one relevant error | Simple parity checks; does not protect against phase flips |
| Phase-flip code | Three physical qubits with basis-changing operations | Convert Z-type errors into an equivalent bit-flip problem | One phase flip, under the idealized model | Requires basis changes; useful for testing whether the noise model matches the code's protection |
| Shor code | Nine physical qubits for one logical qubit | Combine phase- and bit-flip repetition structures | One arbitrary single-qubit Pauli error in the idealized construction | More encoding and syndrome circuits; decoder is usually a structured lookup or stabilizer procedure |
| Surface-code demonstration | Grows with code distance and layout | Measure local stabilizers on a two-dimensional lattice | Protection improves with distance under suitable physical-noise and decoding assumptions | Requires repeated syndrome rounds, connectivity assumptions, and a decoder; best for dedicated stabilizer or circuit-noise studies |
The table is a planning guide rather than a universal performance ranking. A larger code can perform worse than a smaller one when additional gates, measurement operations, idle time, or poor connectivity introduce more noise than the code removes.
What to track
1. Define the logical experiment
Start with a narrowly defined logical task. For a repetition-code tutorial, prepare a logical zero or one, encode it, inject a controlled error on one physical qubit, extract the syndrome, decode, and measure the logical result. To study phase errors, prepare a state that makes phase behavior observable or apply basis changes around the same repetition structure.
Record the logical input, physical qubit count, circuit depth, two-qubit gate count, measurement count, shot count, noise model, random seed where supported, and decoder version or configuration. These fields make later comparisons meaningful. A reproducible experiment setup can also help you separate a code change from an environment or simulator change; see the reproducible quantum experiment setup guide.
2. Track encoding and syndrome extraction separately
Do not report only the final logical error rate. Measure at least three stages:
- Preparation error: the baseline error before encoding, if the experiment includes state preparation.
- Encoding and storage error: the error introduced while creating and holding the code block.
- Syndrome and recovery error: the additional error caused by parity checks, ancillas, corrections, and final measurement.
This breakdown explains why an encoded result may fail to improve even when the code logic is correct. For example, a noisy syndrome circuit can create errors while attempting to detect them.
3. Build the circuit in four explicit phases
- Encoding: place the logical state in a designated data qubit and use entangling operations to create the code word. For the three-qubit bit-flip repetition code, the logical zero and one are represented by three matching computational-basis values.
- Syndrome extraction: compare neighboring data qubits with parity checks. In a circuit model, ancilla qubits can collect parity information through controlled operations and then be measured. Keep ancillas separate from data qubits so the measurement record is unambiguous.
- Decoding: map the syndrome to a likely error location. For a three-qubit repetition code, two parity results identify whether the first, second, or third data qubit disagrees with the others. A no-error syndrome leads to no correction.
- Logical measurement: measure the recovered block and apply a defined interpretation, such as majority vote. Compare that logical result with the intended input rather than counting every physical measurement independently.
4. Measure logical and physical error rates
For a chosen experiment, estimate the physical error rate from a matched unencoded circuit and the logical error rate from the decoded output. A simple estimate is:
error rate = incorrect logical outcomes / total shots
Use the same input distribution, shot budget, noise assumptions, and measurement convention for both cases. Report uncertainty or at least the number of incorrect outcomes and total shots; a small difference can be inconclusive when the sample is small.
For a surface-code study, repeat this measurement across code distances and, when relevant, across several syndrome rounds. Track logical error per round, total circuit depth, data and ancilla qubits, stabilizer-check schedule, decoder latency or runtime, and the fraction of shots with an unresolved or invalid syndrome.
Cadence and checkpoints
Run a baseline checkpoint whenever you change one variable. A useful sequence is:
- Ideal checkpoint: run the encoding, syndrome, decoding, and measurement circuit without noise. Any logical failures here usually indicate a circuit, bit-order, or decoder mismatch.
- Single-error checkpoint: inject one known X, Z, or Y error at a chosen location. Confirm that the code is expected to correct that error under the selected construction.
- Stochastic-noise checkpoint: apply a documented noise model and compare encoded and unencoded circuits. Keep gate and measurement assumptions visible.
- Scaling checkpoint: increase code distance, syndrome rounds, or physical error probability one step at a time. Do not change the decoder and code layout simultaneously unless the purpose is an integration test.
- Portability checkpoint: when moving between SDKs or backends, compare transpiled operations, qubit mapping, measurement order, and supported noise channels before comparing results.
For active development, run the ideal and single-error checks in continuous integration. Repeat stochastic benchmarks monthly or quarterly, or whenever a simulator, decoder, circuit-construction utility, backend target, or connectivity assumption changes. Resource estimates should be recorded alongside results; the quantum resource estimation worksheet provides a useful companion for this inventory.
How to interpret changes
An encoded circuit improves reliability only when its logical error rate is lower than the matched physical or unencoded baseline. If the result gets worse, check the following before concluding that the code is ineffective:
- Noise mismatch: a bit-flip code cannot be expected to correct a dominant phase-flip channel. A mixed X, Y, and Z model may require a broader code.
- Gate overhead: encoding and syndrome extraction add operations. Under a gate-noise model, those operations may outweigh the benefit of correction.
- Measurement errors: a wrong syndrome can cause an incorrect recovery. Include measurement noise when the goal is a realistic workflow test.
- Decoder errors: verify syndrome bit ordering, stabilizer conventions, tie handling, and the mapping from syndrome to correction.
- Connectivity and routing: inserted swaps or longer interaction paths change the actual circuit. Compare the logical circuit with the executed or transpiled circuit.
- Insufficient sampling: preserve shot counts and rerun with a larger budget before treating a small difference as a trend.
Use a logical-error-rate plot only after confirming these controls. For surface codes, inspect the trend across distance rather than relying on one point. A useful study records both benefit and cost: logical error rate, physical error assumptions, qubit count, depth, syndrome rounds, decoder workload, and execution time or shot budget.
QEC is distinct from error mitigation. Mitigation estimates or suppresses noise effects without encoding a logical qubit and performing syndrome-based recovery. If your experiment uses extrapolation, readout correction, or probabilistic techniques instead of a code block, classify it separately and document the distinction. The error mitigation comparison can help maintain that boundary.
When to revisit
Revisit this tutorial whenever your code, decoder, noise model, simulator, or target hardware changes. A quarterly review is a sensible default for a maintained educational repository, while a monthly review is appropriate during active development. The review does not need to rewrite every explanation; it should rerun the checkpoints and update assumptions that affect reproducibility.
At each review, confirm that the code-construction utilities still produce the intended stabilizers, the simulator still applies the documented noise channels, and the decoder still interprets syndrome bits in the same order. Recheck hardware connectivity and routing assumptions before presenting any hardware-oriented result. Update examples when an SDK changes measurement conventions, circuit interfaces, noise-model configuration, or decoder integration.
Use this practical checklist:
- Run an ideal circuit and verify zero logical failures.
- Inject each error type the demonstration claims to correct.
- Compare encoded and unencoded circuits with matched shots and noise.
- Record qubit count, depth, gates, syndrome rounds, decoder settings, and seed information.
- Repeat the benchmark after changing code distance or backend mapping.
- Save raw counts and metadata, not only a plotted error rate.
Start with the three-qubit repetition workflow, make its decoder and measurements transparent, and only then move to Shor or surface-code experiments. That progression turns quantum error correction from an abstract stabilizer topic into a testable programming workflow—and gives you a reliable baseline for every later code comparison.