Quantum Error Correction Plaquettes · Chains · Syndrome Decoding

An interactive walk through the surface code, from stabiliser checks to the deep links with Ising models and percolation thresholds.

The Surface Code Lattice

A surface code of distance \(L\) lives on a square grid. Vertices sit at integer coordinates \((x,y)\) with \(0 \le x,y \le L\). Data qubits occupy the edges between nearest-neighbour vertices. The faces of the grid are plaquettes, each centered at \((p_x, p_y)\) for \(0 \le p_x, p_y < L\).

Plaquettes come in two flavours, assigned by a checkerboard rule. If \((p_x + p_y)\) is even the plaquette is a Z-stabiliser; if odd it is an X-stabiliser. Each stabiliser is a multi-qubit Pauli operator acting on the four data qubits bounding that face.

$$S_Z^{(p)} = \prod_{e \in \partial p} Z_e, \qquad S_X^{(p)} = \prod_{e \in \partial p} X_e$$

In the error-free state the code occupies the joint \(+1\) eigenspace of every stabiliser. An error on a data qubit anticommutes with its neighbouring stabiliser of the conjugate type, flipping the measurement outcome from \(+1\) to \(-1\). These flipped plaquettes form the syndrome.

Interactive LatticeL = 5 · Click edges to flip errors
Toggle edges to introduce errors. Syndrome defects appear on adjacent plaquettes.
Key point. Each error on a single edge always excites exactly the stabilisers of the conjugate type that border it. An X error excites Z-stabilisers; a Z error excites X-stabilisers. This duality is fundamental.

chainsError Chains and Homology

A single-qubit error produces two syndrome defects (or one if the edge borders the boundary). A chain of consecutive errors on a path of edges produces defects only at the two endpoints of the path. The internal plaquettes are each touched twice and their parities cancel.

$$\text{syndrome}(C) = \partial C$$

Here \(C\) is the error chain (a set of edges) and \(\partial\) is the boundary operator. Two chains \(C_1, C_2\) that share the same boundary are homologous: they differ by a closed loop. If the decoder finds any chain matching the observed syndrome (same boundary), the residual error is a closed loop. Closed loops that are topologically contractible act as the identity on the code space. Only non-contractible loops cause a logical error.

Chain ExplorerClick two vertices to draw a shortest-path chain
Click a vertex to set the start point.

The decoder's job is to pair up syndrome defects and connect each pair by a correction chain. If the correction chain, composed with the original error chain, yields only contractible loops, decoding succeeds.

mappingConnection to the Ising Model

The link between surface codes and statistical mechanics runs deep. Consider the random-bond Ising model on a square lattice, where each bond is ferromagnetic with probability \(1-p\) and antiferromagnetic with probability \(p\).

$$H = -\sum_{\langle i,j \rangle} J_{ij}\, \sigma_i \sigma_j, \qquad J_{ij} = \begin{cases} +J & \text{prob } 1-p \\ -J & \text{prob } p \end{cases}$$

A "frustrated plaquette" in the Ising model is one where the product of bonds around its boundary is negative. This is exactly the surface code syndrome: an X-error on edge \(e\) corresponds to flipping the bond sign, and the frustrated plaquettes are the syndrome defects.

The Nishimori line. The maximum-likelihood decoder for the surface code at physical error rate \(p\) maps onto the partition function of the random-bond Ising model evaluated along the Nishimori line, where the temperature satisfies \(e^{-2J/k_BT} = p/(1-p)\). The error correction threshold \(p_c\) corresponds to the phase transition on this line.

Below the threshold the system is in the ferromagnetic (ordered) phase: most error chains are short and decodable. Above it, a percolating cluster of errors destroys the logical information. For the 2D surface code with independent bit-flip noise this gives a threshold around \(p_c \approx 10.3\%\), which coincides with a known multicritical point of the random-bond Ising model on the square lattice.

Random-Bond Ising / Frustrated Plaquettesp = 0.08
Flipped bonds shown in red. Frustrated plaquettes are highlighted.

The decoder as a spin-glass solver

Minimum-weight perfect matching (MWPM) decoding pairs syndrome defects with minimum total separation, exactly as finding the ground state domain-wall configuration in the Ising picture. The accuracy threshold of the code equals the disorder-driven phase transition of the corresponding random-bond model.

thresholdPercolation and the Error Threshold

There is a second statistical-mechanical lens: bond percolation. Mark each edge as "errored" independently with probability \(p\). The connected components of errored edges form clusters. If any cluster spans the lattice from one boundary to the opposite, a logical error becomes likely.

$$P_{\text{logical error}} \sim \begin{cases} e^{-\alpha L} & p < p_c \\ \mathcal{O}(1) & p \ge p_c \end{cases}$$

The bond percolation threshold on the square lattice is exactly \(p_c^{\text{bond}} = 1/2\). The surface code threshold is far below this because the decoder must additionally distinguish homology classes, not merely detect connectivity. But the conceptual picture is the same: below threshold, error clusters are small and isolated; above threshold, a giant connected component spans the system.

Bond Percolationp = 0.30
Clusters shown by colour. Largest cluster highlighted.
Universality. Near the percolation threshold the cluster size distribution follows a power law \(n_s \sim s^{-\tau}\) with \(\tau = 187/91\) in 2D. The correlation length diverges as \(\xi \sim |p - p_c|^{-4/3}\). These critical exponents are universal across lattice types. The surface code threshold inherits analogous finite-size scaling, which is how numerical estimates of \(p_c \approx 10.3\%\) are extracted.

From percolation to decoding failure

A useful mental model: if error clusters percolate, the decoder cannot uniquely determine the homology class of the error. The ambiguity between a correction chain and the true error becomes a non-contractible loop, which is a logical fault. The threshold is where this ambiguity first becomes macroscopic.

∂The Matrix Duality: Cycles, Cuts, and Chain Complexes

The surface code's error correction is secretly linear algebra over \(\mathbb{F}_2\) (arithmetic mod 2, where \(1 + 1 = 0\)). Every relationship between edges, syndromes, and logical operators is encoded in a single matrix: the boundary operator.

The incidence matrix as boundary map

For any graph, define the incidence matrix \(B\) with one row per vertex and one column per edge. Entry \(B_{v,e} = 1\) if vertex \(v\) is an endpoint of edge \(e\), and \(0\) otherwise. Over \(\mathbb{F}_2\) this is the boundary operator \(\partial_1\): it maps each edge to the sum of its two endpoints.

$$\partial_1 : \mathbb{F}_2^{|\text{edges}|} \to \mathbb{F}_2^{|\text{vertices}|}, \qquad (\partial_1)_{v,e} = \begin{cases} 1 & v \in \partial e \\ 0 & \text{otherwise} \end{cases}$$

For the surface code there is a second boundary map from plaquettes to edges. Define \(\partial_2\) with one row per edge and one column per plaquette: \((\partial_2)_{e,p} = 1\) if edge \(e\) borders plaquette \(p\). This gives the chain complex:

$$\mathbb{F}_2^{\text{plaquettes}} \xrightarrow{\;\partial_2\;} \mathbb{F}_2^{\text{edges}} \xrightarrow{\;\partial_1\;} \mathbb{F}_2^{\text{vertices}}$$

The fundamental identity of homology is that the boundary of a boundary is zero:

$$\partial_1 \circ \partial_2 = 0 \quad (\text{mod } 2)$$

This is not a theorem that needs proving. It is a counting argument: every plaquette boundary is a closed loop of edges, and each interior vertex appears in exactly two of those edges, so the mod-2 sum at every vertex vanishes. The matrix product \(B \cdot \partial_2\) is the zero matrix.

The four fundamental subspaces

The two matrices \(\partial_1 = B\) and \(\partial_2\) carve the edge space into three pieces. Over \(\mathbb{F}_2\) the decomposition is:

$$\mathbb{F}_2^{\text{edges}} = \underbrace{\text{im}(\partial_2)}_{\text{plaquette boundaries}} \;\oplus\; \underbrace{\ker(\partial_1) / \text{im}(\partial_2)}_{\text{homology } H_1} \;\oplus\; \underbrace{\text{complement}}_{\text{open chains}}$$

In plain language:

cycle space ker(\(\partial_1\)): edge-sets whose boundary is empty. These are closed loops. Any combination of edges that forms a cycle is in the kernel of the incidence matrix.

boundaries im(\(\partial_2\)): edge-sets that are boundaries of plaquette regions. These are contractible loops. They act trivially on the code space.

homology \(H_1 = \ker(\partial_1) / \text{im}(\partial_2)\): cycles that are not boundaries. These are the non-contractible loops, i.e. the logical operators. For a distance-\(L\) surface code on a planar patch with boundaries, \(H_1\) is one-dimensional: one independent logical operator per encoded qubit.

open chains Chains not in ker(\(\partial_1\)): their boundary is nonzero. The boundary is the syndrome.

CSS codes as dual chain complexes

A CSS (Calderbank-Shor-Steane) code is defined by two classical parity-check matrices \(H_X\) and \(H_Z\) satisfying \(H_X H_Z^\top = 0\). For the surface code these are exactly the two boundary operators:

$$H_Z = \partial_2^\top \quad (\text{plaquettes} \times \text{edges}), \qquad H_X = \partial_2^{\text{dual}\top}$$

The CSS condition \(H_X H_Z^\top = 0\) is the same identity \(\partial^2 = 0\), now on the dual lattice. This is why the Z-stabilisers and X-stabilisers commute: commutativity of Pauli checks is the algebraic statement that boundaries have no boundary.

Incidence Matrix ExplorerL = 3 (small for visibility)
The incidence matrix ∂₁: rows are vertices, columns are edges. Entry = 1 (blue) iff vertex bounds edge.
Node-cycle duality in one sentence. A set of edges is a cycle iff it is in the kernel of the incidence matrix. A set of vertices is a cocycle (cut) iff it is in the kernel of the transpose. These two kernels are orthogonal complements in \(\mathbb{F}_2^{|E|}\). The surface code exploits exactly this orthogonality: X-stabilisers live in one kernel, Z-stabilisers in the other, and their commutativity is guaranteed by \(\partial^2 = 0\).

codeThe Python Implementation

The interactive code underneath this page mirrors the SurfaceCodePatch class in the uploaded Python. The core data structure maps every edge to its adjacent plaquettes, then computes syndromes by XOR-parity counting. The key method:

syndrome_from_error(error_edges, error_type)

For each errored edge, find all adjacent plaquettes of the conjugate type. Flip their parity. The set of plaquettes with odd parity is the syndrome.

The chain_between_vertices method runs BFS to find shortest paths, then converts the vertex sequence into an edge chain. A closed loop (path returning to its start) always produces an empty syndrome in the bulk, because every interior plaquette is touched an even number of times.

Homological algebra in three lines. In the code, chain_from_path builds a 1-chain, syndrome_from_error computes its boundary (a 0-chain on dual vertices), and the vanishing syndrome of a closed loop is the statement \(\partial^2 = 0\).