Consider the distance-5 bit-flip repetition code with checks . Qubit suffers an X error independently with probability .
Show that the most probable error with a given syndrome minimizes with .
Let , and suppose only is flagged. List the two candidate corrections, compute their total weights, and say which one MWPM chooses.
Compute the probabilities of the two candidates, and , and check that they agree with part 2. Which correction would MWPM choose if all were equal?
Solution
Write . The first factor does not depend on . Taking , maximizing over the errors with the given syndrome is the same as minimizing .
A single defect at is explained either by (the path from to the left boundary) or by (the path from to the right boundary). The weights are and each. So the costs are
MWPM picks the four-qubit correction. Running pymatching.Matching(H, weights=w) on the syndrome indeed returns .
and . The four-qubit error is more than three times as likely, which agrees with part 2. With equal all weights are equal, and MWPM picks , which has the smaller Hamming weight. The lesson: “minimum weight” means minimum log-likelihood weight, not minimum number of flips.
Problem 2
Problem 10.2 (A lookup table for the distance-3 rotated code).
Use the layout of the Module 10 notes (Example 10.1), which is the Module 8 layout mirrored left to right and numbered 1 to 9: Z checks , , , ; X checks , , , ; . (Module 8 qubit is qubit here, so the Homework 8 syndrome table carries over after relabeling.)
Explain why there are exactly 16 distinct X-error syndromes.
Find all minimum-weight X errors with syndrome , and .
For each syndrome in part 2, show that all the minimum-weight errors lie in the same logical class. (Hint: what is the product of two of them?)
Syndrome has a unique minimum-weight error. Find it. Is the lookup decoder correct when the true error is that error? When it is ?
Solution
X errors are detected by the four Z checks, so the syndrome lives in . The four Z-check rows are linearly independent (rank 4), so the map is onto , and all syndromes occur.
By brute force, or by hand:
: and . Each sits only in among the Z checks.
: , and .
: , and .
Two errors with the same syndrome differ by an operator with trivial syndrome. It is either a stabilizer or a logical. Here every product is a stabilizer:
, a boundary check.
, a check. , a check.
, a check. , a check.
So in each case the ties are equivalent, and which one is stored does not matter.
The unique minimum-weight error for is : qubit 5 is the only qubit in both and and in no other Z check. If the true error is , the correction cancels it, and decoding succeeds. The error has the same syndrome ( flips only , flips only ). The decoder still applies , and the net operator is , a logical error. That is expected: a distance-3 code corrects all weight-1 errors but not all weight-2 errors.
Problem 3
Problem 10.3 (When entropy beats energy).
In the distance-5 example of the notes (three flagged checks, i.i.d. X noise on 25 qubits), the two logical classes have weight enumerators, truncated at weight 8,
So class B has one error of weight 3, 28 of weight 5, and so on.
Which class does the minimum-weight decoder choose? Does the answer depend on ?
Using only the leading terms, find the at which ML switches from B to A.
Using the truncated enumerators, compute and at and . Which class does ML choose at each?
Explain in one or two sentences why the minimum-weight threshold of a code family can be lower than its ML threshold.
Solution
MW picks class B, which contains the unique weight-3 error. This does not depend on (as long as ).
Class probabilities are . The leading terms are for B and for A, with . A wins when , that is, when , so when .
With :
ML choice
0.05
B
0.10
A
These agree with the exact sums over all stabilizers given in the notes, to three digits. Keeping only the leading terms would have given versus at . The leading-order estimate is too crude this close to the switching point.
ML compares the total probability of each class, and a class with many slightly heavier errors can outweigh one with a single light error. Near threshold, errors are dense and these multiplicities (“entropy”) grow exponentially with size, so ignoring them, as MW does, makes the decoder choose the wrong class more often. The toric code with independent noise shows this: about for MWPM versus about for ML.
Problem 4
Problem 10.4 (Counting and constructing matchings).
Show that the complete graph on nodes has perfect matchings. Evaluate it for .
On an torus with uniform weights, defects sit at , , , . Compute the toric Manhattan distances and the weights of all perfect matchings. Which does MWPM choose?
A planar-code matching graph has an odd number of defects. Explain the boundary-copy construction from the notes, and show that the augmented syndrome graph always has a perfect matching. Show also that every perfect matching of it gives a valid correction.
Solution
Node 1 can be matched to any of the other nodes. Removing that pair leaves a complete graph on nodes. By induction the count is . The values are , and , so brute force quickly becomes hopeless.
On the torus, . This gives , , , , , . The three matchings weigh , and . MWPM chooses .
For each defect , add a copy with an edge of weight , and join all copies pairwise with weight 0. With defects there are nodes, an even number. Pairing every with its own , and the copies with each other as needed, is already a perfect matching, so one always exists. Conversely, in any perfect matching each defect is matched either to another defect (use a shortest path between them) or to its own or another defect’s copy. A copy is only adjacent to and to other copies, so a defect can only be matched to its own copy (use a shortest path from to the boundary). Copies left over pair among themselves at no cost. The union of the chosen paths mod 2 has boundary exactly the defect set, because paths to the boundary end on the boundary node, which is not a check. So it is a valid correction.
Problem 5
Problem 10.5 (The path decomposition behind MWPM).
Let be a graph with positive edge weights. Let be an edge set, and let be the set of nodes with odd degree in .
Prove that is even.
Prove that is the disjoint union of paths, whose endpoints pair up the nodes of , and a set of cycles.
Conclude that the weight of a minimum perfect matching of the complete graph on with edge weights (shortest-path distances).
Where did you use positivity of the weights? How should a decoder handle a mechanism with ?
Solution
The sum of degrees in is , which is even. A sum of integers is even only if an even number of them are odd.
Pick and walk along unused edges of . When the walk enters a node for the -th time, it has used an odd number of ‘s edges (), and ‘s degree is even, so an unused edge remains to leave by. When the walk enters a node of other than , it may stop. (If the walk returns to , it can continue, because ‘s degree is odd and it has now used an even number of ‘s edges.) The walk uses each edge at most once and the graph is finite, so it ends at some . Extract a simple path from to out of the walk. Its edges form a path , and has odd set . Induct. When is empty, every degree is even, and such an edge set is a union of edge-disjoint cycles (by the same walking argument, which must return to its start).
The edges dropped while extracting simple paths form closed walks. They have even degree everywhere and also decompose into cycles.
Each path from to has weight at least , and the cycles have weight . So , the weight of some perfect matching on , which is at least the minimum.
Positivity was used twice: to say the leftover cycles weigh at least 0, and, in the achievability direction of the theorem, to say that cancelling edges mod 2 cannot increase the weight. With the weight is negative, and both steps fail: adding a cycle through edge can lower the cost. The fix is to change variables. Assume mechanism did fire, replace by , and toggle the syndrome bits at the endpoints of edge accordingly. The new variable fires with probability and has positive weight , so the theorem applies again.
Problem 6
Problem 10.6 (A code-capacity threshold with PyMatching).
Build the toric code check matrix ( vertex checks, edge qubits) for . Sample i.i.d. Z errors with probability , decode with pymatching.Matching(Hx).decode_batch, and count a failure when the residual has odd overlap with either of the two dual non-contractible cuts.
Estimate for with at least shots each.
Where do the curves cross? Compare with the literature value of about .
Explain why checking ” has odd overlap with a cut” detects exactly the logical failures.
Solution
Run with the memory guard of the course, as for all scripts:
import numpy as np, pymatchingrng = np.random.default_rng(1)def toric_HX(L): h = lambda r, c: (r % L) * L + (c % L) v = lambda r, c: L * L + (r % L) * L + (c % L) H = np.zeros((L * L, 2 * L * L), dtype=np.uint8) for r in range(L): for c in range(L): for q in (h(r, c), h(r, c - 1), v(r, c), v(r - 1, c)): H[r * L + c, q] = 1 cuts = np.zeros((2, 2 * L * L), dtype=np.uint8) for r in range(L): cuts[0, h(r, 0)] = 1 # dual loop crossing column-0 horizontal edges for c in range(L): cuts[1, v(0, c)] = 1 # dual loop crossing row-0 vertical edges return H, cutsfor L in (8, 12, 16): H, cuts = toric_HX(L); m = pymatching.Matching(H) for p in (0.08, 0.09, 0.10, 0.11, 0.12): E = (rng.random((20000, H.shape[1])) < p).astype(np.uint8) C = m.decode_batch(E @ H.T % 2) fail = ((cuts @ ((E + C) % 2).T) % 2).any(axis=0).mean() print(L, p, round(fail, 4))
Our run (20000 shots per point) gave
0.08
0.09
0.10
0.11
0.12
8
0.132
0.191
0.265
0.339
0.407
12
0.090
0.158
0.252
0.348
0.442
16
0.063
0.137
0.248
0.366
0.482
Your numbers will differ by roughly .
Below larger is better, and at it is worse. Interpolating the and curves gives a crossing near , consistent with .
has zero syndrome, so it is a closed Z-loop (a cycle). A Z-cycle is a product of plaquette stabilizers exactly when it is homologically trivial. On the torus it is trivial exactly when it crosses each of the two independent dual non-contractible loops an even number of times. Those dual loops are the supports of the two logicals, so odd overlap means the residual anticommutes with a logical , which is a logical error.