-
Notifications
You must be signed in to change notification settings - Fork 617
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Upgrade
fuse_rot_angles
to preserve derivatives and global phases (#…
…6031) **Context:** The current implementation of `fuse_rot_angles`, which is used by `merge_rotations` and `single_qubit_fusion`, has the following issues: 1. It does not necessarily preserve global phases. As we move towards global-phase aware standards, this becomes an issue where it wasn't one before. 2. Its derivative is wrong, forming part (but not all) of the bug #5715. In particular, the custom handling of special input values prevents the calculation of correct derivatives, and `fuse_rot_angles` at singular points leads to wrong derivatives, rather than NaN values, which are mathematically well-motivated. 3. A minor technical issue is that the implementation requires nested conditionals, leading to a good bit of code and separate handling of traced JAX code, making it more complex. **Description of the Change:** The implementation of `fuse_rot_angles` is remade entirely. **Benefits:** The remade code uses a comparably simple mathematical expression to compute the fused rotation angles that 1. preserves global phases 2. has the correct derivative everywhere except for well-understandable, predictable singular points. These singular points make sense because rotation fusion is not a smooth map everywhere. The predictability allowed us to write a dedicated test that confirms our understanding of the singularities, at least within a large set of special test points. 3. does not require conditionals beyond those that are implemented in `qml.math.arctan2` anyways, and thus available in all ML interfaces, including JAX with JIT-compatibility. 4. As a bonus, the new implementation supports broadcasting/batching with an arbitrary number of leading dimensions if all angles in each set are broadcasted in the same way (because this is nice, easy to support, and allows us to speed up tests a lot). In summary, the global phases are fixed, Jacobians are only ever NaNs, rather than wrong, and Jacobians are only NaNs when they were NaN or wrong in the current implementation. **Possible Drawbacks:** N/A **Related GitHub Issues:** #5715 (not fixed entirely, just partially) [sc-63642] --------- Co-authored-by: Vincent Michaud-Rioux <[email protected]> Co-authored-by: Korbinian Kottmann <[email protected]> Co-authored-by: Thomas R. Bromley <[email protected]>
- Loading branch information
1 parent
4cd95c3
commit 98c8ed3
Showing
5 changed files
with
530 additions
and
207 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
Oops, something went wrong.