Throughout, the distance-3 repetition code has data qubits and ancillas . Check A is (ancilla 1) and check B is (ancilla 3). A detector stream is .
Problem 1
Problem 9.1 (Reading the streams).
For each pair of outcome streams over rounds , compute the detection events and give the most likely single fault (data flip on which qubit and when, or measurement error on which check and when).
A: and B: .
A: and B: .
A: and B: .
A: and B: . Give two different explanations with two faults each.
Solution
The detection streams (computed):
A: and B: . A space-like pair at . Both checks changed at once, so the middle data qubit 2 flipped between rounds 2 and 3.
A: and B: all zero. A time-like pair on A at : check A’s measurement in round 3 was wrong.
A: and B: all zero. A single event on A at , a boundary event. Data qubit 0 (the end qubit seen only by A) flipped between rounds 1 and 2.
A: and B: all zero. Two events on A, at and . Explanation (i): measurement errors on A in rounds 2 and 3. That gives events at and , and the events cancel. Explanation (ii): data qubit 0 flips before round 2 and flips back before round 4. Two boundary events. Both explanations use two faults. In the decoding graph they are two different edge sets with the same endpoints, and they have the same effect on the observable (qubit 4 is untouched in both). This is degeneracy again, now in space-time.
Problem 2
Problem 9.2 (Where detectors go).
In a memory of the rotated surface code, prove that an X-check outcome in the first round is uniformly random. (Use the measurement rule of Module 6.)
Now consider a memory: data reset to , final data measured in the X basis. Describe the first-round, middle and final detectors and count them.
Prove the count for a distance- repetition code with rounds. Check it against the Stim circuit of the notes (, ).
Solution
The initial state is stabilized by . An X-check anticommutes with for any in its support, so anticommutes with some stabilizer generator of the state. By the measurement rule, the outcome of measuring is then with probability each. No parity involving only this outcome is deterministic, so it cannot be a detector.
Exchange the roles of X and Z. In round 1 only the X-checks are deterministic, and each gets a single-outcome detector. In rounds , all checks get comparison detectors. After the transversal X-basis readout, each X-check is recomputed as the parity of its data outcomes and compared with its last ancilla outcome: more. The total is again . The observable is the parity of the X-basis data outcomes along an string (a column in the layout of Module 8).
All checks are Z-type and deterministic from the start: detectors in round 1, in each of rounds , and final detectors from the data readout. That makes . For , (one round before the REPEAT 5, five inside it) we get , which matches circuit.num_detectors.
Problem 3
Problem 9.3 (A detector error model by hand).
One round of the distance-3 repetition code: reset all qubits; X_ERROR(0.01) on the data; the CNOTs; X_ERROR(0.02) on the ancillas; measure the ancillas (detectors D0 for A, D1 for B); then X_ERROR(0.03) on the data; measure the data; final detectors D2 (A) and D3 (B); observable L0 = data qubit 4.
List every error mechanism with its probability, detectors and observable effect.
Draw the decoding graph. Which edges cross the observable?
Suppose a second, independent X_ERROR(0.03) is applied to data qubit 0 before the final measurement. Which line of the DEM changes, and to what?
Solution
Eight mechanisms (Stim agrees exactly):
fault
probability
symptom
data 0 before round 1
0.01
D0
data 2 before round 1
0.01
D0 D1
data 4 before round 1
0.01
D1 L0
ancilla 1 measurement
0.02
D0 D2
ancilla 3 measurement
0.02
D1 D3
data 0 before readout
0.03
D2
data 2 before readout
0.03
D2 D3
data 4 before readout
0.03
D3 L0
To see why a data-0 flip before round 1 gives only D0: check A reads in round 1 (D0 fires), and the final recomputation does not fire.
Nodes D0, D1 (round 1) and D2, D3 (final), plus a boundary node. Space-like edges: D0-D1 and D2-D3. Time-like edges: D0-D2 and D1-D3. Boundary edges: D0, D2 (left, data 0) and D1, D3 (right, data 4). The two right boundary edges carry L0.
The mechanism D2 now arises from either of two independent faults, so its probability becomes . Stim prints error(0.0582) D2.
Problem 4
Problem 9.4 (Merging many mechanisms).
Let independent mechanisms with probabilities all have the same symptom. Show that the merged mechanism has probability
Check that it reduces to Lemma 9.1 for , and evaluate it for . Why is always?
Solution
Let indicate whether mechanism fires. Then , and by independence
The left side is . Solving gives the formula. For :
For : , so . Direct enumeration of the 8 cases gives the same value. If every , each factor lies in , so the product is and . Merging many weak mechanisms approaches a fair coin but never passes it. A mechanism with would just be “the opposite symptom is the default”.
Problem 5
Problem 9.5 (Hyperedges in the surface code).
Use the rotated code of Module 8 in a memory experiment with many rounds and code-capacity-style data depolarization between rounds.
How many detectors does a error on data qubit 4 flip in a middle round? On qubit 0? On qubit 1?
Explain why a mechanism that flips 4 detectors is not an edge of a graph, and how decompose_errors=True fixes this.
Matching the X-part and Z-part independently ignores the fact that they are correlated (a is one fault, not two). Under depolarizing noise, is the probability of “an X-type flip on qubit ” in the decomposed model or ? What information is lost?
Solution
flips every check of either type containing the qubit, and each flipped check fires its detector for that round. Qubit 4 is in two X-checks (, ) and two Z-checks (, ), so 4 detectors. Qubit 0 (a corner) is in one X-check and one Z-check (): 2 detectors. Qubit 1 is in two X-checks (, ) and one Z-check: 3 detectors. Stim’s undecomposed DEM for this setting indeed contains 3- and 4-detector mechanisms.
An edge has exactly two endpoints (or one plus the boundary). A matching decoder pairs up detection events along edges, so a 4-detector symptom has no representation. Decomposition writes the symptom as the XOR of graphlike pieces, here the X-part (2 Z-check detectors) and the Z-part (2 X-check detectors), printed as error(p) Da Db ^ Dc Dd. Each piece becomes, or is merged into, an ordinary edge.
An X-type flip on happens for or , so it has probability , and likewise for Z-type. The decomposed graph treats the X-flip and the Z-flip as if independent. It cannot see that a makes both happen together with probability , rather than the independence would suggest. This correlation is what “correlated matching” and other decoders in Modules 10 and 11 try to recover. It is a big part of why the depolarizing threshold of the toric code is higher with an optimal decoder than with independent X/Z matching.
Problem 6
Problem 9.6 (A threshold experiment in Stim).
Write a generator rep_phenom(d, r, p, q) for the distance- repetition code with rounds. In each round apply X_ERROR(p) to every data qubit, the CNOTs, X_ERROR(q) to the ancillas, then MR on the ancillas. Finish with a noiseless data readout and final detectors. The observable is the last data qubit.
Check that the circuit has detectors and that the DEM has mechanisms.
With and , estimate the logical error rate per shot with PyMatching for and ( shots each).
Where do the curves cross? Why is this “repetition code with measurement errors” the same graph problem as the toric code under code-capacity noise?
Solution
import stim, pymatching, numpy as npdef rep_phenom(d, r, p, q): data = list(range(0, 2 * d - 1, 2)); anc = list(range(1, 2 * d - 2, 2)); m = len(anc) c = stim.Circuit(); c.append("R", data + anc) for t in range(r): c.append("X_ERROR", data, p) c.append("CX", [x for a in anc for x in (a - 1, a)]) c.append("CX", [x for a in anc for x in (a + 1, a)]) c.append("X_ERROR", anc, q); c.append("MR", anc) for i in range(m): recs = [stim.target_rec(-m + i)] + ([stim.target_rec(-2 * m + i)] if t else []) c.append("DETECTOR", recs, [2 * i + 1, t]) c.append("M", data); n = len(data) for i in range(m): c.append("DETECTOR", [stim.target_rec(-n + i), stim.target_rec(-n + i + 1), stim.target_rec(-n - m + i)], [2 * i + 1, r]) c.append("OBSERVABLE_INCLUDE", [stim.target_rec(-1)], 0) return cfor p in (0.01, 0.03, 0.05, 0.08, 0.10, 0.12, 0.14): for d in (3, 5, 7): c = rep_phenom(d, d, p, p) mt = pymatching.Matching.from_detector_error_model(c.detector_error_model()) det, obs = c.compile_detector_sampler(seed=11).sample(100_000, separate_observables=True) print(p, d, np.mean(mt.decode_batch(det)[:, 0] != obs[:, 0]))
For : 8, 24, 48 detectors and 15, 45, 91 mechanisms. Each round has data mechanisms and measurement mechanisms, all with distinct symptoms.
Our run gave:
0.01
0.03
0.05
0.08
0.106
0.084
0.073
0.10
0.150
0.139
0.140
0.12
0.193
0.201
0.217
0.14
0.237
0.260
0.293
The curves cross near . Below it, larger is better, and the improvement is dramatic at small : is 100 times better than at . Above it, larger is worse. The decoding graph is a 2D square lattice: space (along the chain) times time (rounds). Data errors are the space-like edges and measurement errors are the time-like edges, each with probability . Matching pairs of defects on a 2D square lattice with i.i.d. edge flips is exactly the problem of decoding one error type of the toric code under code-capacity noise (Homework 7, Problem 6), whose matching threshold is about . The boundaries and the observable differ, but the bulk statistics, and hence the threshold, are the same.