Skip to content

Split non commuting pass is added to Catalyst in MLIR#2437

Merged
rniczh merged 42 commits intomainfrom
rniczh/add-mlir-split-non-commuting-pass
Feb 23, 2026
Merged

Split non commuting pass is added to Catalyst in MLIR#2437
rniczh merged 42 commits intomainfrom
rniczh/add-mlir-split-non-commuting-pass

Conversation

@rniczh
Copy link
Copy Markdown
Member

@rniczh rniczh commented Jan 27, 2026

Context:

Description of the Change:

Adds the split-non-commuting pass, which splits quantum functions that measure non-commuting observables into multiple execution groups (In this inital implemenation, we treat each expval as different group). Each group runs in a separate call from the main function.

Steps:

  1. We first run the split-to-single-terms pass to decompose Hamiltonian expval values into single-term observables before this pass runs.
  2. Then we do the transformation to construct groups for each expval.

Before:

func.func @circuit() -> (f64, f64, f64) attributes {qnode} {
  %c100 = arith.constant 100 : i64
  quantum.device shots(%c100) ["", "", ""]
  %0 = quantum.alloc(3) : !quantum.reg
  ...
  %ev0 = quantum.expval %obs_X {group = 0} : f64
  %ev1 = quantum.expval %obs_Y {group = 1} : f64
  %ev2 = quantum.expval %obs_Z {group = 2} : f64
  return %ev0, %ev1, %ev2 : f64, f64, f64
}

After:

func.func @circuit() -> (f64, f64, f64) {
  %r0 = call @circuit.group.0() : () -> f64
  %r1 = call @circuit.group.1() : () -> f64
  %r2 = call @circuit.group.2() : () -> f64
  return %r0, %r1, %r2 : f64, f64, f64
}

func.func private @circuit.group.0() -> f64 attributes {qnode} {
  %c100 = arith.constant 100 : i64
  %c3 = arith.constant 3 : i64
  %divided = arith.divsi %c100, %c3 : i64
  quantum.device shots(%divided) ["", "", ""]
  ...
}

// ... group 1 ...
// ... group 2 ...

Shots are distributed among groups using integer division (rounded down); e.g., 100 shots with 3 groups yields 33 shots per group

Benefits:

Possible Drawbacks:

Related GitHub Issues:
[sc-93667]

@rniczh rniczh changed the title Split non commuting pass is added to Catalyst in MLIR [WIP] Split non commuting pass is added to Catalyst in MLIR Jan 27, 2026
@codecov
Copy link
Copy Markdown

codecov Bot commented Feb 5, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 96.87%. Comparing base (06b405a) to head (91dcf84).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2437      +/-   ##
==========================================
+ Coverage   96.76%   96.87%   +0.10%     
==========================================
  Files         156      155       -1     
  Lines       17030    16838     -192     
  Branches     1664     1623      -41     
==========================================
- Hits        16479    16311     -168     
+ Misses        403      392      -11     
+ Partials      148      135      -13     

☔ 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.

Comment thread mlir/lib/Quantum/Transforms/split_non_commuting.cpp Outdated
Comment thread frontend/catalyst/python_interface/transforms/quantum/__init__.py
Comment thread mlir/lib/Catalyst/Transforms/ApplyTransformSequencePass.cpp
@rniczh rniczh changed the title [WIP] Split non commuting pass is added to Catalyst in MLIR Split non commuting pass is added to Catalyst in MLIR Feb 10, 2026
@rniczh rniczh requested a review from a team February 11, 2026 16:47
Copy link
Copy Markdown
Contributor

@sengthai sengthai left a comment

Choose a reason for hiding this comment

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

Well done, well written! I have a few comments below.

Comment thread mlir/lib/Quantum/Transforms/split_non_commuting.cpp
Comment thread mlir/lib/Quantum/Transforms/split_non_commuting.cpp
Comment thread mlir/lib/Quantum/Transforms/split_non_commuting.cpp Outdated
Comment thread mlir/lib/Quantum/Transforms/split_non_commuting.cpp Outdated
Comment thread mlir/lib/Quantum/Transforms/split_non_commuting.cpp Outdated
Comment thread mlir/lib/Quantum/Transforms/split_non_commuting.cpp Outdated
Comment thread mlir/lib/Quantum/Transforms/split_non_commuting.cpp Outdated
Comment thread mlir/include/Quantum/Transforms/Passes.td
Comment thread mlir/lib/Quantum/Transforms/split_non_commuting.cpp Outdated
Comment thread mlir/lib/Catalyst/Transforms/ApplyTransformSequencePass.cpp
Co-authored-by: Sengthai Heng <sengthai37@gmail.com>
Comment thread frontend/test/lit/test_split_non_commuting.py Outdated
@dime10
Copy link
Copy Markdown
Contributor

dime10 commented Feb 12, 2026

Technically this is for the other pass, but split-to-single-terms seems to rename the qnode to <original name>.quantum, which is maybe not the most descriptive? Maybe something like <original name>.single_terms would describe the action better, and is less likely to conflict with other passes.
This pass's <original name>.group.<n> is pretty clear I think :)

@rniczh
Copy link
Copy Markdown
Member Author

rniczh commented Feb 13, 2026

Maybe something like .single_terms would describe the action better

Thanks @dime10 ! That makes sense. I do this in this PR, because the goal of this PR is to combine both split-to-single-terms and split-non-commuting and unblock the XAS execution for FTQC team. 93df371

@rniczh rniczh requested a review from a team February 17, 2026 15:36
Copy link
Copy Markdown
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.

Thanks @rniczh 🚀

Comment thread mlir/lib/Quantum/Transforms/split_to_single_terms.cpp Outdated
Comment thread mlir/lib/Quantum/Transforms/split_non_commuting.cpp Outdated
Copy link
Copy Markdown
Contributor

@lillian542 lillian542 left a comment

Choose a reason for hiding this comment

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

Thanks @rniczh! Looks good, everything seems to behave as expected :) I've made a couple of minor suggestions to the docs and tests, but after that no further comments from me!

Comment thread doc/releases/changelog-dev.md Outdated
Comment thread doc/releases/changelog-dev.md Outdated
Comment thread frontend/test/pytest/test_split_non_commuting.py Outdated
Comment thread mlir/test/Quantum/SplitNonCommutingTest.mlir
Comment thread frontend/test/pytest/test_split_non_commuting.py
rniczh and others added 7 commits February 23, 2026 10:27
Copy link
Copy Markdown
Contributor

@lillian542 lillian542 left a comment

Choose a reason for hiding this comment

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

Thanks @rniczh, this looks great 🚀

@rniczh rniczh merged commit d5ee2b4 into main Feb 23, 2026
37 checks passed
@rniczh rniczh deleted the rniczh/add-mlir-split-non-commuting-pass branch February 23, 2026 23:37
jzaia18 added a commit that referenced this pull request Mar 13, 2026
**Context:**
#2437 implements the `split-non-commuting` pass as an MLIR pass. This
allows for MLIR representations with multiple qnodes, which is not
currently supported by `mlir_specs`.

**Description of the Change:**
Adds support for MLIR passes with multiple `qnode` entry points to
`mlir_specs`

**Benefits:**

**Possible Drawbacks:**

**Related GitHub Issues:**
[sc-110647]
PennyLaneAI/pennylane#9120 to add frontend
support for this feature

---------

Co-authored-by: Andrija Paurevic <46359773+andrijapau@users.noreply.github.com>
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.

4 participants