-
Notifications
You must be signed in to change notification settings - Fork 42
✨ Add MLIR pass for merging rotation gates #1019
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
Conversation
So far, this PR adds a pass that can merge the following gates:
I'm not sure about how to merge the remaining gates mentioned in #898. I have the feeling that they are fundamentally different and cannot be merged as easily because the respective gates cannot be decomposed into something that commutes. I also still have to figure out why the tests are failing on Windows. I already texted you privately, but if you have any input, I would be very interested, @burgholzer, @DRovara, and @ystade. :) |
I did some more thinking on this topic and I might have an idea: Rotations by Euler Angles are known to be difficult to compose from multiple rotations. That's why quaternions (https://en.wikipedia.org/wiki/Quaternions_and_spatial_rotation) are often used by game engines to represent rotations. I think we might be able to do the same thing here: first translate the three Euler angles to quaternions, then we combine the multiple rotations into one single rotation and then we translate back into Euler angles. If you want we can also chat about this in person tomorrow, @denialhaag. |
Have a look at the current Qiskit code in that regard. I remember that they are doing something very similar in the code since recently. Might serve as some good inspiration. The rules for The two qubit gates are a bit more special. In general, merging might not be particularly easy here. But cancellation is fairly easy to decide as also indicated by the code linked in the issue description. Maybe those gates should be included as special rules there. Just my two cents here though. |
@DRovara, yes, an in-person chat would be nice! I'll be in the office in a bit! :) |
@burgholzer, thanks for the ideas! I'll have a look at the Qiskit implementation! |
For reference, the Qiskit pass is implemented here. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks a lot for the effort! I made some comments with suggestions, feel free to look into them.
One more thing though: As far as I see, this will only work if the parameters are passed as operands and won't work if the parameters are static attributes. This is okay for now, but we should probably keep this in mind and at the very least open a follow-up issue for that.
mlir/lib/Dialect/MQTOpt/Transforms/MergeRotationGatesPattern.cpp
Outdated
Show resolved
Hide resolved
Just for context, the idea was
However, since this PR works with dynamic operands, we can't really know if Once we have that, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I gave the PR another look and I just have some small comments left. I hope they should be addressable without too much effort.
Especially regarding the test cases, I think it is good to set up a good standard early.
Thanks a lot!
mlir/lib/Dialect/MQTOpt/Transforms/MergeRotationGatesPattern.cpp
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great, thanks for the effort! Once the CI is passing, I'm happy with merging this PR - unless @burgholzer wants to have another look, too.
Signed-off-by: Lukas Burgholzer <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Many thanks for all the work on this 🙏🏼 great to see more and more MLIR passes making it into the repository.
I have a couple of comments, which hopefully are fairly easy to address/comment on. One potential simplification, a missing gate, and two more general comments/questions on potential canonicalizations that we are missing.
mlir/lib/Dialect/MQTOpt/Transforms/MergeRotationGatesPattern.cpp
Outdated
Show resolved
Hide resolved
mlir/lib/Dialect/MQTOpt/Transforms/MergeRotationGatesPattern.cpp
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome. Thanks for the changes. This is ready to go in 🚀
Description
This PR adds a pass for merging simple rotation gates.
Fixes #898
Checklist:
I have updated the documentation to reflect these changes.I have added migration instructions to the upgrade guide (if needed).