Qiskit / qiskit-ibm-runtime

IBM Client for Qiskit Runtime
https://docs.quantum.ibm.com/api/qiskit-ibm-runtime
Apache License 2.0
152 stars 154 forks source link

Session.from_id unexpectedly changes the backend #1959

Open dcanuto opened 3 weeks ago

dcanuto commented 3 weeks ago

Describe the bug

The Session.from_id method is returning a Session instance whose backend method returns a backend name different from the session whose ID was passed into from_id.

Steps to reproduce

from qiskit_ibm_runtime import QiskitRuntimeService, Session

service = QiskitRuntimeService(
    token="your_token", instance="your_instance", channel="ibm_cloud"
)

first_backend_name = "ibm_brisbane"

first_session = Session(backend=service.backend(first_backend_name), max_time=8 * 60 * 60)

second_backend_name = "ibm_fez"

second_session = Session(backend=service.backend(second_backend_name), max_time=8 * 60 * 60)

second_session_copy = Session.from_id(second_session.session_id, service)

print(second_session.backend()) # gives me ibm_fez
print(second_session_copy.backend()) # gives me ibm_brisbane (i.e., the backend from first_session)
assert second_session.session_id == second_sesssion_copy.session_id # no error thrown

Expected behavior

The second_session and second_session_copy should both return "ibm_fez" from their backend method.

Suggested solutions

Not sure, but perhaps there is a bug in the session_details method of the QiskitRuntimeService._api_client attribute (used here in Session.from_id)?

Additional Information

kt474 commented 2 weeks ago

@dcanuto Thanks for reporting this. Looks like the session details response from the API doesn't return a backend so the first backend from the list of available backends is returned instead.

{'id': '4733121c-118f-4947-af83-dcc9c81a46bf', 'backend_name': '', 
'interactive_ttl': 60, 
'max_ttl': 28800, 'active_ttl': 28800, 
'state': 'open', 'accepting_jobs': True, 'mode': 'dedicated'}

I follow up with the server side.