-
Notifications
You must be signed in to change notification settings - Fork 603
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
dynamic_one_shot
supports broadcasting; broadcast_expand
supports…
… shot vectors (#5473) **Context:** Native mid-circuit measurements with `default.qubit` are not compatible with parameter broadcasting. Due to the complexity of a "native" implementation, I decided to use `broadcast_expand`, but realized that it does not work with shot vectors. **Description of the Change:** This PR does two things: * Update `dynamic_one_shot` transform to use `broadcast_expand` and process batched results correctly. * Update `broadcast_expand` to support shot vectors. * Raise error when postselecting with broadcasting and returning samples. This change was made to both `dynamic_one_shot` and `defer_measurements` because both transforms use `broadcast_expand` for broadcasting, although `defer_measurements` only uses `broadcast_expand` with postselection. Note that broadcasting with `qml.sample` and postselection will still not work due to ragged dimensions. If reviewers are okay with it, I would like to merge this and leave that improvement as technical debt. cc @trbromley @isaacdevlugt. Edit about note: Talked offline, decided to raise a more informative error if a user requests postselection with broadcasting when returning samples. **Benefits:** Both transforms are more capable. **Possible Drawbacks:** Because of the stacking and squeezing happening in the post-processing function of `broadcast_expand`, counts dictionaries get wrapped inside 0-D numpy arrays, which makes indexing into the dict impossible. To access the dictionary and its contents, one has to use `array.item()` to extract the single item inside the array. **Related GitHub Issues:** #5443
- Loading branch information
Showing
13 changed files
with
29,932 additions
and
27,651 deletions.
There are no files selected for viewing
57,102 changes: 29,515 additions & 27,587 deletions
57,102
.github/workflows/core_tests_durations.json
Large diffs are not rendered by default.
Oops, something went wrong.
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
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
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
Oops, something went wrong.