A Simple Guide to VQEs
Explaining VQEs and how I used them to find the ground state of N2, LiH and O2
If you have tried to learn about VQEs you’ve probably been really confused about what they are. I know I was. This is largely due to the big words that get thrown around. So I’ll try to provide an easy understanding with minimal long words. So how do VQEs work?
How VQEs work
Before I explain how VQEs work here are a few definitions that may help your understanding:
Hamiltonian: The hamiltonian is a matrix that discribes the possible energies of a molecule
Qubit Mapping: Is a process to encode information on a qubit
Ansatz: This is an educated guess of something like the wave function of a molecule
Eigenvalues: Scalars associated with a linear system of equation, best to think of them just as Scalars for simplcity
In theory, VQEs work by varying a parameter, then optimizing for the lowest energy. Thus giving you the lowest Eigenvalue. Sounds simple but there is so much more. So let’s dive deeper.
VQE stands for Variational Quantum Eigensolver. Here’s why:
- Variational: Because the VQE varies parameters in order to find the true value
- Quantum: Because it is a quantum algorithm
- Eigensolver: Because we are solving for the lowest eigenvalue
The VQE is a quantum machine learning algorithm. This means it uses both quantum computations and classical computations.
To explain I’ll use an analogy:
So you're trying to find the lowest point you can limbo. But you don’t own a limbo pole. So what do you do? You simulate yourself on a classical computer and quantum computer. So these are the steps you take to find your lowest limbo point:
- Encode yourself into a qubit in the quantum computer
- Find a range of all the possible heights of the limbo pole where you could have your lowest limbo
- Simulate yourself doing limbos many, many times at varying limbo pole heights on the quantum computer
- Then measure the results from the quantum computer
- Finally, send the results to the classical computer and then the classical computer uses an optimization method like gradient descent to optimize for the lowest possible limbo pole height that you can limbo
- Then repeat step 3–5 till you have found your lowest limbo point
In this example:
- The limbo pole is equal to what parameter that you are varying to find the lowest eigenvalue, ex: distance between molecules.
- Your lowest limbo point is equal to the lowest eigenvalue. ex: a molecule's ground state.
- You are equal to the thing you’re trying to simulate. ex: a molecule.
- The range of your potential lowest limbo point is equal to the range of ansatz.
If you understood that example you can understand how a VQE works.
To explain how a VQE works, I’ll explain how a VQE can be used to simulate a molecule with the goal to find the ground state (lowest energy state of the molecule). These are the steps that are taken to make a VQE:
- Encode the hamiltonian (which is a matrix that describes the possible energies of the molecules) on the qubit with qubit mapping
- Find the ansatz (which is just an educated guess) of the distance between the molecules that the ground state will be found in
- Simulate the molecules at a bunch of different distances on the quantum computer within the ansatz
- Measure the results on the quantum computer. This cause qubit to collapse to 0s and 1s
- Finally, you send the results to the classical computer. The classical computer, using an optimization method like gradient descent optimizes for the lowest possible energy state in the molecule.
- Repeat step 3–5 until you have the ground state of the molecule
So now that you have an intuitive understanding of how a VQE works I’ll explain how it works in Math terms.
Why do VQEs work
The math behind VQE gets pretty complicated but stick in there. The VQE uses the variational method or variational principle from quantum mechanics.
First of all, we need to understand that a Matrix is a Hermitian that is equal to its conjugate transpose. So:
All you need to know about this is it allows us to use the spectral theorem. This allows us to state that the eigenvalues of a hermitian matrix have to be real values. This means that we can use a hermitian matrix to describe our hamiltonians. We can express our hamiltonians as:
To break this down:
- λ¡ = Eigenvalue
- |Ψ¡⟩ = The Eigenvector
The eigenvalue is comparable to the eigenvector. Aswell we can represent the hamiltonian as this:
Then with the previous two-equation, we can combine them and make this equation:
This equation tells us the expectation value of any observable state. Which since |⟨Ψ¡⟩⟨Ψ⟩|² is equal to or greater than 0. We can say this:
This is the most important equation of them all. This is the variational method or variational principle equation that tells us that the expectation value of any wave function. This is equal to or less than the eigenvalue with the Hamiltonian. This final equation is what makes the whole VQE work.
Why VQEs are awesome
So you might be asking why do I care? How are VQEs going to help?
Well, first of all, VQEs are useful right now because they are great at quantum chemistry. This means we can do things like finding the ground state of a molecule and this is useful because it helps us find things like reaction rates and molecular structure. Although right now we only can simulate very small molecules like the diazene molecule which is the largest molecule that has been simulated.
We can expand this even further in the future by eventually being able to make our own materials with the special property that we want. Materials like specialized superconducting materials, space-grade flexible materials, specialized qubits that have longer coherence times or anything you can imagine.
We go even further! Eventually, we could be able to simulate whole systems like batteries and be able to optimize for the materials to make them last longer or understand how certain molecules react with our body like caffeine.
VQEs can also be used for portfolio optimization, more specifically to solve the mean-variance portfolio optimization problem which weights risk and expected return of stock and outputs a probability. It works very similar to how AI stocks predictors work in the sense that it is doing the same thing but it is a quantum computer that models the stock so it has the potential to have increased accuracy and be much faster computation-wise compared to AI forecasters.
Using these principles I was actually able VQE to simulate a bunch of molecules and find the ground state energy of molecules like Lithium Hrydrite, Oxygen gas and Nitrogen gas. I was able to get really great results (the VQE line in the graph is partially hidden by the exact line in the graph). The ground state energy is the one with the lowest energy which you can see below:
The results for N2:
The results for HLi:
The results for O2:
- VQEs work by varying parameters and optimizing for the lowest value
- VQEs have lots of application in quantum chemistry to help us understand the things we interact with daily on a molecule level and to potentially find new materials
- VQEs can be used in finance to optimize portfolios
- VQEs main principle that causes them to work is the variational principle