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

Conversation

kt474
Copy link
Member

@kt474 kt474 commented Jun 5, 2025

Summary

Reported in slack - in the case where nothing is passed into the primitive inside a session/batch context manager, the backend is retrieved based on the name. This could cause issues if things in the backend target were modified.

backend = service.backend("ibm_torino")
backend.target.add_instruction(IfElseOp, name="if_else")

with Batch(backend):
    sampler = SamplerV2() # this would re-init the backend, losing the IfElseOp instruction
    sampler.options.experimental = {"execution_path" : "gen3-experimental"}
    job = sampler.run([isa_circuit])

Details and comments

Fixes #

@ElePT ElePT added the Changelog: Bugfix Include in the Fixed section of the changelog label Jun 12, 2025
Copy link
Collaborator

@ElePT ElePT left a comment

Choose a reason for hiding this comment

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

Thanks for the fix. At a first look it looks reasonable, but it would be better if we could have a regression test to confirm that the code works. I also added a reno suggestion that took me way too long to write :)

kt474 and others added 3 commits June 12, 2025 12:57
Co-authored-by: Elena Peña Tapia <57907331+ElePT@users.noreply.github.com>
Copy link
Collaborator

@ElePT ElePT left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

@kt474 kt474 added this pull request to the merge queue Jun 17, 2025
Merged via the queue into Qiskit:main with commit d4bd788 Jun 17, 2025
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Changelog: Bugfix Include in the Fixed section of the changelog
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants