-
Notifications
You must be signed in to change notification settings - Fork 616
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 handling of trainable_params in qs.copy #6363
Conversation
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.
LGTM
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.
Looks good, thanks for the quick fix! 😄
Co-authored-by: Andrija Paurevic <46359773+andrijapau@users.noreply.github.com>
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #6363 +/- ##
=======================================
Coverage 99.39% 99.39%
=======================================
Files 446 446
Lines 42326 42328 +2
=======================================
+ Hits 42071 42073 +2
Misses 255 255 ☔ View full report in Codecov by Sentry. |
**Context:** 1. The existing implementation of `QuantumScript.copy` relies on users to explicitly pass `trainable_params=None` to recalculate trainable params; however, updating `operations` and/or `measurements` often makes the `trainable_params` list outdated. 2. There is a bug that raises an error when explicitly passing `trainable_params=None` to qs.copy **Description of the Change:** 1. If a user passes `trainable_params` explicitly along with `operations` and/or `measurements`, we continue using the user-defined `trainable_params`. However, if updating `operations`/`measurements` and `trainable_params` is not passed, we default to recalculating for the new tape, rather than to copying over the initial tape's `trainable_params` attribute. 2. We stop trying to cast the input `trainable_params` to a list. I think this was intended to make it possible to pass `trainable_params=1`, but in hindsight, this isn't valid input on in `QuantumScript.__init__` and it shouldn't be valid input here, and calling `list(None)` was the source of the error. [sc-75393] --------- Co-authored-by: Andrija Paurevic <46359773+andrijapau@users.noreply.github.com>
Context:
QuantumScript.copy
relies on users to explicitly passtrainable_params=None
to recalculate trainable params; however, updatingoperations
and/ormeasurements
often makes thetrainable_params
list outdated.trainable_params=None
to qs.copyDescription of the Change:
trainable_params
explicitly along withoperations
and/ormeasurements
, we continue using the user-definedtrainable_params
. However, if updatingoperations
/measurements
andtrainable_params
is not passed, we default to recalculating for the new tape, rather than to copying over the initial tape'strainable_params
attribute.trainable_params
to a list. I think this was intended to make it possible to passtrainable_params=1
, but in hindsight, this isn't valid input on inQuantumScript.__init__
and it shouldn't be valid input here, and callinglist(None)
was the source of the error.[sc-75393]