Skip to content

Provide some guidelines for how to write QNode passes #2483

Merged
dime10 merged 4 commits intomainfrom
qnode-transform-guide
Feb 25, 2026
Merged

Provide some guidelines for how to write QNode passes #2483
dime10 merged 4 commits intomainfrom
qnode-transform-guide

Conversation

@dime10
Copy link
Copy Markdown
Contributor

@dime10 dime10 commented Feb 13, 2026

@github-actions
Copy link
Copy Markdown
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.

1 similar comment
@github-actions
Copy link
Copy Markdown
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.

@codecov
Copy link
Copy Markdown

codecov Bot commented Feb 13, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 96.76%. Comparing base (9cab573) to head (5a96123).
⚠️ Report is 26 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2483      +/-   ##
==========================================
+ Coverage   96.61%   96.76%   +0.14%     
==========================================
  Files         156      156              
  Lines       16984    17016      +32     
  Branches     1657     1658       +1     
==========================================
+ Hits        16409    16465      +56     
+ Misses        421      403      -18     
+ Partials      154      148       -6     

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@dime10 dime10 requested a review from mudit2812 February 19, 2026 15:25
Copy link
Copy Markdown
Contributor

@joeycarter joeycarter left a comment

Choose a reason for hiding this comment

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

Looks good! 💯

I have no notes for now, but may want to revisit next time I write a qnode pass. Thanks @dime10!

Copy link
Copy Markdown
Contributor

@mudit2812 mudit2812 left a comment

Choose a reason for hiding this comment

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

Let me know if this is clear enough. We could add IR example if additional clarity is needed :)

We already have a google doc with an IR example, so it would be great to move it here if this is going to be a centralized guidance doc. Let me see if I can find the doc and send you a link on Slack.

@dime10 dime10 requested review from mudit2812 and paul0403 February 24, 2026 23:42
@dime10 dime10 merged commit 788b78e into main Feb 25, 2026
47 checks passed
@dime10 dime10 deleted the qnode-transform-guide branch February 25, 2026 15:47
dime10 added a commit that referenced this pull request Mar 6, 2026
…#2497)

_Note I don't think this PR is a must, but while working on the
[transform post-processing
epic](https://app.shortcut.com/xanaduai/epic/107240) one of the ideas
was to better formalize some of the attributes we use and might have
implicit assumptions for. The verification introduced here is not very
strong, but it is something. There are several older passes in Catalyst
which currently don't follow the proposed notion of qnode functions
(e.g. they might [not propagate the
attribute](https://github.com/PennyLaneAI/catalyst/blob/main/mlir/lib/Gradient/Transforms/GradMethods/ParameterShift.cpp)
in new functions they create, or they might also have [unusual
structures](https://github.com/PennyLaneAI/catalyst/blob/main/mlir/lib/Mitigation/Transforms/MitigationMethods/Zne.cpp)
like having MPs in a function but device init/quantum allocs in a
different one)._

In this PR, the existing `qnode` attribute is renamed to `quantum.node`
to indicate the dialect origin. Additionally, verification logic is
introduced to formalize the notion of a "qnode" function (see also
#2483), which is characterized by the presence of measurement process
operations. These operations represent an implicit transition from
quantum state manipulation to execution logic and classical
post-processing. While quantum gate operations can appear in functions
that are not qnodes, measurement processes should not as they have this
"non-local" effect. The attribute helps identify functions with quantum
execution semantics during transformations.

The new attribute and verification logic is currently implemented during
the "quantum kernel" phase only, i.e. before `inline-nested-modules` is
called. All functions carrying the attribute ~must have at least one
measurement process~ (I have removed this verification for now since
Catalyst still uses MP-free QNodes as a feature), and all measurement
processes appearing within a nested module (quantum kernel) must be
contained in a func op with that attribute.

To limit the scope of this PR the new attribute is replaced with the
previous `qnode` attribute after lowering the quantum kernel module.

A bug in the xDSL split-non-commuting pass is also fixed (required to
pass the new verification).
9f75c0e

[sc-107492]
multiphaseCFD pushed a commit that referenced this pull request Mar 6, 2026
…#2497)

_Note I don't think this PR is a must, but while working on the
[transform post-processing
epic](https://app.shortcut.com/xanaduai/epic/107240) one of the ideas
was to better formalize some of the attributes we use and might have
implicit assumptions for. The verification introduced here is not very
strong, but it is something. There are several older passes in Catalyst
which currently don't follow the proposed notion of qnode functions
(e.g. they might [not propagate the
attribute](https://github.com/PennyLaneAI/catalyst/blob/main/mlir/lib/Gradient/Transforms/GradMethods/ParameterShift.cpp)
in new functions they create, or they might also have [unusual
structures](https://github.com/PennyLaneAI/catalyst/blob/main/mlir/lib/Mitigation/Transforms/MitigationMethods/Zne.cpp)
like having MPs in a function but device init/quantum allocs in a
different one)._

In this PR, the existing `qnode` attribute is renamed to `quantum.node`
to indicate the dialect origin. Additionally, verification logic is
introduced to formalize the notion of a "qnode" function (see also
#2483), which is characterized by the presence of measurement process
operations. These operations represent an implicit transition from
quantum state manipulation to execution logic and classical
post-processing. While quantum gate operations can appear in functions
that are not qnodes, measurement processes should not as they have this
"non-local" effect. The attribute helps identify functions with quantum
execution semantics during transformations.

The new attribute and verification logic is currently implemented during
the "quantum kernel" phase only, i.e. before `inline-nested-modules` is
called. All functions carrying the attribute ~must have at least one
measurement process~ (I have removed this verification for now since
Catalyst still uses MP-free QNodes as a feature), and all measurement
processes appearing within a nested module (quantum kernel) must be
contained in a func op with that attribute.

To limit the scope of this PR the new attribute is replaced with the
previous `qnode` attribute after lowering the quantum kernel module.

A bug in the xDSL split-non-commuting pass is also fixed (required to
pass the new verification).
9f75c0e

[sc-107492]
kipawaa pushed a commit that referenced this pull request Mar 10, 2026
…#2497)

_Note I don't think this PR is a must, but while working on the
[transform post-processing
epic](https://app.shortcut.com/xanaduai/epic/107240) one of the ideas
was to better formalize some of the attributes we use and might have
implicit assumptions for. The verification introduced here is not very
strong, but it is something. There are several older passes in Catalyst
which currently don't follow the proposed notion of qnode functions
(e.g. they might [not propagate the
attribute](https://github.com/PennyLaneAI/catalyst/blob/main/mlir/lib/Gradient/Transforms/GradMethods/ParameterShift.cpp)
in new functions they create, or they might also have [unusual
structures](https://github.com/PennyLaneAI/catalyst/blob/main/mlir/lib/Mitigation/Transforms/MitigationMethods/Zne.cpp)
like having MPs in a function but device init/quantum allocs in a
different one)._

In this PR, the existing `qnode` attribute is renamed to `quantum.node`
to indicate the dialect origin. Additionally, verification logic is
introduced to formalize the notion of a "qnode" function (see also
#2483), which is characterized by the presence of measurement process
operations. These operations represent an implicit transition from
quantum state manipulation to execution logic and classical
post-processing. While quantum gate operations can appear in functions
that are not qnodes, measurement processes should not as they have this
"non-local" effect. The attribute helps identify functions with quantum
execution semantics during transformations.

The new attribute and verification logic is currently implemented during
the "quantum kernel" phase only, i.e. before `inline-nested-modules` is
called. All functions carrying the attribute ~must have at least one
measurement process~ (I have removed this verification for now since
Catalyst still uses MP-free QNodes as a feature), and all measurement
processes appearing within a nested module (quantum kernel) must be
contained in a func op with that attribute.

To limit the scope of this PR the new attribute is replaced with the
previous `qnode` attribute after lowering the quantum kernel module.

A bug in the xDSL split-non-commuting pass is also fixed (required to
pass the new verification).
9f75c0e

[sc-107492]
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.

5 participants