Skip to content

✨ Add DD buildFunctionality/simulate for static QCO funcs#1915

Open
simon1hofmann wants to merge 11 commits into
mainfrom
feat/dd-qco-functionality
Open

✨ Add DD buildFunctionality/simulate for static QCO funcs#1915
simon1hofmann wants to merge 11 commits into
mainfrom
feat/dd-qco-functionality

Conversation

@simon1hofmann

@simon1hofmann simon1hofmann commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

🤖 AI text below 🤖

Description

Add QCO-native DD construction so static unitary func.func programs can build a matrix DD / simulate a statevector without round-tripping through qc::QuantumComputation.

  • New mlir::qco::buildFunctionality / simulate in DDFunctionality.h
  • Sparse path for standard gates / simple ctrl; dense path for inv, compound ctrl, etc., with QCO MSB → DD LSB basis conversion
  • Wire mapping via qco.static, or qubit block args 0..n-1 when no static ops (synthesis helpers)
  • Rejects measurements and other non-unitary / unsupported ops; gphase and barrier supported
  • Unit tests vs classic dd::{buildFunctionality,simulate}; Weyl reconstruction tests reuse the new API

Fixes #1913

AI Assistance

Used Composer 2.5 and Grok 4.5 via Cursor for parts of this change. I reviewed the full
diff and take responsibility for everything in this PR.

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).
  • AI-assisted commits include an Assisted-by: [Model Name] via [Tool Name] footer.
  • I confirm that I have personally reviewed and understood all AI-generated content, and accept full responsibility for it.

@simon1hofmann simon1hofmann self-assigned this Jul 17, 2026
@simon1hofmann simon1hofmann added DD Anything related to the DD package c++ Anything related to C++ code enhancement Improvement of existing feature MLIR Anything related to MLIR labels Jul 17, 2026
@simon1hofmann simon1hofmann added this to the MLIR Support milestone Jul 17, 2026
…ulate` for static unitary QCO `func.func` programs
@codecov

codecov Bot commented Jul 17, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@simon1hofmann

Copy link
Copy Markdown
Contributor Author

@coderabbitai full review

@coderabbitai

coderabbitai Bot commented Jul 17, 2026

Copy link
Copy Markdown
Contributor
✅ Action performed

Full review finished.

@coderabbitai

coderabbitai Bot commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

The PR adds DD-based construction and simulation for supported MLIR QCO functions, including qubit mapping, gate and matrix application, validation, build integration, and tests. Weyl decomposition tests now use the new DD functionality API.

Changes

QCO DD functionality

Layer / File(s) Summary
Public API and build wiring
mlir/include/mlir/Dialect/QCO/Utils/DDFunctionality.h, mlir/lib/Dialect/QCO/Utils/CMakeLists.txt, mlir/unittests/Dialect/QCO/**/CMakeLists.txt
Declares buildFunctionality and simulate, and links the required QCO matrix and DD libraries.
DD functionality implementation
mlir/lib/Dialect/QCO/Utils/DDFunctionality.cpp
Maps SSA qubits, decodes standard gates, applies matrices and controls, walks single-block functions, and returns DD matrices or vectors with failure handling.
Validation and adoption
mlir/unittests/Dialect/QCO/Utils/test_dd_functionality.cpp, mlir/unittests/Dialect/QCO/Transforms/Decomposition/test_weyl_decomposition.cpp, CHANGELOG.md
Adds positive and negative DD tests, updates Weyl decomposition to use DD functionality, and adds the PR changelog reference.

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant QCOFunction
  participant DDFunctionality
  participant DDPackage
  QCOFunction->>DDFunctionality: Provide MLIR function
  DDFunctionality->>DDFunctionality: Prepare mapping and walk operations
  DDFunctionality->>DDPackage: Apply gates or matrices
  DDPackage-->>DDFunctionality: Return DD result
Loading

Suggested labels: feature

Suggested reviewers: burgholzer

Poem

I’m a rabbit with qubits in rows,
DD matrices where each pathway flows.
Gates hop and phases gleam,
Tests chase failures through the dream.
With ears up high, the wires align—
A tidy quantum trail by design!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 9.09% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed The PR implements direct DD functionality construction and simulation for static QCO func.funcs, matching the goals of #1913.
Out of Scope Changes check ✅ Passed The touched changelog, build files, and tests all support the new DD functionality and do not indicate unrelated scope creep.
Title check ✅ Passed The title clearly summarizes the main change: adding DD build and simulate support for static QCO funcs.
Description check ✅ Passed The description matches the template with a summary, issue reference, AI assistance note, and checklist.
✨ Finishing Touches
✨ Simplify code
  • Create PR with simplified code
  • Commit simplified code in branch feat/dd-qco-functionality

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.

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@mlir/lib/Dialect/QCO/Utils/DDFunctionality.cpp`:
- Around line 101-147: Add parameterized end-to-end semantic parity tests for
every gate handled by decodeStandardGate’s TypeSwitch, comparing QCO behavior
against QC behavior. Include all single- and multi-parameter mappings,
explicitly covering ROp, U2Op, UOp, XXPlusYYOp, and XXMinusYYOp with parameter
ordering validated. Ensure the cases cover every listed gate branch so enum or
decoding discrepancies are detected.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 10dd01db-048b-4134-aad9-73e61c70d6e6

📥 Commits

Reviewing files that changed from the base of the PR and between faa77a7 and 69354d5.

📒 Files selected for processing (8)
  • CHANGELOG.md
  • mlir/include/mlir/Dialect/QCO/Utils/DDFunctionality.h
  • mlir/lib/Dialect/QCO/Utils/CMakeLists.txt
  • mlir/lib/Dialect/QCO/Utils/DDFunctionality.cpp
  • mlir/unittests/Dialect/QCO/Transforms/Decomposition/CMakeLists.txt
  • mlir/unittests/Dialect/QCO/Transforms/Decomposition/test_weyl_decomposition.cpp
  • mlir/unittests/Dialect/QCO/Utils/CMakeLists.txt
  • mlir/unittests/Dialect/QCO/Utils/test_dd_functionality.cpp

Comment thread mlir/lib/Dialect/QCO/Utils/DDFunctionality.cpp
@simon1hofmann

Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jul 17, 2026

Copy link
Copy Markdown
Contributor
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@simon1hofmann
simon1hofmann marked this pull request as ready for review July 17, 2026 14:05
@simon1hofmann
simon1hofmann requested a review from denialhaag July 17, 2026 14:11

@denialhaag denialhaag 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.

Really cool to see this application of the QCO matrices! Thanks, @simon1hofmann! 🙂

This already looks good to me! I only have some minor comments, which you can find below.

Comment thread mlir/include/mlir/Dialect/QCO/Utils/DDFunctionality.h Outdated
Comment thread mlir/lib/Dialect/QCO/Utils/DDFunctionality.cpp Outdated
Comment thread mlir/lib/Dialect/QCO/Utils/DDFunctionality.cpp Outdated
Comment thread mlir/lib/Dialect/QCO/Utils/DDFunctionality.cpp
Comment thread mlir/lib/Dialect/QCO/Utils/DDFunctionality.cpp
Comment thread mlir/unittests/Dialect/QCO/Utils/test_dd_functionality.cpp Outdated
Comment thread mlir/unittests/Dialect/QCO/Utils/test_dd_functionality.cpp Outdated
Comment thread mlir/unittests/Dialect/QCO/Utils/test_dd_functionality.cpp
Comment thread mlir/unittests/Dialect/QCO/Utils/test_dd_functionality.cpp Outdated
Comment thread mlir/unittests/Dialect/QCO/Utils/test_dd_functionality.cpp Outdated
simon1hofmann and others added 3 commits July 17, 2026 20:03
Co-authored-by: Daniel Haag <121057143+denialhaag@users.noreply.github.com>
Signed-off-by: simon1hofmann <119581649+simon1hofmann@users.noreply.github.com>
@simon1hofmann

Copy link
Copy Markdown
Contributor Author

Really cool to see this application of the QCO matrices! Thanks, @simon1hofmann! 🙂

This already looks good to me! I only have some minor comments, which you can find below.

Thanks a lot for the review 🙏
I applied all you suggestions besides one (see the last unresolved comment).

@simon1hofmann
simon1hofmann requested a review from denialhaag July 17, 2026 19:00

@denialhaag denialhaag 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.

Thanks for adressing my comments! 🙂 This LGTM now!

I'll tag @burgholzer for a final review.

@denialhaag
denialhaag requested a review from burgholzer July 17, 2026 21:48
@mergify mergify Bot added the conflict label Jul 19, 2026
Signed-off-by: simon1hofmann <119581649+simon1hofmann@users.noreply.github.com>
@mergify mergify Bot removed the conflict label Jul 20, 2026
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 DD Anything related to the DD package enhancement Improvement of existing feature MLIR Anything related to MLIR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

✨ DD functionality construction / simulation for MLIR QCO programs

2 participants