From e7fe73908e5647bc59db8fb3947587072ae2c114 Mon Sep 17 00:00:00 2001 From: kevin-tian Date: Tue, 24 Oct 2023 12:42:17 -0400 Subject: [PATCH 1/3] don't block if backend not selected --- qiskit_ibm_runtime/session.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/qiskit_ibm_runtime/session.py b/qiskit_ibm_runtime/session.py index 36f7a0f62..43cb57e97 100644 --- a/qiskit_ibm_runtime/session.py +++ b/qiskit_ibm_runtime/session.py @@ -24,6 +24,7 @@ from .runtime_program import ParameterNamespace from .program.result_decoder import ResultDecoder from .ibm_backend import IBMBackend +from .exceptions import RuntimeJobTimeoutError def _active_session(func): # type: ignore @@ -172,7 +173,10 @@ def run( self._session_id = job.job_id() if self._backend is None: - self._backend = job.backend().name + try: + self._backend = job.backend(0).name + except RuntimeJobTimeoutError: + self._backend = None return job From 89902519d5ab50f857d2e013444f2a296bda68fb Mon Sep 17 00:00:00 2001 From: kevin-tian Date: Mon, 13 Nov 2023 13:24:41 -0500 Subject: [PATCH 2/3] add reno --- .../notes/backend-blocking-job-70ebcf44855cbdfd.yaml | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 releasenotes/notes/backend-blocking-job-70ebcf44855cbdfd.yaml diff --git a/releasenotes/notes/backend-blocking-job-70ebcf44855cbdfd.yaml b/releasenotes/notes/backend-blocking-job-70ebcf44855cbdfd.yaml new file mode 100644 index 000000000..c9cf202fb --- /dev/null +++ b/releasenotes/notes/backend-blocking-job-70ebcf44855cbdfd.yaml @@ -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. + From 2a9ff3a25499ffa6ee1f438c335da456c74016e5 Mon Sep 17 00:00:00 2001 From: kevin-tian Date: Tue, 5 Dec 2023 22:17:53 -0500 Subject: [PATCH 3/3] add test --- test/integration/test_session.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/test/integration/test_session.py b/test/integration/test_session.py index b8c086a59..4af012f8a 100644 --- a/test/integration/test_session.py +++ b/test/integration/test_session.py @@ -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."""