|q⟩ Bad Qubits

intermediate · Programming · Quantum Error Detection (Intro)

Checkpoint: Detect an Error

This is a cumulative checkpoint for Module 14. You will assemble the complete three-qubit bit-flip detection circuit — encoding, error injection, and syndrome measurement — in a single exercise.

What you need to build

The three-qubit bit-flip code stores a logical qubit across three physical qubits q0,q1,q2q_0, q_1, q_2. Logical ∣0⟩|0\rangle encodes as ∣000⟩|000\rangle; logical ∣1⟩|1\rangle encodes as ∣111⟩|111\rangle. Two extra syndrome ancilla qubits, q3q_3 and q4q_4, will hold the parity check results.

Step 1 — Encoding

With q0=∣0⟩q_0 = |0\rangle and q1=q2=∣0⟩q_1 = q_2 = |0\rangle, the encoding circuit is two CNOTs:

∣0⟩∣00⟩→CNOT0→1∣0⟩∣00⟩→CNOT0→2∣000⟩.|0\rangle|00\rangle \xrightarrow{\text{CNOT}_{0\to1}} |0\rangle|00\rangle \xrightarrow{\text{CNOT}_{0\to2}} |000\rangle.

Because the data qubit starts in ∣0⟩|0\rangle both ancillas remain ∣0⟩|0\rangle. (Had the data been ∣1⟩|1\rangle, the CNOTs would have spread it to ∣111⟩|111\rangle.)

Step 2 — Injected error

An adversarial bit flip XX strikes q1q_1, turning the data from ∣000⟩|000\rangle to ∣010⟩|010\rangle. The circuit stub already includes this line — do not remove it.

Step 3 — Syndrome measurement

Two parity checks identify the faulty qubit without revealing the logical value:

| Syndrome bit | Parity checked | Circuit | |---|---|---| | s0s_0 into q3q_3 | q0⊕q1q_0 \oplus q_1 | CNOT q0→q3q_0 \to q_3, then CNOT q1→q3q_1 \to q_3 | | s1s_1 into q4q_4 | q1⊕q2q_1 \oplus q_2 | CNOT q1→q4q_1 \to q_4, then CNOT q2→q4q_2 \to q_4 |

Each target qubit accumulates the XOR of its control qubits because each CNOT flips the target once iff the control is ∣1⟩|1\rangle. After two CNOTs, target =c1⊕c2= c_1 \oplus c_2 — the standard fanout trick for parity extraction.

With the injected error (q1=1q_1 = 1, q0=q2=0q_0 = q_2 = 0):

s0=q0⊕q1=0⊕1=1,s1=q1⊕q2=1⊕0=1.s_0 = q_0 \oplus q_1 = 0 \oplus 1 = 1, \qquad s_1 = q_1 \oplus q_2 = 1 \oplus 0 = 1.

Syndrome 1111 is the unique signature of a bit flip on q1q_1. A flip on q0q_0 would give 1010; a flip on q2q_2 would give 0101; no error gives 0000.

Expected final state

After the correct circuit the five-qubit statevector has a single non-zero amplitude: the computational-basis state

∣q0 q1 q2 q3 q4⟩=∣0  1  0  1  1⟩.|q_0\, q_1\, q_2\, q_3\, q_4\rangle = |0\;1\;0\;1\;1\rangle.

Data qubits hold ∣010⟩|010\rangle (the corrupted codeword), syndrome qubits hold ∣11⟩|11\rangle (flagging qubit 1 as the error site). The grader checks the full statevector.

Try it

Complete the three missing sections — encoding, syndrome for s0s_0, and syndrome for s1s_1. The error injection on line c.x(1) is already in place.

Run your code to see the quantum state.

Once your circuit passes, inspect the Statevector panel: only the ∣01011⟩|01011\rangle basis state should carry amplitude, confirming that the syndrome bits correctly flag the injected error.

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