Skip to content

Commit 3d59376

Browse files
authored
Add warning if primitive initalized outside session (#2152)
* Add warning if primitive initalized outside session * Release note
1 parent c66b4e9 commit 3d59376

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

qiskit_ibm_runtime/base_primitive.py

+8
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,14 @@ def _run(self, pubs: Union[list[EstimatorPub], list[SamplerPub]]) -> RuntimeJobV
174174
)
175175

176176
if self._backend:
177+
if get_cm_session():
178+
logger.warning(
179+
"Even though a session/batch context manager is open this job will run in job mode "
180+
"because the %s primitive was initialized outside the context manager. "
181+
"Move the %s initialization inside the context manager to run in a session/batch.",
182+
self._program_id(),
183+
self._program_id(),
184+
)
177185
runtime_options["backend"] = self._backend
178186
if "instance" not in runtime_options and isinstance(self._backend, IBMBackend):
179187
runtime_options["instance"] = self._backend._instance
+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Added a warning for when a primitive is initialized outside of a session or batch context manager.
2+
In this scenario, the job will run in job mode instead of the session or batch.

0 commit comments

Comments
 (0)