Skip to content
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

pennylane-qiskit Qiskit Session error #607

Open
takh04 opened this issue Dec 9, 2024 · 1 comment
Open

pennylane-qiskit Qiskit Session error #607

takh04 opened this issue Dec 9, 2024 · 1 comment

Comments

@takh04
Copy link

takh04 commented Dec 9, 2024

Describe the bug
Using _pennylane_qiskit.qiskit_session_ expects the loop to execute immediately without queueing again. However, the session closes after a single execution with the following error:

qiskit_ibm_runtime.exceptions.IBMRuntimeError: 'The session is closed.'

To Reproduce
Based on this thread, reproducing this error is difficult since it requires an IBM Premium plan. However, you can easily reproduce the error with Fake backends provided by IBM (without an IBM Premium plan).

import pennylane as qml
from pennylane_qiskit import qiskit_session
from qiskit_ibm_runtime import QiskitRuntimeService, Session
from qiskit_ibm_runtime.fake_provider import FakeManilaV2

backend_fake = FakeManilaV2()
dev = qml.device(
    'qiskit.remote', 
    wires=5, 
    backend=backend_fake, 
    session=Session(backend=backend_fake, max_time=900)
)

@qml.qnode(dev)
def circuit(x):
    qml.RX(x, 0)
    qml.CNOT([0, 1])
    return qml.expval(qml.PauliZ(1))

angle = 0.1
with qiskit_session(dev) as session:
    res = circuit(angle)

    while res > 0:
        angle += 0.3
        res = circuit(angle)
        print(res)

Expected behavior
The while loop should execute within the Qiskit Session.

Version (qml.about()):

Name: PennyLane
Version: 0.38.0
Summary: PennyLane is a cross-platform Python library for quantum computing, quantum machine learning, and quantum chemistry. Train a quantum computer the same way as a neural network.
Home-page: https://github.com/PennyLaneAI/pennylane
Author: 
Author-email: 
License: Apache License 2.0
Location: /Users/tak/anaconda3/lib/python3.11/site-packages
Requires: appdirs, autograd, autoray, cachetools, networkx, numpy, packaging, pennylane-lightning, requests, rustworkx, scipy, toml, typing-extensions
Required-by: PennyLane-qiskit, PennyLane_Lightning

Platform info:           macOS-14.6.1-arm64-arm-64bit
Python version:          3.11.3
Numpy version:           1.24.0
Scipy version:           1.10.1
Installed devices:
- lightning.qubit (PennyLane_Lightning-0.38.0)
- default.clifford (PennyLane-0.38.0)
- default.gaussian (PennyLane-0.38.0)
- default.mixed (PennyLane-0.38.0)
- default.qubit (PennyLane-0.38.0)
- default.qubit.autograd (PennyLane-0.38.0)
- default.qubit.jax (PennyLane-0.38.0)
- default.qubit.legacy (PennyLane-0.38.0)
- default.qubit.tf (PennyLane-0.38.0)
- default.qubit.torch (PennyLane-0.38.0)
- default.qutrit (PennyLane-0.38.0)
- default.qutrit.mixed (PennyLane-0.38.0)
- default.tensor (PennyLane-0.38.0)
- null.qubit (PennyLane-0.38.0)
- qiskit.aer (PennyLane-qiskit-0.39.1)
- qiskit.basicaer (PennyLane-qiskit-0.39.1)
- qiskit.basicsim (PennyLane-qiskit-0.39.1)
- qiskit.remote (PennyLane-qiskit-0.39.1)
@CatalinaAlbornoz
Copy link

Hi @takh04 , thank you for suggesting the use of fake backends and the fix! 🤩
I think this could help a lot of people.
Our team is looking into your fix. We'll get back to you once they finish their review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants