This VQE tutorial presents a repeatable workflow for estimating a molecule’s ground-state energy with a variational quantum eigensolver. You will learn how to choose a molecular model, encode its Hamiltonian, select and initialize an ansatz, optimize circuit parameters, and validate the result against chemistry references and classical baselines. The goal is not merely to obtain a number from a quantum circuit, but to determine whether that number is a credible chemistry result.
Overview
The variational quantum eigensolver, or VQE, is a hybrid quantum-classical algorithm for estimating the lowest eigenvalue of a Hamiltonian. In molecular simulation, that eigenvalue represents an approximation of the molecule’s electronic ground-state energy under a chosen computational model.
VQE divides the work between two processors. A quantum circuit prepares a parameterized trial state and measures expectation values for terms in the molecular Hamiltonian. A classical optimizer then updates the circuit parameters to lower the measured energy. The loop continues until the energy appears to converge or the experiment reaches a defined stopping condition.
A useful abstraction is:
E(θ) = ⟨ψ(θ)|H|ψ(θ)⟩
Here, H is the qubit Hamiltonian, |ψ(θ)⟩ is the state prepared by the ansatz, and θ is the vector of variational parameters. Because the true ground-state energy is the minimum allowed expectation value, a valid VQE result should not be judged by optimization alone. It also needs checks for encoding, convergence, circuit quality, sampling noise, and agreement with an appropriate reference.
For developers, the most reliable implementation is an experiment pipeline rather than a single notebook cell:
- Define the molecular geometry and electronic-structure assumptions.
- Generate or import the molecular Hamiltonian.
- Map fermionic operators to qubit operators.
- Choose an ansatz and an initial parameter strategy.
- Evaluate the energy through a simulator or quantum backend.
- Optimize parameters while recording every evaluation.
- Validate the result against classical and physical references.
How to estimate the ground-state energy
1. Fix the molecular problem before writing the circuit
Start with a precise problem definition. Record the molecule, atom ordering, geometry, charge, spin or multiplicity, basis set, active space if used, and any orbital or qubit reduction. Geometry is especially important: changing a bond length changes the Hamiltonian, so two VQE runs can be internally correct while solving different chemical problems.
For a first implementation, a small diatomic molecule at a documented geometry is easier to debug than a large molecule. Use the same geometry and basis when comparing ansatzes, optimizers, or backends. Store these values in a configuration object or experiment file rather than embedding them in scattered code.
2. Build the electronic Hamiltonian
A quantum chemistry library typically begins with one- and two-electron integrals, constructs a fermionic second-quantized Hamiltonian, and maps that operator to qubit terms. The mapped result often has the form:
H = c₀I + c₁P₁ + c₂P₂ + ...
Each Pᵢ is a Pauli word such as a product of X, Y, and Z operators, and each coefficient cᵢ contributes to the final energy estimate. The mapping choice, qubit ordering, orbital ordering, and symmetry reduction must remain consistent with the state-preparation circuit.
In a Qiskit or PennyLane workflow, keep the chemistry layer separate from the circuit layer. One function should produce the molecular data and operator; another should construct the ansatz; a third should evaluate expectation values. This separation makes it easier to test whether an unexpected result comes from the Hamiltonian or from optimization.
3. Select an ansatz that matches the experiment
The ansatz defines the family of states that VQE can explore. A shallow hardware-efficient circuit is convenient for noisy devices, but it may not preserve the molecule’s particle number or other useful symmetries. A chemistry-inspired ansatz can encode more structure, but it may require more gates and deeper entangling patterns.
| Ansatz approach | Strength | Trade-off | Good starting use |
|---|---|---|---|
| Hardware-efficient | Simple, shallow, and adaptable to device connectivity | May explore chemically invalid states or suffer from difficult optimization | Early hardware experiments and circuit studies |
| Unitary coupled-cluster style | Uses chemistry-inspired excitation structure | Can require more depth and parameterized operations | Small molecular benchmarks on simulators |
| Problem-informed custom ansatz | Can encode known symmetries and reduce unnecessary parameters | Requires domain knowledge and careful testing | Focused studies with a fixed molecule or active space |
Do not compare ansatzes only by their lowest reported energy. Track qubit count, parameter count, two-qubit gate count, depth, symmetry behavior, number of energy evaluations, and sensitivity to initialization. A lower energy from a larger circuit may not be the better engineering choice if it is much harder to execute or reproduce.
4. Optimize with an explicit stopping rule
At each iteration, the evaluator prepares the circuit, measures the Hamiltonian terms, and combines their expectation values. The classical optimizer receives the resulting scalar energy and proposes new parameters. Useful stopping conditions include a small absolute energy change over several iterations, a maximum number of evaluations, and a gradient or parameter-change threshold where the chosen optimizer supports it.
Save the complete optimization history: iteration number, energy, parameter vector, evaluation count, backend, shot count, and error-mitigation settings. A final energy without its trajectory cannot show whether the optimizer converged smoothly, stalled, or found one of several local minima.
Inputs and assumptions
VQE results are conditional on the inputs used to create the Hamiltonian. A reproducible experiment should capture at least the following:
- Molecular definition: species, atom coordinates, units, charge, and spin state.
- Chemistry model: basis set, orbital treatment, active-space selection, and any frozen orbitals.
- Qubit encoding: fermion-to-qubit mapping, orbital order, qubit tapering, and symmetry reductions.
- Ansatz: circuit template, depth, parameter order, entangling pattern, and initial values.
- Optimizer: algorithm, learning-rate or step-size settings, bounds, seed, and stopping criteria.
- Evaluation mode: exact expectation values, finite-shot sampling, noise model, hardware backend, and measurement grouping.
- Reference method: the classical calculation used for comparison and whether it uses the same basis and active space.
Reference energies must be compared carefully. An exact diagonalization result in the reduced qubit space can be an excellent debugging reference, but it is not automatically the same as a higher-level chemistry calculation. The comparison is meaningful only when the Hamiltonian and model assumptions match.
For initial debugging, use a statevector or exact-expectation simulator where practical. Then repeat the experiment with shot-based sampling to reveal estimator variance. A noisy simulator or real quantum hardware should be treated as a separate execution condition, not silently mixed with ideal results. The quantum simulator selection guide can help match the simulator to the size and purpose of the experiment.
Worked examples
Example A: establish an ideal baseline
Suppose you choose a small diatomic molecule, fix its bond length, use a documented basis, reduce the problem to a manageable active space, and map the resulting Hamiltonian to a small number of qubits. First, compute a classical reference for that exact reduced Hamiltonian. Next, run VQE with exact expectation values and a reproducible seed.
The first acceptance test is not chemical accuracy. It is implementation agreement: the VQE energy should approach the lowest eigenvalue of the same reduced Hamiltonian within the tolerance you define. If it does not, inspect qubit ordering, signs in Pauli terms, the reference state, parameter ordering, and the energy aggregation code before changing optimizers.
Example B: compare ansatz and optimizer choices
Run two ansatzes with the same molecular input and evaluate them under the same ideal simulator. For each run, record final energy, energy error relative to the reference, number of evaluations, circuit depth, and parameter count. Repeat each configuration with more than one initialization when the parameter landscape is sensitive.
This produces a more useful decision than selecting the smallest final number. An ansatz that reaches nearly the same energy with fewer gates and more stable convergence may be preferable for a hardware experiment. Conversely, an ansatz that is shallow but repeatedly stalls may need a better initialization or a more structured parameterization. If optimization becomes unstable or gradients become uninformative, review techniques for reducing barren plateaus in variational circuits.
Example C: move from exact values to sampled measurements
After the ideal baseline is understood, replace exact expectation values with finite shots. Run the same circuit with a defined shot budget and repeat it using several independent seeds. Report the mean energy, spread across repetitions, and the best and worst optimization trajectories. This separates optimizer variability from measurement variance.
Only after that step should you introduce a noise model or real hardware. On hardware, account for transpilation, connectivity, queue behavior, calibration conditions, and the cost of repeating measurements. If mitigation is applied, report both unmitigated and mitigated values, along with the method and additional sampling overhead. Related workflows for error mitigation and cloud job planning provide useful checks for this stage.
A practical chemistry experiment checklist is:
- Can another developer reconstruct the Hamiltonian from the recorded inputs?
- Does the circuit preserve the intended particle number or symmetry?
- Does the ideal VQE result agree with a reference in the same reduced space?
- Does the optimization history show genuine convergence rather than a lucky final sample?
- How does the result change with initialization, shots, noise, and backend?
- Are energy units, sign conventions, and geometry clearly reported?
When to recalculate
Recalculate the experiment whenever a scientific or execution input changes. A new molecular geometry, basis set, active space, charge, spin state, mapping, or symmetry reduction defines a different Hamiltonian and invalidates direct comparison with the previous energy unless the change is intentional and documented.
Revisit the workflow after quantum SDK or chemistry-library updates when operator-construction APIs, transpilation behavior, measurement primitives, or backend interfaces change. Keep environment versions, configuration files, and small regression tests under version control so an update can be checked against a known Hamiltonian and reference energy.
Repeat hardware-facing runs when the backend, coupling constraints, calibration conditions, shot budget, or error-mitigation procedure changes. Recalculate cost and runtime estimates when provider pricing, queue conditions, quotas, or batching limits change; do not copy an old estimate into a new project plan without checking those inputs.
The most useful next step is to turn the notebook into a parameterized experiment. Put geometry, chemistry settings, ansatz, optimizer, shots, backend, and random seed in a configuration file. Emit a machine-readable result containing the final energy, reference energy, error, evaluation count, circuit metrics, and convergence status. That structure lets you model another molecule, compare a new ansatz, or rerun the same experiment on a cloud backend without losing the assumptions that make the result interpretable.