Skip to content

CSS codes and the Steane code

The last lesson showed how to analyse a stabilizer code once you have its generators. It did not say where good generators come from. One rich source is the theory of classical error-correcting codes, which engineers have been refining since the 1940s. This lesson shows how to turn two classical codes into one quantum code. The recipe is named CSS after Robert Calderbank, Peter Shor and Andrew Steane, who found it in 1995 and 1996.

A classical linear code is a set of bit strings, the codewords, defined by a list of parity checks. Each check names some positions and demands that the bits there sum to an even number.

The three-bit repetition code has two checks: bits 0 and 1 have even sum, and bits 1 and 2 have even sum. Only 000 and 111 pass both. Writing each check as a row, with a 1 in every position it involves, gives the parity-check matrix

H=(110011).H = \begin{pmatrix}1 & 1 & 0\\ 0 & 1 & 1\end{pmatrix}.

A string cc is a codeword exactly when Hc=0Hc = 0, with all arithmetic done modulo 2. If a codeword cc is corrupted to c+ec + e, where ee has a 1 wherever a bit was flipped, then

H(c+e)=Hc+He=He.H(c + e) = Hc + He = He.

This is the syndrome. It depends only on the error, not on which codeword was sent. You have seen all of this already in quantum form.

Classical codes are described by three numbers in single brackets, [n,k,d][n, k, d]: nn bits, kk of them carrying data, and distance dd, the smallest number of bit flips that turns one codeword into another. The repetition code is [3,1,3][3, 1, 3].

The repetition code is wasteful: three bits to send one. Richard Hamming’s code of 1950 sends four data bits in seven, and still corrects any single flip. Its check matrix has an elegant definition: number the positions 1 to 7, and make column jj the number jj written in binary.

H=(000111101100111010101)H = \begin{pmatrix} 0 & 0 & 0 & 1 & 1 & 1 & 1\\ 0 & 1 & 1 & 0 & 0 & 1 & 1\\ 1 & 0 & 1 & 0 & 1 & 0 & 1 \end{pmatrix}

Now suppose bit jj is flipped. The syndrome HeHe is column jj of the matrix, which is jj in binary. The syndrome spells out the position of the error.

SimulatorThe Hamming code

This simulator needs JavaScript.

Things to try:

  1. Flip one bit and read the syndrome as a binary number.
  2. Flip two bits. The syndrome is not zero, so the error is detected, but it points at a third, innocent bit.
  3. Find three bits whose flips cancel out completely, such as 1, 2 and 3. That is the distance at work: the code is [7,4,3][7, 4, 3].
Check

A Hamming codeword arrives with one bit flipped, and the three checks read 1, 1, 0. Which bit is it?

Compare the repetition code’s check matrix with the generators of the bit-flip code:

(110011)⟷ZZIIZZ\begin{pmatrix}1 & 1 & 0\\ 0 & 1 & 1\end{pmatrix} \qquad\longleftrightarrow\qquad \begin{matrix}ZZI\\ IZZ\end{matrix}

They are the same thing. A row of a check matrix becomes a generator by writing ZZ for 1 and II for 0. Such a generator fires exactly when an odd number of the qubits it covers have been hit by XX, which is the classical parity check applied to the pattern of bit flips. So a classical code, written with ZZ‘s, protects against XX errors, with the same syndromes and the same distance.

Phase flips need generators made of XX‘s. By the same argument, a second classical code, written with XX‘s, protects against ZZ errors.

Only one thing can go wrong. Generators must commute. Two ZZ-type strings always commute with each other, and so do two XX-type strings. An XX-type and a ZZ-type string commute when they clash in an even number of places, that is, when their rows share an even number of 1s. So the rule is:

Choose a check matrix HZH_Z and a check matrix HXH_X such that every row of one has an even overlap with every row of the other. In symbols, HXHZT=0H_X H_Z^{\mathsf T} = 0 modulo 2.

Any pair of classical codes that satisfies this gives a quantum code. That is the CSS construction, and codes built this way are CSS codes. Because the two halves are separate, the decoder is separate too: one classical decoder handles the XX errors using the ZZ-type syndrome, and another handles the ZZ errors using the XX-type syndrome. A YY error simply shows up in both.

Take a single check that covers four bits, 1111, for both matrices. Its overlap with itself is four, which is even, so the two generators

XXXXandZZZZXXXX \qquad\text{and}\qquad ZZZZ

commute. Four qubits and two generators leave two logical qubits. A single XX anywhere fires ZZZZZZZZ, and a single ZZ anywhere fires XXXXXXXX, but neither syndrome says where. This is the [[4,2,2]][[4, 2, 2]] code: with distance 2 it can detect one error and cannot correct it. Small experiments often use it for that reason: when a check fires, the run is thrown away.

PuzzleA codeword of the four-qubit code

Starting from ∣0000⟩\ket{0000}, prepare the state stabilized by XXXXXXXX and ZZZZZZZZ that contains ∣0000⟩\ket{0000} and one other bit string. No target is shown.

This puzzle needs JavaScript.

Hint

ZZZZZZZZ allows only bit strings with an even number of 1s. XXXXXXXX flips every bit, so ∣0000⟩\ket{0000} must come with ∣1111⟩\ket{1111} at the same amplitude.

Now use the Hamming matrix. Do its rows have even overlaps? Row 1 and row 2 share positions 6 and 7. Row 1 and row 3 share 5 and 7. Row 2 and row 3 share 3 and 7. And each row overlaps itself in four places. Every overlap is even, so the Hamming matrix can serve as both HXH_X and HZH_Z. The result is the Steane code, with six generators:

IIIXXXXIIIZZZZIXXIIXXIZZIIZZXIXIXIXZIZIZIZ\begin{array}{cc} IIIXXXX & IIIZZZZ\\ IXXIIXX & IZZIIZZ\\ XIXIXIX & ZIZIZIZ \end{array}

Seven qubits and six generators leave one logical qubit. The distance is 3, inherited from the Hamming code, so this is a [[7,1,3]][[7, 1, 3]] code: it corrects any single-qubit error, with two fewer qubits than the Shor code.

In the simulator the qubits are numbered 1 to 7, to match the Hamming code.

SimulatorThe Steane code

This simulator needs JavaScript.

Things to try:

  1. Put an XX on qubit 5. Generators 4 to 6, the ZZ-type ones, read 101, which is 5 in binary.
  2. Clear it and put a ZZ on qubit 5. Now generators 1 to 3, the XX-type ones, read 101.
  3. Put a YY on qubit 5. Both halves of the syndrome read 101.
  4. Put an XX on qubit 2 and a ZZ on qubit 6. Each half of the syndrome locates its own error, and both are fixed. That is two faulty qubits, more than distance 3 promises, but it works because the errors are of different kinds.
  5. Put XX on qubits 2 and 6. Now the ZZ-type half sees two errors of the same kind, and is fooled.
Check

Could we use the repetition code’s check matrix for both HXH_X and HZH_Z, giving generators ZZIZZI, IZZIZZ, XXIXXI and IXXIXX?

The Steane code has a property that matters as much as its size. We need to compute on encoded data without decoding it first, and for this code many logical gates are as simple as they could possibly be.

A logical gate is transversal if it is carried out by applying a separate gate to each physical qubit, with no gate joining two qubits of the same block.

  • Logical XX and ZZ. XX on all seven qubits commutes with every generator and is not a product of them, so it is a logical XX. Likewise ZZ on all seven is a logical ZZ.
  • Logical HH. Apply HH to all seven qubits. Since HXH=ZHXH = Z and HZH=XHZH = X, this turns every XX-type generator into the matching ZZ-type generator and back. The list of generators as a whole is unchanged, so encoded states stay in the code. Meanwhile logical XX and logical ZZ are exchanged, which is what a Hadamard does.
  • Logical CNOT. Take two blocks of seven and apply a CNOT from each qubit of the first to the matching qubit of the second. This works for every CSS code.
  • Logical SS. An SS-type gate on every qubit also works. For this code SS on all seven happens to give the inverse of logical SS, so one applies S†S^\dagger to each instead.

Why care? Because of how errors spread. If one physical gate in a transversal operation is faulty, it damages one qubit in each block it touches, and one error per block is what the code can correct. A gate that coupled qubits within a block could turn one fault into two errors in the same block, which the code cannot. This idea is the starting point of fault tolerance.

The gates above, HH, SS and CNOT, are the same set that the Gottesman–Knill theorem said can be simulated classically. Something more is needed for universal quantum computing, and it turns out that no code can supply it transversally. That too is a story for the fault tolerance lesson.

Check

Why does applying HH to every qubit give a logical gate on the Steane code but not on the Shor code?

The Steane code corrects one error. To correct more we need larger distance, and the codes so far do not grow gracefully. One option is to concatenate, encoding each of the seven qubits in seven more, but then single checks involve qubits scattered across the whole device. Real hardware, especially chips where each qubit talks only to its neighbours, wants the opposite: checks that are small and local, in a code whose distance can be raised just by making it bigger.

That code exists. It is also a CSS code, and it is the subject of the next lesson.

RecallAnswer from memory, then check
LessonFinish this lesson