Skip to content

Conversation

@taminob
Copy link
Collaborator

@taminob taminob commented Jan 15, 2026

Description

While debugging test cases in #1426, I finally figured out why CtrlOp::getBodyUnitary() sometimes returned an invalid UnitaryOpInterface.
Whenever an operation has at least one parameter, the first operation in the modifier's body will be a arith.constant and not the unitary operation like it is currently assumed in the function.

This PR resolves this by iterating over all operations in the body and only returning when the first UnitaryOpInterface operation has been found or there is none.
It affects all crx, crzz, cu, ... operations.

Required for #1426

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.

@taminob taminob self-assigned this Jan 15, 2026
@taminob taminob added bug Something isn't working fix Fix for something that isn't working c++ Anything related to C++ code MLIR Anything related to MLIR labels Jan 15, 2026
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 15, 2026

📝 Walkthrough

Walkthrough

Updated CHANGELOG.md with PR #1464 reference. Modified getBodyUnitary() in both QC and QCO CtrlOp implementations to iterate through body operations instead of assuming the first operation is a UnitaryOpInterface, returning nullptr if none found. Added corresponding test case.

Changes

Cohort / File(s) Summary
Changelog
CHANGELOG.md
Added PR #1464 entry to Unreleased section under MLIR dialect infrastructure items
CtrlOp Implementation
mlir/lib/Dialect/QC/IR/Modifiers/CtrlOp.cpp, mlir/lib/Dialect/QCO/IR/Modifiers/CtrlOp.cpp
Modified getBodyUnitary() to safely iterate over all operations in body region to find first UnitaryOpInterface match, returning nullptr if none exists, instead of directly accessing front operation
QCO CtrlOp Test
mlir/unittests/Dialect/QCO/IR/Modifiers/test_qco_ctrl.cpp
Added new test case bodyUnitaryWithParameter validating getBodyUnitary() retrieval from 2-qubit CRX operation

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Suggested reviewers

  • burgholzer

Poem

🐰 A rabbit's ode to safer bounds:
No more assuming fronts of ops so bright,
We iterate with care through body's height,
Each unitary found gets gentle sight,
Safe nullptr returns make all things right! ✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description check ✅ Passed The PR description covers the problem, solution, and scope; includes required checklist items with most checked as complete. However, the checklist shows documentation, changelog, and upgrade guide items are not fully marked as done, though a changelog entry appears in the raw summary.
Title check ✅ Passed The title clearly identifies the main fix: CtrlOp::getBodyUnitary() handling for operations with parameters, which directly matches the primary change in the changeset.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@codecov
Copy link

codecov bot commented Jan 15, 2026

Codecov Report

❌ Patch coverage is 71.42857% with 2 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
mlir/lib/Dialect/QC/IR/Modifiers/CtrlOp.cpp 66.6% 1 Missing ⚠️
mlir/lib/Dialect/QCO/IR/Modifiers/CtrlOp.cpp 75.0% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

@taminob taminob requested a review from burgholzer January 15, 2026 14:45
@taminob taminob changed the title Fix CtrlOp::getBodyUnitary() for operations with parameters 🐛 Fix CtrlOp::getBodyUnitary() for operations with parameters Jan 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working c++ Anything related to C++ code fix Fix for something that isn't working MLIR Anything related to MLIR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants