question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

VQE optimization history has unexpected plateaus

See original GitHub issue

Environment

  • Qiskit version: 0.37.2
  • Qiskit Terra version: 0.21.2
  • Qiskit Aer version: 0.10.4
  • Python version: 3.9.0
  • Operating system: macOS Big Sur 11.6.4

What is happening?

When using the statevector simulator, the ADAM optimizer, and a callback function in VQE, the energy stored by the callback function displays unexpected plateaus. In an example below, every 9 adjacent iterations have very similar energies.

How can we reproduce the issue?

The code is modified from https://qiskit.org/documentation/tutorials/algorithms/04_vqe_advanced.html

from qiskit import Aer
from qiskit.opflow import X, Z, I
from qiskit.utils import QuantumInstance, algorithm_globals
from qiskit.algorithms import VQE
from qiskit.algorithms.optimizers import ADAM
from qiskit.circuit.library import TwoLocal
import matplotlib.pyplot as plt

H2_op = (-1.052373245772859 * I ^ I) + \
        (0.39793742484318045 * I ^ Z) + \
        (-0.39793742484318045 * Z ^ I) + \
        (-0.01128010425623538 * Z ^ Z) + \
        (0.18093119978423156 * X ^ X)

seed = 50
algorithm_globals.random_seed = seed
qi = QuantumInstance(Aer.get_backend('statevector_simulator'), seed_transpiler=seed, seed_simulator=seed)

ansatz = TwoLocal(rotation_blocks='ry', entanglement_blocks='cz')
optimizer = ADAM(maxiter=10)

intermediate_info = {
    'nfev': [],
    'parameters': [],
    'energy': [],
    'stddev': []
}

def callback(nfev, parameters, energy, stddev):
    intermediate_info['nfev'].append(nfev)
    intermediate_info['parameters'].append(parameters)
    intermediate_info['energy'].append(energy)
    intermediate_info['stddev'].append(stddev)

vqe = VQE(ansatz, optimizer=optimizer, quantum_instance=qi, callback=callback)
result = vqe.compute_minimum_eigenvalue(operator=H2_op)

Plotting intermediate_info['energy'] versus intermediate_info['nfev'] gives image Every 9 adjacent iterations have very similar energies, which seems unexpected with the Adam optimizer. When the number of qubits of the Hamiltonian changes, the length of each plateau can also change (from 9 in the current example).

What should happen?

The expected optimization history of energy with an Adam optimizer should be smoother, without artificial plateaus.

Any suggestions?

I guess that some repeated evaluations are done in optimization, or the callback function is not working properly.

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
woodsp-ibmcommented, Sep 6, 2022

If you look at the plots in this tutorial https://qiskit.org/documentation/tutorials/algorithms/02_vqe_convergence.html you will see similar plateaus. These are where optimizers using gradients are computing say a finite diff gradient using the same objective function - the callback is from the objective function and cannot discriminate how the optimizer is using it. Since the delta around the point is so small when the gradient is computed at the scale of the plots they end up with the staircase like look. (The tutorial has a paragraph in it mentioning gradients and the staircase effect)

Adam uses a finite diff gradient by default. TwoLocal defaults to reps=3 and with 2 qubits that 2 parameters per layer (rep) plus 2 more in a final block so 8 params in total. So I believe the 9 is 1 + 8 i.e one eval at the current point and 8 around it to compute the gradient to go to the next point (the finite diff like scipy only does a small epsilon in one direction in each dimensions)

And the number of points will vary by size of the hamiltonian, number of qubits given the same ansatz structure. Hopefully you can see from my detailing where the 9 comes from in the above.

0reactions
jiayu-shencommented, Sep 10, 2022

Thank you. There is actually a single point on that last plot. The plot does not set the marker, so it may not display. The center of the energy axis of the “empty” plot is at that final energy value.

I will raise another issue with more details.

Read more comments on GitHub >

github_iconTop Results From Across the Web

[2204.07179] ADAPT-VQE is insensitive to rough parameter ...
This same mechanism helps highlight a surprising feature of ADAPT-VQE: It should not suffer optimization problems due to "barren plateaus".
Read more >
aspuru-guzik-group/Meta-VQE - GitHub
It is well known the barren plateau problem of PQC: if the minimization algorithm starts at a random point, both the gradient and...
Read more >
Newest 'vqe' Questions - Quantum Computing Stack Exchange
I am going through portfolio optimization using Qiskit. It really looks interesting. The module has both VQE and QAOA algorithms for optimizing the...
Read more >
VQE method: a short survey and recent developments
VQE has been proposed as an alternative to fully quantum algorithms such as quantum phase estimation (QPE) because fully quantum algorithms ...
Read more >
Variational Quantum Algorithms - YouTube
PennyLane lead developer Nathan Killoran gives an overview of variational quantum algorithms such as VQE, QAOA, QGANs, and more.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found