Skip to content

[MLIR] Add quantum.ctrl region op and ctrl-lowering pass - #3089

Merged
maliasadi merged 15 commits into
mainfrom
ctrl-lowering
Aug 12, 2026
Merged

[MLIR] Add quantum.ctrl region op and ctrl-lowering pass#3089
maliasadi merged 15 commits into
mainfrom
ctrl-lowering

Conversation

@maliasadi

@maliasadi maliasadi commented Aug 3, 2026

Copy link
Copy Markdown
Member

Context:
As part of adding Adjoint/Ctrl region/ops support to the graph-decomposition system, we need to reduce region-level modifiers to op-level nodes before the solver runs (Check the ADR for details). Controlled subcircuits need the same treatment: a Controlled(Op) produced by the solver (or a ctrl region coming from the frontend) must be reduced to op-level controlled gates before calling into the graph solver.

This PR adds the ctrl counterpart to the existing adjoint region infra via a quantum.ctrl region op and a ctrl-lowering pass.

Description of the Change:

We started simply by just implementing a forward walk pass over the region in the ctrl-lowering pass, for each op:

  • gate: rebuilt with the region's controls appended to whatever controls it already carries.
  • already-controlled gate: controls concatenate (via the control-merging method)
  • nested quantum.ctrl: outer controls merged in and lowered on the next iteration
  • structural ops (extract/insert/alloc/dealloc) and classical ops: just cloned

Related GitHub Issues:
[sc-125409]

@maliasadi
maliasadi requested review from kipawaa and paul0403 August 4, 2026 13:48

@kipawaa kipawaa left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nice work @maliasadi 💯 Just requesting a couple of test cases that I think would be good to have

Comment thread mlir/test/Quantum/CtrlTest.mlir
Comment thread mlir/test/Quantum/CtrlTest.mlir
@maliasadi
maliasadi requested a review from kipawaa August 7, 2026 21:38

@paul0403 paul0403 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Nice, thanks @maliasadi !

One thing I'm wondering is do we need a reference semantics version? Since the frontend qp.ctrl will be lowered to reference semantics.

I can help out with the qref.ctrl op (and the bidirectional semantics conversions) in another PR. For now, happy to get this one merged and unblock other graph decomp work!

Comment thread doc/releases/changelog-dev.md Outdated
Comment thread mlir/include/Quantum/IR/QuantumOps.td
Comment thread mlir/lib/Quantum/IR/QuantumOps.cpp
Comment thread mlir/lib/Quantum/IR/QuantumOps.cpp
Comment thread mlir/test/Quantum/CtrlTest.mlir Outdated
Comment thread mlir/test/Quantum/CtrlTest.mlir
Comment thread mlir/test/Quantum/CtrlTest.mlir Outdated
Comment thread mlir/lib/Quantum/Transforms/CtrlLowering/CtrlLowering.cpp
Comment thread mlir/lib/Quantum/Transforms/CtrlLowering/CtrlLowering.cpp
Comment thread mlir/lib/Quantum/Transforms/CtrlLowering/CtrlLowering.cpp Outdated
@codecov

codecov Bot commented Aug 12, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 96.67%. Comparing base (a227f91) to head (fac801e).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #3089   +/-   ##
=======================================
  Coverage   96.67%   96.67%           
=======================================
  Files         166      166           
  Lines       19171    19171           
  Branches     1822     1822           
=======================================
  Hits        18534    18534           
  Misses        475      475           
  Partials      162      162           

☔ View full report in Codecov by Harness.
📢 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.

@maliasadi
maliasadi requested a review from paul0403 August 12, 2026 17:30

@kipawaa kipawaa left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nice, thanks @maliasadi!

@maliasadi
maliasadi merged commit 74f38d2 into main Aug 12, 2026
37 checks passed
@maliasadi
maliasadi deleted the ctrl-lowering branch August 12, 2026 18:54
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