Why a new language
The repetition codes were described by listing code words. That stops working quickly: a code with logical qubits has basis code words, each a superposition of up to basis states. The stabilizer formalism, developed in Gottesman's thesis (Gottesman 1997), describes a code instead by a short list of Pauli operators that leave every code state unchanged. Everything we need (the code space dimension, the syndrome of an error, the logical operators, the distance) then reduces to linear algebra over the two-element field . This lesson builds that algebra and uses it on three famous codes. The surface code, Floquet codes and most codes in current research are stabilizer codes.
The Pauli group
The Pauli group on qubits consists of the tensor products
with
and phase . We write
these as strings, so XZZXI means , character acting on
qubit . Three facts are used constantly:
- Every Pauli squares to , and Hermitian ones (phase ) have eigenvalues .
- Any two Paulis either commute or anticommute. On one qubit, distinct non-identity Paulis anticommute. On qubits, and anticommute exactly when the number of positions where they hold distinct non-identity letters is odd.
- The weight of a Pauli is the number of non-identity positions.
Worked example. XZ and ZX differ at both positions, two
anticommutations, so they commute. XX and ZI differ only at position 0, so
they anticommute.
The binary symplectic picture
Since phases do not affect commutation or weight, drop them and record a Pauli
by two bit strings: if position holds or , and
if it holds or . The Pauli becomes a vector ;
for example XYZI is . Multiplying two Paulis adds their
vectors modulo 2, up to a phase. Commutation becomes the symplectic inner
product
which is 0 when the Paulis commute and 1 when they anticommute: each qubit
contributes 1 exactly when one operator has an -part and the other a
-part there but not both. For XZ and ZX we get
and , total : they commute, as found
above.
Stabilizer groups and codes
A stabilizer group is an abelian subgroup of that does not contain . Its code space is the set of states fixed by every element:
(If were in , it would require , so would be empty; commutation is needed for a common eigenspace to exist.) We describe by independent generators , and stack their symplectic vectors as the rows of the check matrix .
Theorem (Gottesman 1997). If has independent generators, has dimension , so it encodes logical qubits. With possibly redundant generators, .
The idea of the proof: each generator has eigenspaces of equal size, and because the generators are independent and commute, fixing the signs of all of them splits the -dimensional space into subspaces of equal dimension . The code space is the one with all signs ; the others are the "error spaces" that errors move it into.
Example. The bit-flip code is generated by ZZI and IZZ: ,
, so . Its check matrix is
of rank 2. Adding the product ZIZ as a third row does not change the rank or
.
Errors and syndromes
Measuring a generator on a code state always gives . After a Pauli error , the state satisfies , with the minus sign exactly when anticommutes with . The syndrome of is therefore the bit string
a pure commutation pattern that does not depend on the encoded state. In matrix form , where is the vector of and swaps the and halves.
A generator is measured onto an ancilla with a Hadamard, controlled Paulis and
a second Hadamard. For the five-qubit code's generator XZZXI:
The ancilla outcome is 0 for eigenvalue and 1 for . In the lessons on syndrome extraction we will see why the order of these gates matters once they are noisy.
Logical operators and distance
Which errors cannot be detected? Exactly those with zero syndrome, the Paulis that commute with every element of . This set is the centraliser ; for Pauli stabilizer groups it coincides with the normaliser , which is the name used in many texts. It splits into two kinds:
- Stabilizers (, up to phase): they act trivially on every code state. Harmless.
- Logical operators (): they map the code space to itself but act non-trivially on it. Undetectable and harmful.
There are independent logical operators, which can be chosen as pairs that obey the commutation relations of qubits. Two logical operators that differ by a stabilizer act identically on the code space, so each has many representatives of different weights.
The distance is the minimum weight of a logical operator. A code with parameters , , is written (double brackets distinguish quantum from classical codes). It detects every error of weight up to and corrects every error of weight up to : two errors of weight with the same syndrome differ by an element of of weight , which must be a stabilizer, so correcting either one fixes both. This is the Knill-Laflamme condition (Knill and Laflamme 1997) in stabilizer form: is correctable if every product is either in (up to a phase) or anticommutes with some element of .
Example. For the bit-flip code, ZII commutes with ZZI and IZZ and is
not in the group they generate, so it is a logical operator () of
weight 1: the code is . Its distance against errors alone is 3,
but distance counts all Pauli errors.
Three codes in the stabilizer language
The Steane code
Take the parity-check matrix of the classical Hamming code, whose column is the binary representation of :
Use each row once as an -type generator and once as a -type generator:
| -type | -type |
|---|---|
IIIXXXX |
IIIZZZZ |
IXXIIXX |
IZZIIZZ |
XIXIXIX |
ZIZIZIZ |
An -type and a -type generator commute when their supports overlap on an even number of qubits, which holds because any two rows of overlap in 2 positions and each row has weight 4. The six generators are independent, so . This is Steane's code (Steane 1996), the smallest CSS code that corrects an arbitrary single-qubit error, built by the CSS construction of Calderbank, Shor and Steane (Calderbank and Shor 1996): -type checks from one classical code, -type checks from another, with the commutation condition . For CSS codes and errors are detected and corrected separately.
A single error anticommutes with the -type generators whose row has a
1 in column , so its -part of the syndrome is the binary representation
of : it names the qubit, exactly as in the classical Hamming code. The
same holds for with the -type generators, and triggers both. All
21 single-qubit errors have distinct non-zero syndromes. Logical operators
include $\bar X = $ XXXXXXX and $\bar Z = $ ZZZZZZZ, and lighter
representatives such as XXXIIII (multiply XXXXXXX by the stabilizer
IIIXXXX) have weight 3. No Pauli of weight 1 or 2 is a logical operator, so
.
The five-qubit code
The smallest code that corrects an arbitrary single-qubit error uses five
qubits (Laflamme et al. 1996); it was found
independently by Bennett, DiVincenzo, Smolin and Wootters
(1996). Its generators are cyclic shifts:
XZZXI, IXZZX, XIXZZ, ZXIXZ. It is not a CSS code (generators mix
and ). Worked example: the syndrome of IIYII is , because
anticommutes with the in the first two generators and the in the
third, and the fourth has on qubit 2. With 4 generators there are
syndromes, and the identity plus 15 single-qubit errors use every
one of them exactly once. Codes that use every syndrome this way are called
perfect.
Shor's code and degeneracy
Shor's code (Shor 1995) has six -type generators ZZ on
neighbouring qubits inside each block of three, and two -type generators
XXXXXXIII and IIIXXXXXX. Here something new happens: and have
the same syndrome (each anticommutes with XXXXXXIII only), yet the code
corrects both, because is a stabilizer. Correcting when
occurred leaves , which acts trivially. Codes in which distinct
low-weight errors act identically are degenerate. Degeneracy has no classical
analogue, and decoders that ignore it can be suboptimal.
Computing it yourself
All of these statements can be checked by a few dozen lines of NumPy. The core is Gaussian elimination over :
import numpy as np
def to_vec(p):
return np.array([c in "XY" for c in p] + [c in "ZY" for c in p], dtype=np.uint8)
def gf2_rank(m):
m = np.array(m, dtype=np.uint8) % 2
rank = 0
for col in range(m.shape[1]):
rows = [r for r in range(rank, m.shape[0]) if m[r, col]]
if not rows:
continue
m[[rank, rows[0]]] = m[[rows[0], rank]]
for r in range(m.shape[0]):
if r != rank and m[r, col]:
m[r] ^= m[rank]
rank += 1
return rank
five = ["XZZXI", "IXZZX", "XIXZZ", "ZXIXZ"]
H = np.array([to_vec(g) for g in five])
print("k =", 5 - gf2_rank(H)) # k = 1
e = to_vec("IIYII")
n = 5
print([int((g[:n] @ e[n:] + g[n:] @ e[:n]) % 2) for g in H]) # [1, 1, 1, 0]
The exercise extends this to a full toolkit: commutation, syndromes,
membership in the stabilizer group, logical operators of a given weight, and the
distance by brute force over weights Brute force is fine for
, and it lets you confirm the parameters above from the generators
alone. One check compares your Steane syndromes with the table produced by the
KetQat SDK's steane-code product, which computes it independently and
verifies it by state-vector projection.
Common mistakes
- Forgetting to drop phases consistently. The symplectic vector ignores phases; that is fine for commutation, weight and rank, but not for the eigenvalue a measurement returns.
- Counting generators instead of the rank. With redundant generators, , not .
- Calling every zero-syndrome error a logical error. Stabilizers also have zero syndrome and act trivially; only is harmful.
- Taking the weight of one representative as the distance.
XXXXXXXhas weight 7, but the Steane code's distance is 3; minimise over all representatives. - Assuming one error, one syndrome, one correction. In degenerate codes several errors share a syndrome and one correction serves them all.
- Mixing qubit orderings. Here character of a string acts on qubit . Libraries differ; check before comparing syndromes.
Summary
- Paulis are vectors in ; products add, and commutation is the symplectic inner product.
- A stabilizer code is the joint eigenspace of an abelian Pauli group without ; .
- The syndrome of an error is its commutation pattern with the generators.
- Logical operators commute with all stabilizers without being stabilizers; the distance is their minimum weight, and the code corrects errors.
- The five-qubit, Steane and Shor codes are , and ; Steane's is the simplest CSS code and Shor's is degenerate.
This completes the introduction. The next module builds the surface code, a CSS code whose checks are local on a square grid, and simulates it under realistic noise. For a textbook treatment of stabilizer codes see Nielsen and Chuang, section 10.5.