Skip to content

Conversation

@yaelbh
Copy link
Collaborator

@yaelbh yaelbh commented Dec 25, 2025

Part of #2479.

This PR copies code fixes and tests not-yet-approved from the open PR #2498. I suggest to first review #2498, let me fix here in parallel according to the comments of #2498, and only then review this PR.

@yaelbh yaelbh added the executor-preview Issues related to the `executor_preview` branch label Dec 25, 2025
@yaelbh yaelbh requested a review from SamFerracin December 25, 2025 13:58
@yaelbh yaelbh changed the base branch from main to executor_preview December 25, 2025 14:01
Comment on lines -61 to -90
if isinstance(mode, (Session, Batch)):
self._session = mode
self._backend = self._session._backend
self._service = self._session.service

elif open_session := get_cm_session():
if open_session != mode:
if open_session._backend != mode:
raise ValueError(
"The backend passed in to the primitive is different from the session "
"backend. Please check which backend you intend to use or leave the mode "
"parameter empty to use the session backend."
)
logger.warning(
"A backend was passed in as the mode but a session context manager "
"is open so this job will run inside this session/batch "
"instead of in job mode."
)
self._session = open_session
self._backend = self._session._backend
self._service = self._session.service

elif isinstance(mode, IBMBackend):
self._backend = mode
self._service = self._backend.service

else:
raise ValueError(
"A backend or session/batch must be specified, or a session/batch must be open."
)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this equal to what's inside get_mode_service_backend, or are there differences?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is one difference: if get_cm_session() is not None and mode is None, previously there was an error, now it will take the backend from the session.

Copy link
Collaborator

@SamFerracin SamFerracin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, just want to make sure that I am not missing anything in. the lines of code that you removed

)


class TestGetModeServiceBackend(IBMTestCase):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be in test_base_primitive.py?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, because the function that it tests resides in base_primitive.py. I tried to move around the functions and its test in several ways, by starting new files, moving to existing utils files, etc. Everything that I did ended in circular imports that required substantial modifications to unresolve, resulting in effort and amount of modifications that were not justified.

@yaelbh yaelbh requested a review from SamFerracin January 7, 2026 13:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

executor-preview Issues related to the `executor_preview` branch

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants