# VQE, Variational Quantum Eigensolver

Dear All,

I am a fresher to the field of quantum computing and I am going through VQE. I have a fundamental question regarding VQE.

From classical computational chemistry point of view, does the VQE find the global minimum for the given molecular input by doing what is called GEOMETRY OPTIMIZATION or simply does the SINGLE POINT CALCULATION for the given molecular geoemetry.

Thank you

1 Like

Hi @raghavv, and welcome to the forum!

Usually with VQE, single point calculations are the normal route, however, it is possible to use VQE for geometry optimzation.

When calculating a single VQE instance energy, one usually chooses a fixed geometry starting point for the molecule to generate a given Hamiltonian.
An optimization step is then performed over a set of parameters used to prepare a quantum state which is then used to calculate the energy for the Hamiltonian.

As an example, we can calculate the energy using:
E = \langle\Psi(\theta)|H|\Psi(\theta)\rangle = \langle 0 | U^{\dagger}_{\theta} H U_{\theta} | 0 \rangle

By optimizing over the parameters \theta we can find the quantum state |\Psi(\theta)\rangle that minimizes the energy of the Hamiltonian for our fixed geometry, and from the above expectation value calculation, the resulting numerical value.

If you wanted to find the optimal geometry configuration, we can calculate more energies with different geometries, giving us a new Hamiltonian for each.
It is then possible to use the differences in these energies in an outer optimization stage to find the optimal positions for a molecule.

It can also be noted that you are free to optimize over any parameter you’d like.

I hope this helped!

3 Likes

@mlxd. Thank you sir for detailed response. Is there any way we can do geometry optimization using VQE and get the cartesian coordinate of the optimized geometry using Pennylane. Thank you

Hi @raghavv, glad to help. Here is a tutorial on performing geometry optimization with PennyLane for the trihydrogen cation (H3+). This should be a good starting place to try with other molecules too.

1 Like

Thank you so much @mlxd . Wil take into look into it.

1 Like

Let us know how it goes @raghavv!

Sure.! Thank you @CatalinaAlbornoz

@raghavv - were you able to make progress in generalizing from the tutorial to other molecules. I’m (very) new to quantum chemistry myself. I wonder if there is a straightforward way to apply this approach to H2O or other more complex molecules. I’d be very interested to hear your experience

Hi @paul and welcome to the forum!

It is easy and straightforward to apply the geometry optimisation algorithm outlined in this tutorial for the trihydrogen cation, as a case study, to other molecules.

There are basically two parts of the workflow that need to be updated. The first part includes the molecular properties such as atomic symbols and coordinates and the second part is the circuit. For a molecule such as LiH, as an example, you can replace the trihydrogen cation information with:

symbols = ["Li", "H"]
geometry = np.array([0.0, 0.0, 0.0, 0.0, 0.0, 2.969280527])


and the circuit might be built adaptively following this tutorial. Then you can follow the procedure in the geometry optimisation tutorial to optimise the geometry of LiH.

We have used the same procedure to optimise the geometry of H2, H3 cation, BeH2 and H2O and the results are discussed in this paper.

Please feel free to let us know if you have any questions.

Thanks so much. I’m trying to help my high-school aged son with a quantum chemistry project. It’s a steep learning curve for me also, and your guidance here is very helpful!

Thanks again for the links to the tutorials. Is the CCCBDB a good source for initial geometry data for input into the adaptive circuit procedure? And is there a similar source of information for the number of active orbitals? Thanks!

@paul . I have not really tried the code optimizing other molecules (apart from H3+), however I think @sjahangiri has shared the appropriate material for such an effort. In case you are looking for geometry, (source other than CCCBDB, to build new molecules of your choice), you can use a couple of open source molecule builders such as Avogadro(https://avogadro.cc/) or IQmol (http://iqmol.org/). These can be really handy. Hope this helps.

1 Like

Hi @sjahangiri, I’ve built the LiH circuit following the adaptive circuit tutorial, but I’m running into a Wire error in the theta optimization step of the molecular optimization code. There are 10 wires (5 active orbitals), but I’m getting “Wire with label 10 not found in <Wires = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]>”. I’d appreciate any suggestions on what I might be missing. Thanks

Hi @paul.

It looks like somewhere you’re calling “wires=10”. However the last wire is “wires=9” since indexing starts at 0.

If this is not the case then could you share your code so that we can take a look?

I hope this helps!

Here’s the code in github. I’m encountering the error in cell 34. The number of wires is set in cell 27 to be equal to the number of qubits (in this case 10). I’ve just replicated the code from the optimization of molecular geometry tutorial, which used 6 qubits. Again, I’m sure that I’m made a very simple error somewhere (I’m only an amateur programmer!). Thanks very much for taking a look!

Hi @paul, I was able to reproduce your error and I must say it’s puzzling me too.

@josh, Do you have any idea of why this is happening? I was able to reproduce it by changing the symbols, the geometry and the charge with respect to the demo, which works well.

Hi @paul!

The issue arises because, when you redefine the Hamiltonian for the molecular geometry optimization,

def H(x):
return qml.qchem.molecular_hamiltonian(symbols, x, charge=0)[0]



you are not passing the number of active electrons and orbitals as you were earlier, when determining the number of qubits needed!

Without passing these values, the computed Hamiltonian will require 12 qubits.

Instead, if we modify the Hamiltonian definition to include these restrictions, we will now get a Hamiltonian with 10 qubits as expected:

def H(x):
return qml.qchem.molecular_hamiltonian(symbols, x, charge=0, active_electrons=2, active_orbitals=5)[0]


Thanks very much @josh and @CatalinaAlbornoz - that fixed it!