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

Don't block for the first job in a session #1170

Merged
merged 5 commits into from
Dec 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading