Skip to content
Tushar Pandey

Step 3 of 8

Errors, syndromes and decoding

Quantum Error Correction in Practice, part 1: Errors and decoding

Read

In Lesson 1 a 3 by 3 patch of qubits held one logical qubit, watched by four X checks and four Z checks. This page asks what happens after a check fires: how a decoder turns a pattern of fired checks into a correction, and when that correction is wrong.

Two kinds of error, two kinds of check

A qubit can suffer a bit flip X, a phase flip Z, or both at once, Y. Each check is a product of Pauli operators on the qubits at the corners of its tile: X on every corner for an X check, Z on every corner for a Z check. A check fires when an odd number of its qubits carry an error that does not commute with it. An X error commutes with X checks and anticommutes with Z checks, so it fires Z checks only. A Z error fires X checks only, and a Y error fires both kinds.

The patch below has d = 5, and can be set to d = 3, the size of Lesson 1, or to d = 7. Here d is again the distance: the fewest single-qubit errors that change the logical qubit without firing any check. Click a qubit to cycle it through X, Z, Y and back to no error (or use the arrow keys and Enter). Put an X error in the middle, then add X errors on its neighbours in a line, and walk the line to the left or right edge.

This figure needs JavaScript.

Fig. 1A rotated surface code patch. Data qubits sit at the corners of the tiles; orange tiles are X checks and blue tiles are Z checks, with two-qubit checks on the edges. Positions are given as (row, column), counted from (0, 0) at the top left, so at d = 3 the qubit at (r, c) is q(3r + c) of Lesson 1.

A lone X error in the middle fires the two Z checks that touch it. Add a neighbour in the same row and the Z check they share sees two errors and goes quiet: a chain of errors shows only its two ends. Walk the chain to the left or right edge and one end disappears, because the edge qubits belong to only one Z check. A chain that reaches both edges fires nothing at all. That chain is a logical X, the operator Lesson 1 drew along the top row.

The decoder, step by step

The syndrome says where chains end, not where they run, so the decoder has to guess. Many decoders treat the problem as a graph. Each check is a node, each data qubit is an edge between the two checks of one type that it touches, and an edge qubit links its one check to the boundary. Fired checks must be paired up, or paired with the boundary, by paths in this graph.

The decoder in this course is the union-find decoder of Delfosse and Nickerson. It starts with each fired check as a cluster of its own. A cluster with an odd number of fired checks cannot be explained from inside, so it grows by half an edge in every direction, the smallest odd clusters first. When two clusters meet they merge. Growth stops once every cluster holds an even number of fired checks or touches the boundary. Then, inside each cluster, the decoder picks a set of edges that links its fired checks in pairs or to the boundary, and flips those qubits.

The best-known alternative, minimum-weight perfect matching, searches the whole patch for the pairing with the shortest total length. Union-find only looks inside its clusters, so it is simpler, runs in close to linear time in the worst case, and is less accurate: sometimes it picks a longer correction than matching would. At the sizes used in this course it fails up to about twice as often; the threshold lesson measures the gap. Place some errors or draw random ones, then press Next step and watch the clusters grow.

This figure needs JavaScript.

Fig. 2The union-find decoder run by the course's engine. Each growth round is drawn from the decoder's own record: grown edges in the accent colour, cluster checks as dots. Then the correction, then the verdict on what error and correction leave behind.

The correction never needs to match the error qubit for qubit. It only needs to fire the same checks. Error and correction together then fire nothing, which leaves two possibilities. Either they form a product of checks, a stabilizer, which acts trivially on the stored state; or they form a logical operator, a chain from one edge to the opposite edge, and the logical qubit has been changed.

Why the decoder can be fooled

Press Load the example. It places X errors on the left (d + 1)/2 qubits of the top row, then step through the decoder to the verdict.

This figure needs JavaScript.

Fig. 3An error of weight (d + 1)/2 that the decoder completes into a logical X. The course's tests run this example at d = 3, 5 and 7 and confirm the failure.

The decoder flips the other (d − 1)/2 qubits of the top row. Error and correction together cover the whole row, which is the logical X, so the stored qubit has flipped. Yet the guess fires exactly the same checks as the true error, so both explain the syndrome equally well, and the guess uses fewer flips. When errors are independent and rare, fewer flips is more likely, and the guess is the better bet. This syndrome was simply produced by the less likely of the two. No decoder can tell them apart, which is why a code of distance d is only guaranteed to correct (d − 1)/2 errors.

When the checks themselves are wrong

So far every check reported its true value. In hardware a check is measured by a circuit, and that circuit can fail too, reporting a fired check that is not there or missing one that is. A single round of readings cannot tell a misread check from a real error. So the checks are measured over and over, and the decoder looks at detection events: places where a check's reading changes from one round to the next. A data error that appears and stays changes two neighbouring checks once, giving two events side by side in the same round. A misread check is wrong for one round only, giving two events on the same check in consecutive rounds.

The figure below shows this on a slice of five qubits in a line, the repetition code from the repetition code lesson, with four checks measured over four rounds; the last round is read without error, as it is when the data qubits themselves are measured at the end. Choose a case.

This figure needs JavaScript.

Fig. 4Check readings: what each check c0 to c3 reads in each round (red: fired; dashed outline: a reading that is wrong). Check ck compares qubits qk and qk+1, numbered from q0 as on the repetition code page. Detection events: where a reading differs from the round before. The decoder works on the space-time graph of all rounds.

A misread check leaves a pair of events stacked in time, and the decoder, working on a graph whose edges run through time as well as space, pairs them with a time edge: no data qubit is flipped. A data error leaves a pair in space and is corrected as before. The surface code works the same way, with a full patch of checks in every round.

Every decoder makes the wrong guess sometimes. The question for a real machine is how often, and whether a bigger patch makes it rarer. That is the subject of the next lesson.

Cite this lesson T. Pandey, "Errors, syndromes and decoding", Quantum Error Correction in Practice (2026), https://pandey-tushar.com/qec-in-practice/decoding.html