Skip to content

LinCombQGT and LinCombEstimatorGradient do not support BackendEstimator from Qiskit #223

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
Magnusson6359 opened this issue Mar 13, 2025 · 1 comment
Labels
bug Something isn't working

Comments

@Magnusson6359
Copy link

Magnusson6359 commented Mar 13, 2025

Environment

  • Qiskit Algorithms version:
  • 0.3.1
  • Python version:
  • 3.12.7
  • Operating system:
  • Mac OS 15.3.1 (24D70)
  • Environment:
    annotated-types==0.7.0
    appnope==0.1.4
    asttokens==3.0.0
    certifi==2025.1.31
    cffi==1.17.1
    charset-normalizer==3.4.1
    comm==0.2.2
    contourpy==1.3.1
    cryptography==44.0.2
    cycler==0.12.1
    debugpy==1.8.13
    decorator==5.2.1
    dill==0.3.9
    executing==2.2.0
    fonttools==4.56.0
    h5py==3.13.0
    ibm-cloud-sdk-core==3.23.0
    ibm-platform-services==0.61.0
    idna==3.10
    ipykernel==6.29.5
    ipython==9.0.2
    ipython_pygments_lexers==1.1.1
    jedi==0.19.2
    jupyter_client==8.6.3
    jupyter_core==5.7.2
    kiwisolver==1.4.8
    matplotlib==3.10.1
    matplotlib-inline==0.1.7
    mpmath==1.3.0
    nest-asyncio==1.6.0
    numpy==2.2.3
    packaging==24.2
    pandas==2.2.3
    parso==0.8.4
    pbr==6.1.1
    pexpect==4.9.0
    pillow==11.1.0
    platformdirs==4.3.6
    prompt_toolkit==3.0.50
    psutil==7.0.0
    ptyprocess==0.7.0
    pure_eval==0.2.3
    pycparser==2.22
    pydantic==2.9.2
    pydantic_core==2.23.4
    Pygments==2.19.1
    PyJWT==2.10.1
    pylatexenc==2.10
    pyparsing==3.2.1
    pyscf==2.8.0
    pyspnego==0.11.2
    python-dateutil==2.9.0.post0
    pytz==2025.1
    pyzmq==26.3.0
    qiskit==1.4.1
    qiskit-aer==0.16.4
    qiskit-algorithms==0.3.1
    qiskit-ibm-runtime==0.36.1
    qiskit-nature==0.7.2
    requests==2.32.3
    requests_ntlm==1.3.0
    rustworkx==0.16.0
    scipy==1.15.2
    seaborn==0.13.2
    setuptools==76.0.0
    six==1.17.0
    stack-data==0.6.3
    stevedore==5.4.1
    symengine==0.13.0
    sympy==1.13.3
    tornado==6.4.2
    traitlets==5.14.3
    typing_extensions==4.12.2
    tzdata==2025.1
    urllib3==2.3.0
    wcwidth==0.2.13
    websocket-client==1.8.0

What is happening?

When trying to run VarQITE with various different estimators, I could not get the BackendEstimator to work whatsoever. After some searching, I found that the problem lied in trying to use the estimator for the gradient and QFIM circuits via the ImaginaryMcLachlanPrinciple class.

Separately, the V2 estimators are also not supported as far as I can tell.

How can we reproduce the issue?

Below code is taken from the VarQITE tutorial and slightly modified. If var_principle is changed to the one involving the BackendEstimator, the code only runs once.

from qiskit.quantum_info import SparsePauliOp
from qiskit.circuit.library import EfficientSU2
import numpy as np
from qiskit_algorithms.time_evolvers.variational import ImaginaryMcLachlanPrinciple
from qiskit_algorithms import TimeEvolutionProblem
from qiskit_algorithms import VarQITE
from qiskit.quantum_info import Statevector
from qiskit_algorithms import SciPyImaginaryEvolver
import matplotlib.pyplot as plt

from qiskit.primitives import Estimator
from qiskit.primitives import BackendEstimator
from qiskit_ibm_runtime.fake_provider import FakeAthensV2

from qiskit_nature.second_q.mappers import ParityMapper
from qiskit_nature.units import DistanceUnit
from qiskit_nature.second_q.drivers import PySCFDriver
from qiskit_nature.second_q.circuit.library import UCCSD

from qiskit_algorithms.gradients import LinCombEstimatorGradient, LinCombQGT

driver = PySCFDriver(
    atom = "H 0 0 0; H 0 0 0.7",
    unit=DistanceUnit.ANGSTROM,
    charge=0,
    spin=0,
    basis='sto6g'
)
problem = driver.run()
h = problem.hamiltonian.second_q_op()
mapper = ParityMapper(num_particles = problem.num_particles)

hamiltonian = mapper.map(h)

estimator = BackendEstimator(FakeAthensV2())

ansatz = EfficientSU2(num_qubits = hamiltonian.num_qubits, reps=1, su2_gates=["ry"])
init_param_values = [np.pi,np.pi,0,0]

var_principle1 = ImaginaryMcLachlanPrinciple(qgt=LinCombQGT(estimator), gradient=LinCombEstimatorGradient(estimator))
var_principle2 = ImaginaryMcLachlanPrinciple()

# Change here to test the difference
var_principle = var_principle1

time = 5.0
evolution_problem = TimeEvolutionProblem(hamiltonian, time, aux_operators=[hamiltonian])

var_qite = VarQITE(ansatz, init_param_values, var_principle, estimator)
evolution_result = var_qite.evolve(evolution_problem)

init_state = Statevector(ansatz.assign_parameters(init_param_values))
evolution_problem = TimeEvolutionProblem(
    hamiltonian, time, initial_state=init_state, aux_operators=[hamiltonian]
)

h_exp_val = np.array([ele[0][0] for ele in evolution_result.observables])

times = evolution_result.times
plt.plot(times, h_exp_val, label="VarQITE")
plt.xlabel("Time")
plt.ylabel(r"$\langle H \rangle$ (energy)")
plt.legend(loc="upper right");

Output with var_principle1
Image

Output with var_principle2
Image

What should happen?

I expect the evolution to be somewhat different under the BackendEstimator as the QFIM and gradient circuits will be perturbed by device noise.

Any suggestions?

No response

@Magnusson6359 Magnusson6359 added the bug Something isn't working label Mar 13, 2025
@Magnusson6359 Magnusson6359 changed the title LinCombQGT and LinCombEstimatorGradient does not support BackendEstimator from Qiskit LinCombQGT and LinCombEstimatorGradient do not support BackendEstimator from Qiskit Mar 13, 2025
@dobrautz
Copy link

dobrautz commented May 5, 2025

I would also be very interested in the resolution of this issue!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants