Surface Code (Distance-3)
Known limitation (October 2026): this demo's
circuit.pyputs the X and Z checks on the same four plaquettes, where four X/Z pairs anticommute, and starts from |0...0⟩, so its syndromes are mostly random: all eight checks read trivial in under 0.5% of shots with no error (0.37% in an 8,192-shot simulator run), and an X error on d4 gives Z syndrome 1111 in about 6% of shots. The stabilizer layout described on this page is a valid distance-3 rotated surface code, checked in simulation; the demo shows the measurement pattern, not working error detection. A corrected version is planned.
Overview
The surface code is a topological quantum error correcting code and the leading candidate for practical fault-tolerant quantum computing. It uses a 2D lattice of qubits with only nearest-neighbor interactions and has an error threshold of ~1%, achievable with today's hardware. In 2023 Google showed a distance-5 surface code slightly outperforming distance 3, and in 2024 it reported below-threshold operation up to distance 7 on its Willow processor.
This demo uses the qubit budget of a distance-3 rotated surface code: 9 data qubits + 8 ancilla = 17 total qubits.
Why Surface Code?
| Property | Advantage |
|---|---|
| Error threshold | ~1% (achievable with current superconducting and ion-trap hardware) |
| Gate locality | Only nearest-neighbor CX gates (maps directly to 2D chip layout) |
| Scalable | Increase distance d to exponentially suppress logical error rate |
| Simple stabilizers | Weight-4 checks in the bulk and weight-2 checks on the boundary (no complex multi-qubit gates) |
| Industry consensus | Google, IBM, Quantinuum, and others all pursuing surface-code-based architectures |
2D Lattice Layout (Distance-3)
CODEData qubits (d): vertices Ancillae: one per check (faces and boundary edges) X_2 (d1 d2) d0 ──── d1 ──── d2 │ X_0 │ Z_0 │ d3 ──── d4 ──── d5 │ Z_1 │ X_1 │ d6 ──── d7 ──── d8 X_3 (d6 d7) Left edge: Z_2 (d0 d3) Right edge: Z_3 (d5 d8) Faces: weight-4 checks, X and Z alternating like a checkerboard Boundary: weight-2 checks, X on the top and bottom edges, Z on the left and right
Stabilizers
In this rotated layout both kinds of check sit on faces or boundary edges of the grid; the names "star" and "plaquette" come from the original, unrotated surface code lattice. Every X check shares an even number of qubits (0 or 2) with every Z check, so all eight checks commute, and the eight independent checks on 9 data qubits leave exactly one logical qubit with distance 3.
X Stabilizers (Stars) — Detect Z Errors
| Stabilizer | Data Qubits | Operator |
|---|---|---|
| X_0 | d0, d1, d3, d4 | X_0 X_1 X_3 X_4 |
| X_1 | d4, d5, d7, d8 | X_4 X_5 X_7 X_8 |
| X_2 | d1, d2 (top edge) | X_1 X_2 |
| X_3 | d6, d7 (bottom edge) | X_6 X_7 |
Z Stabilizers (Plaquettes) — Detect X Errors
| Stabilizer | Data Qubits | Operator |
|---|---|---|
| Z_0 | d1, d2, d4, d5 | Z_1 Z_2 Z_4 Z_5 |
| Z_1 | d3, d4, d6, d7 | Z_3 Z_4 Z_6 Z_7 |
| Z_2 | d0, d3 (left edge) | Z_0 Z_3 |
| Z_3 | d5, d8 (right edge) | Z_5 Z_8 |
Key Property: Central Qubit
The central qubit d4 is in all four weight-4 stabilizers (X_0, X_1, Z_0, Z_1) and in none of the boundary checks. An X error on d4 flips the two Z-type checks around it (Z_0 and Z_1), a pattern no other single X error produces.
Error Detection
| X Syndrome | Z Syndrome | Interpretation |
|---|---|---|
| 0000 | 0000 | No error |
| 0000 | non-zero | X error detected (Z stabilizers triggered) |
| non-zero | 0000 | Z error detected (X stabilizers triggered) |
| non-zero | non-zero | Y error (both types triggered) |
This table assumes the data qubits are already in the code space. Starting from |0...0⟩, the Z checks read trivial but the X checks come out random in the first round; that round projects the state into the code space, and later rounds detect errors as changes from it (simulated with the layout above: an X on d4 between two rounds flips exactly Z_0 and Z_1).
Logical Operators
- Logical X: Chain of X operators spanning top to bottom (e.g., X_0 X_3 X_6)
- Logical Z: Chain of Z operators spanning left to right (e.g., Z_0 Z_1 Z_2)
- Logical measurement: Determined by boundary conditions
Error Threshold
The surface code can correct errors if the physical error rate satisfies:
p_physical < p_threshold ~ 1%
Below threshold, the logical error rate scales as:
p_logical ~ (p_physical / p_threshold)^((d+1)/2)
Each increase in distance d provides exponential suppression of logical errors.
Scaling with Distance
| Distance d | Data Qubits | Ancilla Qubits | Total Qubits | Logical Error Suppression |
|---|---|---|---|---|
| 3 | 9 | 8 | 17 | baseline |
| 5 | 25 | 24 | 49 | ~Λ times better (Λ = p_th/p; Google measured Λ ≈ 2.1 in 2024) |
| 7 | 49 | 48 | 97 | ~Λ² times better |
| d | d^2 | d^2 - 1 | 2d^2 - 1 | ~(p/p_th)^((d+1)/2) |
Decoding
The surface code requires a classical decoder to interpret syndromes and choose corrections:
- MWPM (Minimum-Weight Perfect Matching): Standard, near-optimal, O(n^3)
- Union-Find: Faster (almost linear time), slightly suboptimal
- Neural Network: Emerging approach, can adapt to hardware-specific noise
Running the Circuit
PYTHONfrom circuit import run_circuit, verify_surface_code # Note: the current circuit.py uses non-commuting checks and starts from # |0...0>, so syndromes are mostly random (see the limitation at the top). # It shows the measurement pattern, not working error detection. # No error: prints a trivial syndrome rate under 0.5% result = run_circuit() print(f"Trivial syndrome rate: {result['trivial_syndrome_rate']:.2%}") # X error on qubit 4 (center): the most frequent Z syndrome varies from run to run result = run_circuit(error_type='X', error_qubit=4) print(f"Z syndrome: {max(result['z_syndrome_counts'], key=result['z_syndrome_counts'].get)}") # Full verification v = verify_surface_code() for check in v["checks"]: print(f"[{'PASS' if check['passed'] else 'FAIL'}] {check['name']}")
Hardware Progress
| Organization | Milestone | Year |
|---|---|---|
| d=5 slightly outperforms d=3 on Sycamore (Nature 614) | 2023 | |
| Below threshold, d=3 to d=7 on Willow (Nature 638) | 2024 | |
| IBM | Heavy-hex variant on Eagle/Heron processors | 2023-24 |
| Quantinuum | Ion-trap surface code demonstrations | 2023-24 |
| QuEra | Neutral atom surface code experiments | 2024 |
Code Properties
| Property | Value |
|---|---|
| Notation | [[9, 1, 3]] (distance-3) |
| Data qubits | 9 |
| Ancilla qubits | 8 |
| Total qubits | 17 |
| Error threshold | ~1% |
| Gate locality | Nearest-neighbor only |
| Topology | 2D planar |
| Decoder | MWPM, Union-Find, or neural |