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

[MLIR] Remove scheduling at FunctionOpInterfaces #1407

Merged

Conversation

erick-xanadu
Copy link
Contributor

@erick-xanadu erick-xanadu commented Jan 3, 2025

Context: The apply_pass function from the frontend is capable of scheduling any MLIR pass from the frontend for a specific qnode. However, in order for the pass to succeed in its compilation, it must allow itself to be scheduled to transform a module.

Description of the Change: There is another branch that I worked on where I moved the bulk of the transformation to Patterns; however, the pattern applicators that are upstream in MLIR do not support running a single iteration of the worklist. I would like at some point to add a custom pattern applicator that doesn't fold and only does a single pass through the worklist (or take a variable). The passes as written represent a single iteration through the worklist. Running a single iteration through the worklist may not yield all full optimizations, but that's how it is currently coded. I think this is acceptable as we don't yet do a cost benefit analysis for any transformation.

Benefits: Can write the following:

import jax
import pennylane as qml

import catalyst


@qml.qjit(keep_intermediate=True)
@catalyst.passes.apply_pass("disentangle-CNOT")
@qml.qnode(qml.device("lightning.qubit", wires=2))
def foo():
    qml.Hadamard(0)
    qml.Hadamard(0)
    qml.Hadamard(1)
    qml.Hadamard(1)
    qml.CNOT(wires=[0, 1])
    return qml.state()


foo()
print(foo.mlir)

@erick-xanadu erick-xanadu requested review from mehrdad2m, a team and isaacdevlugt January 3, 2025 21:49
Copy link
Contributor

@isaacdevlugt isaacdevlugt left a comment

Choose a reason for hiding this comment

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

Thanks @erick-xanadu! 😲 I can't speak for the implementation, so I'll leave the review here to others on the compilation team.

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.

Let's target this bugfix for release :)

mlir/lib/Quantum/Transforms/DisentangleCNOT.cpp Outdated Show resolved Hide resolved
@dime10 dime10 added this to the v0.10.0 milestone Jan 7, 2025
@erick-xanadu erick-xanadu force-pushed the eochoa/2025-01-03/simpler-than-pattern-rewriter branch from f37bf9b to 356bafd Compare January 8, 2025 19:04
@erick-xanadu erick-xanadu changed the base branch from main to v0.10.0-rc January 8, 2025 19:05
@erick-xanadu erick-xanadu requested a review from dime10 January 8, 2025 19:05
@erick-xanadu erick-xanadu force-pushed the eochoa/2025-01-03/simpler-than-pattern-rewriter branch from 356bafd to 8df9efa Compare January 8, 2025 19:06
Copy link

codecov bot commented Jan 8, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 96.67%. Comparing base (b46f05b) to head (a4c3a38).
Report is 12 commits behind head on v0.10.0-rc.

Additional details and impacted files
@@              Coverage Diff               @@
##           v0.10.0-rc    #1407      +/-   ##
==============================================
- Coverage       96.68%   96.67%   -0.01%     
==============================================
  Files              75       75              
  Lines            8266     8272       +6     
  Branches          867      870       +3     
==============================================
+ Hits             7992     7997       +5     
  Misses            221      221              
- Partials           53       54       +1     

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

Copy link
Contributor

github-actions bot commented Jan 8, 2025

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.

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.

🚀

(I'm including this PR in my changelog update, so need to to do anything on that front.)

@dime10
Copy link
Contributor

dime10 commented Jan 8, 2025

Just curious, what was the last commit about? :)

@erick-xanadu
Copy link
Contributor Author

@dime10, walk is recursive. This pass is schedule on quantum ModuleOps. We never nest FunctionOpInterfaces here, so no need for that.

@erick-xanadu erick-xanadu merged commit d08502e into v0.10.0-rc Jan 9, 2025
20 checks passed
@erick-xanadu erick-xanadu deleted the eochoa/2025-01-03/simpler-than-pattern-rewriter branch January 9, 2025 14:46
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