Computing Library › Worked Examples
Worked Examples

One Surface-Code Error-Correction Cycle

Walk a single stabilizer measurement round of a small surface code, inject one bit-flip error, and show how the syndrome localizes it.

Setup

The surface code stores logical information in a 2D lattice of data qubits interleaved with measurement qubits. Each measurement qubit repeatedly measures a stabilizer, a product of Pauli operators on neighboring data qubits, without disturbing the encoded state. A change in a stabilizer outcome flags a nearby error.

Stabilizers

Kronos motion — error correction

Consider a small patch with X-type plaquette stabilizers and Z-type vertex stabilizers. In the error-free ground state every stabilizer returns +1. A single X (bit-flip) error on one data qubit anticommutes with the two adjacent Z stabilizers, flipping both their outcomes to -1.

python
import numpy as np
# 5 data qubits in a plus shape; two Z-stabilizers each act on a pair
stab=[(0,1),(1,2)]           # qubits each Z-stabilizer checks
state=np.zeros(3,int)        # no error -> all parities 0
err=1                        # X error on data qubit 1
for s,(a,b) in enumerate(stab):
    parity=((a==err)+(b==err))%2
    print('stabilizer',s,'->',parity)  # both fire: 1,1

Decoding

The pattern of flipped stabilizers is the syndrome. A decoder, often minimum-weight perfect matching, pairs up the defects and infers the shortest error chain that explains them, here a single X on the shared qubit. Applying the inferred correction returns all stabilizers to +1 without ever measuring the logical state.