← Back to section · Software & Developer Tools
How Quantum Circuit Simulators Work: State Vectors, Tensor Networks, and the Memory Wall
Simulating a quantum circuit on a classical computer is, at bottom, a trade between different exponential costs. This article explains the four mainstream routes — state vector, density matrix, tensor network and stabiliser simulation — where each one's cost comes from, what scale each can reach, and which one to pick for a given circuit.
While real quantum hardware remains scarce and expensive to queue for, most quantum algorithm development actually happens on classical simulators. But “simulating a quantum circuit” is not one problem: the state of n qubits in principle needs 2^n complex numbers to describe completely, and no exact simulation escapes some form of exponential cost. Simulators differ in where they hide that cost — in memory, in time, or in scope. This article walks through the four mainstream routes.
State Vectors: The Whole Wavefunction in Memory
State-vector simulation is the most direct route: maintain an array of 2^n complex numbers, one amplitude per computational basis state, and update the whole array with each gate’s matrix as the gate is applied. Qiskit Aer’s statevector method, Cirq’s default simulator and Google’s qsim all take this route (with differing implementation optimisations).
The cost is transparent: at 16 bytes per double-precision complex number, memory demand is 16×2^n bytes. Twenty qubits take about 16 MiB — effortless; 30 qubits about 16 GiB — a workstation starts to strain; 32 qubits, 64 GiB; 40 qubits, 16 TiB — supercomputer territory. Every additional qubit doubles the memory. This wall cannot be engineered away; it comes from the representation itself.
The strength of the state vector is generality and exactness: any gate and any circuit runs, and probabilities and amplitudes can be read out directly — the default choice for algorithm debugging. Its domain follows accordingly: exact results at around thirty qubits.
Density Matrices: Squaring the Cost for Noise
Real devices are noisy, and a noiseless state vector cannot answer “what will this machine actually output”. Density-matrix simulation maintains a 2^n × 2^n matrix, which can represent mixed states and noise processes such as decoherence — at the price of squaring the memory: after the amplitudes become a matrix, even 20 qubits already need on the order of 16 GiB. Practical tools therefore often switch to quantum trajectories: decompose the noise process into many state-vector runs with random perturbations and average statistically, trading time for memory. Qiskit Aer’s density_matrix method and automatic method selection, and Cirq’s noise simulation support, are all positions inside this trade-off space.
Tensor Networks: Contract, Don’t Store
Tensor-network simulation asks a different question: instead of writing out the final state, treat every gate as a small tensor, let the whole circuit form a tensor network, and compute the final amplitude (or samples) by contracting that network. The total cost of contraction depends not on the qubit count itself but on the network’s entanglement structure — formally, on the treewidth of the contraction path.
That yields a completely different domain of applicability: when circuits are shallow, wide and limited in entanglement range (such as the random circuits of certain near-term hardware demonstrations), tensor networks can handle dozens or even hundreds of qubits within ordinary memory; conversely, once circuits grow deep and entanglement global, the cost of the optimal contraction path explodes exponentially as well. Qiskit Aer offers a tensor_network method, and Google’s qsim and a line of research codes support tensor contraction too. A further trait is “compute on demand”: if you only need one amplitude or a set of samples, you never pay for writing out the full state.
Stabiliser Simulation: The Clifford Shortcut
One more class of circuits can be simulated exactly and efficiently: circuits consisting only of Clifford gates (H, CNOT, S, …) and computational-basis measurements. The Gottesman–Knill theorem guarantees such circuits can be simulated in polynomial time on a classical computer, tracking not amplitudes but stabiliser generators — O(n²) classical information for n qubits. CHP, by Scott Aaronson and Daniel Gottesman, was an early representative implementation; for quantum error-correction research, Craig Gidney’s Stim has taken this route to its extreme — designed for fast sampling of large error-correction circuits (surface codes and the like), it handles Clifford circuits at the scale of tens of thousands of qubits and is now core infrastructure in the field. The price is scope: once a circuit contains many non-Clifford gates (such as T gates), stabiliser methods must be combined with other techniques (e.g. stabiliser decomposition), and the cost grows exponentially in the number of non-Clifford gates.
In Between: Hybrid Methods and GPUs
Real tools do not always follow a single route to the end. The Schrödinger–Feynman hybrid cuts a circuit in two, simulates each half with state vectors, and stitches the cut together with a path sum over the entanglement across it — trading time for memory to push the reachable qubit count a few beyond the state-vector limit; Qiskit Aer’s automatic method selection picks among state vector, density matrix and other methods according to the circuit and configuration. Another engineering route is GPU acceleration: state-vector updates are essentially large vector operations, and a GPU’s high-bandwidth memory suits them well; qsim, Qiskit Aer and others offer GPU backends. This does not change the exponential law, but it lifts “what a workstation can run” a step above thirty qubits — with VRAM capacity as the new hard constraint. One common misunderstanding is worth clearing up: a simulator outputs exact amplitudes or an ideal distribution, while real hardware outputs noisy samples; treating a simulator’s ideal result directly as “the result of quantum computation” skips the entire layer of noise — which is exactly why noise simulation (density matrices and trajectories) is indispensable in algorithm validation.
How to Choose: Circuit First, Tool Second
| Your circuit | First-choice route | Representative tools | Sense of scale |
|---|---|---|---|
| General circuit, exact amplitudes needed | State vector | Qiskit Aer, Cirq, qsim | ~30 qubits (memory-bound) |
| Noisy, output distribution needed | Density matrix / trajectories | Qiskit Aer, Cirq | Density matrix ~20 qubits; trajectories higher |
| Many qubits, shallow, limited entanglement | Tensor network | Qiskit Aer (tensor_network) | Dozens to hundreds of qubits, structure permitting |
| Clifford-dominated (error correction) | Stabiliser simulation | Stim | Tens of thousands of qubits |
In one sentence: simulators are not stronger or weaker in the abstract — only matched or mismatched to a circuit’s structure. Ask how deep your circuit is, how wide its entanglement spreads, whether it carries noise and what fraction of its gates are Clifford, and the answer points at one of the routes.
References
- Qiskit Aer documentation: https://qiskit.github.io/qiskit-aer/
- Cirq simulator documentation: https://quantumai.google/cirq
- The Stim repository: https://github.com/quantumlib/Stim
- The qsim repository: https://github.com/quantumlib/qsim
Tags: quantum simulatorsstate vectortensor networks