Different results with VQE on versions 0.26.0 and 0.27.0

Hi!

I have noticed very different results when using VQE on PennyLane version 0.26.0 and when using it on PennyLane 0.27.0

My code is the following (the geometry values are just for testing):

import pennylane as qml
from pennylane import numpy as np

seed = 1234
np.random.seed(seed) 

symbols  = ['H', 'H', 'H']
geometry = np.array([-0.0399, -0.0038, 0.0, 1.5780, 0.8540, 0.0, 2.7909, -0.5159, 0.0], requires_grad = False)
electrons = 2
charge = 1

%time H, qubits = qml.qchem.molecular_hamiltonian(symbols, geometry, charge=charge)

hf_state = qml.qchem.hf_state(electrons, qubits)

singles, doubles = qml.qchem.excitations(electrons, qubits)

s_wires, d_wires = qml.qchem.excitations_to_wires(singles, doubles)

dev = qml.device("default.qubit", wires=qubits)

@qml.qnode(dev)
def circuit(params, wires, s_wires, d_wires, hf_state):
    qml.UCCSD(params, wires, s_wires, d_wires, hf_state)
    return qml.expval(H)

params = np.random.random(len(singles) + len(doubles))
print(params)

optimizer = qml.GradientDescentOptimizer(stepsize=0.1)

for n in range(11):
    %time params, energy = optimizer.step_and_cost(circuit, params,wires=range(qubits), s_wires=s_wires, d_wires=d_wires, hf_state=hf_state)
    if n % 2 == 0:
        print("step = {:},  E = {:.8f} Ha".format(n, energy))

With PennyLane 0.26 I obtain the following:

CPU times: user 694 ms, sys: 0 ns, total: 694 ms
Wall time: 1.38 s
[0.78535858 0.77997581 0.27259261 0.27646426 0.80187218 0.95813935
0.87593263 0.35781727]
CPU times: user 673 ms, sys: 0 ns, total: 673 ms
Wall time: 1.35 s
step = 0, E = 0.26146914 Ha
CPU times: user 564 ms, sys: 0 ns, total: 564 ms
Wall time: 1.12 s
CPU times: user 688 ms, sys: 0 ns, total: 688 ms
Wall time: 1.37 s
step = 2, E = 0.24324925 Ha
CPU times: user 566 ms, sys: 0 ns, total: 566 ms
Wall time: 1.13 s
CPU times: user 681 ms, sys: 0 ns, total: 681 ms
Wall time: 1.36 s
step = 4, E = 0.22191782 Ha
CPU times: user 697 ms, sys: 0 ns, total: 697 ms
Wall time: 1.39 s
CPU times: user 568 ms, sys: 0 ns, total: 568 ms
Wall time: 1.14 s
step = 6, E = 0.19712825 Ha
CPU times: user 690 ms, sys: 1.68 ms, total: 692 ms
Wall time: 1.37 s
CPU times: user 565 ms, sys: 0 ns, total: 565 ms
Wall time: 1.12 s
step = 8, E = 0.16858973 Ha
CPU times: user 690 ms, sys: 0 ns, total: 690 ms
Wall time: 1.38 s
CPU times: user 570 ms, sys: 9.75 ms, total: 580 ms
Wall time: 1.16 s
step = 10, E = 0.13611113 Ha

With PennyLane 0.27.0 I get this:

CPU times: user 690 ms, sys: 10.8 ms, total: 701 ms
Wall time: 1.97 s
[0.78535858 0.77997581 0.27259261 0.27646426 0.80187218 0.95813935
0.87593263 0.35781727]
CPU times: user 572 ms, sys: 2.63 ms, total: 575 ms
Wall time: 1.15 s
step = 0, E = -0.73428150 Ha
CPU times: user 672 ms, sys: 6.1 ms, total: 678 ms
Wall time: 1.37 s
CPU times: user 566 ms, sys: 1.18 ms, total: 567 ms
Wall time: 1.13 s
step = 2, E = -0.76374619 Ha
CPU times: user 664 ms, sys: 18.3 ms, total: 682 ms
Wall time: 1.37 s
CPU times: user 672 ms, sys: 0 ns, total: 672 ms
Wall time: 1.36 s
step = 4, E = -0.79437752 Ha
CPU times: user 564 ms, sys: 0 ns, total: 564 ms
Wall time: 1.15 s
CPU times: user 676 ms, sys: 0 ns, total: 676 ms
Wall time: 1.36 s
step = 6, E = -0.82591780 Ha
CPU times: user 566 ms, sys: 0 ns, total: 566 ms
Wall time: 728 ms
CPU times: user 689 ms, sys: 20.8 ms, total: 710 ms
Wall time: 1.26 s
step = 8, E = -0.85804157 Ha
CPU times: user 581 ms, sys: 1.7 ms, total: 583 ms
Wall time: 1.41 s
CPU times: user 692 ms, sys: 5.81 ms, total: 697 ms
Wall time: 1.68 s
step = 10, E = -0.89036698 Ha

I expected to get the same results with both version. What has changed? Which is the correct one?

Thanks in advance!

Hello combarro,

It does seem that PennyLane 0.27.0 is having some hiccups with optimization in some particular cases. I will consult with our team and hopefully we can give you a solution soon. For now, I would stick with 0.26.0 until we figure out what changed in 0.27.0.

OK, understood. I’ll stick with 0.26.0, thanks.