|q⟩ Bad Qubits

beginner · Programming · Measurement & Probability in Code

Checkpoint: Predict Then Measure

This lesson is a checkpoint. Before you build a circuit, you should be able to predict what its measurement distribution will look like. Building the circuit and running it is the second step — confirming your prediction. That two-step habit — predict, then verify — is what separates debugging by intuition from debugging by physics.

The CNOT gate

Before building the circuit, meet the gate it relies on. The controlled-NOT (CNOT) is a two-qubit gate with a control qubit and a target qubit: it flips the target if and only if the control is 1|1\rangle, and leaves the target alone when the control is 0|0\rangle. On the four basis states (control listed first):

0000,0101,1011,1110.|00\rangle \to |00\rangle,\quad |01\rangle \to |01\rangle,\quad |10\rangle \to |11\rangle,\quad |11\rangle \to |10\rangle.

In code, c.cx(control, target) applies it. CNOT is linear, so applied to a superposition of control values it acts on each branch at once — which is exactly what turns a product state into an entangled one below. (Module 11 returns to CNOT and the rest of the controlled-gate family in depth.)

A two-qubit circuit to analyze

Consider the circuit that applies a Hadamard to the first qubit, then a controlled-NOT with the first qubit as control and the second as target:

00HI12(0+1)0CNOT12(00+11).|00\rangle \xrightarrow{H \otimes I} \tfrac{1}{\sqrt{2}}(|0\rangle + |1\rangle) \otimes |0\rangle \xrightarrow{\text{CNOT}} \tfrac{1}{\sqrt{2}}(|00\rangle + |11\rangle).

Let's trace each step carefully.

Step 1 — Hadamard on qubit 0. The initial state is 00|00\rangle. Applying HH to qubit 0 and the identity to qubit 1 gives

12(0+1)0=12(00+10).\tfrac{1}{\sqrt{2}}(|0\rangle + |1\rangle) \otimes |0\rangle = \tfrac{1}{\sqrt{2}}(|00\rangle + |10\rangle).

Both qubits are independent at this point.

Step 2 — CNOT(0 → 1). The CNOT flips qubit 1 whenever qubit 0 is 1|1\rangle and leaves qubit 1 alone when qubit 0 is 0|0\rangle. Applying it term by term:

0000,1011.|00\rangle \to |00\rangle, \qquad |10\rangle \to |11\rangle.

So the state becomes

Φ+=12(00+11).|\Phi^+\rangle = \tfrac{1}{\sqrt{2}}(|00\rangle + |11\rangle).

This is a Bell state — a maximally entangled two-qubit state.

Predicting the measurement distribution

Applying the Born rule to Φ+|\Phi^+\rangle is direct. The state is a superposition of exactly two computational basis states, each with amplitude 12\tfrac{1}{\sqrt{2}}:

P(11) = \left|\tfrac{1}{\sqrt{2}}\right|^2 = \tfrac{1}{2}.$$ The other two outcomes have **amplitude zero**: $$P(01) = 0, \qquad P(10) = 0.$$ Write down your prediction before running: a histogram with two equal bars at "00" and "11", and empty bars at "01" and "10". <Callout type="tip"> The fact that "01" and "10" never appear reflects entanglement: the two qubits are correlated. Measuring qubit 0 as `0` instantly tells you qubit 1 is also `0`, and measuring qubit 0 as `1` tells you qubit 1 is `1`. A classical mixture that is 50% (00) and 50% (11) would produce the same histogram in this basis — the quantum advantage becomes visible only when the same entangled pair is measured in multiple incompatible bases, as Bell's inequality makes precise. </Callout> ## Try it Build the circuit that produces $|\Phi^+\rangle$ and confirm your prediction by measuring both qubits. The grader checks that the probability distribution matches $P(00) = P(11) = 0.5$ and $P(01) = P(10) = 0$. <RunnableExample /> Open the **Probabilities** tab after running. You should see exactly two bars of equal height at positions "00" and "11" — no probability at "01" or "10". If the pattern matches your written prediction, you have completed the checkpoint.

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