DeepPractise
DeepPractise

Measurements & Shots in Practice

Track: Quantum Programming · Difficulty: Beginner · Est: 12 min

Measurements & Shots in Practice

Overview

This page demonstrates how measurement shows up in real results:

  • you run the same circuit many times (shots)
  • you get a distribution of outcomes (counts)
  • results fluctuate because measurement is probabilistic

The goal is to make the Born rule feel concrete in code and output.

Conceptual Mapping

In Foundations, you learned:

  • amplitudes describe a quantum state
  • measurement outcomes are probabilistic
  • probabilities come from amplitudes (Born rule)

In code, that becomes:

  • a circuit prepares a state (by applying gates)
  • measurement produces classical bits
  • repeating many times produces a histogram-like summary of outcomes

So “running a circuit” is closer to “running an experiment many times” than “calling a deterministic function once.”

Code Walkthrough

A one-qubit experiment: prepare a superposition, then measure.

from qiskit import QuantumCircuit
from qiskit_aer import AerSimulator
 
qc = QuantumCircuit(1, 1)
qc.h(0)
qc.measure(0, 0)
 
sim = AerSimulator()
result = sim.run(qc, shots=200).result()
counts = result.get_counts()
 
print(counts)

Line by line:

  • QuantumCircuit(1, 1) creates one qubit and one classical bit.
  • qc.h(0) prepares a state where measuring can yield 0 or 1.
  • qc.measure(0, 0) stores the measurement into classical bit 0.
  • shots=200 repeats the same circuit 200 times.
  • get_counts() returns how many times each bitstring occurred.

Try changing only one thing:

  • run with shots=20, then shots=2000

You’ll see the distribution stabilize as shots increase.

Results & Interpretation

counts is a dictionary like:

  • {'0': 108, '1': 92} (example)

Interpretation:

  • each key is a classical measurement outcome
  • each value is how many times that outcome happened

Why it fluctuates:

  • even if the “true” probability is balanced, each shot is a random sample
  • small sample sizes have more visible randomness

Connection to the Born rule:

  • the circuit prepares a quantum state with amplitudes
  • measurement probabilities come from those amplitudes
  • counts approximate probabilities when shots are large enough

So a histogram is not “noise in the code.” It’s what probabilistic measurement looks like when you collect data.

Turtle Tip

Turtle Tip

If you want probabilities, you must run many shots. A single shot is one sample, not a probability estimate.

Common Pitfalls

Common Pitfalls
  • Running too few shots and drawing strong conclusions from a noisy-looking histogram.
  • Expecting exactly equal counts for balanced outcomes.
  • Forgetting that measurement happens only where you place measure(...).
  • Confusing sampling randomness with hardware noise (on simulators, the randomness is still part of measurement).

Quick Check

Quick Check
  1. What does shots mean conceptually?
  2. Why do results fluctuate even on an ideal simulator?
  3. How do counts relate to measurement probabilities?

What’s Next

So far you’ve only seen measurement outcomes. Next we’ll inspect the statevector in simulation to connect “amplitudes” directly to the probabilities that show up in counts—and why you can’t do that on real hardware.