-
Notifications
You must be signed in to change notification settings - Fork 615
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update
qml.math.norm
for dispatching autograd
; stop rounding when…
… postselecting (#4766) **Context:** Differentiation of `qml.math.norm` does not work for L2 norm. This was causing incorrect gradients with autograd. Moreover, due to the rounding function, the gradient of `QNode`s being postselected is incorrect, so that needs to be removed. **Description of the Change:** * Add private function to compute the norm for `autograd` interface with `qml.math.norm` when `ord=None` and `axis=None`. Otherwise, we dispatch to `scipy.linalg.norm` as we did before. * Stop rounding the norm of the state when renormalizing the state vector after postselection. Instead, we check if the norm is close to 0 and set it to exactly 0 if it is. This condition is only checked is the state vector is not abstract. * Added warning to `qml.measure` docs about jitting with postselection on zero probability states. **Benefits:** * `qml.math.norm` is differentiable for all interfaces for `ord=None` and `axis=None`. * Postselection doesn't lead to incorrect gradients. **Possible Drawbacks:** Postselection with jitting can lead to incorrect results and errors if postselecting on a state with zero probability. However, this is an edge case that is not causing problems frequently. **Related GitHub Issues:** #4867 --------- Co-authored-by: Christina Lee <[email protected]>
- Loading branch information
Showing
10 changed files
with
297 additions
and
16 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
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.