So far every code in this course has been a list of Pauli strings with no geometry attached. The Steane code checks are weight 4, but if we wanted a bigger Steane-like code, the checks would get heavier and act on qubits that are far apart. Real hardware cannot do that easily. Superconducting chips, for example, only couple each qubit to a few neighbours on a 2D grid.

The toric code (Kitaev, 1997) solves this by putting the code on a lattice. Every check acts on 4 neighbouring qubits, whatever the code size. Even so, the distance grows with the lattice size . This module builds the toric code from scratch and introduces the topological language (chains, boundaries, homology) that the next five modules rely on.

Learning goals. After this module you should be able to

  1. define the toric code on an torus and prove that its star and plaquette checks commute;
  2. count independent checks and derive the parameters ;
  3. describe errors as chains, syndromes as their boundaries, and logical operators as non-contractible loops (homology classes);
  4. explain anyons as the endpoints of error strings, and why homologous errors are equivalent (degeneracy).

Prerequisites: stabilizer codes and logical operators (Module 3) and the CSS construction with check matrices (Module 4).

1. The lattice and the checks

Take an square grid and glue opposite sides together: the right edge to the left edge, the top edge to the bottom edge. The result is a grid drawn on a torus (the surface of a doughnut). It has

  • vertices, labelled with (row , column , read mod );
  • edges: a horizontal edge from to and a vertical edge from to ;
  • faces, where face is the square whose top-left corner is vertex .

We put one qubit on every edge, so . For a vertex , its star is the set of 4 edges that touch it. For a face , its plaquette is the set of 4 edges around it.

Definition 7.1 (Toric code).

The toric code on the torus is the CSS stabilizer code on edge qubits with stabilizer group generated by

In coordinates, acts on and acts on . The X-type checks form the rows of (a matrix) and the Z-type checks form the rows of (an matrix).

This is Kitaev’s convention: X on stars, Z on plaquettes. Some sources (for example Pesah’s interactive tutorial) use the opposite assignment. The two versions are the same code with X and Z swapped, but every “which boundary, which logical” statement flips with it. This course uses the convention above throughout.

Bp Av star Av: X on 4 edges at v plaquette Bp: Z on 4 edges qubit (one per edge) copy of row/column 0 Av and Bp share 2 edges so they commute L = 3: 18 qubits, 9 stars, 9 plaquettes
Proposition 7.1 (Stars and plaquettes commute).

Every commutes with every . Hence is abelian, and .

Notice what this buys us. The checks have weight 4 and act on neighbouring qubits, for every . The lattice can grow while the measurement circuits stay the same size.

2. Counting the parameters

There are stars and plaquettes, so generators on qubits. If they were independent, the code would encode qubits. They are not independent.

Lemma 7.1 (The only relations).

The product of all stars is the identity, and the product of all plaquettes is the identity. These are the only relations: .

Theorem 7.1 (Parameters of the toric code).

The toric code on the torus is an code.

The value of follows directly from Lemma 7.1 and the CSS formula of Module 4:

The distance is proved in Section 4 (Proposition 7.3). We checked both numbers by computer for small sizes: and for , and a brute-force search over and gives minimum logical weight exactly for .

Example 7.1 (The smallest instance, L = 2).

Order the 8 qubits as . Rows of are the stars at , and rows of are the plaquettes at the same four labels:

Every column of each matrix has exactly two 1s: each edge has two endpoints and borders two faces. So the rows of each matrix sum to zero. Each matrix has rank 3, and one can check . This gives . At the shortest non-contractible loop has length 2, so this is an code. It detects any single error but cannot correct one.

Beyond the tiny case of Example 7.1, at we get , at we get . The rate goes to zero. That price comes with any code built on a 2D grid, and we return to it in Module 12.

3. Chains, boundaries and homology

The real reason the toric code works is topological. The language needs only arithmetic mod 2.

A 1-chain is a set of edges, written as a vector (bit is 1 if edge is in the set). Adding two chains means symmetric difference: an edge in both cancels. In the same way, 0-chains are sets of vertices () and 2-chains are sets of faces ().

Definition 7.2 (Chain complex of the lattice).

The boundary maps are linear maps over :

where sends a face to the sum of its 4 edges and sends an edge to the sum of its 2 endpoints. As matrices, (vertex-edge incidence) and (edge-face incidence). A chain with is a cycle: every vertex touches an even number of its edges, so is a union of closed loops. A chain of the form is a boundary: it is the outline of a region of faces.

faces C2 = F2F edges (qubits) C1 = F2E vertices C0 = F2V d2 = HZT d1 = HX Z-logicals: ker d1 / im d2 (cycles mod boundaries) d1 d2 = 0 is exactly HX HZT = 0

The key identity is : the boundary of a boundary is empty. The outline of a region is a closed loop, so it has no endpoints. Written in matrices this reads , which is exactly Proposition 7.1. (Remark 7.1 below shows the same bookkeeping works on any closed surface.) The CSS commutation condition and “the boundary of a boundary is zero” are the same statement.

Now translate the stabilizer language into the chains of Definition 7.2. A Z-type Pauli is labelled by a 1-chain .

Proposition 7.2 (Syndrome = boundary).

For a Z-type error , the star syndrome is . The flipped stars are exactly the endpoints of the chain . Dually, for an X-type error the plaquette syndrome is . It flags the faces at the ends of the corresponding path on the dual lattice, whose vertices are faces and whose edges cross the original edges.

So the stabilizer formalism and the topology match up:

stabilizer languagechain language (Z-type)
Z-type Pauli 1-chain
syndrome boundary (endpoints)
commutes with all stars: is a cycle (closed loops)
product of plaquettes: is a boundary
logical Z operatorcycle that is not a boundary
equivalent logicalshomologous cycles ()
Theorem 7.2 (Logical operators are homology classes).

The Z-type logical operators of the toric code, modulo stabilizers, are in one-to-one correspondence with the first homology group of the torus with coefficients:

The two generators are the horizontal and vertical non-contractible loops. The X-type logicals are described the same way on the dual lattice: .

Remark 7.1 (Other surfaces).

Nothing above used the torus specifically, only a cellulation of a closed surface. For a connected closed orientable surface of genus (a doughnut with holes), the same proof gives and , hence

where is the Euler characteristic. The torus has , so . A sphere () encodes nothing: on a sphere every loop is a boundary.

4. Logical operators and the distance

On the dual lattice, an X-type operator commutes with every plaquette when it lives on a closed dual loop: a loop that crosses edges and passes through faces. Each face is entered and exited once, so the loop crosses 0 or 2 of its edges. Define

acts on the column of horizontal edges cut by a vertical dual loop, and acts on the row of vertical edges cut by a horizontal dual loop.

Z1: Z on a primal loop X1: X on a dual loop the one shared qubit contractible loop = product of 2 plaquettes Both logical loops wrap the torus; they overlap on one qubit, so X1 and Z1 anticommute.

The horizontal primal loop and the vertical dual loop cross at exactly one qubit, . So they anticommute. and do not share any qubit, so they commute. Altogether (verified for ):

This is the commutation pattern of and on two independent qubits, so and are logical Paulis for the two encoded qubits.

Moving a logical operator. Multiplying by the plaquettes in row 0 gives Z on the row loop . The plaquette edges on row 0 cancel and those on row 1 remain. The loop has slid down by one row without changing the logical action. Any non-contractible loop that winds once horizontally is equivalent to , however wiggly. This is why the toric code is called topological: only the winding of the loop matters, not its exact path. It also explains a common confusion. A loop that winds twice around the torus is not a new logical. Mod 2 it is homologous to the trivial loop, because .

Proposition 7.3 (Distance).

Every nontrivial logical operator of the toric code has weight at least , and the loops , have weight exactly . Hence .

For there are exactly weight-3 Z-type logicals: the 3 straight rows and the 3 straight columns (brute-force count). A non-contractible loop of length exactly cannot turn a corner. Each step has to advance in the winding direction.

5. Errors, strings and anyons

Now look at errors. By Proposition 7.2, a Z error on a set of edges lights up the stars at the endpoints of . The interior of the string is invisible to the checks: each interior vertex sees two flips, which cancel.

Z error string (primal path) flipped stars (vertices) X error string (dual path) flipped plaquettes Defects sit only at the two endpoints of each string. Interior checks see 2 errors.

Concretely, on the torus:

  • on (a path from vertex to ) flips exactly the stars at and ;
  • on (a dual path through the faces of row 3) flips exactly the plaquettes and .

A outcome of a check is called a defect or excitation. Physicists call the flipped stars -particles (electric charges) and the flipped plaquettes -particles (magnetic fluxes). These are quasiparticles, not real particles. They are a useful picture: an error string creates a pair of particles at its ends, and growing the string moves them apart. A single defect can never appear on its own. The product of all stars is , so mod 2 and defects always come in pairs.

Three things can happen to a string:

  1. It stays open. Two defects are visible. The decoder must guess a correction string joining them.
  2. It closes into a contractible loop. The defects meet and annihilate. The loop is a boundary, that is, a product of checks, so it acts trivially on the code. No harm done.
  3. It closes into a non-contractible loop. The defects annihilate after travelling around the torus. Now the error is a logical operator, and the state has been changed without any syndrome. This is a logical error, and it needs at least single-qubit errors. (Remark 7.2 gives the physicist’s version of why crossing loops anticommute.)
Remark 7.2 (Braiding).

Moving an -particle all the way around a closed loop applies . If is contractible, . When one of the enclosed plaquettes holds an -particle, so on the state, the state picks up a sign . This “mutual semion” phase is the signature of topological order. It is also why a closed loop and a closed loop that cross once anticommute, just as and do.

6. Degeneracy: homologous errors are the same error

Two different errors can have the same syndrome and the same effect on the logical state. If for some plaquette , then and act identically on every codeword, because acts as on the codespace. In chain language: if , the strings and have the same endpoints and differ by the outline of a region.

E: weight 2 E' = E Bp: weight 4 same endpoints same syndrome E E' = Bp is a stabilizer: both corrections work
Example 7.2 (Two paths, one correction).

On the torus, let , the straight path from vertex to . Let , the detour that goes down, right, up and right. Their product is on , which is . So : both flip the stars at and . Moreover, correcting with leaves , which does nothing. (Checked numerically.)

Example 7.2 has two consequences for decoding, the subject of Module 10.

  • The decoder only has to get the homology class right. Given defects at the endpoints, any correction string with the same endpoints works, as long as (the error times the correction) is a boundary, not a non-contractible loop. With two defects close together, the short path almost certainly works.
  • Counting errors is misleading. On the toric code, a huge number of distinct error chains share each syndrome and each homology class. The best decoder (maximum likelihood) sums probabilities over the whole class rather than picking the single most likely chain. Minimum-weight matching, which picks the shortest correction, is a very good approximation, because pairing up defects by short paths usually lands in the right class.

Try it yourself below. The playground uses the planar rotated surface code of Module 8, not the torus: the patch has boundaries, so a single defect can pair with an edge instead of another defect. The string and anyon picture is the same. Click data qubits to place errors and watch which checks light up, then press Decode to see a matching correction and whether it lands in the right class.

7. The physics view: a Hamiltonian with protected ground states

Kitaev originally proposed the toric code as a physical system, not just a code. Consider the Hamiltonian

All terms commute (Proposition 7.1), so they can be diagonalized together. The lowest energy is reached when every , which is exactly the codespace . It is 4-fold degenerate on the torus, one dimension per state of 2 logical qubits. Each violated check costs energy 2, so an anyon pair costs energy 4 above the ground state.

The degeneracy is topologically protected. The only operators that can tell the four ground states apart are non-contractible loops of length at least . A weak local perturbation therefore splits the ground states only by an amount that shrinks exponentially in . There is one catch. Moving anyons costs no extra energy once they exist, so at any nonzero temperature thermal anyon pairs wander around and eventually wrap the torus. The 2D toric code is not a self-correcting memory. It needs active error correction: measure the checks repeatedly and decode. That is what the rest of this course does.

Summary

  • The toric code puts qubits on the edges of an torus, with X-type star checks and Z-type plaquette checks (Definition 7.1). A star and a plaquette overlap on 0 or 2 edges, so they commute.
  • There are two relations (product of all stars , product of all plaquettes ), giving and the parameters (Theorem 7.1).
  • With and , the condition is . Syndromes are boundaries, logical Z operators are cycles that are not boundaries, and the logical space is (Theorem 7.2). On a genus- surface, .
  • Logical operators are non-contractible loops (primal for Z, dual for X). The shortest has length , so .
  • Errors are strings with defects (anyons) at their endpoints. Homologous errors are equivalent, and this degeneracy is what decoders exploit.

Further reading

  • A. Yu. Kitaev, Fault-tolerant quantum computation by anyons, Ann. Phys. 303, 2 (2003), arXiv:quant-ph/9707021. The original toric code paper.
  • E. Dennis, A. Kitaev, A. Landahl, J. Preskill, Topological quantum memory, J. Math. Phys. 43, 4452 (2002), arXiv:quant-ph/0110143. Homology, decoding, and the link to statistical mechanics.
  • A. Pesah, An interactive introduction to the surface code (2023), arthurpesah.me/blog/2023-05-13-surface-code. Note that it uses the opposite X/Z convention.
  • A. N. Cleland, An introduction to the surface code, SciPost Phys. Lect. Notes 49 (2022).
  • K. Fujii, Quantum Computation with Topological Codes: from qubit to topological fault-tolerance, arXiv:1504.01444, Ch. 3 (chain complexes).
  • Error Correction Zoo, Kitaev surface code, errorcorrectionzoo.org/c/surface.

Next: Module 8 cuts the torus open to get a planar code with only one logical qubit but a much simpler layout.

Homework

Homework 7: The Toric Code