-
Notifications
You must be signed in to change notification settings - Fork 585
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
Transforms shallow copy qnode #4736
Conversation
Hello. You may have forgotten to update the changelog!
|
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.
Just two comments, otherwise looks good! Thanks 💯
if it's just the device, what about a simpler copy, like: device = self.device
self.device = None
qnode_copy = super().__copy__(self)
self.device = qnode_copy.device = device
return qnode_copy |
Is this a proposal for
|
it was for qnode.copy. is there no default copy behaviour if an object doesn't override the dunder? maybe not |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## v0.33.0-rc0 #4736 +/- ##
==============================================
Coverage ? 99.64%
==============================================
Files ? 380
Lines ? 33986
Branches ? 0
==============================================
Hits ? 33864
Misses ? 122
Partials ? 0 ☔ View full report in Codecov by Sentry. |
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.
Thanks it looks good 👍
Closes #4731 [sc-48599]
Currently, transforms deep copy the qnode when they are applied. Unfortunately, this also deep copies the device.
Copying the device leads to issues like:
pickling errors for
lightning.kokkos
(see above issue)Unnecessary allocation of large amounts of memory
No longer being able to use the original devices' tracker:
This bugfix downgrades the deep copy of a qnode to a shallow copy that preserves the device.
To better separate the original from the copy, QNode now defines a custom
__copy__
method that shallow copies theexecute_kwargs
,transform_program
, andgradient_kwargs
. These were the three fully mutable properties of the qnode.