Quantum Circuit Simulator
Type a circuit — Hadamards, CNOTs, rotations, Toffolis — and watch an exact simulation of up to 10 qubits: probabilities, measurement counts, the full state vector and each qubit's entanglement. It runs in your browser.
Build a circuit
Circuit diagram
Run a circuit to draw it.
Exact probabilities
Measurement results
State vector
Each qubit on its own
Bloch vector (x, y, z) of the qubit's reduced state, and its entanglement with the other qubits. Length 1 means the qubit is in a pure state by itself; shorter means it is entangled.
Show the Larzscript program that just ran
Run a calculation to see the exact program.
This is the real program the page sent to the Larzscript interpreter (compiled to WebAssembly) in your browser. The library it imports is the same code the automated tests check.
What you are simulating
A qubit is a quantum two-level system whose state is a pair of complex amplitudes (α, β) with |α|² + |β|² = 1. Measuring it gives 0 with probability |α|² and 1 with probability |β|². n qubits have 2n amplitudes, one for every bit string, and gates are unitary matrices that rotate that vector without changing its length. The Hadamard gate H creates the equal superposition (|0⟩ + |1⟩)/√2; the CNOT gate flips a target qubit when its control is 1, and together they generate entanglement.
Example: the Bell state
The two-gate circuit h 0; cnot 0 1 produces (|00⟩ + |11⟩)/√2. Either qubit alone is a perfectly random coin, but the two always agree — and each shows exactly 1 bit of entanglement. Measured 1,000 times with seed 7 the counts are 502 × 00 and 498 × 11; the outcomes 01 and 10 never occur.
Try these
Grover search for the state |11⟩ in two qubits (the second preset) finds it with probability 100% in a single round. The quantum Fourier transform of |011⟩ gives eight equally likely outcomes, but their phases carry the frequency information — look at the state-vector table. Teleportation moves an unknown state from qubit 0 to qubit 2: after the circuit qubit 2 has Bloch vector (0.71286, 0.60044, 0.36236), which is exactly the vector of the state ry(1.2)·rz(0.7) prepared on qubit 0, and it is now unentangled (entropy 0.00000).
Accuracy and verification
The simulator is checked against an independent brute-force implementation that builds every gate as a full 2n×2n matrix: 48 random circuits on 1–5 qubits agree on every amplitude to 10−12, as do Pauli expectation values, Bloch vectors and entanglement entropies. Deliberately breaking the simulator in seven different ways (a flipped sign, reversed qubit order, swapped control and target, a wrong angle…) makes the tests fail every time, so the tests genuinely test it.
Limits: ideal, noiseless qubits and exact measurements. Real quantum hardware has errors; this is the mathematical model, not a noise simulation. The circuit language is deliberately small — see the library to script anything else.
Frequently asked questions
What is a quantum circuit simulator?
A program that tracks the full quantum state of a small quantum computer on an ordinary computer. For n qubits the state is 2n complex numbers (amplitudes); each gate updates those numbers exactly, and measurement picks an outcome with probability equal to the amplitude squared. It cannot scale to large machines — that exponential cost is exactly why quantum computers are interesting — but for up to about 10 qubits in your browser it is a faithful model.
How do I read the circuit language?
One gate per line (or separated by semicolons): h 0 puts qubit 0 into an equal superposition; cnot 0 1 flips qubit 1 if qubit 0 is 1; x, y, z, s, t are single-qubit gates; rx, ry, rz 2 pi/2 rotate by an angle (numbers, pi, pi/4, 2*pi/3); cz, cp (controlled phase), swap and ccx (Toffoli) act on several qubits. Qubit 0 is the leftmost bit of every printed state.
What does the 'entanglement' column mean?
It is the entropy, in bits, of one qubit's reduced state. A qubit that is still in a definite state on its own has entropy 0; a qubit that is maximally entangled with the rest — like either half of a Bell pair — has 1 bit. In the Bell-state example above both qubits show 1.0, even though the pair as a whole is in one perfectly definite quantum state.
Why do the measured counts differ from the exact probabilities?
Measurement is random. In the Bell example the exact probabilities are 50% and 50%, and a simulated run of 1,000 shots gives 502 and 498 — statistical fluctuation of roughly ±16. The shots use a seeded generator so a run is reproducible; change the seed to see a different sample.
How many qubits can it handle?
Up to 10 here, which is 1,024 amplitudes and takes a fraction of a second per gate. The underlying library, written in Larzscript, can simulate 14 qubits natively at about a tenth of a second per gate; memory and time double with every extra qubit.
Every number on this page is computed by the open-source larzscript-cosmos library (quantum, physmath), written in Larzscript, and checked against independent references in its test suite. How it is verified →