Skip to content

Don't re-retrieve backend in session cm #2282

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

Merged
merged 5 commits into from
Jun 17, 2025
Merged
Show file tree
Hide file tree
Changes from 2 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
17 changes: 4 additions & 13 deletions qiskit_ibm_runtime/base_primitive.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,19 +86,10 @@ def _get_mode_service_backend(mode: Optional[Union[BackendV2, Session, Batch]] =
raise ValueError("mode must be of type Backend, Session, Batch or None")
elif get_cm_session():
mode = get_cm_session()
service = mode.service # type: ignore
try:
backend = service.backend(
name=mode.backend(), # type: ignore
instance=mode._instance, # type: ignore
use_fractional_gates=mode._backend.options.use_fractional_gates, # type: ignore
)
except (AttributeError, TypeError):
backend = service.backend(
name=mode.backend(), # type: ignore
instance=mode._instance, # type: ignore
)
return mode, service, backend # type: ignore
service = mode.service
backend = mode._backend

return mode, service, backend
else:
raise ValueError("A backend or session must be specified.")

Expand Down
4 changes: 4 additions & 0 deletions release-notes/unreleased/2282.bug.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Running jobs in a :class:`~.Session` or :class:`~.Batch` with
a context manager and initializing a primitive without any parameters will reinitialize the
Session/Batch backend. This could cause issues if the backend target has been modified so instead,
the actual backend object is now used.