|q⟩ Bad Qubits

beginner · Programming · Measurement & Probability in Code

Histograms of Outcomes

When a simulation finishes, you need a way to see all the outcome probabilities at once rather than reading raw numbers. A measurement histogram is exactly that: a bar chart where each bar represents one possible bitstring, and the bar's height is the probability that bitstring is the result of a measurement.

What a histogram shows

For an nn-qubit circuit there are 2n2^n possible bitstrings. The histogram places one bar for each bitstring on the horizontal axis and the probability (derived from the Born rule applied to the final state vector) on the vertical axis. Because probabilities must sum to one, the total area of all bars always equals 1.

Consider a single qubit in the equal superposition

+=12(0+1).|{+}\rangle = \tfrac{1}{\sqrt{2}}\bigl(|0\rangle + |1\rangle\bigr).

The Born rule gives P(0)=122=12P(0) = \bigl|\tfrac{1}{\sqrt{2}}\bigr|^2 = \tfrac{1}{2} and P(1)=12P(1) = \tfrac{1}{2}, so the histogram shows two bars of identical height 0.50.5.

Now extend to two independent qubits, each in +|{+}\rangle. The joint state is the tensor product

++=12(00+01+10+11).|{+}\rangle \otimes |{+}\rangle = \tfrac{1}{2}\bigl(|00\rangle + |01\rangle + |10\rangle + |11\rangle\bigr).

Every amplitude equals 12\tfrac{1}{2}, so every squared amplitude equals 14\tfrac{1}{4}. The histogram displays four equal bars — one for 00, one for 01, one for 10, and one for 11.

Connecting bars to amplitudes

A histogram is a visual shorthand for the probability vector produced by the Born rule. If you see a bar at 01 reaching height 0.250.25, that tells you the amplitude on 01|01\rangle has magnitude 0.25=0.5\sqrt{0.25} = 0.5. Taller bars flag the most likely outcomes; any missing bar means the corresponding state has zero amplitude.

Try it

Prepare a two-qubit circuit so that all four bitstrings (00, 01, 10, 11) appear with equal probability. The grader checks the full probability distribution — four equal bars are the only passing answer.

Run your code to see the quantum state.

After running, open the Probabilities tab to see the histogram. Confirm that each of the four bars reaches exactly 0.250.25.

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