For the rotated code we use the layout of the notes: data , X-checks , Z-checks (syndrome bits in this order), and .
Problem 1
Problem 8.1 (The smallest planar code).
Apply Definition 8.1 with . List the data sites, number them in reading order, and write down all checks.
Verify that the checks commute, find , and give weight-2 logical operators , . Conclude that this is a code.
For distance , compare the total qubit count (data plus one ancilla per check) of the planar and rotated codes. What does the ratio tend to as ?
Solution
The grid is . Data sites ( even) are , numbered . The X-checks sit at and : and . The Z-checks sit at and : and . All four checks have weight 3, since every check touches a boundary.
meets in and in . meets them in and . All overlaps are even, so everything commutes. The four checks are independent, so . Take (the top row of horizontal edges) and (the left column). meets each X-check in 2 or 0 qubits, meets each Z-check in 2 or 0 qubits, and , share qubit 0, so they anticommute. No single-qubit Pauli commutes with all four checks: every qubit is in at least one X-check and one Z-check. So , and the code is .
The planar code uses qubits and the rotated code . The ratio is at , at , at , and it tends to . The rotated code saves a factor of two asymptotically.
Problem 2
Problem 8.2 (Lookup-table decoding of the 17-qubit code).
Consider X errors only. They are detected by the 4 Z-checks.
For each of the 16 possible syndromes, find a minimum-weight X error that produces it. Which syndromes need weight 2?
The decoder applies the table entry for the observed syndrome. Show that it corrects every single X error.
Show that the weight-2 error causes a logical failure, while is corrected. Why is this consistent with ?
Solution
Using the single-qubit syndromes from Example 8.1 and brute force over weights (bits in the order ):
syndrome
0000
0001
0010
0011
0100
0101
0110
0111
min-weight error
syndrome
1000
1001
1010
1011
1100
1101
1110
1111
min-weight error
Apart from , seven syndromes come from single errors. The other eight (0011, 0101, 0111, 1010, 1011, 1101, 1110, 1111) need weight 2. Ties are broken arbitrarily: for instance is a stabilizer and up to stabilizers.
Every single-qubit error has a syndrome whose table entry is either itself or its degenerate partner (, ). In the second case the residual is or , which are stabilizers. So all 9 single X errors are corrected.
has syndrome , the same as . The decoder applies , leaving : a logical error. has syndrome , whose table entry is itself, so it is corrected. A distance-3 code is only guaranteed to correct weight . Some weight-2 errors are corrected, but not all of them. is two thirds of a logical string, and the decoder completes the string instead of undoing it.
Problem 3
Problem 8.3 (Equivalent logical strings).
In the rotated code, show that and are both equivalent to , by writing each product with as an explicit product of X-checks.
Show that is also a logical X operator.
Prove that any X-type logical anticommutes with any Z-type logical in a CSS code, as long as both are nontrivial. Deduce that a horizontal and a vertical boundary-to-boundary string must cross an odd number of times.
Solution
. Then . Both products are products of X-checks (checked numerically), so all three columns are equivalent.
, which is times the bottom boundary check. Its path goes down column 0 and then steps right along the bottom edge.
Let be a nontrivial X-logical and a nontrivial Z-logical. With , the X-type logical classes are , so with a product of X-checks. Likewise . commutes with because is in the normalizer, and commutes with . Hence and commute or anticommute exactly as and do: they anticommute. For an X-string and a Z-string this means their supports overlap in an odd number of qubits, so they cross an odd number of times.
Problem 4
Problem 8.4 (Pauli propagation in the check circuits).
Use the X-check circuit of Proposition 8.2 (ancilla , data in CNOT order).
An error hits the ancilla just after CNOT , for (with meaning before the first CNOT, after the first ). Which data error results, and is the measurement outcome flipped?
Show that, up to multiplication by the check , every case has data weight at most 2.
Repeat part 1 for a error on the ancilla of the Z-check circuit.
Solution
X on the control is copied to the target of every later CNOT. The ancilla’s own X then passes through the final and becomes , which does not flip a Z-basis measurement.
fault after CNOT
data error
outcome flipped?
0
(= the check)
no
1
no
2
no
3
no
4
none
no
(Stim confirms and : the propagated Paulis are _XXXZ and __XXZ, with the ancilla last.)
Multiplying by , which acts trivially on the code, turns into and the full check into . The worst case is (weight 2) at . This is the hook error.
In the Z-check the ancilla is the target, so a Z on it is copied back to the controls of later CNOTs: after CNOT the data error is on the last qubits ( for ). A on the ancilla commutes with the final Z-measurement, so the outcome is not flipped. By contrast, an on the Z-check ancilla does not spread at all (X on a target stays put) and simply flips the outcome.
Problem 5
Problem 8.5 (How hook errors cost distance).
Suppose the X-checks of the rotated code use the N order (TL, BL, TR, BR).
Which pair of data qubits does a hook error on the ancilla of hit? Find a second single-qubit fault such that the two faults together apply up to stabilizers.
Explain why the memory-Z experiment (sensitive to X errors) loses distance, but the memory-X experiment does not.
For general odd with the bad order, explain why faults suffice for a logical error, matching the Stim table in the notes.
Solution
In N order the last two corners are TR and BR, which are qubits and . A hook gives , a vertical pair in column 2. One more data error completes , an entire column, which is equivalent to by Problem 8.3. Both faults happen in the same round, and commutes with every Z-check. So once the round is complete nothing is detected, and the final readout flips. Stim’s shortest_graphlike_error on our N/N circuit finds exactly this pattern: a two-qubit depolarizing fault that leaves an X on the X-ancilla at coordinates during the second CNOT layer, plus an X on data qubit 2.
Memory-Z prepares and measures , so it fails when an undetected X-type logical (, a vertical string) occurs. N-order hooks on X-checks are vertical pairs, so they help build . Z-type hooks on the Z-checks come from the Z-check ordering. If that ordering is correct (N order, last pair vertical, perpendicular to the horizontal ), memory-X keeps full distance.
A logical X error needs X on a whole column of qubits (up to stabilizers). With bad ordering, each hook supplies two vertically adjacent qubits of that column for one fault. Covering qubits takes hooks plus one single error when is odd: faults. This gives for , as in the table.
Problem 6
Problem 8.6 (Surface code circuits in Stim).
Generate stim.Circuit.generated("surface_code:rotated_memory_z", distance=d, rounds=d, after_clifford_depolarization=p, after_reset_flip_probability=p, before_measure_flip_probability=p, before_round_data_depolarization=p) with for . Count the detectors and explain the count.
Compute len(circuit.shortest_graphlike_error()). Is the circuit-level distance equal to ?
circuit.num_qubits reports 26 for . How many qubits does the circuit actually use, and why the difference?
Solution
import stimfor d in (3, 5): c = stim.Circuit.generated("surface_code:rotated_memory_z", distance=d, rounds=d, after_clifford_depolarization=1e-3, after_reset_flip_probability=1e-3, before_measure_flip_probability=1e-3, before_round_data_depolarization=1e-3) print(d, c.num_detectors, len(c.shortest_graphlike_error()), c.num_qubits)
We get 24 detectors for and 120 for . In round 1, only the Z-checks are deterministic, because the data starts in . Rounds give a detector for every one of the checks, comparing it with the previous round. The final data readout reconstructs the Z-checks once more. The total is , which is and .
Yes: the graphlike distance is and . Stim’s generator uses a hook-safe CNOT order.
The circuit uses qubits. num_qubits is the largest qubit index plus one, and Stim numbers qubits by position on a coordinate grid, so some indices are never used. This is a common source of confusion when counting hardware.