Hello! Welcome to your seventh lesson in the module on Quantum Error Correction Fundamentals.
In our last lesson, we constructed the encoding circuit for the 9-qubit Shor code. We established that it is a [[9,1,3]] stabilizer code defined by a set of eight commuting stabilizer generators: six -type generators to detect bit-flips within blocks, and two -type generators to detect phase-flips across blocks.
Today, we will build directly on that foundation. Our learning outcome is to implement the syndrome measurement circuits for the 9-qubit Shor code to extract bit-flip and phase-flip error syndromes. We will design the specific quantum circuits that measure the eigenvalues of each of the eight stabilizer generators, and then see how the combined 8-bit result—the syndrome—uniquely identifies single-qubit errors.
1. The Principle of Stabilizer Measurement
Before diving into the specifics of the Shor code, let's briefly revisit the general method for measuring the eigenvalue of a Pauli operator, . The standard circuit uses an auxiliary qubit, or ancilla, prepared in the state. A controlled- operation is applied, where the ancilla is the control and the data qubits are the target. Finally, the ancilla is measured in the Hadamard basis.
generic_stabilizer_measurement
Figure from "Quantum error correction : an introductory guide" by C. G. Brell. This diagram shows the general circuit for measuring a stabilizer operator P_i using an ancilla qubit A_i. The ancilla is prepared in |+\rangle, a controlled-P_i gate is applied, and the ancilla is then measured in the X-basis (equivalent to H then Z-basis measurement).
The measurement outcome of the ancilla directly corresponds to the eigenvalue of for the data state. If the ancilla is measured as , the eigenvalue is +1 (no error detected by this stabilizer). If it's measured as , the eigenvalue is -1 (an error has anti-commuted with this stabilizer). Our task is to construct the controlled-P gates for all eight of the Shor code's generators.
2. Measuring Bit-Flip Syndromes (Z-type Stabilizers)
The first six generators of the Shor code detect bit-flip errors. They are of the form . Let's take the first generator, , as our example. We need a circuit to measure its eigenvalue.
A key insight is that the eigenvalue of for a computational basis state is +1 if the parity of the bits is even () and -1 if the parity is odd (). Therefore, measuring is equivalent to measuring the bitwise parity of qubits and .
The circuit to measure the parity of two qubits, and , and write the result to an ancilla qubit is:
- Initialize the ancilla:
H(a) - Compute parity:
CNOT(qi, a)followed byCNOT(qj, a) - Return to computational basis:
H(a) - Measure the ancilla:
Measure(a)

To measure the six bit-flip syndromes, we would use six separate ancilla qubits and repeat this pattern for each of the pairs:
- Syndrome bit (for ):
CNOT(q0, a0),CNOT(q1, a0) - Syndrome bit (for ):
CNOT(q1, a1),CNOT(q2, a1) - ...and so on for , , , and .
Each of these six sub-circuits will produce one bit of the final syndrome. A '1' indicates that a bit-flip may have occurred that distinguishes the two qubits involved (e.g., a flip on but not ).
3. Measuring Phase-Flip Syndromes (X-type Stabilizers)
The remaining two generators detect phase-flip errors across the blocks. They are multi-qubit Pauli-X operators:
Measuring these follows a more direct implementation of the controlled-Pauli gate. A controlled- gate is simply a CNOT gate where the ancilla is the control and the data qubit is the target. To measure an operator like , we just chain these CNOTs together.
The circuit to measure on qubits 0 through 5 using ancilla is:
- Initialize the ancilla:
H(a6) - Apply controlled-X operations:
CNOT(a6, q0),CNOT(a6, q1),CNOT(a6, q2),CNOT(a6, q3),CNOT(a6, q4),CNOT(a6, q5) - Return to computational basis:
H(a6) - Measure the ancilla:
Measure(a6)
If the ancilla state is applied to the data, it leaves the state . After the final Hadamard, the ancilla's state will depend on whether was an eigenstate of . A measurement of '1' on the ancilla means a phase-flip error (or any error that anti-commutes with ) has likely occurred.
An identical circuit structure is used to measure with an eighth ancilla, , targeting qubits 3 through 8.
The following resource provides a detailed guide to quantum error correction. While it discusses syndrome measurement in a general stabilizer context, its explanation is directly applicable here.
Quantum error correction : an introductory guide
The paper "Quantum error correction : an introductory guide" by C. Brell provides a solid introduction to stabilizer measurement. The principles it outlines for a general [[n, k, d]] code form the basis for our specific Shor code implementation.
Please review Section 4, "Stabilizer codes", focusing on Figure 4 and the accompanying text (Equation 29). This section formalizes the syndrome extraction process we've just discussed, showing how each ancilla measurement reveals the eigenvalue of its corresponding stabilizer generator. You don't need to read the full section, but focusing on the circuit diagram and its description will reinforce the general principle.
4. Interpreting the Syndrome
Once we run these eight measurement circuits, we obtain an 8-bit string, . This is the error syndrome. The value of this syndrome tells us which error occurred. How? An error flips the syndrome bit if and only if it anti-commutes with the corresponding stabilizer generator .
Let's consider two examples:
-
Case 1: Bit-flip error
- Z-stabilizers: anti-commutes with any operator on qubit 4. This includes and . So, we expect and . All other generators act on other qubits, so they commute with .
- X-stabilizers: commutes with all Pauli-X operators. Thus, it commutes with and . We expect and .
- Full Syndrome:
00110000. This syndrome points to a bit-flip in block 2 ( are non-zero) and specifically to qubit 4, which is the only one involved in both and .
-
Case 2: Phase-flip error
- Z-stabilizers: commutes with all generators. All six bit-flip syndrome bits will be 0.
- X-stabilizers: anti-commutes with . Both and contain an term. Therefore, anti-commutes with both. We expect and .
- Full Syndrome:
00000011. This syndrome indicates no bit-flip error but a phase-flip error in a qubit common to the support of and , i.e., in block 2 (qubits 3,4,5).
The following lecture notes include a table summarizing the syndromes for all single-qubit Pauli errors.
These lecture notes on Quantum Error Correction by R. Renes provide a concise but comprehensive overview of the Shor code's stabilizer structure.
Please read Section 1.6.5, "Shor code stabilizer structure". Focus on the table at the end of the section. It explicitly lists the syndromes for all single-qubit X, Y, and Z errors. Compare the syndromes we derived for X4 and Z4 with the entries in the table to verify our reasoning.
Test your understanding!
What syndrome would you expect for a error? Recall that .
Show answer
An error will anti-commute with a stabilizer if an odd number of its Pauli components anti-commute.
- Z-stabilizers:
- The part anti-commutes with (no) and (yes).
- The part commutes with all Z-stabilizers.
- So, only anti-commutes. Syndrome bits should be
000001.
- X-stabilizers:
- The part anti-commutes with (no) and (yes).
- The part commutes with all X-stabilizers.
- So, only anti-commutes. Syndrome bits should be
01.
The full syndrome for is 00000101. You can verify this in the table from the resource LINK.
Your Task: Implementation
Now it's time to put this into practice. Your task is to implement and simulate the syndrome extraction process. Given your background in implementing simulations, this should be a familiar process of building a model (the circuit) and testing it against theoretical predictions (the syndromes).
Please use a quantum circuit simulator like Qiskit or Cirq to perform the following steps:
- Build the Encoder: Start by creating the 9-qubit Shor code encoding circuit from the previous lesson. Encode the state into the logical state .
- Introduce an Error: Manually insert a single-qubit Pauli error on one of the nine data qubits. For example, apply an
Xgate toq_5. - Build the Syndrome Measurement Circuit: Create a circuit that measures all eight stabilizer generators. This will require 9 data qubits and 8 ancilla qubits.
- For each of the six Z-stabilizers, implement the parity measurement circuit using two CNOTs targeting an ancilla.
- For each of the two X-stabilizers, implement the circuit using a chain of CNOTs controlled by an ancilla.
- Simulate and Verify:
- Combine the circuits: Encoder Error Syndrome Measurement.
- Run the simulation and measure the eight ancilla qubits.
- The 8-bit outcome is your measured syndrome. Compare it to the expected syndrome for the error you introduced (e.g., for , you'd expect the syndrome
00011000). - Repeat for a phase-flip error, like
Zonq_1, and verify you get the expected syndrome00000010.
This exercise directly addresses the learning outcome by having you construct and use the syndrome measurement circuits to identify specific, known errors.
Conclusion
In this lesson, we have designed the complete syndrome measurement apparatus for the 9-qubit Shor code.
Key Takeaways:
- Syndrome measurement relies on using ancilla qubits to non-destructively measure the eigenvalues of the stabilizer generators.
- Z-type stabilizers () are measured using a circuit that computes the parity of the two corresponding data qubits.
- X-type stabilizers () are measured using a chain of CNOT gates controlled by an ancilla.
- The resulting 8-bit syndrome is a unique fingerprint that, for single-qubit errors, allows us to diagnose both the type and location of the error.
Preview of the next lesson:
We have now seen how to encode a state and how to detect an error. The final step in the error correction process is to use the syndrome to apply a corrective operation. In the next lesson, we will complete the cycle by implementing the decoding logic and correction operations for the 9-qubit Shor code to recover the original logical state.