Skip to content

Preserve bit locations through pickle #13980

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 6 commits into from
Mar 13, 2025

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 the bit locations on setstate by iterating over the dag's qubits and clbits.

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 the bit locations on
__setstate__ by iterating over the dag's qubits and clbits.

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 2.0.0 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

@mtreinish mtreinish added the stable backport potential The bug might be minimal and/or import enough to be port to stable label Mar 10, 2025
@coveralls
Copy link

coveralls commented Mar 10, 2025

Pull Request Test Coverage Report for Build 13821976559

Details

  • 20 of 20 (100.0%) changed or added relevant lines in 1 file are covered.
  • 24 unchanged lines in 3 files lost coverage.
  • Overall coverage decreased (-0.01%) to 88.107%

Files with Coverage Reduction New Missed Lines %
crates/accelerate/src/unitary_synthesis.rs 1 94.69%
crates/qasm2/src/lex.rs 5 91.73%
crates/qasm2/src/parse.rs 18 96.68%
Totals Coverage Status
Change from base Build 13819553093: -0.01%
Covered Lines: 72686
Relevant Lines: 82497

💛 - Coveralls

kevinhartman
kevinhartman previously approved these changes Mar 12, 2025
@kevinhartman kevinhartman added this pull request to the merge queue Mar 12, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Mar 12, 2025
Copy link
Contributor

@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.

Re-approving after the merge conflict is fixed.

@ElePT ElePT added this pull request to the merge queue Mar 13, 2025
Merged via the queue into Qiskit:main with commit 9dcc668 Mar 13, 2025
20 checks passed
mergify bot pushed a commit that referenced this pull request Mar 13, 2025
* Preserve bit locations through pickle

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 the bit locations on
__setstate__ by iterating over the dag's qubits and clbits.

Fixes #13976

* Fix clippy

* Update docstrings

* Fix name change after rebase

(cherry picked from commit 9dcc668)
github-merge-queue bot pushed a commit that referenced this pull request Mar 13, 2025
* Preserve bit locations through pickle (#13980)

* Preserve bit locations through pickle

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 the bit locations on
__setstate__ by iterating over the dag's qubits and clbits.

Fixes #13976

* Fix clippy

* Update docstrings

* Fix name change after rebase

(cherry picked from commit 9dcc668)

* Fix method name for stable/2.0 vs main

---------

Co-authored-by: Matthew Treinish <[email protected]>
raynelfss pushed a commit to raynelfss/qiskit that referenced this pull request Mar 20, 2025
* Preserve bit locations through pickle

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 the bit locations on
__setstate__ by iterating over the dag's qubits and clbits.

Fixes Qiskit#13976

* Fix clippy

* Update docstrings

* Fix name change after rebase
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 stable backport potential The bug might be minimal and/or import enough to be port to stable
Projects
None yet
Development

Successfully merging this pull request may close these issues.

DAGCircuit.find_bit does not work if a dag is deep-copied
5 participants