-
Notifications
You must be signed in to change notification settings - Fork 625
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix handling of trainable_params in qs.copy (#6363)
**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>
- Loading branch information
1 parent
129820f
commit cd7d941
Showing
3 changed files
with
81 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters