What is a qubit?
I wanted to understand quantum computing properly, which for me means building the thing rather than driving a framework that does the linear algebra in the basement and hands back an answer.
Building a NumPy quantum simulator from a single qubit to Shor's algorithm, density matrices, noise, and error correction. Nothing asserted that the code cannot show.
This series builds quantum computing from nothing but NumPy: a qubit is a length-two complex array, a gate is a small matrix, and everything mysterious (superposition, entanglement, interference, measurement) is something you can watch happen inside the array rather than take on faith.
The arc runs in three movements. Posts 0 through 3 build the pure-state machinery and cash it in on Grover’s search. Posts 4 through 6 build the quantum Fourier transform, phase estimation, and Shor’s algorithm, the payoff of the pure-state picture. Posts 7 through 12 rebuild the engine to scale, then give up the pure-state picture itself: density matrices, noise and decoherence, error correction, the consolidated engine in full, and a closing essay on what the Born rule does and does not mean.
Every post executes its own code. The library behind the series, qfs, lives
at queelius/quantum-from-scratch
with a test suite that includes differential checks against Qiskit. The
consolidated engine, reproduced verbatim in post 11, is about fifty lines.
I wanted to understand quantum computing properly, which for me means building the thing rather than driving a framework that does the linear algebra in the basement and hands back an answer.
In post 0 a qubit was a unit vector in $\mathbb{C}^2$, and everything about it fit in a length-two array.
So far the qubits have mostly sat still.
Deutsch-Jozsa and Bernstein-Vazirani solved artificial promise problems.
The last three posts built circuits whose payoff was a single global fact read out by interference.
The last post built the Quantum Fourier Transform and promised it was a readout instrument.
This is the one everyone has heard of: the algorithm that factors integers in polynomial time and, if a big enough quantum computer is ever built, breaks RSA.
This post does not add a quantum idea.
Every state in this series so far has been a single vector with definite amplitudes.
Last post ended with a warning: the off-diagonal coherences of a density matrix are the fragile part, and a real qubit loses them on its own.
Last post was the bad news: a real qubit leaks its coherence into the environment and forgets what it was doing.
Across the series I kept saying the simulator was small: a qubit is an array, a gate is a matrix, the whole thing is a few hundred lines.
The very first useful thing our simulator did, back in post 0, was turn a vector of amplitudes into a vector of probabilities.