DeepPractise
DeepPractise

Statevector Simulation

Track: Quantum Gates & Circuits · Difficulty: Beginner · Est: 13 min

Statevector Simulation

Overview

Up to now, we’ve described circuits as sequences of gates acting on a quantum state, followed by measurement.

When you actually “run” a circuit in software, you need a representation of the quantum state. This page answers a practical execution question:

  • What does it mean for a simulator to keep a statevector, and what can (and can’t) you learn from it?

Understanding this removes confusion about why simulation can feel “more powerful” than real execution, and it prepares you to interpret measurement results correctly.

Intuition

Before measurement, ideal quantum evolution is deterministic. If you start from a known initial state and apply a fixed sequence of unitary gates, the resulting quantum state is fixed.

The randomness appears only when you measure.

A statevector simulator takes advantage of this:

  • it explicitly stores the amplitudes of the full quantum state,
  • applies gates as deterministic updates to those amplitudes,
  • and (if you choose) computes exact measurement probabilities from those amplitudes.

This is like having access to the “inside” of the quantum state, not just the sampled outcomes. That’s convenient for learning and debugging.

But there is a cost:

  • the number of amplitudes grows exponentially with the number of qubits.

Formal Description

What a statevector represents

For nn qubits, the computational basis consists of 2n2^n basis states. A general pure state can be written as

ψ=x{0,1}nαxx,|\psi\rangle = \sum_{x\in\{0,1\}^n} \alpha_x |x\rangle,

where:

  • xx is a bitstring like 000…0 or 101…1,
  • x|x\rangle is the corresponding basis ket,
  • αx\alpha_x is a complex amplitude,
  • and normalization means xαx2=1\sum_x |\alpha_x|^2 = 1.

The statevector is the list of amplitudes {αx}\{\alpha_x\}.

Deterministic evolution before measurement

If a circuit applies unitary gates whose overall unitary is UcircuitU_{\text{circuit}}, then

ψfinal=Ucircuitψstart.|\psi_{\text{final}}\rangle = U_{\text{circuit}} |\psi_{\text{start}}\rangle.

This update is deterministic. A statevector simulator computes it directly.

Why simulators can access the full state

In software, the simulator has the data structure holding all amplitudes. So it can:

  • print amplitudes,
  • compute exact probabilities P(x)=αx2P(x)=|\alpha_x|^2,
  • compute overlaps and expectation values directly.

A real experiment does not give direct access to all amplitudes; it gives samples from measurement.

Limitations of statevector simulation

The main limitation is scaling.

  • For nn qubits, you store 2n2^n complex numbers.
  • Doubling the number of qubits squares the state space size.

So statevector simulation becomes infeasible as nn grows. This is why “simulating a quantum computer” quickly becomes hard on classical machines.

Worked Example

Consider 2 qubits starting from 00|00\rangle. Apply H on the first qubit. The resulting state is

ψ=12(00+10).|\psi\rangle = \tfrac{1}{\sqrt{2}}(|00\rangle + |10\rangle).

A statevector simulator would store four amplitudes corresponding to:

  • 00,01,10,11|00\rangle, |01\rangle, |10\rangle, |11\rangle.

In this example:

  • amplitude of 00|00\rangle is 1/21/\sqrt{2},
  • amplitude of 10|10\rangle is 1/21/\sqrt{2},
  • the other two amplitudes are 0.

So the simulator can compute exact measurement probabilities:

  • P(00)=1/2P(00)=1/2, P(10)=1/2P(10)=1/2, and P(01)=P(11)=0P(01)=P(11)=0.

If you actually measure, you won’t see “50%” directly. You will see a finite list of outcomes, and the frequencies will approach 50% as you repeat.

Turtle Tip

Turtle Tip

Keep the mental split: unitary evolution is deterministic; measurement produces randomness. Statevector simulation shows you the deterministic state before measurement.

Common Pitfalls

Common Pitfalls
  • Don’t confuse “simulator prints amplitudes” with “real devices reveal amplitudes.” Real execution gives samples, not the full statevector.
  • Don’t forget the exponential scaling: 2n2^n amplitudes becomes huge quickly.

Quick Check

Quick Check
  1. For nn qubits, how many computational-basis amplitudes are in the statevector?
  2. Before measurement, why is the circuit’s evolution deterministic?

What’s Next

Statevector simulation explains the internal state, but real execution usually gives you samples. Next we explain measurement sampling and shots: why repeated runs are required and how histograms arise from probabilistic measurement.