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
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.
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.
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 answerSimulator now, NISQ hardware soon
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.
the program: gates laid on wires, left to right
repeated identical runs of the circuit
bar chart approximating the output distribution
noisy hardware with no full error correction yet
Primary source
IBM Quantum LearningFree, 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
Sources