← Quantum Store · Guides · Lessons · Glossary · Packages · About · Türkçe
Noise and quantum error correction course · Lesson 3 / 5 · 10 min
The phase-flip code and Shor’s nine-qubit code
Seen in the H basis, a phase flip turns into a bit flip. Use this to correct phase flips, and meet Shor’s code, the first quantum code that corrects any single-qubit error by nesting two codes.
In the H basis a phase flip is a bit flip
The H gate swaps the Z basis and the X basis: H·Z·H = X. So a phase flip behaves like a bit flip on qubits with H applied. To catch phase flips it is enough to encode the data as |+++⟩ and |−−−⟩ instead of |000⟩ and |111⟩.
Before measuring the syndrome, H is applied to the three qubits again; the phase flip turns back into a bit flip, and the same syndrome circuit as in the repetition code finds where it is.
from qiskit import QuantumCircuit
from qiskit.quantum_info import Operator, Statevector
hzh = QuantumCircuit(1)
hzh.h(0)
hzh.z(0)
hzh.h(0)
x = QuantumCircuit(1)
x.x(0)
print(Operator(hzh).equiv(Operator(x))) # True: H·Z·H = X
for wrong in [None, 0, 1, 2]:
qc = QuantumCircuit(5)
qc.cx(0, 1)
qc.cx(0, 2)
qc.h([0, 1, 2]) # |000⟩ → |+++⟩
if wrong is not None:
qc.z(wrong) # a single phase flip
qc.h([0, 1, 2]) # go back: the phase flip became a bit flip
qc.cx(0, 3)
qc.cx(1, 3)
qc.cx(1, 4)
qc.cx(2, 4)
probs = Statevector(qc).probabilities_dict()
print(wrong, max(probs, key=probs.get)[:2])
# True
# None 00
# 0 01
# 1 11
# 2 10
Shor’s code
In 1995 Peter Shor nested the two codes: the logical qubit is first spread over three qubits with the phase-flip code, then each of those three is spread over three qubits with the bit-flip code. The result is one logical qubit stored in nine physical qubits, which corrects a single X error, Z error or a combination of the two on any qubit.
This was the first proof that quantum error correction is possible. Until then many physicists believed that the decay of continuous-valued amplitudes could not be corrected. The fact that errors can be broken down into X and Z components removed this obstacle.
More efficient codes
After Shor’s code more efficient codes were found: Steane’s 7-qubit code and the 5-qubit code, the smallest code that can correct a single qubit error. Today the code with the highest hopes is the surface code, which only needs operations between neighbouring qubits on a two-dimensional grid. It is the subject of the next lesson.
Try it yourself
The H, Z, H circuit is the core of the single-qubit phase-flip code: the Z error acts like an X between the H gates and makes the result 1. Put an X in place of the Z: this time the X becomes invisible in the H basis and the result stays 0. X and Z errors are each other’s mirror image in the H basis.
Open the circuit in your browserThe circuit playground is in Turkish. Button guide: “1000 kez ölç” = measure 1000 times, “Durum vektörünü göster” = show the state vector, “Bu devrenin Qiskit kodu” = this circuit’s Qiskit code, “Geri al” = undo, “Temizle” = clear. Click a gate in the circuit to remove it.
Key points
- H·Z·H = X: in the H basis a phase flip turns into a bit flip.
- The phase-flip code encodes data as |+++⟩ and |−−−⟩ and uses the same syndrome circuit.
- Shor’s 9-qubit code (1995) is the first quantum code that corrects any single-qubit error.
- Later the 7- and 5-qubit codes and the surface code were found.
Test yourself
In how many physical qubits does Shor’s code store one logical qubit?
- 3
- 5
- 9
Show the answer
9. Each of the three qubits of the phase-flip code is spread over three with the bit-flip code: 3 × 3 = 9.
← The repetition code: finding an error without looking at the data · The surface code and the threshold: the road to fault-tolerant quantum computers →