beginner · Programming · Building & Reading Quantum Circuits
Debugging a Circuit
Even a one-gate mistake in a quantum circuit produces a completely wrong state. Learning to read the
statevector output and trace it back to a gate error is one of the core debugging skills in
quantum programming.
The target: the Bell state
The simplest entangled two-qubit state is the Bell state
∣Φ+⟩=21(∣00⟩+∣11⟩).
The standard circuit that produces it is:
Apply H to qubit 0 — this puts qubit 0 into the equal superposition
21(∣0⟩+∣1⟩).
Apply a CNOT with qubit 0 as control and qubit 1 as target.
After step 1 the two-qubit state is
21(∣0⟩+∣1⟩)⊗∣0⟩=21(∣00⟩+∣10⟩).
The CNOT flips qubit 1 whenever qubit 0 is ∣1⟩, turning ∣10⟩→∣11⟩ while
leaving ∣00⟩ unchanged:
CNOT[21(∣00⟩+∣10⟩)]=21(∣00⟩+∣11⟩)=∣Φ+⟩.✓
Both amplitudes are 21, and the probabilities are each 21.
What a gate bug looks like
Suppose someone replaces H with X — the bit-flip gate. Then step 1 gives
X∣0⟩=∣1⟩ (a definite ∣1⟩, not a superposition), so the two-qubit state
before the CNOT is ∣10⟩. The CNOT flips qubit 1 because the control is ∣1⟩,
leaving ∣11⟩. The result is a product state, not a Bell state:
Buggy output:∣11⟩(no superposition, no entanglement).
Reading the statevector immediately reveals this: a single amplitude of 1 on the ∣11⟩
component, instead of two equal amplitudes on ∣00⟩ and ∣11⟩. The fix is obvious once
you see it — the wrong gate is on qubit 0.
Try it
The starter code has the bug described above. Run it, read the statevector, identify the wrong gate,
and replace it so the circuit produces ∣Φ+⟩.
Run your code to see the quantum state.
After your fix, the Statevector panel should show two equal amplitudes
≈0.707=21 on ∣00⟩ and ∣11⟩, with all other components
zero. That is the signature of the Bell state.
Sign in on the full site to ask questions and join the discussion.