Recommended resources
The freely available resources this lesson will direct you to.
Hello! Welcome to the sixth lesson in our module on Quantum Error Correction Fundamentals.
In our previous lesson, we implemented the 5-qubit "perfect" code. We saw how to construct syndrome measurement circuits and use the resulting syndrome—a unique fingerprint for each single-qubit error—to perform a correction. This provided a concrete application of the stabilizer formalism we had developed.
Today, we turn our attention to the first quantum error-correcting code ever discovered: the 9-qubit Shor code. Our goal is to construct the encoding circuit for the 9-qubit Shor code and demonstrate that it is a stabilizer code. This code introduces the powerful concept of concatenation and showcases a different approach to protecting a logical qubit.
1. Concatenated Codes: Building the Shor Code
The Shor code elegantly protects against both bit-flip () and phase-flip () errors by composing, or concatenating, two simpler codes.
-
Inner Code: 3-Qubit Bit-Flip Code
This code protects against a single error. It encodes a single qubit state into three qubits:- $|0\rangle \to |000\rangle$
- $|1\rangle \to |111\rangle$
The circuit for this is simply two CNOT gates, with the input qubit as the control and two ancillas as targets.
-
Outer Code: 3-Qubit Phase-Flip Code
This code protects against a single error. It achieves this by performing the bit-flip encoding in the Hadamard basis (). The encoding is:- $|0\rangle \to |+_L\rangle = \frac{1}{\sqrt{2}}(|000\rangle + |111\rangle)$
- $|1\rangle \to |-_L\rangle = \frac{1}{\sqrt{2}}(|000\rangle - |111\rangle)$
The circuit for this involves first creating a GHZ-like state.
The Shor code is constructed by first applying the phase-flip encoding and then applying the bit-flip encoding to each of the three resulting qubits.
2. The Encoding Circuit
Let's construct the circuit for encoding an initial state on qubit into the 9-qubit Shor code state, using qubits as ancillas (initially in the state). The process is as follows:
-
Outer Encoding (Phase-Flip Part): We first create the superposition characteristic of the phase-flip code. This involves entangling the input qubit with two other qubits, say and .
- Apply a Hadamard gate to .
- Apply CNOT gates from to and from to .
After this stage, the state on qubits is .
-
Inner Encoding (Bit-Flip Part): Now, we apply the bit-flip code to each of the three qubits from the previous step. We group the nine qubits into three blocks: , , and .
- Block 1: Apply CNOTs from to and . This encodes the state of .
- Block 2: Apply CNOTs from to and . This encodes the state of .
- Block 3: Apply CNOTs from to and . This encodes the state of .
The following resource from IBM Quantum's learning platform illustrates this exact construction.
The article 'The 9-qubit Shor code' provides an excellent description of the code's construction as a concatenated code and presents the corresponding encoding circuit.
Please read the first two subsections, 'Code description' and 'Correcting bit-flip and phase-flip errors'. Focus on the structure of the encoding circuit diagram. Note how it's composed of an initial 'outer code' part followed by three parallel 'inner code' blocks. This directly visualizes the concatenation process we've just discussed.
The resulting logical basis states, and , are:
These expressions can look intimidating, but they follow directly from the circuit: the outer encoding creates the three identical superpositions, and the inner encoding replaces each with and each with .
3. The Shor Code as a Stabilizer Code
Now we need to demonstrate that this code fits into the stabilizer formalism we've been using. A stabilizer code is the simultaneous eigenspace of a set of commuting Pauli operators, known as the stabilizer generators. For the 9-qubit Shor code, we need independent generators.
Where do these generators come from? They arise directly from the stabilizers of the constituent codes.
Stabilizers for Bit-Flip Errors
The inner code (bit-flip code) for each of the three blocks is stabilized by operators that check if adjacent qubits are the same. These are:
- Block 1 (qubits 0,1,2): ,
- Block 2 (qubits 3,4,5): ,
- Block 3 (qubits 6,7,8): ,
This gives us our first six stabilizer generators. For example, consider . In the state , it acts on terms like and . In both cases, the eigenvalues of and are the same ( or ), so their product is . The state is thus stabilized.
Stabilizers for Phase-Flip Errors
The outer code protects against phase-flips by encoding the logical information in the relative phase of a GHZ-like state. The stabilizers for this code must check the parity of the blocks. These operators act across the three blocks:
This provides the final two stabilizer generators. Let's check one, for instance . This operator acts as on the first block and on the second block. We know that .
When we apply to , it transforms:
This is exactly the original state . The same holds for .
The following lecture notes formally list these generators and define the Shor code in terms of them.
Recap of Shor code - Lecture #25
These lecture notes from UC Berkeley's course on ECC concisely define the Shor code via its logical states and explicitly list its eight stabilizer generators.
Please read Section 2, 'Recap of Shor code', and the first part of Section 3, 'Stabilizer Codes'. Pay close attention to the list of 8 stabilizer generators (labeled P1...P8) in Section 2.1. Note that the notes use a slightly different, but equivalent, set of generators (e.g., Z1Z2 and Z2Z3 instead of Z1Z2 and Z1Z3). Section 3 reinforces the definition of a stabilizer code, confirming that the Shor code is a primary example.
The eight generators you saw are:
- Bit-flip checks (6 generators):
- Phase-flip checks (2 generators):
All these operators are products of Pauli matrices, they all commute with each other (you can verify this), and they form an independent set of generators for an Abelian group. The Shor code is defined as the 2-dimensional subspace of the full -dimensional Hilbert space that is simultaneously stabilized by all eight of these operators. This confirms that the Shor code is indeed a [[9, 1, 3]] stabilizer code.
Test your understanding!
Let's say an error occurs. Which of the eight stabilizer generators will anti-commute with this error, thus flipping their measured eigenvalue from +1 to -1?
Show answer
We need to find the generators that have a non-identity Pauli operator on qubit 7 that is not .
- : Act on qubits 0-5. They commute with .
- : Has at qubit 7. Since , this generator anti-commutes. Eigenvalue flips.
- : Has at qubit 7. Since , this generator anti-commutes. Eigenvalue flips.
- : Acts on qubits 0-5. It commutes with .
- : Has at qubit 7. Since , this generator commutes.
So, only generators and will anti-commute with an error. The resulting syndrome will signal a bit-flip error in the third block, localized to qubit 7.
Conclusion
In this lesson, we dissected the 9-qubit Shor code, the pioneering work in quantum error correction. We saw how it is not a monolithic construction, but rather a clever composition of two simpler codes.
Key Takeaways:
- The Shor code is a concatenated code, combining a 3-qubit phase-flip (outer) code and three 3-qubit bit-flip (inner) codes.
- The encoding circuit reflects this structure: an initial stage entangles three qubits for phase protection, followed by three parallel blocks of bit-flip encoding.
- The Shor code is a stabilizer code. Its eight generators are inherited from its constituent parts: six -type generators check for bit-flips within blocks, and two -type generators check for phase-flips across blocks.
- The code is defined as the common eigenspace of these eight commuting generators.
Preview of the next lesson:
Now that we have constructed the Shor code and understand its stabilizer group, the next logical step is to see it in action. In our next lesson, we will implement the syndrome measurement circuits for the Shor code to extract the bit-flip and phase-flip error syndromes, building on the techniques we used for the 5-qubit code.