Quantum Computing · Part E — 16

Running a Circuit

Everything so far has been theory on paper. This is where you actually press run. A quantum program isn’t a function that returns an answer — it’s a recipe you execute thousands of times and tally. You write a circuit, a compiler reshapes it for a real chip, and the machine hands back a histogram of samples. Learning to read that histogram is the last skill of the course.

↩ before you start · keep these handy
·From QC 01: a circuit is a sequence of gates on wires; any operation decomposes into a small native set.
·From QI 8a: a measurement at the end collapses each qubit to a classical 0 or 1.
·From QI 11: real chips have limited connectivity, a fixed native gate set, and per-gate noise.
🔑 symbol decoder · every new term, in plain words
shotone full run of the circuit: prepare, apply gates, measure. Gives one bitstring. histogramthe tally of how many shots gave each bitstring — your estimate of the output probabilities. transpilerewrite your circuit using only the chip’s native gates and its allowed qubit connections. native gatesthe handful of operations a given device runs directly — everything else is built from them. coupling mapwhich qubits are physically allowed to talk (do a two-qubit gate) on the chip. backendthe thing that runs the circuit — a simulator on your laptop or a real quantum processor over the cloud.
feel

You don’t read the state — you sample it

A circuit ends in a measurement, and measurement gives you just one bitstring — a single dice roll from the distribution the circuit set up. One roll tells you almost nothing. So you run the exact same circuit again and again, collecting outcomes, until the tally reveals the shape of the distribution. The quantum part built a cleverly loaded set of dice; the classical part is just counting. More shots, sharper picture — and the cost you pay is time on the machine.

🏛️ everyday picture

Imagine a strange pair of dice that always land showing the same face as each other — but which face is random. Roll them once: you see “4–4” and learn little. Roll them a thousand times and tally: you discover they never disagree, and each matched pair shows up equally often. You’ve measured the rule without ever being told it. That is exactly how you learn what a quantum circuit does — one shot is a roll, the histogram is the tally.

recapA measurement yields one bitstring; you repeat over many shots and read the answer off the histogram.
play

Run a circuit and watch the histogram

Pick a circuit, set the number of shots, and hit run. The bars are the measured counts. With few shots they wobble; with many they settle onto the true probabilities. Flip on a noisy backend to see how a real chip smears outcomes that should be impossible.

▸ circuit runner{{ backendLabel }}
{{ w.label }} {{ b.label }}
shots {{ shotsLabel }}
{{ b.count }}
{{ b.key }}
{{ b.pct }}
−− dashed = ideal probability {{ spread }}
recapCounts approach the ideal probabilities as shots grow; noise adds weight to outcomes that should be zero.
math

Counts, and how far they wander

The circuit fixes a probability p for each bitstring (Born rule: p = |amplitude|²). Run N shots and the count for an outcome is a binomial random number centred on N·p:

estimate  p̂ = count ⁄ N  ·  error ≈ √( p(1−p) ⁄ N )
to halve the error, quadruple the shots (error ∝ 1⁄√N)

That 1⁄√N is why a few shots wobble and thousands look smooth. For an expectation value — the number most algorithms (VQE, QAOA) actually want — you assign each outcome a value and average over the shots:

⟨Z⟩ ≈ (1⁄N) Σshots (+1 for 0, −1 for 1)
noise pulls this estimate toward 0 — the price of a real device
✎ worked example · how many shots for 1% error?
1.A fair outcome has p = 0.5, so p(1−p) = 0.25.
2.Want error ≈ 0.01: set √(0.25⁄N) = 0.01.
3.Square both sides: 0.25⁄N = 0.0001 → N = 2500.
4.So ≈ 2500 shots for ±1% — and 10× tighter needs 100× the shots.
recapp̂ = count⁄N with error ≈ √(p(1−p)⁄N); precision costs shots as 1⁄√N, and noise biases estimates toward 0.
why

Your circuit is not what the chip runs

You write H, CNOT, T — whatever’s convenient. The device only knows a few native gates, and it can only do a two-qubit gate between qubits that are physically wired together (its coupling map). The transpiler bridges the gap: it rewrites every gate into native ones and inserts SWAPs to shuttle qubits next to each other when your CNOT asks for two that aren’t neighbours.

Every inserted gate is another chance to fail, so transpilers fight to keep the circuit shallow. The takeaway: the same logical circuit can run beautifully on one chip and terribly on another, purely because of layout and noise.

recapTranspiling maps your circuit onto native gates and the coupling map, adding SWAPs — fewer gates, less noise.
⚠ common misconceptions

“One run gives me the answer.” A single shot is one sample from a distribution. You need many shots to estimate the probabilities — and for a probabilistic algorithm, to be confident which outcome is the real signal.

“Measurement shows me the amplitudes.” It never does. You only ever see classical bitstrings; the amplitudes and phases are inferred from how outcomes are distributed, never read off directly.

“If it works on the simulator, it works on hardware.” The simulator is noiseless and fully connected. A real backend adds gate errors, readout errors, and connectivity limits — which is exactly why Parts C and D of this course exist.

✓ you can now
describe the run loop: build → transpile → many shots → histogram
read a measurement histogram and estimate probabilities and ⟨Z⟩
use error ≈ √(p(1−p)⁄N) to choose a shot count
explain native gates, coupling maps, and why transpiling matters
★ that’s the whole track

You’ve gone from wiring a single gate to running a real circuit on noisy hardware — the entire arc of building and operating a quantum computer. Pair it with the Quantum Information course and you’ve seen both halves: what quantum information is, and how you build with it.

← 15 Thresholds & Magic course complete · back to QC home