|q⟩ Bad Qubits

advanced · Programming · Implementing the Surface Code

Matching Decoders (Overview)

A decoder turns a syndrome into a correction. For the surface code the workhorse algorithm is minimum-weight perfect matching (MWPM), which exploits a beautiful fact: errors create detection events in pairs, and the most likely error is the one that connects those events by the shortest path.

Detection events as graph vertices

Recall that a detection event is a check whose value changed between rounds. Consider ZZ-type checks, which fire on XX errors. A single XX error on a bulk data qubit touches two neighbouring ZZ-checks, so it lights up two detection events. A chain of kk adjacent XX errors lights up events only at its two endpoints — all the interior checks see an even number of flips and stay quiet.

So whatever error chain occurred, the lit detection events always come in pairs marking the ends of chains. The decoder's task is to guess the chains from the endpoints.

Matching on a graph

Build a graph whose vertices are the lit detection events. Connect every pair of vertices by an edge weighted by the distance between them on the lattice — the minimum number of data qubits an error chain would have to flip to join them. A perfect matching pairs up all the vertices; its weight is the total length of the chosen chains. MWPM finds the matching of minimum total weight:

M^=argminM perfect matching(u,v)Mw(u,v).\hat{M} = \arg\min_{M \text{ perfect matching}} \sum_{(u,v)\in M} w(u, v).

Each matched pair tells the decoder a chain of corrections to apply between those two events. Under the standard independent-error model, edge weights are set to wlog ⁣(p/(1p))w \propto -\log\!\big(p/(1-p)\big) for per-step error probability pp, so the minimum-weight matching is exactly the most probable error configuration consistent with the syndrome.

Why it usually works — and when it fails

For low physical error rates, short chains dominate, and matching nearby events almost always recovers the true error up to a harmless stabilizer (a closed loop that acts trivially on the logical state). The decoder fails only when the real error chain and the correction chain together wind all the way across the patch, forming a logical operator — and that requires at least dd errors, which is exponentially unlikely below threshold.

Where it fits

MWPM is fast (near-linear time in practice) and has a high threshold, which is why it remains a default surface-code decoder. Modern alternatives — union-find, belief propagation, and neural decoders — trade some accuracy for speed or vice versa, but they all solve the same underlying problem: pairing detection events into the most likely error. The next lessons make precise what "a chain of length dd" means for the logical qubit and for the code's tolerance to errors.

Sign in on the full site to ask questions and join the discussion.