|q⟩ Bad Qubits

advanced · Programming · Advanced Hamiltonian Simulation

Measuring Dynamical Quantities

Evolving a state is only half the job — the physics lives in the observables you measure afterward. This lesson shows how to extract expectation values like ⟨Z⟩\langle Z\rangle and correlation functions from a circuit, using nothing but computational-basis measurement statistics.

Expectation values from the ZZ-basis

The simulator measures in the computational (ZZ) basis, returning the probabilities pxp_x of each bitstring xx. For a single qubit the magnetisation ⟨Z⟩\langle Z\rangle follows directly from the two outcome probabilities, because ZZ has eigenvalue +1+1 on ∣0⟩|0\rangle and −1-1 on ∣1⟩|1\rangle:

⟨Z⟩=(+1) p0+(−1) p1=p0−p1.\langle Z\rangle = (+1)\,p_0 + (-1)\,p_1 = p_0 - p_1.

No extra gates are needed: any observable diagonal in the computational basis is just a weighted sum of the measured probabilities, with weights equal to its eigenvalues.

Measuring off-diagonal observables

What about ⟨X⟩\langle X\rangle or ⟨Y⟩\langle Y\rangle? They are not diagonal in the ZZ-basis, so we rotate the measurement basis first:

The general recipe: to measure a Pauli PP, conjugate by the single-qubit gate that maps Z→PZ \to P, measure in the ZZ-basis, and combine with the ±1\pm 1 eigenvalue weights.

Correlation functions

A two-point correlation function such as ⟨ZiZj⟩\langle Z_i Z_j\rangle measures how the spins at sites ii and jj are statistically linked. Since ZiZjZ_i Z_j is diagonal, it is again a sum over basis probabilities weighted by the parity (−1)xi+xj(-1)^{x_i + x_j} of the two relevant bits:

⟨ZiZj⟩=∑x(−1)xi⊕xj px.\langle Z_i Z_j\rangle = \sum_x (-1)^{x_i \oplus x_j}\, p_x.

Tracking ⟨ZiZj⟩\langle Z_i Z_j\rangle as a function of evolution time gives a dynamical correlation function, the central object in studies of transport, thermalisation, and information spreading (light cones) in quantum many-body systems.

A clean analytic check

Prepare a single qubit with a YY-rotation RY(θ)R_Y(\theta) applied to ∣0⟩|0\rangle:

RY(θ)∣0⟩=cos⁡θ2 ∣0⟩+sin⁡θ2 ∣1⟩.R_Y(\theta)|0\rangle = \cos\tfrac{\theta}{2}\,|0\rangle + \sin\tfrac{\theta}{2}\,|1\rangle.

The outcome probabilities are p0=cos⁡2θ2p_0 = \cos^2\tfrac{\theta}{2} and p1=sin⁡2θ2p_1 = \sin^2\tfrac{\theta}{2}, so

⟨Z⟩=p0−p1=cos⁡2θ2−sin⁡2θ2=cos⁡θ.\langle Z\rangle = p_0 - p_1 = \cos^2\tfrac{\theta}{2} - \sin^2\tfrac{\theta}{2} = \cos\theta.

For θ=π/3\theta = \pi/3 this gives ⟨Z⟩=cos⁡(π/3)=12\langle Z\rangle = \cos(\pi/3) = \tfrac12. The exercise checks exactly this: that the measured p0−p1p_0 - p_1 reproduces the analytic cos⁡θ\cos\theta.

Try it

Prepare the state RY(π/3)∣0⟩R_Y(\pi/3)|0\rangle and return the circuit. The grader reads the measured probabilities and checks that ⟨Z⟩=p0−p1\langle Z\rangle = p_0 - p_1 equals cos⁡(π/3)=12\cos(\pi/3) = \tfrac12.

Run your code to see the quantum state.

Sign in on the full site to ask questions and join the discussion.