Qiskit / qiskit-ibm-runtime

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

Sampler.run blocks for first job in session to complete if no backend was specified #1165

Closed mriedem closed 6 months ago

mriedem commented 11 months ago

Describe the bug

Using the ibm_cloud channel, I create a Session without a backend specified to let the server pick the backend.

I run a Sampler job using:

service = QiskitRuntimeService(
        channel="ibm_cloud",
        token=os.getenv('IBM_CLOUD_API_KEY'),
        instance=os.getenv('IBM_CLOUD_CRN'),
        url=os.getenv('IBM_CLOUD_URL', "https://test.cloud.ibm.com"))
session = Session(service=service)
options = Options(
        resilience_level=0,
        execution=dict(shots=1)
    )
sampler = Sampler(options=options, session=session)
job = sampler.run(ReferenceCircuits.bell())

The run() call blocks until the job is complete. This blocks me from being able to submit more jobs in the same session in batch mode.

Steps to reproduce

See above.

Expected behavior

Sampler.run() should return once I've submitted the job and not block waiting for the backend to be determined once the first job in the session is complete.

Suggested solutions

I believe the relevant code is here:

https://github.com/Qiskit/qiskit-ibm-runtime/blob/0.12.2/qiskit_ibm_runtime/session.py#L178

That job.backend() call is blocking when no backend is specified when creating the session:

https://github.com/Qiskit/qiskit-ibm-runtime/blob/0.12.2/qiskit_ibm_runtime/runtime_job.py#L258-L259

Maybe pass a timeout value of 0 and handle RuntimeJobTimeoutError and just leave backend unset in the Session instance?

Additional Information

kt474 commented 6 months ago

Closing this, backend will be required on the cloud channel in a future release