Skip to content
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

Preserve bit locations through pickle #13981

Merged

Conversation

mtreinish
Copy link
Member

Summary

Previously when we were pickling a DAGCircuit the bit locations fields were forgotten about. So when we loaded a DAGCircuit from a pickle the bit locations were empty. This would cause any call to find_bit() to raise an error because there was no entry for any of the bits in the dag. This commit fixes this by reconstructing by including the bit locations fields in the object state returned by getstate and populating the fields from the provided state in setstate/

Details and comments

Fixes #13976

Previously when we were pickling a DAGCircuit the bit locations fields
were forgotten about. So when we loaded a DAGCircuit from a pickle the
bit locations were empty. This would cause any call to find_bit() to
raise an error because there was no entry for any of the bits in the
dag. This commit fixes this by reconstructing by including the bit
locations fields in the object state returned by __getstate__ and
populating the fields from the provided state in __setstate__/

Fixes Qiskit#13976
@mtreinish mtreinish added the Changelog: Bugfix Include in the "Fixed" section of the changelog label Mar 10, 2025
@mtreinish mtreinish added this to the 1.4.2 milestone Mar 10, 2025
@mtreinish mtreinish requested a review from a team as a code owner March 10, 2025 12:24
@qiskit-bot
Copy link
Collaborator

One or more of the following people are relevant to this code:

  • @Qiskit/terra-core

@Cryoris
Copy link
Contributor

Cryoris commented Mar 10, 2025

CI is very unhappy about the missing #[new] function; from the PyO3 user guide this doesn't seem to be available per default

By default, it is not possible to create an instance of a custom class from Python code. To declare a constructor, you need to define a method and annotate it with the #[new] attribute.

@Cryoris Cryoris added this pull request to the merge queue Mar 11, 2025
Merged via the queue into Qiskit:stable/1.4 with commit 1d334fa Mar 11, 2025
16 checks passed
@mtreinish mtreinish deleted the stable-fix-bitlocations-dropped-on-pickle branch March 11, 2025 09:17
@mtreinish
Copy link
Member Author

Oops I forgot the release note here, lets not forget to add it when we release 1.4.2.

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.

3 participants