Skip to content
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

Add merge rotation pass #1162

Merged
merged 60 commits into from
Oct 11, 2024
Merged

Add merge rotation pass #1162

merged 60 commits into from
Oct 11, 2024

Conversation

rmoyard
Copy link
Contributor

@rmoyard rmoyard commented Sep 30, 2024

Description of the Change:

Add the merge rotations pass, rotations angles are summed in rotation gates removed. It works for multirzop, and customop ({"RX", "RY", "RZ", "PhaseShift", "Rot", "CRX", "CRY", "CRZ", "ControlledPhaseShift", "CRot"}) .

@paul0403
Copy link
Contributor

paul0403 commented Oct 9, 2024

Note that I added an analysis object in #1186 to check for if a gate operation and its parent gate operation are correctly matched for the purposes of peephole optimizations like merge rotations and cancel inverses. It might be beneficial to merge that PR and use the added analysis if you want.

@rmoyard rmoyard marked this pull request as ready for review October 11, 2024 15:20
@rmoyard rmoyard requested a review from paul0403 October 11, 2024 15:49
Base automatically changed from cancel_inverse_adjoint to main October 11, 2024 17:23
Copy link
Contributor

@paul0403 paul0403 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, looks good! Just some small points from me

mlir/include/Quantum/Transforms/Passes.h Show resolved Hide resolved
mlir/test/Quantum/MergeRotationsTest.mlir Show resolved Hide resolved
mlir/test/Quantum/MergeRotationsTest.mlir Show resolved Hide resolved
mlir/test/Quantum/MergeRotationsTest.mlir Show resolved Hide resolved
mlir/lib/Quantum/Transforms/MergeRotationsPatterns.cpp Outdated Show resolved Hide resolved
Copy link

codecov bot commented Oct 11, 2024

Codecov Report

Attention: Patch coverage is 93.33333% with 1 line in your changes missing coverage. Please review.

Project coverage is 97.90%. Comparing base (6126963) to head (0213ae7).
Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
frontend/catalyst/passes.py 93.33% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1162      +/-   ##
==========================================
- Coverage   97.93%   97.90%   -0.03%     
==========================================
  Files          77       77              
  Lines       10921    10935      +14     
  Branches      971      973       +2     
==========================================
+ Hits        10695    10706      +11     
- Misses        179      180       +1     
- Partials       47       49       +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@paul0403
Copy link
Contributor

I think codecov does not cover lit tests. One pytest in https://github.com/PennyLaneAI/catalyst/blob/main/frontend/test/pytest/test_peephole_optimizations.py
(like cancel_inverse) is fine by me, as long as the most expansive tests are at the mlir lit test layer.

Copy link
Contributor

@paul0403 paul0403 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🥳

@rmoyard rmoyard merged commit 35b6849 into main Oct 11, 2024
45 of 47 checks passed
@rmoyard rmoyard deleted the merge_rotations branch October 11, 2024 21:19
@rmoyard
Copy link
Contributor Author

rmoyard commented Oct 11, 2024

[sc-72014]

paul0403 added a commit that referenced this pull request Oct 15, 2024
**Context:**
In #1162 the mlir pass for merging rotation was added, and the pattern
included `qml.Rot` (and `CRot`).
However, it was then realized that these two kinds of rotations should
not be merged, as [the rotation is specified via
](https://docs.pennylane.ai/en/stable/code/api/pennylane.Rot.html)
`rot(a, b, c) = rz(c) ry(b) rz(a)`

This means 
`rot(a, b, c) rot(d, e, f) != rot(a+d, b+e, c+f)`
since y and z rotations do not commute.


**Description of the Change:**
Remove `qml.Rot` (and `CRot`) from merge rotation pass patterns


**Benefits:**
No numerical errors
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants