A repetition code is a simple approach to error correction:
to protect a bit x, make two copies:
0→0001→111
If a single-bit error occurs, e.g. 000→100,
a majority vote resets the minority bit.
Clearly, this does not protect against multi-bit errors,
but that is usually not necessary.
In quantum computing, where error correction is much more important,
repetition codes can also be used,
albeit with some complications,
as discussed below.
Bit flip code
Suppose that we want to detect errors in
the following arbitrary qubit state ∣ψ⟩:
∣ψ⟩=α∣0⟩+β∣1⟩
For now, let us limit ourselves to detecting bit flips,
where α and β get switched:
α∣0⟩+β∣1⟩→Error→β∣0⟩+α∣1⟩
One way to defend against this is
the quantum version of a classical repetition code:
∣ψ⟩→Encoder→∣ψ⟩=α∣000⟩+β∣111⟩
In other words, a logical∣0⟩ (written ∣0⟩)
is represented by 3 physical qubits, and vice versa:
∣0⟩→∣0⟩=∣000⟩∣1⟩→∣1⟩=∣111⟩
Such a transformation is easy to achieve with the following sequence
of quantum gates:
So, a little while after encoding the state ∣ψ⟩ like that,
a bit flip occurs on the 2nd qubit:
∣ψ⟩→Error→α∣010⟩+β∣101⟩
But now there is a problem: how do we detect this error?
We could measure the state, but that would make it collapse,
which is probably not what we want.
The trick is to use operators called stabilizers,
in this case for example ZZI=Z1⊗Z2⊗I3,
where I is identity and Z is the Pauli-Z gate.
The 3-qubit basis states are its eigenvectors:
We could measure ZZI for ∣ψ⟩,
and if the eigenvalue is −1,
we know that a bit flip has occurred,
whereas if the eigenvalue is +1,
there is maybe no error (∣001⟩ and ∣110⟩ are false negatives).
These false negatives are fixed by including another stabilizer IZZ,
with these eigenvectors:
In which case ∣100⟩ and ∣011⟩ are false negatives.
In other words, IZZ cannot detect if the 1st qubit was flipped,
while ZZI cannot protect the 3rd qubit.
But by using both, we know exactly which qubit was flipped
thanks to the eigenvalues:
Error
ZZI
IZZ
I
+1
+1
X1
−1
+1
X2
−1
−1
X1
+1
−1
Where e.g. X3 denotes that the 3rd qubit was flipped.
The measurement outcomes on the last three rows are called error syndromes,
and are obtained by a syndrome measurement.
Fortunately, we can measure ZZI and IZZ
without affecting ∣ψ⟩ itself,
by applying CNOTs to some ancillary qubits
and then measuring those:
The two measurements, respectively representing ZZI and IZZ,
yield ∣1⟩ if a bit flip definitely occurred,
and ∣0⟩ otherwise.
There is no entanglement,
so the input is untouched.
Phase flip code
The above system protects us against all single-qubit bit flips.
Unfortunately, that is not enough:
qubits can also experience a phase flip:
α∣0⟩+β∣1⟩→Error→α∣0⟩−β∣1⟩
How to detect that?
If we want to protect against phase flips instead of bit flips,
we can simply do the same as before,
but along the X-axis intead of the Z-axis:
∣0⟩→∣0⟩=∣+++⟩∣1⟩→∣1⟩=∣−−−⟩
Such that an arbitrary state ∣ψ⟩ is encoded as follows,
by the circuit shown below:
∣ψ⟩→Encoder→∣ψ⟩=α∣+++⟩+β∣−−−⟩
A phase flip along the Z-axis
corresponds to a bit flip along the X-axis ∣+⟩→∣−⟩.
In this case, the stabilizers are XXI and IXX,
and the error detection circuit is as follows:
This system protects us against all single-qubit phase flips,
but not against bit flips.
Shor code
What kind of repetition code would we need
if we want to detect both bit flips and phase flips?
The most straightforward option is the Shor code.
Starting from a phase flip encoding:
We add protection against bit flips
by using a repetition code for each physical qubit:
∣0⟩=(2∣000⟩+∣111⟩)⊗3∣1⟩=(2∣000⟩−∣111⟩)⊗3
This encoding is achieved by the following quantum circuit,
which simply consists of the phase flip encoder,
followed by 3 copies of the bit flip encoder:
We thus use 9 physical qubits to store 1 logical qubit.
Fortunately, more efficient schemes exist.
The bit flip stabilizers ZZI and IZZ
are applied on a per-block basis, like so: