Skip to content
Current section
The Quantum Computing Enthusiast’s Hub
Saved
All sections

All sections

Saved
Skip Learn navigation
Encyclopedia
Topic

Statevector simulation

Classical numerical propagation of the complex amplitudes of an ideal pure quantum state.

Also called wavefunction simulator

Edition released Coverage: Overview · Technical
On this page

Definition and significance

A statevector simulator stores 2^n complex amplitudes for n qubits and applies the selected operations to them. It is an exact representation of an arbitrary pure state up to numerical precision, but it uses resources growing exponentially with qubit count. It is valuable for small-system reference calculations, debugging and comparisons against other simulation representations.

Its internal amplitude array is privileged classical information. A physical quantum processor does not reveal the full array through one measurement, so an algorithm using direct amplitude inspection is a classical simulation procedure rather than a hardware-compatible readout method.

Mechanism and mathematical treatment

With complex128 values, the raw amplitude array uses 16 times 2^n bytes. At n=30 that is 17,179,869,184 bytes, or 16 GiB, before additional buffers. A one-qubit gate updates pairs of amplitudes whose indices differ in the relevant bit. The operation count is proportional to 2^n for a dense statevector, even though the gate matrix itself is only two by two.

For a qubit designated as the leftmost tensor factor, the indexing stride differs from software that treats qubit zero as the least significant factor. A simulator's native ordering must be recorded before comparing its arrays to the encyclopedia's equations.

Fully worked reference example

In left-to-right q0,q1 ordering, begin with vector [1,0,0,0]. Apply H tensor I to get [1/sqrt(2),0,1/sqrt(2),0]. Apply CX with q0 as control to get [1/sqrt(2),0,0,1/sqrt(2)]. Squaring magnitudes gives the Bell distribution [1/2,0,0,1/2].

If a simulator returns tiny residual amplitudes such as 10^(-16), those can reflect floating-point arithmetic rather than physical error. Conversely, exact simulation of a chosen noisy channel does not mean that the channel faithfully models a real device. Numerical correctness and model validity are separate questions.

Limitations and common misconceptions

Not every quantum state needs a dense statevector: stabilizer and tensor-network representations can exploit structure. Claims about a maximum simulated qubit count are incomplete without circuit structure, precision, memory, hardware and output task. Sampling a state repeatedly may be cheap once it is computed, unlike re-preparing a physical state for each shot.

Scientific relationships

A pure-state vector and a general mixed-state operator require different representations.

Pauli-preserving circuits can be represented without a dense amplitude vector.

Low-rank tensor structure can replace a dense amplitude representation.

Finite arithmetic affects fidelity to the selected mathematical model.

An in-place gate update with a complete index rule

Store n-qubit amplitudes in encyclopedia order, with q0 the most significant tensor factor. For a gate on qubit k, define mask=2^(n-1-k). Visit each index j whose mask bit is zero, and pair it with j+mask. If the gate matrix is [[u00,u01],[u10,u11]], first save a=psi[j] and b=psi[j+mask], then write psi[j]=u00*a+u01*b and psi[j+mask]=u10*a+u11*b. Saving both old values before either write is essential for an in-place implementation.

Each pair is visited exactly once because one member has the selected bit zero and the other one. There are 2^(n-1) pairs, so the update uses work proportional to the statevector length and constant extra storage beyond the vector. The gate's two-by-two matrix does not need to be expanded into a dense 2^n-by-2^n matrix. Forming that large matrix would waste both memory and multiplication work.

For n=3 and k=1, mask=2 and the pairs are (0,2),(1,3),(4,6),(5,7). The pairing rule depends on the declared tensor convention. In a representation where q0 is least significant, the mask is instead 2^k. A gate routine should receive or fix one convention, rather than infer it from a circuit drawing.

A complex-valued update checked by normalization

Take the normalized input vector [1,i,2,-1,0,1,-i,2]/sqrt(13). Apply H to q1 using the four pairs above. The output is [3,i-1,-1,i+1,-i,3,i,-1]/sqrt(26). For example, pair (1,3) starts as (i,-1)/sqrt(13) and becomes (i-1,i+1)/sqrt(26). Both real and imaginary components are required.

The squared magnitudes of the output numerators are 9,2,1,2,1,9,1,1, summing to twenty-six. This independently confirms normalization. Applying the same H update again returns the original vector because H squared is identity. The two checks test different aspects: normalization can survive some wrong unitary permutations, while the round trip can survive using a consistently wrong qubit index. An asymmetric known-output calculation is needed to verify the intended target qubit.

The example contains no random sampling and no physical noise. Floating-point residuals in a numerical implementation are arithmetic discrepancies relative to this exact vector. They should not be reported as decoherence or gate infidelity. A simulator can incorporate a physical noise model separately, but then its representation and stochastic or mixed-state semantics must be specified.

Sampling and mid-circuit measurement

For terminal computational measurement, form probabilities p_j=|psi_j|^2 and their cumulative sums. Draw a uniform number in [0,1) and return the first index whose cumulative probability exceeds it. Repeating this sampling step after one state calculation produces independent ideal output samples, assuming independent random draws. It is much cheaper than recalculating the same circuit for every terminal shot and has a different cost structure from repeated hardware preparation.

For a mid-circuit measurement of qubit k, first sum probabilities over indices with the relevant bit zero to obtain p0. Sample an outcome b. Zero all amplitudes inconsistent with b and divide the remaining amplitudes by sqrt(p_b). Subsequent gates act on that conditional state. If p_b is zero, that branch cannot be sampled in exact arithmetic; a numerical implementation should not divide by zero or fabricate a normalized branch.

When classical feedback depends on the outcome, repeated executions may follow different branches. Reusing one terminal state for all shots is then invalid unless the branching structure has been handled appropriately. One can simulate each stochastic trajectory or propagate an explicit ensemble or density matrix. The appropriate method depends on how many distinct branches occur and what output statistics are needed.

Memory and observable access

At n=28, a complex128 statevector alone occupies 16 times 2^28 bytes, exactly four GiB. A second equally sized work buffer doubles that storage before program overhead, gate data and output arrays. A simulator that reports only the raw vector size can therefore understate peak memory. Changing to complex64 halves storage but changes numerical precision; it does not change exponential scaling.

A Pauli expectation can often be computed without forming a matrix by pairing amplitudes according to its bit-flip pattern and accumulating their signed complex products. This gives an exact simulator expectation up to arithmetic error, without shot noise. It is privileged access to a classical representation, so it should be compared with hardware expectation estimation only after including the difference in output access.

The complete reference procedure above is language-independent pseudocode. The accompanying mathematical checks use ordinary classical arrays; no quantum SDK behavior or version compatibility is asserted. A practical implementation must also define its integer indexing limits, complex precision and random-number semantics.

Dense state-array memory accounting

A dense complex128 statevector stores 2^n complex amplitudes at 16 bytes each, so its raw array occupies 16 times 2^n bytes. At 30 qubits this is 16 GiB, and at 31 it is 32 GiB. One GiB is 2^30 bytes. A dense 15-qubit density matrix instead stores 4^15 complex entries and also occupies 16 GiB. These numbers exclude workspaces and other simulator overhead. They describe a classical representation, not physical quantum-device memory, speed or cost.

Sources

  • Google Quantum AI / Cirq · Documentation · quantumai.google
    Verification scope

    Recorded source check ·

    Simulation guide retrieved; explicit qubit_order semantics and distinction between state and measurement output inspected.

    Conceptual reference semantics only. No code execution or universal backend support claim.