qiskit-community / qiskit-aqua

Quantum Algorithms & Applications (**DEPRECATED** since April 2021 - see readme for more info)
https://qiskit.org/aqua
Apache License 2.0
571 stars 377 forks source link

ADAPT-VQE fails with Aer simulator #1467

Closed MariaSapova closed 3 years ago

MariaSapova commented 3 years ago

Information

What is the current behavior?

Adapt-VQE works fine with BasicAer, but fails with Aer backends (both statevector_simulator and qasm_simulator). In previous qiskit verstion VQEAdapt worked fine.

AquaError: 'Circuit execution failed: ERROR: Failed to load qobj: Invalid parameterized qobj: instruction param position out of range'

Steps to reproduce the problem

After molecule definition I use built-in methods:

backend = Aer.get_backend('qasm_simulator')
quantum_instance = QuantumInstance(backend)
solver = VQEUCCSDFactory(quantum_instance)
adapt = AdaptVQE(transformation, solver)
res = adapt.solve(driver)

What is the expected behavior?

Computation runs fine without error, as in BasicAer case

mrossinek commented 3 years ago

Hi @MariaSapova! Unfortunately, I am unable to reproduce your error. But I am happy to try and help you debug this problem. I would like to clarify a few things first:

For completeness, here is the snippet which I wrote in order to try reproducing your error:

from qiskit import __version__ as terra_version
from qiskit import Aer
from qiskit.aqua import __version__ as aqua_version
from qiskit.aqua import QuantumInstance
from qiskit.chemistry.algorithms import AdaptVQE, VQEUCCSDFactory
from qiskit.chemistry.drivers import PySCFDriver
from qiskit.chemistry.transformations import FermionicTransformation
from qiskit.providers.aer import __version__ as aer_version

print(f'Qiskit Aqua:\t{aqua_version}')
print(f'Qiskit Aer:\t{aer_version}')
print(f'Qiskit Terra:\t{terra_version}')

driver = PySCFDriver()
transformation = FermionicTransformation()
backend = Aer.get_backend('statevector_simulator')
quantum_instance = QuantumInstance(backend)
solver = VQEUCCSDFactory(quantum_instance)
adapt = AdaptVQE(transformation, solver)
res = adapt.solve(driver)
print(res)

Here is the output which I obtained with Python 3.6.12 on my Fedora 33 machine and using the latest master-branch installation of all Qiskit modules:

/home/oss/Files/Qiskit/src/qiskit-terra/qiskit/__init__.py:90: DeprecationWarning: Using Qiskit with Python 3.6 is deprecated as of the 0.17.0 release. Support for running Qiskit with Python 3.6 will be removed in a future release.
  "future release.", DeprecationWarning)
Qiskit Aqua:    0.9.0.dev0+049b945
Qiskit Aer:     0.8.0
Qiskit Terra:   0.17.0.dev0+8a52ab2
=== GROUND STATE ENERGY ===

* Electronic ground state energy (Hartree): -1.857275030145
  - computed part:      -1.857275030145
  - frozen energy part: 0.0
  - particle hole part: 0.0
~ Nuclear repulsion energy (Hartree): 0.719968994449
> Total ground state energy (Hartree): -1.137306035696

=== MEASURED OBSERVABLES ===

  0:  # Particles: 2.000 S: -0.000 S^2: -0.000 M: 0.000

=== DIPOLE MOMENTS ===

~ Nuclear dipole moment (a.u.): [0.0  0.0  1.3889487]

  0:
  * Electronic dipole moment (a.u.): [0.0  0.0  1.3889487]
    - computed part:      [0.0  0.0  1.3889487]
    - frozen energy part: [0.0  0.0  0.0]
    - particle hole part: [0.0  0.0  0.0]
  > Dipole moment (a.u.): [0.0  0.0  0.0]  Total: 0.
                 (debye): [0.0  0.0  0.0]  Total: 0.
For completeness, here are the results obtained with Python 3.8.6 ``` Qiskit Aqua: 0.9.0.dev0+049b945 Qiskit Aer: 0.8.0 Qiskit Terra: 0.17.0.dev0+8a52ab2 === GROUND STATE ENERGY === * Electronic ground state energy (Hartree): -1.857275030145 - computed part: -1.857275030145 - frozen energy part: 0.0 - particle hole part: 0.0 ~ Nuclear repulsion energy (Hartree): 0.719968994449 > Total ground state energy (Hartree): -1.137306035696 === MEASURED OBSERVABLES === 0: # Particles: 2.000 S: -0.000 S^2: -0.000 M: 0.000 === DIPOLE MOMENTS === ~ Nuclear dipole moment (a.u.): [0.0 0.0 1.3889487] 0: * Electronic dipole moment (a.u.): [0.0 0.0 1.3889487] - computed part: [0.0 0.0 1.3889487] - frozen energy part: [0.0 0.0 0.0] - particle hole part: [0.0 0.0 0.0] > Dipole moment (a.u.): [0.0 0.0 0.0] Total: 0. (debye): [0.0 0.0 0.0] Total: 0. ```
mrossinek commented 3 years ago

Having found out about the meta package version numbering I know was able to reproduce your error with a stable-branch installation of Qiskit. Let me dig into this a little bit more and get back to you on this.

mrossinek commented 3 years ago

PR #1447 fixes this issue and was merged about a week ago. Thus, my initial attempt of reproducing the bug failed, because it is no longer present on the master branch.

This means that you have several options:

We can also see whether it is possible to release a Qiskit Aqua 0.8.2 based on 0bf9873 which would allow you to install this bug fix via pip but that is not a decision which I can make. @woodsp-ibm @manoelmarques what do you think about this?

MariaSapova commented 3 years ago

@mrossinek thank you! I installed master version of qiskit and now it works fine. However, I would like to point out one thing: with qasm simulator aux_operator values grow quadratically with the number of shots. I've already mentioned the same thing for QEOM #1460.

I think that it would be nice to normalize them.

image

woodsp-ibm commented 3 years ago

While you seem to have an appropriate ground state the other operators, such as number of particles (1.948676 million!) and dipole moment are way off (to put it mildly!) @mrossinek Any comments here?

mrossinek commented 3 years ago

Hi @woodsp-ibm. I was actually just working on a fix together with @Cryoris. See the new PR #1473

mrossinek commented 3 years ago

Since the Aqua core is in the process of being merged into Terra, I re-opened the PR which fixes this over there. See Qiskit/qiskit-terra#5496

mrossinek commented 3 years ago

This issue is now also fixed in the migrated Aqua core inside of Terra. Closing.