ZKSF logo, a neon quantum brainZKSF
← All articles

Quirk and the Browser Quantum Circuit Simulators

· 9 min read · ZKSF team

Ask which quantum circuit simulator is best and you will get an argument. Ask where each one stops and you get a number, which is considerably more useful. This is that number: for the free browser tools, for the libraries sitting behind them, and for what has to happen when a circuit outgrows both.

Quirk, and why it earned its reputation

Quirk is a quantum circuit simulator that runs entirely inside a browser tab. Craig Gidney wrote it and it lives at algassert.com/quirk. You drag gates onto wires and the display updates as you place them: amplitudes, Bloch spheres, conditional probabilities, all recomputed live. There is no install, no account and no run button, because the Quirk simulator rebuilds the entire state on every single edit.

That one design decision is why the Quirk quantum simulator remains the fastest way to understand what a gate actually does to a state. A Bloch sphere that moves while you drag a rotation teaches more in a minute than a page of matrix algebra does in an hour. If you are learning the gates, close this and go and use it. This is not a competitive comparison and Quirk quantum computing demos are not something we are trying to replace.

It is also why the Quirk quantum circuit simulator cannot follow you very far. Rebuilding everything on every keystroke is only affordable while everything is small, and small here is not a matter of taste or of effort. It is arithmetic, and the arithmetic is unusually unforgiving.

The wall, and exactly where it sits

A statevector quantum computer simulator stores one complex amplitude for every basis state. At double precision each amplitude occupies 16 bytes, and an n-qubit register has 2^n of them, so the memory required is exactly 16 x 2^n bytes. Nothing in the implementation moves that figure. It is identical for a browser tab, a workstation and a national supercomputer.

qubits        amplitudes    statevector memory
    16            65,536                 1 MiB
    20         1,048,576                16 MiB
    24        16,777,216               256 MiB
    28       268,435,456                 4 GiB
    30     1,073,741,824                16 GiB
    32     4,294,967,296                64 GiB
    34    17,179,869,184               256 GiB
    40 1,099,511,627,776                16 TiB

Read the row at 28 qubits. A browser tab permitted a few gigabytes reaches approximately there and then dies, and it dies whether the simulator was written brilliantly or carelessly. Every browser-based qubit simulation is bounded by that right-hand column rather than by its author's skill. The cruelty of the table is the doubling: each additional qubit doubles the requirement, so buying twice the machine buys exactly one more qubit.

We measured where that curve stops being a laptop question and becomes a datacentre question in The 34-Qubit Wall.

The serious libraries hit the same wall

It is tempting to assume the browser is the problem and that a proper library solves it. It is not, and they do not.

The qsim toolkit, Google's C++ statevector engine driven from Cirq, is a genuinely excellent piece of software: heavily vectorised, multithreaded, careful about memory layout and gate fusion. It is bound by the identical table. Extremely fast arithmetic over 16 TiB is still 16 TiB, and the machine holding it is not one you have.

QuantumSim goes the other way, propagating a density matrix rather than a statevector so that noise can be modelled explicitly instead of assumed away. The physics is richer and the ceiling is lower. A density matrix has 2^n by 2^n entries, so its memory grows as 16 x 4^n, which means a 20-qubit density matrix costs precisely what a 40-qubit statevector costs. Twenty qubits, 16 TiB.

That is the part which surprises people who assume a quantum computing simulator is limited mainly by engineering effort. Three tools, three design philosophies, one identical exponential.

What sits past the wall

The route past thirty qubits is not a larger statevector. It is to stop storing one at all. Three methods do exactly that, each by giving something up in exchange, and each of the runs below cost a tenth of a cent on our standard rate.

run                                    engine           qubits    cost   certificate
tensor network, certified bound        mps.quimb.cpu        40   $0.001   613aa866278e4c81
expectation value, Pauli propagation   pauli.cpu           192   $0.001   5b8b2c4309d44d41
error-correcting code, stabilizer      clifford           1001   $0.001   86125198363b4d02

Each of those certificate IDs resolves without an account, at api.zksf.org/certify/ followed by the id. They are records of actual runs rather than screenshots, and anyone can open them.

The 40-qubit tensor network run is the one worth opening first. A matrix product state is approximate by construction: it keeps the correlations that carry weight and discards the remainder, which is exactly why it fits in memory that a statevector never could. That makes it ran an insufficient claim on its own, so the certificate carries the truncation bound alongside the result. The answer arrives with a statement of how wrong it is permitted to be, which is the only defensible way to publish an approximation. Tensor networks explained covers the mechanism in detail.

The 1001-qubit stabilizer run is the opposite case. The stabilizer method is exact for Clifford circuits, so its certificate reports an error bound of exactly zero. There is nothing there to approximate and the certificate says so, which is a stronger statement than a number merely close to zero.

Simulator, emulator, or the real thing

The term quantum emulator gets used loosely, and separating it out matters because the distinction decides which of the tools above you actually want. We took it apart in emulator or simulator. The short version: emulating a device means reproducing its noise, its qubit topology and its native gate set, while simulating a circuit means computing what the mathematics says ought to happen. Quirk does the second, beautifully, at small widths. QuantumSim leans towards the first. Neither substitutes for the other, and confusing them produces results that look authoritative and mean nothing.

Past a certain point neither substitutes for hardware either, which is why the same API that carries these fifteen engines also reaches six real quantum processors. Choosing between simulation and a device is its own decision, and we set out the reasoning in CPU, GPU or QPU.

Which one to use

you want to                                 reach for
see what a gate does to a state             Quirk, in a browser tab
teach or demonstrate a small circuit        Quirk, in a browser tab
run an exact circuit up to ~30 qubits       a statevector engine: qsim toolkit, or cpu
model one device's noise faithfully         a density-matrix tool such as QuantumSim
30 to 60 qubits with a bounded error        tensor network, mps.quimb.cpu
expectation values on hundreds of qubits    Pauli propagation, pauli.cpu
thousands of qubits, Clifford gates only    stabilizer, clifford
the real device, with its real errors       one of the six QPUs

None of this is an argument against browser tools. Quirk is the correct answer to a question a great many people are genuinely asking, and a free quantum circuits simulator that opens in a tab is worth more to somebody learning than any quantity of certified infrastructure. The argument is only that the question changes underneath you. The moment a circuit is wide enough to be interesting, the tool that taught you the gates cannot run it, and the honest thing for the next tool to do is tell you how far off its answer might be.

Our own browser demo is at /try/, free and without an account, and it hands off to the engines above when a circuit outgrows what a tab can hold.

Run your own 100-qubit circuit, with an error bar.

Share this articleLink copied