-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Fix equality and pickling of DAGCircuit
with stretches
#14000
base: main
Are you sure you want to change the base?
Conversation
This is only really a user-facing error message when working with DAGCircuit, since QuantumCircuit first checks if the bits being added to it are duplicates. And, in the case of DAGCircuit, the previous error message was already unfriendly: ValueError: Existing bit ShareableQubit(Owned { register: OwningRegisterInfo { name: "q16", size: 2, subclass: QUBIT }, index: 0 }) cannot be re-added in strict mode.
Tracks stretches the same way we track vars. Also happens to fix a bug in DAG equality where order mattered between stretch captures (it should never have). And, fixes a serialization bug with stretches.
One or more of the following people are relevant to this code:
|
Pull Request Test Coverage Report for Build 13819534045Warning: This coverage report may be inaccurate.This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.
Details
💛 - Coveralls |
If we have any we get it indirectly through tests that are using multiprocessing (like transpiling > 1 circuit) because pickle will be used for IPC or deep copy which also internally uses pickle. That being said see #13980 for some explicit tests I had to add for another pickle bug that's been around since 1.3 (when we ported DAGCircuit to rust). |
Great, thanks! I've added a few tests based on those here to validate that stretches are preserved after pickling and deepcopy. I also tested vars locally, but I found that there's a bug there that predates 2.0 so those tests aren't added in this PR (we ought to address that separately): |
Summary
During testing, I've found two bugs with
DAGCircuit
's handling of stretches:DAGCircuit
does not properly pickle stretches #13999They are fixed here.
Details and comments
I've also reworked
DAGCircuit
's tracking of stretches to be the same as what we do for vars. Namely, there's now just anidentifier_info
field (which replacesvar_info
) which makes it easier to detect name collisions between all identifiers in tracking, and also should make it easier to support native handling of stretches in the future.To make things a bit cleaner, I've moved
Var
tolib.rs
and defined a macroimpl_circuit_identifier
to reduce boilerplate between ourQubit
,Clbit
,Var
, and nowStretch
identifier types.I've also moved the logic of pickling identifier info tracking from
__getstate__
and__setstate__
toFromPyObject
andIntoPyObject
implementations.To-do
DAGCircuit
. Can that possibly be true?