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

[WIP] Added loop boundary optimization pass #1476

Draft
wants to merge 23 commits into
base: main
Choose a base branch
from

Conversation

sengthai
Copy link
Contributor

@sengthai sengthai commented Jan 20, 2025

Context:

The Loop Boundary Optimization identifies and optimizes redundant quantum operations that occur at loop iteration boundaries, where operations at iteration boundaries often cancel each other out.

This method is standalone pass but also integrated in merge rotation and cancel inverses pass.

It specifically targets:

  1. Pattern recognition: Identifies matching quantum operations at the beginning and end of loop iteration.
  2. Operation Hoisting:
    • Moves matching operations from loop boundaries to outside loop
    • Top-edge and operations are hoisted before the loop and after the loop, respectively.

Description of the Change:

  • Register new pass for loop boundary optimization
  • Implement to support this method on merge_rotation and cancel_inverses pass

Benefits:

  • Eliminates redundant operations that cancel each other between iterations
  • Reduces quantum circuit depth and gate count
  • Effective for compute/uncompute patters in loops

Limited Scope

  • Only works with perfectly matching operations
    • Support gates: Pauli gates, H gate, CNOT, and rotation gates.

Possible Drawbacks:

  • Increased compilation time

[sc-83037]

Copy link
Contributor

Hello. You may have forgotten to update the changelog!
Please edit doc/releases/changelog-dev.md on your branch with:

  • A one-to-two sentence description of the change. You may include a small working example for new features.
  • A link back to this PR.
  • Your name (or GitHub username) in the contributors section.

sengthai and others added 4 commits January 20, 2025 21:35
Co-authored-by: paul0403 <79805239+paul0403@users.noreply.github.com>
Co-authored-by: paul0403 <79805239+paul0403@users.noreply.github.com>
Co-authored-by: paul0403 <79805239+paul0403@users.noreply.github.com>
Copy link
Contributor

@dime10 dime10 left a comment

Choose a reason for hiding this comment

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

Nice work so far! I left a few comments regarding the foundations of the pass, but since it's still a work in progress I didn't look at the code too closely yet :)

#define GEN_PASS_DECL_LOOPBOUNDARYOPTIMIZATIONPASS
#include "Quantum/Transforms/Passes.h.inc"

struct LoopBoundaryOptimizationPass
Copy link
Contributor

Choose a reason for hiding this comment

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

This doesn't have to be solved now, but I do think in the future we'll want a single pass that applies many quantum peephole optimizations, similarly to the canonicalize pass in MLIR. That way, we can actually make use of the fixed-point greedy pattern applicator, taking advantage of one peephole optimization enabling another.

@paul0403
Copy link
Contributor

Remember to link to the shortcut story! You can see how this is done on other PRs :D

@sengthai
Copy link
Contributor Author

Remember to link to the shortcut story! You can see how this is done on other PRs :D

Of course, will do. Thanks Paul!

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.

3 participants