Measurement
You never see amplitudes directly. Measuring a qubit always gives a plain 0 or 1, and the amplitudes only decide how likely each one is.
The Born rule
For a qubit in the state , measurement gives
After the measurement the qubit is left in whichever state was seen. The superposition is gone, so measuring again gives the same answer.
Shots
One measurement tells you almost nothing about the probabilities. Real quantum computers, and qsengine, run the circuit many times and count the results. Each run is a shot. A rotation by about the Y axis gives
import math
import qsengine
qc = qsengine.QuantumCircuit(1)
qc.ry(0, math.pi / 3)
print(qc.probabilities())
print(qc.run(shots=1000, seed=7))Output
[0.75 0.25]
{'1': 257, '0': 743}probabilities() gives the exact 0.75; 1000 shots give 743, close to it but not exact.
The more shots, the closer the counts get to the probabilities. probabilities() skips sampling altogether, which no real device can do. See Running circuits.
Phase: what measurement cannot see
Amplitudes can be negative or complex, and squaring hides the difference. These two states give exactly the same measurement statistics:
The sign is called the relative phase, and it is not just bookkeeping: a later gate can turn it into a difference you can measure. Hadamard twice returns to , but a Z gate in the middle flips the phase and the result becomes :
qc = qsengine.QuantumCircuit(1)
qc.h(0)
qc.h(0)
print(qc.probabilities())
qc = qsengine.QuantumCircuit(1)
qc.h(0)
qc.z(0)
qc.h(0)
print(qc.probabilities())Output
[1. 0.]
[0. 1.]The Z gate changed nothing you could measure on its own, yet it flipped the final answer.
This is the effect quantum algorithms rely on: steer the phases so wrong answers cancel and right answers add up. The Deutsch-Jozsa algorithm is a complete example.