-
Notifications
You must be signed in to change notification settings - Fork 191
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
Deep copy from Program.compile()
#688
Conversation
Codecov Report
@@ Coverage Diff @@
## master #688 +/- ##
=======================================
Coverage 98.69% 98.69%
=======================================
Files 75 75
Lines 9209 9212 +3
=======================================
+ Hits 9089 9092 +3
Misses 120 120
Continue to review full report at Codecov.
|
if name not in ("circuit", "reg_refs", "init_reg_refs"): | ||
setattr(p, name, copy.deepcopy(val)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Optimally, we should deep-copy the circuit as well, but since the may contain regrefs, this isn't as straight-forward to do. Just making a deepcopy here would cause two errors:
- Due to
MeasuredParameter
not supportingdeepcopy
(because of the different signature of the__new__()
method). A__deepcopy__()
method would potentially need to be added. - Any copied (not referenced) regrefs would raise the unnerving
"RegRef state has become inconsistent."
issue we had earlier.
We could e.g., override the __deepcopy__
method for the Command
class, but that would require it to only deep-copy everything except symbolic parameters. Alternatively, add a copy_everything_except_regref
method to Command
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because this is a potentially actionable item, perhaps is worth to have it as a (TODO) comment in the code. It might get lost here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've created an issue for this instead (#691). I think it's better to keep track of it there rather than as a TODO which can easily be lost. 🙂
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've created an issue for this instead (#691). I think it's better to keep track of it there rather than as a TODO which can easily be lost. 🙂
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great @thisac!
One question only: why programs should share the same references for the registers? Why copy everything else except reg_refs
?
Co-authored-by: Sebastián Duque Mesa <[email protected]>
Context:
The compiler create a linked copy of the program by calling
Program._linked_copy()
, which retains the same regrefs. Since the copy is shallow, it also keeps the same TDM parameters in a TDM program. These parameters are updated by the compiler and thus changed in both the compiled program and the initial program, while the circuit is only changed in the compiled program.Description of the Change:
Program._linked_copy()
is updated to create a deep-copy of all attributes except the ones containing register references, including e.g., the TDM parameters.Benefits:
The compiler actually returns a copy of the program without changing anything in the original program.
Possible Drawbacks:
None
Related GitHub Issues:
None