Why a variational method
Phase estimation, from the previous module, can read off an energy to many bits, but it needs long coherent circuits with controlled time evolution. The variational quantum eigensolver (VQE) asks much less of the quantum computer. It prepares a family of states with a short parameterised circuit, measures the energy, and lets a classical optimiser adjust to lower it. The idea was demonstrated on a photonic processor by Peruzzo and coauthors (Peruzzo et al. 2014) and analysed systematically by McClean and coauthors (McClean et al. 2016).
The price is that VQE is a heuristic. This lesson makes precise which part is a theorem (the energy is an upper bound) and which parts are not (whether the optimiser finds a good state, how many measurements it needs, and whether any of this beats classical methods).
The variational principle
Theorem. Let be Hermitian with smallest eigenvalue . For every normalised state ,
with equality if and only if lies in the eigenspace of .
Proof. has an orthonormal eigenbasis with eigenvalues . Expand with . Then
since every term in the last sum is non-negative. Equality forces whenever .
Two consequences matter in practice. Every energy a correct VQE reports is an upper bound on ; an energy below the exact ground energy proves a bug (or, on hardware, a biased estimator). And a low energy does not imply a good state: if the gap is small, a state with energy close to can still have a large weight on excited states.
Hamiltonians as sums of Pauli strings
A quantum computer measures in the computational basis, so we need in a form whose pieces are easy to measure. The Pauli strings form an orthogonal basis of matrices under the trace inner product: if and otherwise. Hence every Hermitian can be written as
The coefficients are real because and are Hermitian. In this course a string such as means with the first letter on qubit 0, the most significant bit.
Worked example. The two-qubit SWAP gate is Hermitian. Its traces against the sixteen Pauli strings are and , and zero for the rest, so
General -qubit matrices need up to terms, but physical Hamiltonians are local and have polynomially many. Our running example is the open transverse-field Ising chain
with terms. For and the terms are , , , and , each with coefficient .
A ground energy by hand
For , commutes with swapping the qubits. On the symmetric states and we find , and , so acts as the matrix with eigenvalues . The two antisymmetric states are eigenvectors with energies and . The ground energy is therefore , which is at . The exercise uses this closed form to test your Hamiltonian builder.
Measuring an expectation value
To estimate for one Pauli string, rotate each qubit so that the relevant Pauli becomes , measure in the computational basis, and multiply the eigenvalues of the measured qubits.
- For : no rotation.
- For : apply , since .
- For : apply and then , since .
- For : ignore the qubit.
A single shot returns the eigenvalue , where is the parity of the measured bits on the non-identity positions. It is a random variable with mean and variance , so shots give an estimate with standard error . The energy is the weighted sum ; the identity term needs no measurement.
Worked example. At the VQE optimum for the three-site chain () the exact expectation values are , and . The energy is . Estimating from 1,000 shots has standard error ; the exercise's sampler with seed 1 returns 0.860, within one standard error. Reaching an energy error of needs far more shots; the lesson on VQE in practice turns this into a measurement budget.
Choosing an ansatz
The ansatz is the parameterised circuit. It fixes which states the optimiser can reach, so it fixes the best possible energy before any optimisation happens.
Hardware-efficient ansätze alternate layers of single-qubit rotations with entangling gates that are native to the device, as in the experiments of Kandala and coauthors (Kandala et al. 2017). They are shallow and easy to run, but they ignore the structure of . The one used in this course's exercise applies to every qubit, then a ladder of CNOTs, repeated, with a final rotation layer:
Because and CNOT are real matrices, this ansatz only produces states with real amplitudes. That is enough for the transverse-field Ising model, whose ground state can be chosen real, but it would be a hidden limitation for a Hamiltonian whose ground state needs complex phases.
Problem-inspired ansätze build the structure of the problem into the circuit: in chemistry, unitary coupled-cluster circuits generated by excitations from a reference state; for spin models, the Hamiltonian variational ansatz that alternates exponentials of the terms of . They respect symmetries and often need fewer parameters, at the cost of deeper circuits.
Expressiveness is not free. Too few entangling gates and the ground state is out of reach; the numbers below show this. Too many generic layers and the optimisation landscape becomes hard to navigate, which the lesson on VQE in practice discusses under barren plateaus.
The VQE loop
- Choose (seeded random starts, or a physically motivated guess).
- Prepare and estimate .
- Let a classical optimiser propose a new ; repeat until the energy stops improving.
- Report the lowest energy, its uncertainty, and the parameters.
In this lesson energies come from the exact state vector, so the optimiser sees a smooth, noise-free function and BFGS works well. For the three-site chain with , exact diagonalisation gives . With the exercise's ansatz and four seeded restarts:
| ansatz layers (CNOT ladders) | parameters | lowest energy found |
|---|---|---|
| 0 (product state) | 3 | |
| 1 | 6 | |
| 2 | 9 |
The product ansatz stops at no matter how well it is optimised: the ground state is entangled and no product state can represent it. One ladder is close but not exact; two reach to optimiser precision. These are numerical observations for this instance, not general laws about layer counts.
The KetQat SDK has an independent implementation with a different ansatz layout and a gradient-free optimiser (KetQat SDK). It also reports whether its ansatz can represent the ground state at all:
from ketqat_runner import catalog
record = catalog.run("[email protected]", seed=7, hamiltonian="transverse-ising",
qubits=3, layers=2)
r = record.result
print(round(r["energy"], 6), round(r["exact_ground_energy"], 6), r["ansatz_can_represent_ground_state"])
This prints -3.493959 -3.493959 True. With entangling=False it reports -3.162278 and False,
the same product-state ceiling as above, found by a different optimiser on a different code path.
What VQE does not promise
- No convergence guarantee. The energy landscape is non-convex; the optimiser can stall above even when the ansatz could reach it. Use several seeded restarts and report them all.
- No accuracy guarantee. On hardware the energy is a statistical estimate, and noise biases it. An energy needs an error bar.
- No proven advantage. Small instances like these are solved instantly by exact diagonalisation, and for larger ones VQE competes with very strong classical methods. Whether VQE outperforms them for any practically relevant problem is open.
- No chemistry from approximate coefficients. The SDK's two-qubit H2 Hamiltonian is a testbed whose coefficients are, by the SDK's own provenance note, not a validated molecular Hamiltonian. Use it to test algorithms, not to report molecular energies.
Exercise: a first VQE loop
In vqe-first-loop you build Pauli matrices and Hamiltonians, decompose matrices into Pauli
strings, write the ansatz, the energy, a shot-based Pauli estimator, and a BFGS-based VQE with
seeded restarts. The checks test your decomposition on SWAP and on a random Hermitian matrix, the
two-site closed form , the variational principle at 50 random parameter vectors,
convergence to for the three-site chain, the sampled estimator against exact values within
five standard errors, and agreement with the SDK product on the Ising model and on a custom
Hamiltonian.
Common mistakes
- Reversing the Pauli string order. If your Hamiltonian treats the first letter as the least significant qubit but your ansatz does not, every energy at fixed parameters is wrong, even though the exact ground energy (a property of the spectrum) is unchanged. Test energies of basis states, not just .
- Dropping the identity term. It shifts every energy by a constant; the optimum parameters do not change, so the bug hides until you compare with a reference energy.
- Measuring with only a Hadamard. , not ; you need first.
- Reporting an energy below . With exact expectation values this is impossible; it means the Hamiltonian, the state or the expectation value is wrong.
- Treating one optimiser run as the answer. Restart from several seeds and compare.
Summary
The variational principle guarantees that every energy expectation is an upper bound on the ground energy, with equality only in the ground eigenspace. To use it on a quantum computer, write as a sum of Pauli strings with , estimate each by rotating into its eigenbasis and averaging outcomes, and let a classical optimiser lower the energy of a parameterised ansatz. The ansatz decides what is reachable: a product ansatz cannot capture an entangled ground state, while two entangling layers suffice for the three-site Ising chain. Everything beyond the upper bound, including convergence, measurement cost and any advantage over classical methods, has to be checked rather than assumed. The lesson on VQE in practice continues with measurement budgets, gradients and debugging; a later lesson asks what quantum speed-ups are actually known.