← Quantum Store · Guides · Lessons · Glossary · About · Türkçe

Advanced course: Shor, VQE, QAOA and quantum walks · Lesson 3 / 6 · 12 min

VQE: finding the lowest energy of a molecule

The variational quantum eigensolver (VQE) joins a quantum and a classical computer in a loop. Learn the variational principle and find the lowest energy of a small problem with Qiskit.

Why does chemistry need quantum computers?

How a molecule behaves, for example whether a drug binds to a protein, is decided by the lowest-energy state of its electrons (the ground state). Because electrons obey quantum rules, computing this state exactly on a classical computer gets exponentially harder as the number of electrons grows.

The energy of a molecule is given by an observable called the Hamiltonian. In Qiskit a Hamiltonian is written as a weighted sum of the Pauli strings you met in the Qiskit course. For example, the hydrogen molecule (H₂), simplified using its symmetries, can be represented with just two qubits.

The variational principle

The expectation value of the energy measured in any state can never be lower than the energy of the ground state. So if we look for the state that makes the energy as small as possible, we get closer to the ground state.

VQE turns this idea into a loop: the quantum computer prepares a parameterised circuit (the ansatz) and measures the energy with the Estimator; a classical optimisation algorithm changes the angles in the direction that lowers the energy. The loop runs until the energy stops dropping.

A small VQE with Qiskit

Below is a single-qubit Hamiltonian H = Z + X; its lowest energy is −√2 ≈ −1.414. The ansatz is a single ry(θ) gate and the energy is cos θ + sin θ. A classical optimisation method called COBYLA changes θ to lower this value and finds −1.414.

import numpy as np
from scipy.optimize import minimize
from qiskit import QuantumCircuit
from qiskit.circuit import Parameter
from qiskit.primitives import StatevectorEstimator
from qiskit.quantum_info import SparsePauliOp

H = SparsePauliOp.from_list([('Z', 1.0), ('X', 1.0)])
theta = Parameter('theta')
ansatz = QuantumCircuit(1)
ansatz.ry(theta, 0)
estimator = StatevectorEstimator()

def energy(x):
    return float(estimator.run([(ansatz, H, x)]).result()[0].data.evs)

result = minimize(energy, x0=[0.1], method='COBYLA')
print(result.fun, -np.sqrt(2))   # both about -1.4142

Strengths and weaknesses

VQE uses short circuits, so it can be tried on today’s noisy devices; that is why it has been one of the most studied algorithms since it was proposed in 2014. But every energy measurement needs thousands of repetitions, a badly chosen ansatz may never reach the right answer, and in large circuits the optimisation can get stuck on flat regions called “barren plateaus”.

So far the molecules solved with VQE are small ones that classical computers can also solve easily. A real advantage needs larger and less noisy devices.

Try it yourself

This circuit builds the state (|0⟩ − |1⟩)/√2; it is the lowest-energy state of the X observable and its expectation value is −1. Open the state vector and see that the amplitudes are 0.707 and −0.707: VQE looks for exactly this kind of lowest-energy state.

Open the circuit in your browser

The circuit playground is in Turkish. Button guide: “1000 kez ölç” = measure 1000 times, “Durum vektörünü göster” = show the state vector, “Bu devrenin Qiskit kodu” = this circuit’s Qiskit code, “Geri al” = undo, “Temizle” = clear. Click a gate in the circuit to remove it.

Key points

Test yourself

According to the variational principle, which is true of the energy measured with an ansatz?

Show the answer

It can never be lower than the ground-state energy. Every state has an energy equal to or greater than the ground-state energy; that is why VQE approaches the ground state by lowering the energy.

← Shor’s algorithm: factoring with phase estimation · QAOA: a quantum approach to optimisation problems →

Share: X · LinkedIn