Skip to content

VQE and QAOA

The training loop from Variational circuits is not tied to data. Replace “error on the training set” by any quantity a quantum computer can measure, and the same loop minimises that instead. This lesson covers the two most studied cases: finding the lowest energy of a quantum system, and finding a good solution to an optimisation problem. Neither has any data to load, so the bottleneck from Encoding data does not arise. That is one reason they were the first hopes for useful work on small, noisy machines.

A quantum system is described by its Hamiltonian HH, a Hermitian matrix. Its eigenvalues are the energies the system can have, and its eigenvectors are the states with those energies. The lowest eigenvalue E0E_0 is the ground-state energy and its eigenvector is the ground state. A great deal of chemistry and materials science comes down to finding these, because that is the state matter settles into when cold.

For any state ∣ψ⟩\ket{\psi}, the average energy found by measuring is the expectation value

⟨H⟩=⟨ψ∣H∣ψ⟩.\langle H\rangle = \bra{\psi}H\ket{\psi}.

For nn qubits, HH is a 2n×2n2^n \times 2^n matrix. Finding its lowest eigenvalue classically becomes impossible by brute force somewhere past 50 qubits, which is why one would want to use a quantum computer.

Write any state in terms of the eigenstates ∣Ek⟩\ket{E_k} of HH, as ∣ψ⟩=∑kck∣Ek⟩\ket{\psi} = \sum_k c_k\ket{E_k}. Then

⟨ψ∣H∣ψ⟩=∑k∣ck∣2Ek  ≥  E0∑k∣ck∣2=E0.\bra{\psi}H\ket{\psi} = \sum_k |c_k|^2 E_k \;\ge\; E_0 \sum_k |c_k|^2 = E_0 .

The average energy is a weighted average of the eigenvalues, and no average is below the smallest value. This is the variational principle: every state you can prepare gives an upper bound on the ground-state energy, with equality only for the ground state itself.

That turns the search into an optimisation with a clear direction. Lower is always better, and you can never go too far.

A quantum computer cannot measure an arbitrary matrix in one go. But any Hamiltonian can be written as a sum of Pauli terms, each a product of II, XX, YY and ZZ on the individual qubits, and the expectation value of a sum is the sum of the expectation values.

The running example is two spins:

H=− Z⊗Z  −  h (X⊗I+I⊗X).H = -\,Z\otimes Z \;-\; h\,(X\otimes I + I\otimes X).

The first term is lowest when the two qubits agree, in ∣00⟩\ket{00} or ∣11⟩\ket{11}. The other two represent a field of strength hh that pulls each qubit towards ∣+⟩\ket{+}. The terms cannot all be satisfied at once, and the ground state is a compromise. For this small case the exact answer is known: E0=−1+4h2E_0 = -\sqrt{1 + 4h^2}.

To estimate ⟨H⟩\langle H\rangle you measure each term on fresh copies of the state:

  • ⟨Z⊗Z⟩\langle Z\otimes Z\rangle: measure both qubits and score +1+1 if they agree, −1-1 if they differ.
  • ⟨X⊗I⟩\langle X\otimes I\rangle: apply HH to the first qubit, then measure it. The Hadamard turns an XX measurement into a ZZ measurement.

Then combine the averages with the coefficients −1-1, −h-h and −h-h.

Check

How many different measurement set-ups does this three-term Hamiltonian need?

The variational quantum eigensolver, or VQE, puts the pieces together.

  1. Choose a parametrised circuit, called the ansatz, that prepares a state ∣ψ(θ)⟩\ket{\psi(\theta)}.
  2. Measure the Pauli terms and combine them into E(θ)=⟨ψ(θ)∣H∣ψ(θ)⟩E(\theta) = \bra{\psi(\theta)}H\ket{\psi(\theta)}.
  3. Let a classical optimiser adjust θ\theta to lower EE, and repeat.

The simulator runs VQE on the two-spin Hamiltonian with a two-angle ansatz. An RY(α)R_Y(\alpha) on the first qubit followed by a CNOT makes cos⁡α2∣00⟩+sin⁡α2∣11⟩\cos\tfrac{\alpha}{2}\ket{00} + \sin\tfrac{\alpha}{2}\ket{11}, so α\alpha controls the entanglement. Then both qubits are rotated by β\beta.

SimulatorFind a ground state

H = −Z⊗Z − h (X⊗I + I⊗X)

|00⟩ ── RY(α) on qubit 0 ── CNOT ── RY(β) on both qubits

Energy over α (across) and β (up), each from −π to π. Brighter is lower. Click to jump.

Things to try, with the field at h=1h = 1:

  1. Set α=0\alpha = 0. The CNOT then does nothing and the state is a product state. Slide β\beta to find the lowest energy. You should reach −2.000-2.000 at β=π2≈1.57\beta = \tfrac{\pi}{2} \approx 1.57, which is the state ∣++⟩\ket{++}.
  2. Now move α\alpha. Near α=0.46\alpha = 0.46 the energy drops to the exact value, −5≈−2.236-\sqrt5 \approx -2.236. No product state gets below −2-2. The remaining 0.2360.236 is only available with entanglement.
  3. Reset and press the optimiser button a few times. Watch the marker move across the map.
  4. Change hh. At h=0h = 0 the field is off and the ground states are simply ∣00⟩\ket{00} and ∣11⟩\ket{11}. At h=2h = 2 the field dominates. The whole landscape changes shape with the problem.

Notice that the variational principle held throughout. The energy never went below the exact value, wherever you put the sliders.

Check

A VQE run on hardware reports an energy slightly below the known exact ground-state energy. What does that indicate?

VQE was first run in 2014 on a photonic chip, for a two-electron molecule, and has since been run on many small molecules and models. What it has not done is beat the best classical methods on a problem of practical interest. The obstacles are known.

  • Measurements. A molecule’s Hamiltonian has thousands to millions of Pauli terms, and useful chemistry needs the total to within about a thousandth of a hartree, the natural unit of energy for molecules. Since the error of an average falls only as one over the square root of the number of shots, the number of shots is very large.
  • The ansatz. It must be able to reach the ground state, yet remain trainable. Flexible, unstructured ansätze run into the barren plateaus of the last lesson.
  • Noise. Errors in the gates leave the qubits in a mixture of the intended state and others, and the mixture has a higher energy. The optimiser cannot train its way below the floor that noise sets.

For chemistry in the long run, most researchers expect the workhorse to be phase estimation on error-corrected machines, with variational methods possibly supplying the starting state.

The second algorithm aims at problems with no physics in them. Take MaxCut. You are given a graph, and must divide its vertices into two groups so that as many edges as possible run between the groups. Such edges are said to be cut. Finding the best division is hard for large graphs: no efficient classical algorithm is known, and none is expected.

Give each vertex a qubit, with 0 and 1 naming the two groups. A bit string zz is then a division, and its quality is the number of edges it cuts, C(z)C(z). As an operator,

C=∑edges (i,j)12(1−ZiZj),C = \sum_{\text{edges } (i,j)} \tfrac12\bigl(1 - Z_i Z_j\bigr),

since ZiZjZ_i Z_j is +1+1 when the two bits agree and −1-1 when they differ. Maximising ⟨C⟩\langle C\rangle is the same kind of task as minimising an energy.

The quantum approximate optimisation algorithm, QAOA, introduced by Farhi, Goldstone and Gutmann in 2014, uses a particular ansatz for this:

  1. Start with every qubit in ∣+⟩\ket{+}, an equal superposition of all possible divisions.
  2. Apply the cost layer e−iγCe^{-i\gamma C}, which multiplies each bit string ∣z⟩\ket{z} by the phase e−iγC(z)e^{-i\gamma C(z)}.
  3. Apply the mixer layer, a rotation e−iβXe^{-i\beta X} on every qubit.
  4. Repeat steps 2 and 3 for pp rounds, each with its own angles.
  5. Measure. The outcome is a bit string, which is a candidate division.

Neither layer achieves anything alone. The cost layer changes only phases, so the probabilities stay uniform. The mixer alone leaves ∣+⟩\ket{+} unchanged, since ∣+⟩\ket{+} is an eigenstate of XX. Together they make an interference experiment, as in the Quantum Algorithms track: the cost layer marks each division with a phase that depends on its quality, and the mixer lets the amplitudes of neighbouring divisions add or cancel accordingly.

SimulatorQAOA for MaxCut, one layer
Graph

Expected cut over γ (across) and β (up), each from 0 to π. Brighter is larger. Click to jump.

Things to try on the square, where the best division cuts all 4 edges:

  1. Set γ=0\gamma = 0 and move β\beta, then the other way round. The expected cut stays at 2.00, the same as random guessing.
  2. Find the bright spot near γ=0.79\gamma = 0.79, β=0.39\beta = 0.39. The expected cut rises to 3.00, and the chance that a single measurement gives a perfect division rises from 12.5% to 53%.
  3. Switch to the square with a diagonal. Its best cut is still 4, but one layer now manages an expected cut of only about 3.24.

One layer does not find the optimum with certainty, and it is not meant to. You run the circuit many times and keep the best bit string seen.

Check

What does one run of a QAOA circuit give you?

With more rounds QAOA does better, and as pp grows without limit it can approach the true optimum. At small pp its reach is limited. For graphs in which every vertex has three neighbours, one round is guaranteed to cut about 69% of the best possible number of edges, while the best classical algorithm with a proven guarantee, due to Goemans and Williamson, reaches about 88% on every graph. Deeper circuits improve the quantum figure, at the price of more gates, more noise and a harder training problem.

As of this writing there is no convincing evidence that QAOA outperforms the best classical optimisers on problems of practical size. Whether it can, at depths that hardware could support, is an open research question.

The next lesson steps back and asks the same question of the whole field.

RecallAnswer from memory, then check
LessonFinish this lesson