Skip to content
Tutorials Center
My learning

Topics

Lesson 31 of 39 ยท Applications and Outlook

VQE and Variational Quantum Algorithms

Learn how the variational quantum eigensolver finds ground-state energies of molecules: ansatz, cost function, classical optimizer, with a runnable H2 example.

One of the most promising uses of quantum computers is simulating quantum systems themselves: molecules, materials, catalysts. Richard Feynman's original motivation for quantum computing was exactly this. Finding the ground-state energy of a molecule tells you its stable structure, reaction energies and more, yet the cost of exact classical methods grows exponentially with the number of electrons.

Algorithms like phase estimation can solve it with provable guarantees but need deep, error-corrected circuits. The variational quantum eigensolver (VQE) takes a different path for today's noisy hardware: use a short parameterized circuit on the quantum computer and let a classical optimizer tune it.

The variational principle

For any Hamiltonian H (the energy operator) and any normalized state |psi>, the expected energy is never below the true ground-state energy E0:

Text
<psi|H|psi>  >=  E0

So minimizing the energy over a family of states gets you as close to E0 as the family allows. VQE is a hybrid loop:

  1. Ansatz. A parameterized circuit U(theta) prepares |psi(theta)> from a simple start state.
  2. Measure the cost. Write H as a sum of Pauli strings, H = sum c_i P_i. Measure each <P_i> on the quantum computer (the Estimator primitive from Qiskit basics) and add: E(theta) = sum c_i <P_i>.
  3. Update. A classical optimizer (COBYLA, SPSA, L-BFGS, Adam, ...) proposes a new theta.
  4. Repeat until the energy stops decreasing.
flowchart LR
    A["Parameters theta"] --> B["Quantum computer: prepare state, measure Pauli terms"]
    B --> C["E(theta) = sum of c_i <P_i>"]
    C --> D["Classical optimizer"]
    D --> A

The VQE loop: the quantum device evaluates, the classical computer optimizes.

From molecule to qubits

To get a Pauli-sum Hamiltonian from a molecule you need chemistry software (PySCF, Qiskit Nature, PennyLane's qchem, OpenFermion). The steps: compute one- and two-electron integrals in a chosen basis set; write the electronic Hamiltonian in second quantization; map fermionic operators onto qubits with the Jordan-Wigner, Bravyi-Kitaev or parity mapping; optionally remove qubits through symmetries. The hydrogen molecule H2 in a minimal basis ends up on just 2 qubits after reduction. At the bond length 0.735 angstrom its qubit Hamiltonian is, in the common parity-reduced form:

Text
H = -1.0524 II + 0.3979 IZ - 0.3979 ZI - 0.0113 ZZ + 0.1809 XX

(The constant term includes the nuclear repulsion energy, and the values here are rounded.)

Run VQE for H2

Our ansatz starts from the Hartree-Fock reference, which has one electron in each of the two lowest orbitals, and rotates it into a mixture with the doubly-excited configuration. It uses an X, an RY(theta) and a CNOT. First, the exact answer for comparison, then the variational scan.

Python VQE for H2: ansatz, energy and optimization

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The reference state (theta = 0) gives the Hartree-Fock energy. The rotation lowers it by the correlation energy, about 0.02 Hartree, which classical mean-field methods miss. The tuned state reaches the exact ground state, because the two-qubit ansatz spans the whole relevant subspace.

Optimize with noisy measurements

On real hardware each <P_i> is estimated from a finite number of shots, so the energy has statistical noise. The next example mimics that and uses the parameter-shift rule gradient (exact for the single RY gate) with plain gradient descent.

Python Gradient descent with shot noise

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

All three runs end close to the optimum; with 100,000 shots the result is almost exact, while with 100 shots the optimizer wanders around the minimum. In practice, noise-tolerant optimizers like SPSA (which needs just two energy evaluations per step, whatever the number of parameters) are popular on hardware.

Choosing an ansatz

The ansatz decides what VQE can reach and how hard it is to train:

  • Chemistry-inspired: UCCSD (unitary coupled cluster with singles and doubles) is accurate but deep. Adaptive methods (ADAPT-VQE) grow the circuit one operator at a time.
  • Hardware-efficient: layers of single-qubit rotations and native entangling gates. Shallow and device-friendly, but can be too general.
  • Problem-specific: use symmetries of the problem to restrict the circuit.

Known obstacles:

  • Barren plateaus. For wide, random, deep ansatzes the gradient of the cost shrinks exponentially with the number of qubits, making training impossible. Remedies: shallow or structured ansatzes, smart initialization, local cost functions.
  • Measurement cost. Large molecules have thousands to millions of Pauli terms. Grouping commuting terms and "classical shadows" reduce the shots.
  • Noise. Gate noise biases the energy; mitigation from NISQ error mitigation helps. Because the variational principle holds only for noiseless states, noisy energies can even go below the true ground state.
  • Local minima and optimizer stalls.

Whether VQE can beat the best classical chemistry methods on useful problems is still an open question. Many experts expect real quantum advantage in chemistry to need fault-tolerant phase estimation. VQE remains the standard way to learn the workflow, and its pieces (ansatz, estimator, classical optimizer) are shared by QAOA and quantum machine learning.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. What does the variational principle guarantee?

    <psi|H|psi> >= E0 for every normalized state, so lower is always closer to the ground state (for noiseless states).
  2. 2. In VQE, which task does the classical computer perform?

    The quantum device evaluates the energy; a classical optimizer chooses the next parameters.
  3. 3. What is the correlation energy?

    It is the part of the exact energy that mean-field theory misses, which VQE aims to recover.
  4. 4. What is a barren plateau?

    Deep random ansatzes give an almost flat cost landscape, making optimization infeasible.

Summary

  • VQE minimizes E(theta) = <psi(theta)|H|psi(theta)> with a quantum circuit for the state and a classical optimizer for the parameters.
  • Molecules are mapped to Pauli-sum qubit Hamiltonians; H2 needs just 2 qubits and recovers the correlation energy.
  • Shot noise, barren plateaus and measurement cost limit VQE; noise-robust optimizers and good ansatzes help.
  • The same hybrid pattern underlies QAOA and quantum machine learning.

Next: QAOA and Quantum Optimization