|q⟩ Bad Qubits

advanced · Programming · Implementing the Surface Code

Checkpoint: One Surface-Code Round

This checkpoint ties the module together: you will run one round of stabilizer measurements on a small chain, inject a single error, and read off a syndrome that pinpoints it — exactly the input a matching decoder consumes.

The setup

Take a one-dimensional chain of three data qubits, 0,1,20, 1, 2 — the bit-flip "spine" of a small surface-code patch. Two neighbouring ZZ-type checks watch it:

S1=Z0Z1(ancilla 3),S2=Z1Z2(ancilla 4).S_1 = Z_0 Z_1 \quad\text{(ancilla } 3\text{)}, \qquad S_2 = Z_1 Z_2 \quad\text{(ancilla } 4\text{)}.

The middle data qubit 11 is shared by both checks. This is the key structural feature of the surface code: an error on a shared qubit lights up both adjacent checks, which is how the decoder localises it.

What a middle error does

Suppose a bit-flip X1X_1 strikes the middle data qubit, leaving the data in 010|010\rangle. Then

S1:  q0q1=01=1,S2:  q1q2=10=1.S_1: \; q_0 \oplus q_1 = 0 \oplus 1 = 1, \qquad S_2: \; q_1 \oplus q_2 = 1 \oplus 0 = 1.

Both checks fire — syndrome (1,1)(1, 1). Compare with an error on an end qubit, say X0X_0, which would give syndrome (1,0)(1, 0) since only S1S_1 touches qubit 00. The pattern of which checks fire is therefore a fingerprint of where the error is:

| Error | S1S_1 | S2S_2 | |--------|-------|-------| | none | 0 | 0 | | X0X_0 | 1 | 0 | | X1X_1 | 1 | 1 | | X2X_2 | 0 | 1 |

A decoder reads the syndrome column and infers the most likely error. Here (1,1)(1,1) unambiguously points at the middle qubit.

Try it

Build the full round in one circuit on five qubits: data 0,1,20,1,2, ancilla 33 for S1=Z0Z1S_1=Z_0Z_1, ancilla 44 for S2=Z1Z2S_2=Z_1Z_2. Inject the error with c.x(1), extract each check with a pair of CNOTs into its ancilla, then measure both ancillas. The grader checks that the only outcome with non-zero probability is 01011|01011\rangle — data 010010, syndrome (1,1)(1,1).

Run your code to see the quantum state.

After running, the Probabilities tab should show a single bar at 0101101011: the middle qubit is flipped and both syndrome bits read 11, exactly localising the error.

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