# Completely Different Results when running ADAPT-VQE tutorial

**URL:** <https://discuss.pennylane.ai/t/completely-different-results-when-running-adapt-vqe-tutorial/1683>\
**Category:** PennyLane Help\
**Created:** [February 20, 2022, 6:46pm UTC](https://discuss.pennylane.ai/t/completely-different-results-when-running-adapt-vqe-tutorial/1683 "2022-02-20T18:46:06Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Hatedfate](https://yyz2.discourse-cdn.com/flex012/user_avatar/discuss.pennylane.ai/hatedfate/32/909_2.png) [@Hatedfate](https://discuss.pennylane.ai/u/Hatedfate)\
**Post date:** [February 20, 2022, 6:46pm UTC](https://discuss.pennylane.ai/t/completely-different-results-when-running-adapt-vqe-tutorial/1683/1 "2022-02-20T18:46:06Z")

</div>

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](https://pennylane.ai/qml/demos/tutorial_adaptive_circuits.html).

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:

```auto
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:

```auto
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:

```auto
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:

```auto
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

```

---

<div class="post-metadata">

**Author:** ![josh](https://yyz2.discourse-cdn.com/flex012/user_avatar/discuss.pennylane.ai/josh/32/100_2.png) [@josh](https://discuss.pennylane.ai/u/josh)\
**Post date:** [February 21, 2022, 11:03am UTC](https://discuss.pennylane.ai/t/completely-different-results-when-running-adapt-vqe-tutorial/1683/2 "2022-02-21T11:03:52Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Hatedfate](https://yyz2.discourse-cdn.com/flex012/user_avatar/discuss.pennylane.ai/hatedfate/32/909_2.png) [@Hatedfate](https://discuss.pennylane.ai/u/Hatedfate)\
**Post date:** [February 21, 2022, 5:20pm UTC](https://discuss.pennylane.ai/t/completely-different-results-when-running-adapt-vqe-tutorial/1683/3 "2022-02-21T17:20:29Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![josh](https://yyz2.discourse-cdn.com/flex012/user_avatar/discuss.pennylane.ai/josh/32/100_2.png) [@josh](https://discuss.pennylane.ai/u/josh)\
**Post date:** [February 22, 2022, 6:59am UTC](https://discuss.pennylane.ai/t/completely-different-results-when-running-adapt-vqe-tutorial/1683/4 "2022-02-22T06:59:32Z")

</div>

@Hatedfate that is really strange 🤔

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?

---

<div class="post-metadata">

**Author:** ![Hatedfate](https://yyz2.discourse-cdn.com/flex012/user_avatar/discuss.pennylane.ai/hatedfate/32/909_2.png) [@Hatedfate](https://discuss.pennylane.ai/u/Hatedfate)\
**Post date:** [February 23, 2022, 12:27am UTC](https://discuss.pennylane.ai/t/completely-different-results-when-running-adapt-vqe-tutorial/1683/5 "2022-02-23T00:27:06Z")

</div>

@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!

---

<div class="post-metadata">

**Author:** ![josh](https://yyz2.discourse-cdn.com/flex012/user_avatar/discuss.pennylane.ai/josh/32/100_2.png) [@josh](https://discuss.pennylane.ai/u/josh)\
**Post date:** [February 23, 2022, 5:22am UTC](https://discuss.pennylane.ai/t/completely-different-results-when-running-adapt-vqe-tutorial/1683/6 "2022-02-23T05:22:01Z")

</div>

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

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

---

<div class="post-metadata">

**Author:** ![sjahangiri](https://yyz2.discourse-cdn.com/flex012/user_avatar/discuss.pennylane.ai/sjahangiri/32/1443_2.png) [@sjahangiri](https://discuss.pennylane.ai/u/sjahangiri)\
**Post date:** [February 23, 2022, 1:54pm UTC](https://discuss.pennylane.ai/t/completely-different-results-when-running-adapt-vqe-tutorial/1683/7 "2022-02-23T13:54:51Z")

</div>

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.
