Superposition · Gates · Measurement

How you actually
program a qubit.

A classical bit is a switch. A qubit is a direction in space that you rotate with pulses and read out as probability. This walks through the physics that makes it possible and the linear algebra you program against — every diagram below runs the real math.

The object you're computing with

A bit that is a vector, not a value

A classical bit is either 0 or 1. A qubit's state is a unit vector built from two basis directions, written |0⟩ and |1⟩:

|ψ⟩ = α|0⟩ + β|1⟩    with   |α|² + |β|² = 1

α and β are complex amplitudes. The crucial rule — the only place randomness enters — is the Born rule: when you measure, you get 0 with probability |α|² and 1 with probability |β|². Before that, the qubit genuinely holds both, weighted by these amplitudes. "Superposition" is just both basis vectors having nonzero amplitude at once.

For an engineer it's cleanest to think of it as a 2-element complex vector. Every operation you'll apply is a matrix multiply on that vector. There is no hidden machinery — this is the state.
Instrument 01 — the state lives on a sphere

The Bloch sphere

Two complex numbers with a normalization constraint and an irrelevant global phase leave exactly two real degrees of freedom — which is a point on a sphere. The north pole is |0⟩, the south pole is |1⟩, and everything on the equator is an equal superposition that differs only in phase (the angle around the vertical axis). Gates are rotations of this arrow. Click them and watch.

apply a gatesingle-qubit rotations

Press H from |0⟩: the arrow swings to the equator — a perfect 50/50 superposition. Press H again and it returns to |0⟩. That round trip is interference, and it's the whole game (more in §2).
The physical question

How is a real qubit put into superposition?

On hardware a qubit is a two-level quantum system: the two lowest energy levels of a superconducting circuit (a transmon — billions of electrons behaving as one quantum object) or two electronic states of a trapped ion. |0⟩ is the ground state, |1⟩ the excited state.

You drive it with an electromagnetic pulse — microwaves for a transmon, a laser for an ion — tuned to the energy gap between the levels. The pulse doesn't "set" a value; it makes the state rotate continuously between |0⟩ and |1⟩ for as long as it's applied. This is a Rabi oscillation. The amount of rotation is the pulse area (intensity × duration).

instrument 02 — drive the qubitRabi oscillation

Drag the pulse area. The probability of finding the qubit excited is P(1) = sin²(area/2). Notice it's smooth and reversible — nothing collapses until you measure.

|0⟩
|1⟩
Reading it out

Measurement collapses the vector

You can never read α and β directly. A measurement forces the qubit to commit to |0⟩ or |1⟩, with probabilities |α|² and |β|², and the superposition is destroyed — the arrow snaps to a pole. One run gives one classical bit. To recover the probabilities you prepare the same state and measure many times. These repeated runs are called shots.

instrument 03 — sample the stateshots & collapse

This measures the current superposition (set it with the buttons), collapsing it each shot and tallying outcomes. With few shots the histogram is noisy; with many it converges to |α|², |β|².

last result:
ideal probabilities
|0⟩
|1⟩
measured tally (0 shots)
|0⟩
|1⟩
Two qubits, one state

Entanglement

Put two qubits together and the state lives in a 4-dimensional complex space — amplitudes for |00⟩, |01⟩, |10⟩, |11⟩. Most states in that space cannot be written as two separate qubits. The classic example is the Bell state (½ weight on |00⟩ and |11⟩): each qubit alone looks like a coin flip, but the two outcomes are perfectly correlated. Measure one and you instantly know the other — every shot.

instrument 04 — measure a Bell paircorrelated outcomes

State: (|00⟩ + |11⟩)/√2. Each measurement collapses both qubits together. Watch: A and B always agree, yet which value comes up is random 50/50.

last: qubit A =   qubit B =
00
01
10
11
01 and 10 stay empty no matter how many shots you take. The qubits never disagree — that impossible-to-fake correlation is what entanglement buys you, and it's the raw material for quantum teleportation, error correction, and speedups.
What a program is

A circuit is a sequence of matrix multiplies

Quantum programming is not if/else over qubit values — you can't read them mid-flight without collapsing them. Instead a program is a fixed pipeline: prepare qubits in |0⟩, apply a list of gates (rotations), then measure. Each gate is a unitary matrix; running the circuit means multiplying the state vector by each gate in order. "Unitary" just means reversible and norm-preserving — it keeps |ψ⟩ a valid unit vector.

For n qubits the state vector has 2ⁿ complex entries. Three qubits → 8 amplitudes; 50 qubits → 2⁵⁰ ≈ a quadrillion. A gate acts on all of them at once. That exponential state space is the resource — the trick of algorithm design is sculpting amplitudes with interference so the wrong answers cancel and the right ones add.

The vocabulary

The gates you'll actually use

gatematrixwhat it does
X[[0,1],[1,0]]NOT / bit flip. Swaps amplitudes of |0⟩ and |1⟩.
Z[[1,0],[0,−1]]Phase flip. Leaves |0⟩, negates |1⟩. Invisible to a direct measurement — but visible after interference.
H1/√2 [[1,1],[1,−1]]Hadamard. Maps |0⟩ → equal superposition. The standard way to enter superposition in code.
S, T[[1,0],[0,i]] · [[1,0],[0,e^{iπ/4}]]Small phase rotations (90°, 45°). Used to dial in interference.
CNOT4×4, flips target
if control = 1
The key two-qubit gate. Conditional logic + the gate that creates entanglement.
A small set — typically {H, T, CNOT} — is universal: any quantum computation can be built from it, exactly like NAND is universal for classical logic.
Instrument 05 — build & run

Two-qubit circuit simulator

Add gates left to right. The simulator multiplies the real 4-dimensional state vector and shows you the resulting amplitudes and measurement probabilities. Build the Bell state with the preset and watch |01⟩ and |10⟩ stay at zero.

q0 |0⟩
q1 |0⟩
q0:
q1:
state vector (amplitudes)
measurement probabilities
|00⟩
|01⟩
|10⟩
|11⟩
The same thing in code

Programming it with Qiskit

Qiskit (Python, IBM) is the most common way to write circuits. The code below is exactly the Bell-state circuit from the simulator above — build it, then either run it on a simulator or send it to real hardware.

# pip install qiskit qiskit-aer
from qiskit import QuantumCircuit
from qiskit_aer import AerSimulator

qc = QuantumCircuit(2, 2)   # 2 qubits, 2 classical bits

qc.h(0)              # Hadamard on q0 -> (|0> + |1>)/sqrt(2)
qc.cx(0, 1)          # CNOT: entangle q0 (control) with q1 (target)
qc.measure([0,1], [0,1]) # collapse each qubit into a classical bit

sim = AerSimulator()
result = sim.run(qc, shots=1024).result()
print(result.get_counts())
# -> {'00': ~512, '11': ~512}   never '01' or '10'
1

Allocate. QuantumCircuit(2, 2) reserves 2 qubits (start in |0⟩) and 2 classical bits to hold the readout. Quantum and classical registers are always tracked separately.

2

Superpose. qc.h(0) applies Hadamard to q0 — this is the line that creates superposition, the software counterpart of the π/2 pulse from §1. q0 is now 50/50.

3

Entangle. qc.cx(0,1) is CNOT. Because q0 is in superposition, "flip q1 if q0 is 1" applies to both branches at once, linking them: you get |00⟩ and |11⟩ together, never the mixed terms.

4

Measure. Nothing is known until measure. Each of the 1024 shots reruns the whole circuit and collapses it, so the output is a histogram — matching the probability bars in the simulator above.

Mental model for an engineer: the circuit is a pure function compiled to a sequence of matrix multiplies, measure is the only stochastic, irreversible step, and shots is your Monte-Carlo sample size for estimating the output distribution.
Where the speedup comes from

Interference does the work

A superposition over 2ⁿ states is not free parallelism — if you just measure it you get one random answer, no better than guessing. The art is arranging gates so that amplitudes for wrong answers destructively interfere (cancel toward zero) while the right answer's amplitude constructively grows. You saw the mechanism in §1: H·H returns to |0⟩ because two paths to |1⟩ cancel.

Real algorithms are exactly this, scaled up. Grover's search repeatedly reflects amplitudes to pump probability toward the marked item, finding it in √N steps instead of N. Shor's algorithm uses a quantum Fourier transform to make interference expose the period of a function — which cracks the factoring problem behind RSA. Both are interference machines, not brute-force-parallel ones.

Reality check

Where the field is now

Today's machines are NISQ — Noisy Intermediate-Scale Quantum. Two hard limits dominate practice:

Decoherence

Superposition is fragile. Stray interaction with the environment leaks the state away in microseconds to milliseconds, so a circuit must finish before the qubit "forgets." This caps how deep your gate sequence can be.

Gate error & correction

Every physical gate is slightly wrong (~0.1–1%). Quantum error correction spreads one logical qubit across many physical ones — needing thousands of good physical qubits per reliable logical qubit. That overhead is the current frontier.

superconducting (IBM, Google) trapped ions (IonQ, Quantinuum) neutral atoms (QuEra) photonics (PsiQuantum)
Good starting point in practice: write circuits in Qiskit, debug on the local statevector simulator (deterministic, lets you inspect amplitudes like the tool above), then submit to real hardware only once the logic is right — hardware time is queued and noisy.