Back to Learn

Quantum Computing 101

Measurement

Measurement is where a quantum state becomes classical data, and it changes the state it reads.

In this lesson you will learn to

  • Predict measurement probabilities and the counts you expect over many shots.
  • Explain collapse and why repeated measurements agree.
  • Measure in the X or Y basis by rotating the state first.
  • Sample measurement counts from a state in Qiskit.

Shots and Counts

Measuring a qubit gives one classical bit. You never see α or β directly, only a 0 or a 1.

To learn the probabilities you repeat the experiment. Each repetition is called a shot. Over many shots, the fraction of 0s approaches |α|² and the fraction of 1s approaches |β|².

Kub measures the state (√3/2)|0⟩ + (1/2)|1⟩ again and again. Every shot gives a single 0 or 1; only the counts over many shots reveal the probabilities 75% and 25%.

Worked example: probabilities and shots

Use a state with a larger amplitude for |0⟩ than for |1⟩.

∣ψ⟩=32∣0⟩+12∣1⟩|\psi\rangle=\frac{\sqrt{3}}{2}|0\rangle+\frac{1}{2}|1\rangle
P(0)=34=75%P(1)=14=25%P(0)=\frac{3}{4}=75\%\qquad P(1)=\frac{1}{4}=25\%
1000 shots ⟶ about 750 zeros and 250 ones1000\text{ shots}\ \longrightarrow\ \text{about }750\text{ zeros and }250\text{ ones}
from qiskit import QuantumCircuit
from qiskit.quantum_info import Statevector
import math

qc = QuantumCircuit(1)
qc.ry(math.pi / 3, 0)          # amplitudes sqrt(3)/2 and 1/2

state = Statevector.from_instruction(qc)
print(state.sample_counts(shots=1000))
# e.g. {'0': 742, '1': 258}  (different every run)

Collapse

Measurement does not just read the qubit; it changes it. After you observe 0 the state is |0⟩, and after you observe 1 it is |1⟩. This is called collapse.

If no gate acts in between, measuring again gives the same answer with certainty. The randomness happens once, at the first measurement.

Measuring |+⟩ gives 0 or 1 with equal odds, but the state then becomes the result. Measuring again, with no gates in between, repeats the same answer.

Worked example: measure twice

∣+⟩=∣0⟩+∣1⟩2|+\rangle=\frac{|0\rangle+|1\rangle}{\sqrt{2}}
First result 0:∣+⟩⟶∣0⟩(50%)First result 1:∣+⟩⟶∣1⟩(50%)\begin{aligned}\text{First result }0&:\quad |+\rangle\longrightarrow|0\rangle\quad (50\%)\\\text{First result }1&:\quad |+\rangle\longrightarrow|1\rangle\quad (50\%)\end{aligned}
∣0⟩→measure again0 (100%)∣1⟩→measure again1 (100%)|0\rangle\xrightarrow{\text{measure again}}0\ (100\%)\qquad |1\rangle\xrightarrow{\text{measure again}}1\ (100\%)
›Check yourself: A qubit in |+⟩ is measured and gives 1. You then apply H and measure again. What are the odds now?

After the first measurement the state is |1⟩. H turns it into |−⟩, so the second measurement is 50/50. Without the first measurement, H would have turned |+⟩ into |0⟩ and you would read 0 every time: the early measurement destroyed the interference.

Measuring in Other Bases

Hardware measures in the Z basis: it asks "0 or 1?". To ask a different question, rotate the state first. Applying H before measuring turns |+⟩ into 0 and |−⟩ into 1, so H followed by a measurement is an X-basis measurement.

For the Y basis, apply S† and then H before measuring. The same trick lets you estimate how much of a state points along any axis.

Worked example: reading |−⟩ in the X basis

H∣+⟩=∣0⟩H∣−⟩=∣1⟩H|+\rangle=|0\rangle\qquad H|-\rangle=|1\rangle
S†∣+i⟩=∣+⟩ ⇒ HS†∣+i⟩=∣0⟩HS†∣−i⟩=∣1⟩S^\dagger|{+i}\rangle=|+\rangle\ \Rightarrow\ HS^\dagger|{+i}\rangle=|0\rangle\qquad HS^\dagger|{-i}\rangle=|1\rangle
from qiskit import QuantumCircuit
from qiskit.quantum_info import Statevector

qc = QuantumCircuit(1)
qc.x(0)
qc.h(0)          # prepare |->
qc.h(0)          # rotate the X basis onto the Z basis
print(Statevector.from_instruction(qc).probabilities_dict(decimals=3))
# {'1': 1.0}: |-> reads as 1

Key Takeaways

  • A single shot returns one bit; probabilities only show up in counts over many shots.
  • Counts approach |α|² and |β|², with noise shrinking like 1/√shots.
  • Measurement collapses the state onto the result, so repeating it gives the same answer.
  • Rotate before measuring to measure in another basis: H for X, S† then H for Y.

What To Practice

Practice predicting outcomes, choosing the right measurement basis, and decoding two-qubit states.