How does VQE work?

Here is the VQE overview from Peruzzo et al. 2013

I am trying to understand in detail how each step works, assuming at first one qubit and a Hamiltonian of the form: $$$$\tag{1} H = \sum_{i}a_i H_i\;,\quad a_i\in\mathbb{R}$$$$

The first step "quantum step preparation" consists in finding an ansatz, that is to say a parameterized operator, which is applied to the qubit initial state $$|0\rangle$$ and enables to move the qubit to any other state in the Hilbert space (represented by the Bloch sphere).

The second step "quantum module" turns the qubit into the right basis so as to be measured in the Z direction.

Here is my current understanding of how VQE works:

• The VQE uses as many qubits in parallel as terms in the Hamiltonian
• To obtain the expectation value for each Hamiltonian term you need to perform the blue background algorithm part several times, each time starting with the same ansatz parameters
• Once expectation values are all estimated for the first used ansatz parameters, the expectation value of Hamiltonian can be classically computed from Eq. 1. To optimize the ansatz parameters, the previous steps need to be performed again with a priori other random ansatz parameters until one retrieves a map of $$\langle H\rangle$$ with respect to ansatz parameters and is able to numerically approach $$\langle H\rangle$$ partial derivative with respect to these ansatz parameters.

Am I understanding VQE correctly?

Disclaimer: most of my comprehension of VQE comes from Musty Thoughts, and I highly recommend his articles to get a deeper explanation of VQE.

• The VQE uses as many qubits in parallel as terms in the Hamiltonian

No, for a sum of $$2^n\times2^n$$ Hamiltonians, $$n$$ qubits are used. The number of terms in this sum is irrelevant.

The principle in VQE is that you want to find the smallest eigenvalue of a sum of Hamiltonian that can be written as Pauli strings. For instance, let's say that for the $$2$$-qubit case the Hamiltonian is: $$H=3XY -2ZX$$ (Note: here the product is the tensor product $$XY=X\otimes Y$$)

What VQE does is:

1. Prepare a state accordingly to the ansatz and the current parameters (initially chosen randomly)
2. For each Pauli string in the sum, you will measure the state in the appropriate basis: $$\left\{|0\rangle,|1\rangle\right\}$$ for $$Z$$, $$\left\{|+\rangle,|-\rangle\right\}$$ for $$X$$, $$\left\{|i\rangle,|-i\rangle\right\}$$ for $$Y$$ (and no measure for $$I$$, we assume we always measure $$1$$). You will do this process enough times to get a good approximate of these expectation values, and once per Pauli strings in the sum.
3. You update the parameters accordingly to the results you got, and you repeat.

Thus, you can see that the number of qubits is linked to the length of the Pauli strings in our Hamiltonian. The number of terms in the sum is rather the number of iterations needed to make a step within the algorithm.

• To obtain the expectation value for each Hamiltonian term you need to perform the blue background algorithm part several times, each time starting with the same ansatz parameters

• Once expectation values are all estimated for the first used ansatz parameters, the expectation value of Hamiltonian can be classically computed from Eq. 1. To optimize the ansatz parameters, the previous steps need to be performed again with a priori other random ansatz parameters until one retrieves a map of ⟨H⟩ with respect to ansatz parameters and is able to numerically approach ⟨H⟩ partial derivative with respect to these ansatz parameters.

You're almost right. You can indeed compute $$\langle\psi(\theta)|H|\psi(\theta)\rangle$$ once you got all the $$\langle\psi(\theta)|H_i|\psi(\theta)\rangle$$, but the parameters are not randomly selected. The point is to use a classical optimization algorithm that will tell us which parameters we should try next.

Basically, most of these algorithms work like this: we give them a number of parameters and the bounds for these parameters, and the function to optimize. Here, the function is $$\langle\psi(\theta)|H|\psi(\theta)\rangle$$ and the parameters are $$\theta$$. So, we launch the optimizer, they tell us "ok, give me the value of $$\langle\psi\left(\theta_1\right)|H|\psi\left(\theta_1\right)\rangle$$", we compute it on the Quantum Computer, we give it back to the optimizer, and they give us back another value which should be a little bit better.

The way these optimizers work is however way out-of-scope of this question (and probably of this site).

Don't hesitate to tell me whether something's not clear!

• Thanks very much for your sound answer. Indeed, my understanding also comes from "Musty Thoughts". My understanding is that to classically optimize the parameter $\theta$, you need at least two points. This means you need first to compute $\langle\psi(\theta_0)|H|\psi(\theta_0)\rangle$, you cannot optimize yet, you need to perform a second quantum computation $\langle\psi(\theta_1)|H|\psi(\theta_1)\rangle$ and then, you can feed the classical optimizer with $\theta_0$ and $\theta_1$, this former outputs a $\theta_2$ parameter. Is this a good understanding ? Commented Jun 13, 2023 at 9:09
• @deb2014 It's a slightly different questions as this is essentially about the inner workings of the classical optimizers. However, this is surely the case: evaluating the gradient is done via a computation using different parameters, so surely another computation is required. If the gradient is not used, then one might think that a single point is not enough to get a good overview of this parameters' region. So I think you're correct, but this is specific to each optimizer I guess Commented Jun 13, 2023 at 9:55
• Just to be sure about your Hamiltonian example $H= 3XY - 2ZX$. As you said this is a 2-qubit system, the first qubit undergoes $X$ than $Z$ and the second one, $Y$ then $X$. As I want to compute $\langle\psi |XY|\psi\rangle$ and $\langle\psi |ZX|\psi\rangle$ in parallel, I need 2 qubits for each. So the VQE circuit for this Hamiltonian will have four lines, four qubits, is it right ? Commented Jun 15, 2023 at 13:34
• @deb2014 No, the product here is the tensor product. You will deal with this Hamiltonian term by term. The first term is $X\otimes Y$, so you create the state $|\psi(\theta)\rangle$, apply an $H$ gate on the first qubit to measure in the $|\pm \rangle$ basis, apply a $\frac{1}{\sqrt{2}}\begin{pmatrix}1&1\\i&-i\end{pmatrix}$ gate on the second qubit to measure in the $|\pm i\rangle$ basis, and then measure. You do this several times to get $\langle\psi(\theta)|XY|\psi(\theta)\rangle$. You then do it for $\langle\psi(\theta)|XY|\psi(\theta)\rangle$ and sum these results with the right weights Commented Jun 15, 2023 at 14:08
• Thanks, it is clear now : qubit number = number of tensor products, number of terms in the sum = number of computations to do. Commented Jun 19, 2023 at 11:47