Skip to content

Commit

Permalink
Don't block for the first job in a session (Qiskit#1170)
Browse files Browse the repository at this point in the history
* don't block if backend not selected

* add reno

* add test
  • Loading branch information
kt474 authored Dec 6, 2023
1 parent b264bf1 commit f2e24e4
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
6 changes: 5 additions & 1 deletion qiskit_ibm_runtime/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
from .runtime_job import RuntimeJob
from .utils.result_decoder import ResultDecoder
from .ibm_backend import IBMBackend
from .exceptions import RuntimeJobTimeoutError
from .utils.default_session import set_cm_session
from .utils.deprecation import deprecate_arguments

Expand Down Expand Up @@ -180,7 +181,10 @@ def run(
self._setup_lock.release()

if self._backend is None:
self._backend = job.backend().name
try:
self._backend = job.backend(0).name
except RuntimeJobTimeoutError:
self._backend = None

return job

Expand Down
8 changes: 8 additions & 0 deletions releasenotes/notes/backend-blocking-job-70ebcf44855cbdfd.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
fixes:
- |
Fixed an issue where the first job in a cloud channel session without a backend passed
in would block other jobs from starting. This would happen because the first job would
attempt to retrieve the backend from the job which required the job to be in a
completed state.
13 changes: 13 additions & 0 deletions test/integration/test_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,19 @@ def test_session_from_id(self, service):
job = sampler.run(ReferenceCircuits.bell(), shots=400)
self.assertEqual(session_id, job.session_id)

@run_integration_test
def test_session_no_backend(self, service):
"""Test session without passing in backend."""
if self.dependencies.channel == "ibm_quantum":
self.skipTest("Not supported on ibm_quantum")
with Session(service) as session:
sampler = Sampler(session=session)
job1 = sampler.run(ReferenceCircuits.bell(), shots=400)
job2 = sampler.run(ReferenceCircuits.bell(), shots=400)
self.assertTrue(job1.backend())
self.assertTrue(job2.backend())
self.assertEqual(job1.backend().name, job2.backend().name)


class TestBackendRunInSession(IBMIntegrationTestCase):
"""Integration tests for Backend.run in Session."""
Expand Down

0 comments on commit f2e24e4

Please sign in to comment.