Skip to content

Real Machines

Programming a quantum computer

Circuits, shots, and histograms, hands on

You have built qubits, gates, entanglement, and interference on paper. Now the payoff: this is how you actually run one. A quantum program is a circuit, you run it many times, and you read a histogram of outcomes. That is the entire workflow, and by the end of this lesson you will have driven it yourself.

The expectation to correct

People imagine running a quantum program means pressing go and reading back the answer, one clean number, the way a classical function returns a value. It does not work like that. A quantum computer hands you a sample, one random basis state drawn by the Born rule. One run tells you almost nothing. You learn the answer only by running the same circuit thousands of times and looking at the distribution.

The workflow in four steps

Programming today, whether on a simulator or real hardware, is always the same loop. There is no magic in the tooling once you have the physics picture you already built.

First, build a circuit: lay gates on wires, left to right. Second, add gates at the end. Third, pick a backend - a simulator on your laptop or a real quantum processor over the cloud - and run , say a thousand repetitions. Fourth, collect the results into a : the bar heights approximate the true probabilities , sharpening as you add shots.[1]

Drive it yourself

Here is a live console. Pick a challenge, or start blank and drag gates from the palette onto the wires (CNOT is two clicks: control, then target in the same column). Watch three things move together: the exact state vector, the Qiskit code that would produce it, and - when you press Run shots - the histogram. This is the whole loop in one place.

challenge

Loaded the Bell recipe: H on q0, then CNOT from q0 to q1. Run the shots and watch |00> and |11> split the counts. Click a gate to remove it and try your own.

Live console: edit the circuit, read the exact state vector, run shots, and watch the Qiskit code update as you build.
Palette
q0q1H
State vector
|00>0.70750%
|01>00%
|10>00%
|11>0.70750%
qc = QuantumCircuit(2)
qc.h(0)
qc.cx(0, 1)

What you built: Build a circuit, then read its state below.

Start with Bell state: an H then a CNOT builds . Run the shots and you get roughly half |00> and half |11>, almost never |01> or |10>: the two qubits are entangled, perfectly correlated, yet each one alone looks random. Then try Mini-Grover: a longer circuit that superposes both qubits, flips the phase of |11>, and inverts about the mean. One pass and the shots pile almost entirely onto |11> - interference has amplified the marked answer to near-certainty. The same gates you drew, now doing real work.

The same circuit, written in code

The console shows Qiskit code live as you build. Written by hand, the Bell program is only a few lines - and it makes the shots-and-histogram loop explicit:

from qiskit import QuantumCircuit
from qiskit_aer import AerSimulator

qc = QuantumCircuit(2, 2)
qc.h(0)              # put q0 into an equal superposition
qc.cx(0, 1)          # entangle: q1 follows q0
qc.measure([0, 1], [0, 1])

result = AerSimulator().run(qc, shots=1000).result()
print(result.get_counts())   # ~ {'00': 503, '11': 497} - a histogram, not one answer
A Bell state in Qiskit: build, measure, run many shots, read the histogram.

Simulator now, NISQ hardware soon

On a laptop simulator the histogram is clean, because the math is exact. On today's real machines it is not. We live in the - Noisy Intermediate-Scale Quantum - where devices have enough qubits to be interesting but not enough error correction to be clean. Run the Bell circuit on real hardware and you will see small bars on |01> and |10> too: that is decoherence and gate error leaking into your answer. Reading a histogram means reading the noise too.

Lock it in

  • A quantum program is a circuit; running it means taking many shots and reading a histogram, not receiving a single return value.
  • Each shot samples one basis state by the Born rule; the histogram approximates the output probabilities and sharpens with more shots.
  • The workflow is build, measure, choose a backend, run shots, read the distribution - identical on a simulator or real hardware.
  • On NISQ hardware the histogram carries noise from decoherence and gate error, so outcomes that should be zero show small nonzero bars.

Check yourself

You run a circuit for 1000 shots. What does the resulting histogram give you?

Why are results from today's NISQ hardware noisy?

Recall: describe the workflow to run a quantum program, and define a shot and a histogram.

The whole loop, from circuit to distribution. Try to state it, then check.

Match each programming term to its meaning.

drop here

the program: gates laid on wires, left to right

drop here

repeated identical runs of the circuit

drop here

bar chart approximating the output distribution

drop here

noisy hardware with no full error correction yet

Primary source

IBM Quantum Learning

Free, hands-on courses that take you from a first circuit to running shots on real IBM hardware in the browser, using exactly the build-run-histogram loop this lesson drills.

Ask your teacher

You can now build and run circuits - the machinery is no longer a black box. The last module steps back to the big picture: where the field actually is, and the one consequence you should act on. Ask me how to try a circuit on real IBM or IonQ hardware for free, why compilers have to "transpile" your gates to a chip's native set, and how Quirk[2] lets you feel these circuits by dragging gates in your browser.

Sources

  1. 1.IBM Quantum Learning - build, run, and read circuits
  2. 2.Quirk - a drag-and-drop quantum circuit simulator (Craig Gidney)