Ansatz: the trial circuit behind every variational quantum algorithm
An ansatz is the parametrised quantum circuit that a variational algorithm such as VQE or QAOA tunes. It fixes which states the computer can prepare, so the optimiser can only find the best state inside that family. There are three kinds: hardware-efficient ansätze built from the gates a device runs well, problem-inspired ones built from the structure of the problem (UCCSD for molecules, the QAOA circuit for optimisation), and adaptive ones grown one operator at a time. In our run on hydrogen a compact chemistry ansatz reached the exact energy at every bond length, while a hardware-efficient circuit with several times as many weights missed it in part of its runs.
Updated
At a glance
- What it is
- A circuit with free angles, , that prepares a trial state. A classical optimiser tunes the angles; the circuit decides which states can be reached at all.
- Where the word comes from
- German for an approach or a first attempt. In physics and mathematics it is an educated guess at the form of a solution, with parameters left free. The plural is ansätze.
- Where it is used
- In every variational quantum algorithm: VQE, QAOA, quantum neural networks and quantum generative models[2].
- The main kinds
- Hardware-efficient, problem-inspired (UCCSD, the QAOA circuit, the Hamiltonian variational ansatz) and adaptive (ADAPT-VQE).
- The trade-off
- An ansatz that can reach more states is harder to train, because its gradients get smaller[10].
- Our run on hydrogen
- UCCSD with 5 weights was within chemical accuracy at 36 of 36 bond lengths. A hardware-efficient circuit with 20 weights was within it in 131 of 180 runs.
What an ansatz is
A variational quantum algorithm does not run a fixed circuit. It starts from a state that is easy to prepare, , applies a circuit whose gates depend on a list of angles , and so prepares a trial state . The processor measures a cost on that state, for example the energy of a Hamiltonian , and a classical optimiser changes to lower it. The circuit is the ansatz. Peruzzo and colleagues introduced this loop as the variational quantum eigensolver[1], and the same loop with other costs runs QAOA, quantum neural networks and most other algorithms written for today's processors[2].
The ansatz sets a ceiling on the result. For an energy, every trial state obeys , where is the true ground-state energy: the measured value is an upper bound, and the optimiser pushes it down. It can only push as far as the best state the ansatz contains. If the ground state lies outside the family, no optimiser finds it. If the family is very large, the optimiser may not find it either, for the reason given below. Choosing an ansatz means choosing a family small enough to search and large enough to hold the answer.
The word is older than quantum computing. In German an Ansatz is an approach or a first attempt, and physicists use it for an assumed form of a solution with a few parameters left open, such as a trial wavefunction in the variational method. Quantum computing kept the word and made the trial function a circuit. That is also the difference between an ansatz and a quantum circuit in general: any sequence of gates is a circuit, while an ansatz is a circuit with free parameters and a family of states it is meant to cover.
The main types of ansatz
Reviews of the field sort ansätze by how much they know about the problem: none (hardware-efficient), a lot (problem-inspired), or whatever the run itself discovers (adaptive)[2].
| Type | How it is built | Why choose it | What it costs | Source |
|---|---|---|---|---|
| Hardware-efficient | Layers of single-qubit rotations and of the entangling gates a device runs natively, repeated a few times. | It is shallow, so today's processors can run it, and it needs no knowledge of the problem. | It knows nothing about the problem and can break its symmetries, and its gradients shrink as it gets deeper and wider. | [3] |
| Unitary coupled cluster (UCCSD) | Single and double excitations of the electrons out of the Hartree-Fock state, exponentiated and split into gates. | It is built from chemistry: it starts at the mean-field answer and adds the correlations that matter most, and it keeps the number of electrons. | It is deep. The number of excitations grows roughly with the fourth power of the number of orbitals[5]. | [4] |
| QAOA circuit | A cost layer built from the objective of an optimisation problem, alternated with a mixing layer, times. | It has only angles, and the problem is written into the circuit. | The answer improves only as grows, and every cost layer needs an entangling gate for each pair of variables that interact. | [6] |
| Hamiltonian variational | Each layer evolves the state under the terms of the problem's own Hamiltonian, one group of terms at a time, with a free angle for each group. | It has few angles per layer and follows the structure of the model being solved. | Its depth grows with the number of terms in the Hamiltonian, and it is tied to one model. | [7] |
| Adaptive (ADAPT-VQE) | It is grown during the run: at each step the operator with the largest energy gradient is taken from a pool and appended. | The circuit is tailored to one molecule and ends up shorter than UCCSD at the same accuracy. | It needs many extra measurements, since the gradient of every candidate is measured at every step. | [8] |
In quantum machine learning the ansatz is the trainable part of a quantum neural network, usually a few hardware-efficient layers placed after the gates that encode the data. In generative modelling it is the circuit of a quantum circuit Born machine.
Expressibility against trainability
Two properties describe what an ansatz can do before any problem is named. Expressibility is how much of the space of states the circuit can reach, and entangling capability is how much entanglement its states carry on average. Sim and colleagues made both measurable, by comparing the states a circuit produces from random angles with states drawn uniformly at random[9]. More layers and more entangling gates raise both.
More is not better. Holmes and colleagues showed that the more expressive an ansatz is, the flatter its cost landscape becomes[10]. At the extreme, a deep hardware-efficient circuit with random angles sits on a barren plateau: its gradients shrink exponentially with the number of qubits, and the optimiser has nothing to follow[11]. An ansatz that can prepare almost any state can be trained to prepare almost none of them.
Problem-inspired ansätze answer this by reaching less. UCCSD only prepares states with the right number of electrons that lie near the Hartree-Fock state, and the QAOA circuit only moves along directions set by the cost function. That keeps the search small enough to train. The price is the first limit again: a restricted family can miss the answer. The same structure that keeps a circuit trainable can also make it cheap to simulate classically, which the barren plateau page covers.
The same molecule, two ansätze: our run
in the STO-3G basis with the Jordan-Wigner mapping, on 4 qubits, at 36 bond lengths. Every run minimises the energy with SciPy's L-BFGS-B and exact gradients on eigenkit's noiseless simulator, and is compared with the exact ground-state energy of the same Hamiltonian. Random starts use seeds 0 to 4 at every bond length. The full setup is on the VQE bond scan page.
| Ansatz | Starting point | Weights | Within chemical accuracy | Largest error |
|---|---|---|---|---|
| UCCSD, one repetition | Hartree-Fock state | 5 | 36 of 36 | 0.00000004 mHa |
| UCCSD, one repetition | Random angles | 5 | 180 of 180 | 0.000003 mHa ± 0.000002 mHa |
| Hardware-efficient, 2 layers | Random angles | 20 | 131 of 180 | 118.9 mHa ± 161.7 mHa |
| Hardware-efficient, 4 layers | Random angles | 36 | 168 of 180 | 9.6 mHa ± 11.8 mHa |
Run vqe-dissociation-curves of 2026-11-03, mean and spread over 5 seeds, on Molecular Hamiltonians of H2 and LiH in the STO-3G basis, integrals computed by PySCF. Errors are in millihartree (mHa) above the exact energy; chemical accuracy is 1.6 mHa. From the Hartree-Fock state the count is over bond lengths and the error is the largest on the grid. From random angles the count is over single runs, one per bond length and seed, and the error is the largest on the grid, as a mean and spread over the seeds.
Reading the run
The ansatz that knew the problem won with the fewest weights. UCCSD has 5 weights here, and it ended within chemical accuracy every time, from the Hartree-Fock state and from random angles alike. The hardware-efficient circuit had 20 weights at two layers and 36 at four, and it was within chemical accuracy in 131 of 180 and 168 of 180 runs. All of its misses were at stretched bonds, where the two electrons are most strongly correlated. More layers helped, and still did not make it reliable.
This is the easy case for UCCSD. has two electrons, and with two electrons one repetition of UCCSD can represent the exact ground state, so the family contains the answer. Molecules with more correlated electrons are less forgiving, and the UCCSD circuit grows much faster with the size of the molecule than the hardware-efficient one does.
An ansatz comes with a starting point. On LiH with its core orbital frozen, the same UCCSD construction has 44 weights. From the Hartree-Fock state it was within chemical accuracy at 40 of 40 bond lengths. From random angles it was within it in 0 of 25 runs, and stopped as far as 128.2 mHa ± 4.1 mHa above the exact energy. The reference state is part of what makes a chemistry ansatz work, not a detail of the setup.
On hardware the ranking can turn around. These runs have no noise and exact gradients. On a real device every two-qubit gate adds error, and the depth of UCCSD is what today's processors cannot afford. The hardware-efficient ansatz was proposed for exactly that reason, and its first experiment found ground-state energies of molecules on up to six qubits[3]. Which ansatz is better depends on the error budget of the machine as much as on the molecule.
Try it: one Hamiltonian, four ansätze
from eigenkit.chemistry import (
VQE,
exact_ground_state_energy,
fermi_hubbard_dimer,
hardware_efficient_ansatz,
jordan_wigner,
uccsd_ansatz,
)
# Two electrons on two sites: 4 qubits, small enough to solve exactly.
observable, offset = jordan_wigner(fermi_hubbard_dimer(t=1.0, u=2.0))
exact = exact_ground_state_energy(observable, 4, offset=offset)
ansatze = {
"hardware-efficient, 1 layer": hardware_efficient_ansatz(n_qubits=4, layers=1),
"hardware-efficient, 3 layers": hardware_efficient_ansatz(n_qubits=4, layers=3),
"UCCSD, 1 repetition": uccsd_ansatz(n_qubits=4, n_electrons=2, reps=1),
"UCCSD, 2 repetitions": uccsd_ansatz(n_qubits=4, n_electrons=2, reps=2),
}
for name, ansatz in ansatze.items():
vqe = VQE(restarts=5, random_state=0)
result = vqe.solve(observable, 4, offset=offset, ansatz=ansatz)
print(f"{name:30s} {ansatz.n_weights:2d} weights {result.energy - exact:.6f} above exact")
# hardware-efficient, 1 layer 12 weights 0.382515 above exact
# hardware-efficient, 3 layers 28 weights 0.000000 above exact
# UCCSD, 1 repetition 5 weights 0.236068 above exact
# UCCSD, 2 repetitions 10 weights 0.000000 above exactThe Fermi-Hubbard dimer needs no chemistry packages, so this runs in a few seconds after pip install eigenkit. The comments are what one run with eigenkit 1.2.2 printed, an illustration and not a measurement to cite. Both of the smaller circuits stop above the ground state, and the optimiser reports each run as converged: the family did not contain the answer. UCCSD with one repetition stops on the first excited level. Two repetitions reach the ground state, as do three layers of the hardware-efficient circuit, which needs almost three times as many weights to do it.
How to choose an ansatz
There is no best ansatz, only one that fits a problem and a machine. These five checks are the ones the runs above reward.
Start from the problem, not from the circuit
For a molecule, start with UCCSD on the Hartree-Fock state. For an optimisation problem written as a QUBO, the QAOA circuit is the ansatz. For a lattice model, build the layers from its Hamiltonian. For a machine-learning model, a few qubits with a shallow trainable block are the usual choice. An ansatz that carries the structure of the problem needs fewer weights to hold the answer.
Count what the machine can run
Count the two-qubit gates and the depth of the circuit after it is compiled for the device, and compare them with the device's error rates. If the problem-inspired circuit does not fit, a hardware-efficient one is the fallback, and it is less reliable, as in the run above.
Keep the symmetries and the reference state
A ground state has a fixed number of electrons and a fixed spin. An ansatz that keeps them searches a far smaller space than one that does not, and starting from the Hartree-Fock state puts the search next to the answer. On LiH the starting point alone decided whether the run succeeded.
Start shallow, and add layers while the score improves
Each layer adds weights and expressibility, and moves the circuit towards a barren plateau. Begin with one or two layers and stop when the result stops improving.
Run several seeds, and keep the classical answer next to it
A converged run is not a correct one: in the code above two circuits converge to the wrong energy. Repeat every setting from several random starts, and at sizes where it is possible compare with exact diagonalisation or with a classical method such as CCSD(T).
Questions
What is an ansatz in quantum computing?
It is a quantum circuit with free angles that prepares a trial state. A variational algorithm such as VQE or QAOA measures a cost on that state and lets a classical optimiser tune the angles. The ansatz decides which states the algorithm can reach, so it sets a ceiling on how good the result can be.
What does the word ansatz mean?
Ansatz is German for an approach or a first attempt. In physics and mathematics it means an assumed form of a solution with some parameters left free, which are then fixed by solving the problem. In quantum computing the assumed form is a parametrised circuit.
What is the plural of ansatz?
Ansätze, the German plural, is the form most papers use. Ansatzes is also seen in English.
What is a hardware-efficient ansatz?
It is an ansatz made of layers of single-qubit rotations and of the entangling gates a given device runs natively. It is shallow enough for today's processors and needs no knowledge of the problem, but it can break the problem's symmetries and becomes hard to train as it grows.
What is the UCCSD ansatz?
UCCSD is the unitary coupled-cluster ansatz with single and double excitations. It starts from the Hartree-Fock state of a molecule and applies exponentials of operators that move one or two electrons into unoccupied orbitals. It is the standard chemistry ansatz for VQE, and its circuits are much deeper than hardware-efficient ones.
Is the QAOA circuit an ansatz?
Yes. QAOA is a variational algorithm with a fixed ansatz: a layer built from the cost function alternated with a mixing layer, repeated a chosen number of times, with two angles for each repetition.
How do I choose an ansatz for VQE?
Start from the problem: UCCSD on the Hartree-Fock state for a molecule. Check that the compiled circuit fits the error budget of the device, and fall back to a hardware-efficient ansatz if it does not. Keep the symmetries of the problem, start shallow, and compare several random starts with an exact or classical answer at small sizes.
What is the difference between an ansatz and a quantum circuit?
Every ansatz is a quantum circuit, but not every circuit is an ansatz. A circuit is any sequence of gates. An ansatz is a circuit with free parameters, chosen so that the states it can prepare are likely to include the solution of a problem.
Sources
- A. Peruzzo, J. McClean, P. Shadbolt, M.-H. Yung, X.-Q. Zhou, P. J. Love, A. Aspuru-Guzik, J. L. O'Brien. A variational eigenvalue solver on a photonic quantum processor. Nature Communications 5, 4213, 2014. arXiv:1304.3061.
- M. Cerezo, A. Arrasmith, R. Babbush, S. C. Benjamin, S. Endo, K. Fujii, J. R. McClean, K. Mitarai, X. Yuan, L. Cincio, P. J. Coles. Variational quantum algorithms. Nature Reviews Physics 3, 625–644, 2021. arXiv:2012.09265.
- A. Kandala, A. Mezzacapo, K. Temme, M. Takita, M. Brink, J. M. Chow, J. M. Gambetta. Hardware-efficient variational quantum eigensolver for small molecules and quantum magnets. Nature 549, 242–246, 2017. arXiv:1704.05018.
- J. Romero, R. Babbush, J. R. McClean, C. Hempel, P. J. Love, A. Aspuru-Guzik. Strategies for quantum computing molecular energies using the unitary coupled cluster ansatz. Quantum Science and Technology 4, 014008, 2018. arXiv:1701.02691.
- J. Tilly, H. Chen, S. Cao, D. Picozzi, K. Setia, Y. Li, E. Grant, L. Wossnig, I. Rungger, G. H. Booth, J. Tennyson. The variational quantum eigensolver: a review of methods and best practices. Physics Reports 986, 1–128, 2022. arXiv:2111.05176.
- E. Farhi, J. Goldstone, S. Gutmann. A quantum approximate optimization algorithm. arXiv preprint, 2014. arXiv:1411.4028.
- D. Wecker, M. B. Hastings, M. Troyer. Progress towards practical quantum variational algorithms. Physical Review A 92, 042303, 2015. arXiv:1507.08969.
- H. R. Grimsley, S. E. Economou, E. Barnes, N. J. Mayhall. An adaptive variational algorithm for exact molecular simulations on a quantum computer. Nature Communications 10, 3007, 2019. arXiv:1812.11173.
- S. Sim, P. D. Johnson, A. Aspuru-Guzik. Expressibility and entangling capability of parameterized quantum circuits for hybrid quantum-classical algorithms. Advanced Quantum Technologies 2, 1900070, 2019. arXiv:1905.10876.
- Z. Holmes, K. Sharma, M. Cerezo, P. J. Coles. Connecting ansatz expressibility to gradient magnitudes and barren plateaus. PRX Quantum 3, 010313, 2022. arXiv:2101.02138.
- J. R. McClean, S. Boixo, V. N. Smelyanskiy, R. Babbush, H. Neven. Barren plateaus in quantum neural network training landscapes. Nature Communications 9, 4812, 2018. arXiv:1803.11173.
Run it yourself with eigenkit
eigenkit is EigenOrbit's open-source Python library: write a circuit once, run it on any simulator or QPU, and test it against a classical baseline on your own data before you invest in it or rule it out.
$ pip install eigenkit