|q⟩ Bad Qubits

advanced · Programming · Implementing Error-Correcting Codes

The Shor Nine-Qubit Code

The first quantum code, written down by Peter Shor in 1995, protects one logical qubit using nine physical qubits. It is a beautiful example of concatenation: a code built by nesting one code inside another. The Shor code corrects an arbitrary single-qubit error — any XX, YY, or ZZ on any one of the nine qubits.

Two layers of redundancy

Recall the two basic three-qubit codes:

Shor's trick is to compose them. Take the phase-flip code as the outer code, then encode each of its three qubits with the inner bit-flip code. The result protects against both, and therefore — because Y=iXZY = iXZ — against YY as well.

The logical states

Working out the concatenation gives the two logical codewords:

0L=122(000+111)(000+111)(000+111),|0_L\rangle = \frac{1}{2\sqrt{2}} \bigl(|000\rangle + |111\rangle\bigr) \bigl(|000\rangle + |111\rangle\bigr) \bigl(|000\rangle + |111\rangle\bigr), 1L=122(000111)(000111)(000111).|1_L\rangle = \frac{1}{2\sqrt{2}} \bigl(|000\rangle - |111\rangle\bigr) \bigl(|000\rangle - |111\rangle\bigr) \bigl(|000\rangle - |111\rangle\bigr).

Each codeword is a product of three blocks, qubits {0,1,2}\{0,1,2\}, {3,4,5}\{3,4,5\}, and {6,7,8}\{6,7,8\}. Inside a block the ±\pm sign between 000|000\rangle and 111|111\rangle stores the logical phase information; the three blocks together store the logical bit redundantly across the +/+/- pattern. There are 23=82^3 = 8 equally weighted product terms, so every nonzero amplitude is 1220.354\tfrac{1}{2\sqrt{2}} \approx 0.354.

Building the encoder

The encoder for 0L|0_L\rangle runs the two layers in order, starting from 000000000|000000000\rangle:

  1. Outer (phase) layer. Copy qubit 0 onto the two other block leaders with cx(0,3) and cx(0,6), then apply a Hadamard to each leader (qubits 0, 3, 6). On the all-zero input this places each leader in 12(0+1)\tfrac{1}{\sqrt{2}}(|0\rangle + |1\rangle).
  2. Inner (bit) layer. Inside each block, copy the leader to its two partners: cx(0,1), cx(0,2) for the first block, and likewise cx(3,4), cx(3,5) and cx(6,7), cx(6,8). Each 12(0+1)\tfrac{1}{\sqrt{2}}(|0\rangle + |1\rangle) leader fans out into 12(000+111)\tfrac{1}{\sqrt{2}}(|000\rangle + |111\rangle).

Distance and what it corrects

The Shor code has distance 3: the smallest weight of a logical (undetectable) error is three single-qubit Paulis. A distance-dd code corrects up to (d1)/2\lfloor (d-1)/2 \rfloor errors, so the Shor code corrects any single-qubit error. The inner blocks catch a bit flip on any one qubit; the outer phase-flip structure catches a ZZ on any block; and a YY trips both at once.

Try it

Encode the Shor logical 0L|0_L\rangle on nine qubits. The grader checks the full statevector, so all eight product terms must appear with amplitude 122\tfrac{1}{2\sqrt{2}} and every other amplitude must vanish.

Run your code to see the quantum state.

After running, open the statevector panel: exactly eight basis states are populated, each with amplitude 0.354\approx 0.354, corresponding to the eight ways of choosing 000|000\rangle or 111|111\rangle independently in the three blocks.

Sign in on the full site to ask questions and join the discussion.