Skip to content

🚧 Python Compiler #1677

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

Closed
wants to merge 21 commits into from
Closed

Conversation

erick-xanadu
Copy link
Contributor

@erick-xanadu erick-xanadu commented Apr 23, 2025

Context:

Description of the Change: Initial design:

  1. Use the same interface as plugins to denote adding a pass. E.g.,
# also pipeline
@apply_pass("catalyst_xdsl_plugin.pass-name")
@qml.qnode(device)
def func(): ...

will denote that we are running pass-name to the func qnode and the pass comes from xDSL.

  1. With the xDSL plugin being used during compilation, it will trigger a different path. The idea here is that xDSL will be in charge of running the apply-transform-sequence pass that we currently use in MLIR. This pass is the one that uses the transform dialect and applies already named passes.
  2. We will look at each pass-name and if it exists in MLIR, run it on MLIR. If it doesn't exist in MLIR, look for it registered in xDSL and apply it.
  3. After finishing running the apply-transform-sequence pass in xDSL, we will change the run command sent to Catalyst to omit it and continue the lowering process as usual.

Benefits:

Possible Drawbacks:

Related GitHub Issues:

@erick-xanadu erick-xanadu force-pushed the eochoa/2025-04-22/python-compiler branch from fbb545b to e5d1469 Compare April 30, 2025 17:08

class DeepCancelInversesSingleQubitPattern(pattern_rewriter.RewritePattern):
@pattern_rewriter.op_type_rewrite_pattern
def match_and_rewrite(self, funcOp: func.FuncOp, rewriter: pattern_rewriter.PatternRewriter):
Copy link
Contributor

Choose a reason for hiding this comment

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

I made the implementation a bit better by replacing recursion with a while loop. cancel_ops is not needed anymore:

    @pattern_rewriter.op_type_rewrite_pattern
    def match_and_rewrite(self, funcOp: func.FuncOp, rewriter: pattern_rewriter.PatternRewriter):
        """Deep Cancel for Self Inverses"""
        for op in funcOp.body.walk():

            while isinstance(op, CustomOp) and op.gate_name.data in self_inverses:

                next_user = None
                for use in op.results[0].uses:
                    user = use.operation
                    if isinstance(user, CustomOp) and user.gate_name.data == op.gate_name.data:
                        next_user = user
                        break

                if next_user is None:
                    break

                rewriter._replace_all_uses_with(next_user.results[0], op.in_qubits[0])
                rewriter.erase_op(next_user)
                rewriter.erase_op(op)

                op = op.in_qubits[0].owner

Copy link
Contributor Author

Choose a reason for hiding this comment

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

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.

a.py Outdated
return qml.state()


qml.capture.disable()
Copy link
Contributor

Choose a reason for hiding this comment

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

Just a note that if capture is disabled before executing, the tracing will happen without the plxpr pipeline. I'll share more details on Slack.

@erick-xanadu
Copy link
Contributor Author

Dropped in favour of #1715 and PennyLaneAI/pennylane#7367

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