Skip to content

✨ Add a pass cancelling self-inverse gates across call boundaries - #2200

Open
DRovara wants to merge 1 commit into
mlir/auxiliary-qubit-hoistingfrom
mlir/function-boundary-commutation
Open

✨ Add a pass cancelling self-inverse gates across call boundaries#2200
DRovara wants to merge 1 commit into
mlir/auxiliary-qubit-hoistingfrom
mlir/function-boundary-commutation

Conversation

@DRovara

@DRovara DRovara commented Aug 20, 2026

Copy link
Copy Markdown
Collaborator

🤖 AI text below 🤖

Description

Seventh of a stack replacing #1970. Builds on #2199.

quantum-function-boundary-commutation drops a self-inverse gate applied right before a call when the callee starts by applying the same gate to that argument. The caller-side gate is erased and the call is redirected to a copy of the callee without the callee-side one.

Copies are cached per callee and parameter index. The gate removed inside the copy belongs to one specific argument, so sharing a copy between parameters would drop a gate the second call site never had — that was a miscompile in the original PR, keyed only by callee name.

Testing

5 cases in test_qco_function_boundary_commutation.cpp, scheduled on this pass alone: the cancellation itself, specialization reuse across call sites, a separate specialization per parameter, and the cases that must not cancel (different gates, controlled gates).

I also ran a whole-library unity-build check here, compiling all 19 sources of MLIRQCOTransforms as one translation unit — clean. This and #2197 both touch the shared copyFunction helper, and a duplicate static definition in that area broke the docs build during the original PR.

optimizations 170.

AI assistance

Code and this description were produced with Claude Code (Opus 5) and Codex, acting on my instructions and within the scope I authorized.

Checklist

  • The pull request only contains commits that are focused and relevant to this change.
  • I have added appropriate tests that cover the new/changed functionality.
  • I have updated the documentation to reflect these changes.
  • I have added entries to the changelog for any noteworthy additions, changes, fixes, or removals.
  • I have added migration instructions to the upgrade guide (if needed).
  • The changes follow the project's style guidelines and introduce no new warnings.
  • The changes are fully tested and pass the CI checks.
  • I have reviewed my own code changes.

If PR contains AI-assisted content:

  • Any agent that created, edited, or submitted GitHub content was explicitly authorized for that scope, as required by our AI Usage Guidelines.
  • Every agent-authored or agent-edited public text body begins with the visible disclosure 🤖 *AI text below* 🤖 (titles are exempt).
  • I have disclosed AI assistance in the PR description.
  • I confirm that I have personally reviewed and understood all AI-generated content, and accept full responsibility for it.

@DRovara
DRovara force-pushed the mlir/function-boundary-commutation branch 2 times, most recently from c1e0255 to 74f14e1 Compare August 24, 2026 09:33
@DRovara
DRovara force-pushed the mlir/function-boundary-commutation branch from 74f14e1 to df6be2d Compare August 24, 2026 09:52
@codecov

codecov Bot commented Aug 24, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 93.33333% with 4 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
...timizations/QuantumFunctionBoundaryCommutation.cpp 93.2% 4 Missing ⚠️

📢 Thoughts on this report? Let us know!

@DRovara
DRovara force-pushed the mlir/function-boundary-commutation branch 2 times, most recently from 78260b5 to be8d787 Compare August 25, 2026 08:02
@DRovara
DRovara force-pushed the mlir/function-boundary-commutation branch from be8d787 to d0f1678 Compare August 25, 2026 10:48
@burgholzer
burgholzer force-pushed the mlir/function-boundary-commutation branch from d0f1678 to 6c11286 Compare August 25, 2026 21:44
@DRovara
DRovara force-pushed the mlir/function-boundary-commutation branch 2 times, most recently from 529efe4 to 5c497cf Compare August 26, 2026 14:11
@DRovara
DRovara force-pushed the mlir/function-boundary-commutation branch from 5c497cf to 65aae9c Compare August 26, 2026 14:34
@DRovara
DRovara marked this pull request as ready for review August 26, 2026 14:37
@DRovara
DRovara force-pushed the mlir/function-boundary-commutation branch from 65aae9c to a8a3d80 Compare August 27, 2026 11:40
@DRovara
DRovara force-pushed the mlir/function-boundary-commutation branch 2 times, most recently from 0c2aa0c to 217cabf Compare August 28, 2026 07:28
@DRovara
DRovara force-pushed the mlir/function-boundary-commutation branch from 217cabf to 0fc6a4f Compare August 28, 2026 08:11
@burgholzer
burgholzer force-pushed the mlir/function-boundary-commutation branch from 0fc6a4f to 6615c42 Compare August 28, 2026 12:30
@burgholzer burgholzer added feature New feature or request c++ Anything related to C++ code MLIR Anything related to MLIR labels Aug 28, 2026
Commute compatible operations across function boundaries and cover the call-site rewrites.

Assisted-by: Claude Opus 5 <noreply@anthropic.com>

Assisted-by: Codex
@burgholzer
burgholzer force-pushed the mlir/function-boundary-commutation branch from 6615c42 to d5ab43e Compare August 30, 2026 14:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

c++ Anything related to C++ code feature New feature or request MLIR Anything related to MLIR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants