VQE Suite / Physics

State Representations & Measurement

The same statevector that the Convergence tab optimizes also drives the Statevector table, the QSphere, and the Measure button, this page derives what each of those views actually shows.

From θ to amplitudes and probabilities

The ansatz statevector, derived on the Hamiltonian & Ansatz page by tracing the circuit gate by gate, is

∣ψ(θ)⟩=cos⁡θ2 ∣01⟩+sin⁡θ2 ∣10⟩|\psi(\theta)\rangle = \cos\tfrac{\theta}{2}\,|01\rangle + \sin\tfrac{\theta}{2}\,|10\rangle

using this site's basis index convention (basis index =2q1+q0= 2q_1 + q_0, see src/lib/physics/statevector.ts), the same convention the Statevector table's BASIS_LABELS and the QSphere's point layout both use. Both amplitudes are always real for this ansatz, so the Statevector table's Phase column only ever reads 0° or 180°, and the QSphere colors points by the sign of the real amplitude (green positive, blue negative) rather than a general complex phase.

Measurement probabilities are the squared amplitudes, exactly what probabilitiesOf() in src/lib/physics/measurement.ts computes:

P(01)=cos⁡2θ2,P(10)=sin⁡2θ2P(01) = \cos^2\tfrac{\theta}{2}, \qquad P(10) = \sin^2\tfrac{\theta}{2}

At the VQE converged θ∗≈−0.22974\theta^\ast \approx -0.22974: P(01)≈98.69%P(01) \approx 98.69\%,P(10)≈1.31%P(10) \approx 1.31\%, the near certainty of the |01⟩ outcome you see reflected in both the Statevector table and the QSphere's point sizes (point radius ∝P\propto \sqrt{P}, so area encodes probability).

The reduced state of qubit 0, and why it's mixed

reducedDensityMatrixQubit0() partial traces qubit 1 out of the full 2-qubit state: ρ0[a][b]=∑q1⟨2q1+a∣ψ⟩⟨ψ∣2q1+b⟩\rho_0[a][b] = \sum_{q_1} \langle 2q_1{+}a | \psi \rangle \langle \psi | 2q_1{+}b \rangle. For this ansatz only the ∣01⟩|01\rangle and ∣10⟩|10\rangle amplitudes are nonzero, so every off diagonal cross term vanishes and the sum collapses to a diagonal matrix:

ρ0=(sin⁡2θ200cos⁡2θ2)\rho_0 = \begin{pmatrix} \sin^2\tfrac{\theta}{2} & 0 \\ 0 & \cos^2\tfrac{\theta}{2} \end{pmatrix}
For this particular ansatz, ρ0\rho_0's diagonal entries are literally the same numbers as the measurement probabilities above, a coincidence of this ansatz's structure (only two, mutually exclusive on qubit 0 basis states are populated), not a general fact about reduced states.

purity() then computes Tr⁡(ρ02)\operatorname{Tr}(\rho_0^2), which for a diagonal matrix is just the sum of the squared diagonal entries:

Tr⁡(ρ02)=sin⁡4θ2+cos⁡4θ2\operatorname{Tr}(\rho_0^2) = \sin^4\tfrac{\theta}{2} + \cos^4\tfrac{\theta}{2}

At θ=0\theta = 0 (the untrained ansatz, exactly ∣01⟩|01\rangle) this gives 11 exactly, qubit 0 is a pure, unentangled product state. At θ∗≈−0.22974\theta^\ast \approx -0.22974 it drops to ≈0.97407\approx 0.97407: the converged ground state is entangled, if only slightly, across the two qubits, a real property of the H2 ground state this ansatz reaches, not an artifact of the visualization.

Measurement is a real single sample, not an animation

Clicking Measure ▸ on the Statevector tab calls sampleMeasurement(), which draws one Math.random() value and walks the cumulative distribution of ∣amplitude∣2|\text{amplitude}|^2 until it exceeds the draw (inverse CDF sampling), a single projective measurement, done once per click, not a scripted collapse effect. Run repeatedly, the outcome frequencies converge to the probabilities above; a 20,000-sample check against this exact implementation matched the true probabilities to within statistical error (max deviation ≈0.00074, consistent with the expected p(1−p)/N\sqrt{p(1-p)/N} sampling noise).

See it running live on the VQE Suite playground, the Statevector, QSphere, and Step by Step tabs all read from the same runH2AnsatzStatevector(theta) call.

Source: src/lib/physics/statevector.ts, entanglement.ts, measurement.ts, vqe.ts