qiskit-ibm-runtime icon indicating copy to clipboard operation
qiskit-ibm-runtime copied to clipboard

`Session.close` and `Batch.close` do not close the session and batch on the new IQP

Open t-imamichi opened this issue 9 months ago • 6 comments

Describe the bug Session.close and Batch.close do not close the session and the batch.

Steps to reproduce (update) I made a reproducible script https://github.com/Qiskit/qiskit-ibm-runtime/issues/2188#issuecomment-2742082563

In [10]: from qiskit_ibm_runtime import QiskitRuntimeService, Batch

In [11]: service = QiskitRuntimeService(name="...")  # new IQP

In [12]: session = Batch.from_id('...', service)

In [13]: session.status()
Out[13]: 'Pending'

In [14]: session.close()  # There is no running job

In [15]: session.status()
Out[15]: 'Pending'   # expected to be "Closed"

Expected behavior The status become Closed as same as the conventional IQP. I tried the same script on the conventional IQP and the status becomes Closed after close().

Suggested solutions

Additional Information

  • qiskit-ibm-runtime version: 0.37.0
  • qiskit version: 1.4.1
  • Python version: 3.12.9
  • Operating system: macOS 15.3.2

t-imamichi avatar Mar 19 '25 14:03 t-imamichi

My understanding is that Session.close() calls this endpoint which just sets the accepting_jobs flag to false. So if there are still are pending jobs in the session, the status will be Pending. Only once there are no more pending jobs will the status update to Closed.

Getting this for both IQP and the new IQP on cloud

Image

kt474 avatar Mar 19 '25 17:03 kt474

I made a script to reproduce the behavior. I confirmed that the behavior on new IQP is different from that on the conventional IQP. The last line of the new IQP is expected to be "Closed" as same as the conventional IQP.

from time import sleep

from qiskit_ibm_runtime import Batch, QiskitRuntimeService, __version__

print(__version__)

for name, iqp in [
    ("primitives", "conventional IQP"),
    ("notebooks-internal", "new IQP"),
]:
    print(iqp)
    service = QiskitRuntimeService(name=name)
    backend = service.backend("test_eagle_us-east")
    batch = Batch(backend)
    sleep(1)
    print(batch.status())
    print("call close()")
    batch.close()
    sleep(1)
    print(batch.status(), "\n")
0.37.0
conventional IQP
Pending
call close()
Closed

new IQP
Pending
call close()
Pending 

The status on the new IQP is also "Pending" (not "Closed") even if close() is called and there is no job. Image

t-imamichi avatar Mar 21 '25 02:03 t-imamichi

@francabrera is this an expected discrepancy between the two APIs?

kt474 avatar Mar 21 '25 16:03 kt474

the behaviour should be the same, and is what is being referenced before (the close method in this package marks the session as not accepting new jobs). The time to transition from "pending - not accepting new jobs" to closed is what changes in the new API, which takes longer time to move to the close from "pending - not accepting new jobs", this may change in the future.

francabrera avatar Mar 27 '25 12:03 francabrera

The time to transition from "pending - not accepting new jobs" to closed is what changes in the new API, which takes longer time to move to the close from "pending - not accepting new jobs", this may change in the future.

Is this extended transition time included in usage for a session?

jyu00 avatar Mar 27 '25 13:03 jyu00

Is this extended transition time included in usage for a session?

this only happens for workloads created with no jobs on it (as in the Batch example), so there is no usage reported for these workloads

francabrera avatar Mar 27 '25 13:03 francabrera

I tried my script https://github.com/Qiskit/qiskit-ibm-runtime/issues/2188#issuecomment-2742082563 today (April 22, 2025), but the issue has not been fixed yet. What is the status of this issue?

0.38.0
conventional IQP
/Users/ima/tasks/5_2025/scripts/2025/runtime/batch.py:12: DeprecationWarning: The "ibm_quantum" channel option is deprecated and will be sunset on 1 July. After this date, ibm_cloud will be the only valid channel. For information on migrating to the new IBM Quantum Platform on the "ibm_cloud" channel, review the migration guide https://quantum.cloud.ibm.com/docs/migration-guides/classic-iqp-to-cloud-iqp .
  service = QiskitRuntimeService(name=name)
Pending
call close()
Closed

new IQP
Pending
call close()
Pending

t-imamichi avatar Apr 22 '25 07:04 t-imamichi

I tried my script #2188 (comment) today (April 22, 2025), but the issue has not been fixed yet. What is the status of this issue?

Issue opened on the server side - multi-channel-scheduler issue 2782

kt474 avatar Apr 22 '25 15:04 kt474

I tried my script on July 3 and the behavior is not updated yet.

0.40.1
new IQP
Pending
call close()
Closed

t-imamichi avatar Jul 03 '25 02:07 t-imamichi

Image

Are you expecting the Session/Batch to be closed? I think it's working as intended now.

kt474 avatar Jul 08 '25 20:07 kt474

My bad. You are right. It behaves as same as the old IQP now. I close this issue.

t-imamichi avatar Jul 09 '25 02:07 t-imamichi