Completely Different Results when running ADAPT-VQE tutorial

Hello, I am going through the tutorial for ADAPT-VQE again to make sure I didn’t miss anything, but when I ran the codes I got completely different results. The link to there tutorial is here.

The first issue I encountered is that some of the gradient is 0 for some reason when it really shouldn’t be. What I got:

Excitation : [0, 1, 2, 3], Gradient: 0.0
Excitation : [0, 1, 2, 5], Gradient: 0.0
Excitation : [0, 1, 2, 7], Gradient: 0.0
Excitation : [0, 1, 2, 9], Gradient: 0.034264511701721276
Excitation : [0, 1, 3, 4], Gradient: 0.0
Excitation : [0, 1, 3, 6], Gradient: 0.0
Excitation : [0, 1, 3, 8], Gradient: -0.008566127925430305
Excitation : [0, 1, 4, 5], Gradient: 0.0
Excitation : [0, 1, 4, 7], Gradient: 0.0
Excitation : [0, 1, 4, 9], Gradient: 0.0
Excitation : [0, 1, 5, 6], Gradient: 0.0
Excitation : [0, 1, 5, 8], Gradient: 0.0
Excitation : [0, 1, 6, 7], Gradient: 0.0
Excitation : [0, 1, 6, 9], Gradient: 0.0
Excitation : [0, 1, 7, 8], Gradient: 0.0
Excitation : [0, 1, 8, 9], Gradient: 0.0

What is Expected:

Excitation : [0, 1, 2, 3], Gradient: -0.01278217515766102
Excitation : [0, 1, 2, 5], Gradient: 1.5585406229479133e-19
Excitation : [0, 1, 2, 7], Gradient: 3.6591823321385755e-19
Excitation : [0, 1, 2, 9], Gradient: 0.03426451170167856
Excitation : [0, 1, 3, 4], Gradient: 1.6940658945086012e-19
Excitation : [0, 1, 3, 6], Gradient: -1.3552527156068781e-20
Excitation : [0, 1, 3, 8], Gradient: -0.03426451170167851
Excitation : [0, 1, 4, 5], Gradient: -0.023581529020676145
Excitation : [0, 1, 4, 7], Gradient: 0.0
Excitation : [0, 1, 4, 9], Gradient: 0.0
Excitation : [0, 1, 5, 6], Gradient: 0.0
Excitation : [0, 1, 5, 8], Gradient: 1.151964808265851e-19
Excitation : [0, 1, 6, 7], Gradient: -0.023581529020676173
Excitation : [0, 1, 6, 9], Gradient: 0.0
Excitation : [0, 1, 7, 8], Gradient: -1.35525271560683e-20
Excitation : [0, 1, 8, 9], Gradient: -0.12362273485599037

Note: It is exactly the same code that I had copy and pasted, so I don’t think the code is the issue here.

After that I’ve encountered another issue that is probably tie to the first and it is the fact that the algorithm does not converge properly.

What I got:

n = 0,  E = -7.85513767 H, t = 1.17 s
n = 1,  E = -7.85585993 H, t = 1.21 s
n = 2,  E = -7.85642249 H, t = 1.20 s
n = 3,  E = -7.85686535 H, t = 1.21 s
n = 4,  E = -7.85721832 H, t = 1.22 s
n = 5,  E = -7.85750361 H, t = 1.21 s
n = 6,  E = -7.85773773 H, t = 1.21 s
n = 7,  E = -7.85793296 H, t = 1.23 s
n = 8,  E = -7.85809846 H, t = 1.23 s
n = 9,  E = -7.85824102 H, t = 1.15 s
n = 10,  E = -7.85836572 H, t = 1.24 s
n = 11,  E = -7.85847636 H, t = 1.23 s
n = 12,  E = -7.85857579 H, t = 1.21 s
n = 13,  E = -7.85866614 H, t = 1.21 s
n = 14,  E = -7.85874902 H, t = 1.24 s
n = 15,  E = -7.85882566 H, t = 1.23 s
n = 16,  E = -7.85889701 H, t = 1.14 s
n = 17,  E = -7.85896378 H, t = 1.21 s
n = 18,  E = -7.85902654 H, t = 1.25 s
n = 19,  E = -7.85908573 H, t = 1.26 s

Note: If you graph this using any software, you will see that this does not converge in 20 iterations. However, it will converge after around 100+ iterations which is unexpected because the result from the tutorial converged at around 15-20+ iterations. Also, I realized that the algorithm is always around 1-1.3 seconds while the same algorithm on the tutorial is around 2-2.5 seconds.

What is Expected:

n = 0,  E = -7.86266587 H, t = 2.66 s
n = 1,  E = -7.87094621 H, t = 2.71 s
n = 2,  E = -7.87563100 H, t = 2.21 s
n = 3,  E = -7.87829146 H, t = 2.65 s
n = 4,  E = -7.87981705 H, t = 2.19 s
n = 5,  E = -7.88070477 H, t = 2.62 s
n = 6,  E = -7.88123143 H, t = 2.16 s
n = 7,  E = -7.88155161 H, t = 2.61 s
n = 8,  E = -7.88175217 H, t = 2.21 s
n = 9,  E = -7.88188237 H, t = 2.77 s
n = 10,  E = -7.88197041 H, t = 2.20 s
n = 11,  E = -7.88203267 H, t = 2.64 s
n = 12,  E = -7.88207879 H, t = 2.68 s
n = 13,  E = -7.88211452 H, t = 2.19 s
n = 14,  E = -7.88214335 H, t = 2.76 s
n = 15,  E = -7.88216743 H, t = 2.33 s
n = 16,  E = -7.88218814 H, t = 2.68 s
n = 17,  E = -7.88220634 H, t = 2.17 s
n = 18,  E = -7.88222261 H, t = 2.62 s
n = 19,  E = -7.88223734 H, t = 2.17 s

Hi @Hatedfate! Can I ask what version of PennyLane you have installed locally?

If you upgrade to the latest version (pip install pennylane --upgrade), does this get fixed?

Hi @josh,

I have PennyLane 0.21.0 and yes, I have already tried pip install pennylane --upgrade and it didn’t work. However, I want to point out that it managed to work properly in my PyCharm IDE, but it did not seem to work properly in the jupyter notebook (same Python). Perhaps, there is an issue with Jupyter Notebook and not the code itself?

@Hatedfate that is really strange :thinking:

The reason I originally suggested upgrading your PennyLane version is that there was a known bug in v0.20 of PennyLane that was causing the Adapt-VQE demo to give the incorrect results — the same incorrect results you posted above.

A bugfix in v0.21 fixed this, and reverted the Adapt-VQE demo to give the correct results.

Could it be that your Jupyter notebook kernel is using a virtual environment that has PL v0.20 installed, whereas PyCharm is using an environment with PL v0.21?

2 Likes

@josh I believe that was the issue. Apparently, I did in fact upgrade pennylane, but my Jupyter Notebook didn’t for some reason and not until I restart my computer. I’ve noticed I was getting the correct results this morning when I rerun the circuit.

As a side question because my question did not get fully answered on my previous post, when simulating a PES of a molecule (i.e. - LiH, BeH2) using ADAPT-VQE, am I suppose to create an entirely new ADAPT-VQE at every iteration (basically everytime the interatomic distance increases)?

Appreciate your help!

No worries @Hatedfate, glad it’s working now!

Regarding your ADAPT-VQE question, I’ll tag @sjahangiri who might know the answer.

Hi @Hatedfate. Regarding your question:

when simulating a PES of a molecule (i.e. - LiH, BeH2) using ADAPT-VQE, am I suppose to create an entirely new ADAPT-VQE at every iteration (basically everytime the interatomic distance increases)?

In principle, yes, the optimum excitations obtained for a given geometry are not necessarily transferable to other geometries. However, for small molecules such as those you mentioned, it is likely that the geometries near the equilibrium one have a similar set of optimum excitations.

If you are interested in building the PES over a wide range of geometries, it is safer to apply the adaptive method at each iteration. Please let us know if you have any other questions.

1 Like