One of the leading algorithms in the NISQ quantum computer is called VQE (Variational Quantum Eigensolver). The name sounds hard, but the explanations are often overwhelmingly difficult^{1}. I would like to approach this with a short approach.

## Conclusion

VQE is, in essence, the following:

```
qc = QuantumCircuit(1)
qc.ry(Parameter("θ"), 0)
print(VQE(Estimator(), qc, SPSA()).compute_minimum_eigenvalue(Pauli("Z")).optimal_parameters)
```

{Parameter(θ): 3.141592653589793}

## The detail

The VQE story is generally accompanied by the following difficult explanations.

- Quantum chemical calculations
- Full CI
- Quantum phase estimation

- Schrödinger equation and Hamiltonian
- Second quantization
- Eigenvalues of the ground state of the Hamiltonian

However, these are mainly related to how to formulate the problem and how to make mathematical models. Therefore, they can be separated from the main routine of VQE.

The main routine of VQE is essentially the same as the optimization routine of deep learning, which is a numerical calculation to find the minimum value of a given cost function.

The code I wrote at the beginning of this post is too rough, but if we write it more carefully, it would be as follows:

```
from qiskit import QuantumCircuit
from qiskit.quantum_info import Pauli
from qiskit.circuit import Parameter
from qiskit.primitives import Estimator
from qiskit_algorithms.minimum_eigensolvers import VQE
from qiskit_algorithms.optimizers import SPSA
qc = QuantumCircuit(1)
qc.ry(Parameter("θ"), 0)
estimator = Estimator() # a too to define the cost function
operator = Pauli("Z") # the objective to analyze
optimizer = SPSA() # an optimizer
vqe = VQE(estimator, qc, optimizer) # a trainer which trains a model inside a loop
result = vqe.compute_minimum_eigenvalue(operator)
print(result.optimal_parameters)
```

Mathematically, we take a function

as the cost function, and $\theta$ is to be optimized so that $f(\theta)$ is minimized. It is obvious that $\theta = \pm \pi$ are optima and take the minimum value $-1$ . Thus, going back to the beginning, we have

{Parameter(θ): 3.141592653589793}

It is quick to start the story where the cost function $f(\theta) = \cos \theta$ is given.

- Determine randomly the initial value of $\theta$
- Update $\theta$ iteratively with an appropriate optimizer
- If the loss function value doesn't seem to change, optimization is complete

These procedures are like what we have seen often somewhere... Yes! Deep Learning.

SPSA (Simultaneous Perturbation Stochastic Approximation) is used as an optimizer that fits the situation of NISQ quantum computer, but if we assume an ideal situation where a reliable gradient values can be calculated, there is no problem to optimize with Adam. **It is completely an optimization method for deep learning**.

## Wrap up

I have tried to reduce difficult portions as much as possible to concentrate on the main routine of the VQE, although it becomes a little more complicated than I expected.

There are various types of quantum machine learning, but the above is in essence **optimizing a cost function** created from a quantum mechanical point of view with **an optimization method similar to that often used in deep learning**.

While the case of quantum chemical computation is a direct quantum mechanical problem, problems such as the traveling salesman problem and other route optimization problems are not quantum mechanical in nature. However, even for such problems, in some cases, the (mathematical) formulation of the problem can be done within the framework of quantum computation. **If you find merit in quantum computation**, you can use the formulation in the style of quantum computation and obtain a numerical solution by optimization similar to that used in deep learning.

## Top comments (1)

I really appreciate seeing genuine quantum computing programming content on here (most other posts seem to be lazy Chat-GPT copy and paste). As someone working in quantum computing, it's always wonderful seeing people write with passion and experience about the topic.

I did smile at the phrase "easy VQE" though (as I'm not sure I found VQE or QAOA particularly easy when I first encountered them!). Please keep writing, this is great stuff.