|q⟩ Bad Qubits

intermediate · Programming · Quantum Error Detection (Intro)

Correcting a Bit Flip

Once syndrome measurement has told us which qubit flipped, the correction step is straightforward: apply the gate that undoes the error. For a bit-flip code this means applying a Pauli XX to the identified qubit, because X2=IX^2 = I.

Recap: the three-qubit bit-flip code

The three-qubit bit-flip code protects one logical qubit by spreading it across three physical qubits:

0L=000,1L=111.|0_L\rangle = |000\rangle, \qquad |1_L\rangle = |111\rangle.

A general logical state α0L+β1L=α000+β111\alpha|0_L\rangle + \beta|1_L\rangle = \alpha|000\rangle + \beta|111\rangle lives in the two-dimensional code space spanned by 000|000\rangle and 111|111\rangle.

If qubit kk suffers a bit flip, the XkX_k error moves the code space into an error space:

| Error | Logical 0 state | Logical 1 state | |-------|-----------------|-----------------| | none | 000|000\rangle | 111|111\rangle | | X0X_0 | 100|100\rangle | 011|011\rangle | | X1X_1 | 010|010\rangle | 101|101\rangle | | X2X_2 | 001|001\rangle | 110|110\rangle |

The four error spaces are mutually orthogonal, so they can be distinguished without any information about α\alpha or β\beta.

The syndrome and what it means

Syndrome measurement computes two parity bits using ancilla qubits and CNOT gates, without ever measuring the data qubits directly:

s0=q0q1,s1=q1q2.s_0 = q_0 \oplus q_1, \qquad s_1 = q_1 \oplus q_2.

The two bits together identify the error:

| s0s_0 | s1s_1 | Syndrome | Indicated error | |--------|--------|----------|-----------------| | 0 | 0 | 00 | No error | | 1 | 1 | 11 | X1X_1 (qubit 1 flipped) | | 1 | 0 | 10 | X0X_0 (qubit 0 flipped) | | 0 | 1 | 01 | X2X_2 (qubit 2 flipped) |

Applying the correction

Given syndrome s0=s1=1s_0 = s_1 = 1, we know qubit 1 flipped. The correction is simply

X1X1ψerror=X12ψ=ψ,X_1 \cdot X_1 |\psi_{\text{error}}\rangle = X_1^2 |\psi\rangle = |\psi\rangle,

because X2=IX^2 = I. More generally the correction table is:

| Syndrome | Gate to apply | |----------|---------------| | 00 | None (II) | | 11 | XX on qubit 1 | | 10 | XX on qubit 0 | | 01 | XX on qubit 2 |

After correction the register is back in the code space, with the logical information intact.

Try it

The starter code injects an XX error on qubit 1, placing the register in 010|010\rangle. The syndrome would read (s0,s1)=(1,1)(s_0, s_1) = (1, 1). Apply the correction gate to restore the state to 000|000\rangle.

Run your code to see the quantum state.

After pressing Check you should see the statevector collapse back to the all-zero state 000|000\rangle, confirming that the logical information has been recovered.

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