Phase flips and the Shor code
The repetition code ended with a problem. It catches a bit flip on any one qubit, but a phase flip, the gate, passes straight through it. This lesson fixes that, and the result is the first code ever found that protects a qubit against every kind of single-qubit error. Peter Shor published it in 1995.
A phase flip is a bit flip in another basis
Section titled “A phase flip is a bit flip in another basis”Recall what does to the states and :
In the basis a phase flip is a bit flip. That is the identity from the gates lesson seen from the other side. So we can reuse the whole repetition code, with and in place of and :
This is the three-qubit phase-flip code. To build it, encode with the two CNOTs you already know, then change basis with an on every qubit.
Build the encoder for the phase-flip code. The input on the top wire is , which must become , an equal superposition of all eight bit strings. Your circuit is also tested on the input , which must become .
This puzzle needs JavaScript.
Hint
Three gates alone make , but they would send the input to . Spread the top qubit's value with two CNOTs first.
Finding a phase flip
Section titled “Finding a phase flip”For bit flips we asked whether neighbouring qubits agree in the basis. For phase flips we ask whether they agree in the basis:
- Do qubits 0 and 1 have the same sign?
- Do qubits 1 and 2 have the same sign?
Both parts of the encoded state, and , answer yes to both questions. After a phase flip on the middle qubit they become and , and both answer no to both. As before, the answers locate the error and say nothing about and .
How do we ask the question? “Do these two qubits have the same sign?” is a measurement of the operator . A pair with the same sign is unchanged by it. A pair with different signs picks up a factor of :
To read that sign out, use phase kickback, the trick behind Deutsch’s algorithm. Put an ancilla in and let it control an on each data qubit. If the data picks up under , that sign lands on the part of the ancilla and turns into . A final converts this to a 0 or a 1.
The two data qubits are in : their signs differ. Make the bottom wire end in to record that, leaving the data exactly as it was. Your circuit is also tested on data with equal signs, where the bottom wire must end in , and on two entangled states.
This puzzle needs JavaScript.
Hint
on the ancilla, a CNOT from the ancilla onto each data qubit, then on the ancilla again.
Compare this with the parity check of the last lesson. There the data qubits were the controls and the ancilla was the target. Here the CNOTs are turned around and wrapped in a pair of gates. One circuit measures , the other measures .
With two such measurements, on qubits 0 and 1 and on qubits 1 and 2, the syndrome table is the same as before with in place of :
| Syndrome | Meaning | Correction |
|---|---|---|
| 00 | No phase flip | Nothing |
| 10 | Qubit 0 has the odd sign | on qubit 0 |
| 11 | Qubit 1 has the odd sign | on qubit 1 |
| 01 | Qubit 2 has the odd sign | on qubit 2 |
The encoded state has suffered a phase flip on one qubit. Read the signs, find it and repair it.
This puzzle needs JavaScript.
Hint
A on a qubit puts a minus sign on every term in which that qubit is 1. Look for the bit that all the negative terms share.
The weakness has only moved
Section titled “The weakness has only moved”We have gained protection against and lost it against . Since and , a bit flip on any one qubit gives
No two qubits disagree in sign, so the syndrome is 00, and yet the encoded state has changed. The two codes fail in mirror-image ways.
The phase-flip code corrects one phase flip. What happens if two of its qubits suffer phase flips?
Two phase flips leave the third qubit with the odd sign, so the syndrome blames it. A there completes three phase flips, which swap and . Like the bit-flip code, this code handles one error and is fooled by two.
Nine qubits: one code inside another
Section titled “Nine qubits: one code inside another”Shor’s idea was to use both codes at once, one inside the other. This is called concatenation.
- Encode the qubit with the phase-flip code, giving three qubits.
- Encode each of those three with the bit-flip code, giving nine.
Under the first step . Under the second, each becomes , and each becomes the same with a minus sign. So the two encoded basis states are
The subscript stands for logical: these are the states of the protected qubit, as opposed to the nine physical qubits that carry it. The nine fall into three blocks of three: qubits 0 to 2, 3 to 5, and 6 to 8.
Build the encoder for the Shor code. The input on the top wire is , which must become : eight terms, one for each way of choosing 000 or 111 in each block. Your circuit is also tested on the input , which must become . Eleven gates do it.
This puzzle needs JavaScript.
Hint
Wires 0, 3 and 6 lead the three blocks. First run the phase-flip encoder on those three wires: two CNOTs from wire 0, then an on each. Then run the bit-flip encoder inside each block: two CNOTs from each leader. Gates on different wires can share a column.
How it corrects
Section titled “How it corrects”A bit flip on any qubit is caught inside its own block. Each block is a little bit-flip code, so we measure the two parities in each block, six checks in all, exactly as in the last lesson. The signs between the terms play no part in this.
A phase flip on any qubit changes the sign in its block: becomes . To find out which block, compare the signs of neighbouring blocks. That takes two more checks, each a product of six operators:
A subscript names the qubit a gate acts on. Three gates on a block leave alone and put a minus sign on , so each of these checks asks “do these two blocks have the same sign?”
Both at once, the gate , sets off both kinds of check, and the two corrections are made independently.
That is eight checks on nine qubits. Each check that is measured halves the space of allowed states, and : exactly one qubit’s worth of freedom is left over to hold the data. The next lesson turns this counting into a method.
A phase flip hits qubit 4, in the middle block. Which checks report something?
A phase flip is invisible to the checks. It changes the sign of the middle block, which then differs from both of its neighbours, so both sign comparisons report a difference.
Different errors, same damage
Section titled “Different errors, same damage”Notice that the phase-flip syndrome names a block, not a qubit. That is enough. A on qubit 3, on qubit 4 or on qubit 5 has exactly the same effect on every encoded state, because all three turn into . We may undo the flip with a on any qubit of the block.
A code in which different errors act identically, and so need not be told apart, is called degenerate. Classical codes have nothing like it. It will matter again for the surface code.
The real error was a phase flip on qubit 5. The correction applied a to qubit 3 instead. What is the result?
and do the same thing to the middle block, and each undoes itself. Applying one after the other gives back the original state.
Any error at all
Section titled “Any error at all”We have dealt with , and . Real noise is none of these exactly: it is a small unwanted rotation, or a leak of energy, or a stray measurement. Two facts from earlier lessons show that this does not matter.
First, from the lesson on quantum channels: the matrices , , and form a basis for all matrices. So whatever happens to one qubit can be written as
for some complex numbers . Applied to an encoded state , it gives a superposition of four things: the undamaged state, the state with a bit flip, with both flips, and with a phase flip.
Second, the digitisation of errors from the last lesson: those four states give four different syndromes, so measuring the syndrome collapses the superposition onto one of them. The continuous error becomes one definite error, chosen at random, and the syndrome says which.
So a code that corrects , and on a qubit corrects every possible error on that qubit. The Shor code does this for any one of its nine qubits. You could replace one qubit with a completely different one and the data would survive.
What it costs
Section titled “What it costs”- Nine physical qubits for one logical qubit. The next lesson brings this down to five, which turns out to be the minimum, and the one after it introduces a seven-qubit code that is easier to compute with.
- One error only. Two errors in the wrong places produce a syndrome that points to the wrong correction.
- Perfect checks assumed. We have taken for granted that the encoding and the syndrome measurements themselves work flawlessly. Removing that assumption is the subject of the lesson on fault tolerance.
Describing the code took a page of state vectors. The next lesson introduces a notation in which the Shor code is just a list of eight short strings, and in which finding a syndrome needs no state vectors at all.
Remember it
Section titled “Remember it”How does the three-qubit phase-flip code encode ?
As : the bit-flip code followed by an on every qubit.
How do you measure on two data qubits using an ancilla?
on the ancilla, a CNOT from the ancilla onto each data qubit, on the ancilla again, then measure it.
How is the nine-qubit Shor code built?
By concatenation: encode with the phase-flip code, then encode each of its three qubits with the bit-flip code. is three copies of .
What are the eight checks of the Shor code?
Two parities inside each block of three, which find bit flips, and two six-qubit checks comparing the signs of neighbouring blocks, which find phase flips.
Why does correcting , and errors correct every single-qubit error?
Any single-qubit error is a combination of , , and , and measuring the syndrome collapses that combination onto one of them.
What is a degenerate code?
One in which different errors act identically on encoded states, so they need not be told apart. In the Shor code a on any qubit of a block has the same effect.