Inspecting the Statevector (Simulation Only)
Track: Quantum Programming · Difficulty: Beginner · Est: 14 min
Inspecting the Statevector (Simulation Only)
Overview
This page demonstrates a powerful learning tool: inspecting the statevector.
It answers: What amplitudes did my circuit create, and how do they map to measurement probabilities?
Important: statevectors are available in simulation, not from real hardware.
Conceptual Mapping
In Foundations:
- a pure quantum state can be written as a vector of amplitudes over basis states
- probabilities come from amplitudes (Born rule)
In code:
- a simulator can keep the full state internally
- you can ask the simulator to return it
But on real hardware:
- you cannot “peek” at amplitudes directly
- the only standard access is through repeated measurements (shots)
This is why statevector inspection is a learning and debugging tool, not an experimental shortcut.
Code Walkthrough
We’ll prepare a one-qubit state and request the simulator’s statevector.
from qiskit import QuantumCircuit
from qiskit_aer import AerSimulator
qc = QuantumCircuit(1)
qc.h(0)
qc.save_statevector()
sim = AerSimulator(method="statevector")
result = sim.run(qc).result()
state = result.get_statevector()
print(state)Line by line:
QuantumCircuit(1)creates one qubit (no classical bits needed here).qc.h(0)prepares a superposition.qc.save_statevector()tells the simulator to record the statevector.AerSimulator(method="statevector")uses a simulation mode that tracks amplitudes.get_statevector()returns the final statevector.
Now connect this to measurement:
from qiskit import QuantumCircuit
from qiskit_aer import AerSimulator
qc = QuantumCircuit(1, 1)
qc.h(0)
qc.measure(0, 0)
sim = AerSimulator()
counts = sim.run(qc, shots=500).result().get_counts()
print(counts)Same state preparation, but now we sample measurement outcomes.
Results & Interpretation
A statevector printout may look like “two complex numbers.” Conceptually:
- entry 0 corresponds to the amplitude of basis state
|0⟩ - entry 1 corresponds to the amplitude of basis state
|1⟩
Mapping amplitudes to probabilities:
- probability of
0is the squared magnitude of the|0⟩amplitude - probability of
1is the squared magnitude of the|1⟩amplitude
Then counts approximate those probabilities with sampling noise.
Bloch sphere connection (conceptual):
- for one qubit, the statevector represents a point on the Bloch sphere (up to a global phase)
- gates like
Hrotate that point - measurement in the computational basis samples outcomes based on where that point lies relative to the measurement axis
Why this is not possible on real hardware:
- hardware does not hand you its internal amplitudes
- measurement collapses the state
- you learn the state only indirectly through many measurements and careful experimental design
Turtle Tip
Use statevector inspection to understand what your circuit intends to do. Then switch to shot-based measurement to understand what you can actually observe.
Common Pitfalls
- Thinking the statevector is something you can retrieve from a real quantum device.
- Confusing amplitudes with probabilities (amplitudes can be negative or complex).
- Forgetting that measurement changes what you can inspect (after measuring, you no longer have the pre-measurement state).
- Overusing statevector tools and skipping the discipline of interpreting counts.
Quick Check
- What does a statevector entry represent conceptually?
- How do you convert an amplitude into a measurement probability?
- Why can’t real hardware return a statevector on demand?
What’s Next
Now that you can connect amplitudes to probabilities, we’ll build a two-qubit Bell state and measure correlations. That’s where entanglement becomes visible in real measurement results.
