Skip to content

✨ Add reusable quantum functions to QC and QCO - #2336

Merged
burgholzer merged 10 commits into
mainfrom
codex/qco-function-model
Sep 3, 2026
Merged

✨ Add reusable quantum functions to QC and QCO#2336
burgholzer merged 10 commits into
mainfrom
codex/qco-function-model

Conversation

@burgholzer

@burgholzer burgholzer commented Sep 2, 2026

Copy link
Copy Markdown
Member

🤖 AI text below 🤖

Description

Add a frontend-neutral function model for reusable quantum helpers:

  • mark unitary func.func definitions with mqt.unitary and represent their calls with qc.call or qco.call;
  • expose complete callback-based function and call APIs in both program builders;
  • use one positional QCO ABI: ordinary results first, then the updated value of each borrowed scalar qubit argument;
  • preserve supported functions and calls across QC/QCO conversion while rejecting representations that would lose information; and
  • treat generic func.call operations as local wire-analysis boundaries, avoiding speculative interprocedural mapping and caches.

The deliberately narrow unitary contract covers gate definitions needed by future OpenQASM, Qiskit, and jeff integrations without result annotations, recursive matrix synthesis, or a new function abstraction. This branch is based directly on main and is independent of #2196 and its stack.

Validation

  • Full Debug and Release C++ suites: 3,840 passed and one expected skip each.
  • uvx nox -s cpp-lint, uvx nox -s lint, and git diff --check passed.
  • Doxygen output retains the full documentation for all 90 generated gate methods in each builder, with no new warnings relative to main. The @file summary is retained.
  • The latest documentation correction changes no non-comment C++ tokens. Existing trailing Doxygen syntax and inline unused-parameter comments are preserved.

Build and C++ lint validation used #2352's dependency and test-RPATH fixes as a temporary local overlay. That overlay was removed afterward and is not part of this PR; both PRs remain based on main.

Codex assisted with implementation, documentation restoration, and local validation.

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.

@burgholzer
burgholzer force-pushed the codex/qco-function-model branch from 7773ec8 to 4982de2 Compare September 2, 2026 23:32
@burgholzer burgholzer added c++ Anything related to C++ code Core Anything related to the Core library and IR feature New feature or request MLIR Anything related to MLIR labels Sep 2, 2026
@codecov

codecov Bot commented Sep 2, 2026

Copy link
Copy Markdown

@burgholzer burgholzer self-assigned this Sep 2, 2026
@burgholzer burgholzer added this to the v4.0.0 - IEEE Quantum Week milestone Sep 2, 2026
@burgholzer
burgholzer force-pushed the codex/qco-function-model branch from 4982de2 to 30ea067 Compare September 3, 2026 00:20
@burgholzer burgholzer removed their assignment Sep 3, 2026
@burgholzer

Copy link
Copy Markdown
Member Author

@MatthiasReumann @DRovara I haven't looked through all the details here yet, but this PR may be interesting for the both of you.
Matthias, it addresses some of the concerns that you may have had on the WireIterator call handling.
Damian, this was mostly inspired by the lack of any production user/consumers of the IPO passes and multiple function handling. This triggered me, which eventually led to the implementation here which feels quite nice already and actually rather close to some of the things we also had in the original RFC for the dialect rewrite but never got to so far. I plan to add the respect new capabilities to all the supported formats in follow-up PRs.
This is more so an FYI than a call for action.

Comment thread mlir/lib/Dialect/QCO/Utils/FunctionUtils.cpp
@burgholzer burgholzer self-assigned this Sep 3, 2026
@burgholzer
burgholzer force-pushed the codex/qco-function-model branch from ad32279 to d2e592b Compare September 3, 2026 11:05
@coderabbitai

coderabbitai Bot commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

Important

Approval pending

CodeRabbit has no unresolved comments, but it has not reviewed the latest commit.

Use the checkbox below to review the latest commit. CodeRabbit will approve the changes if it finds no blocking issues.

  • 🔍 Trigger review

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.

@DRovara DRovara left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Awesome, this looks pretty cool. I like the idea of the unitary marker for unitary functions.

I have to admit I am a bit behind and still haven't fully grasped the idea behind the MQT dialect here (unitary functions aren't necessarily MQT-exclusive), but I also understand just having that as a joint source to avoid duplication.

I have a few minor comments and one major concern regarding the IPO passes, where we will have to think of some solution.

Comment thread mlir/lib/Dialect/MQT/IR/MQTDialect.cpp Outdated
Comment thread mlir/lib/Dialect/MQT/IR/MQTDialect.cpp
Comment thread mlir/include/mlir/Dialect/QCO/Utils/WireIterator.h
@mergify mergify Bot added the conflict label Sep 3, 2026
burgholzer and others added 9 commits September 3, 2026 19:31
Assisted-by: GPT-5.6 via Codex
Adopt a trailing positional qubit-result ABI for reusable QCO functions. Add direct unitary calls, builder support, and loss-minimizing QC/QCO conversion in both directions.

Treat generic calls as local wire-analysis boundaries and remove the speculative interprocedural qubit and tensor mapping caches.

Assisted-by: GPT-5.6 via Codex
Resolve the hosted clang-tidy findings and exercise the unitary function, call, trace, and conversion rejection contracts missing from patch coverage.

Assisted-by: GPT-5.6 via Codex
Resolve the entry function through mqt.entry_point so both builders can finalize modules whose entry symbol was renamed.

Assisted-by: GPT-5.6 via Codex
Reuse the QC-to-QCO register materialization path for unitary and generic calls, including calls nested in converted modifier regions.

Assisted-by: GPT-5.6 via Codex
Add verified source-name metadata for function symbols that must be uniquified, and preserve it across QC/QCO conversion.

Assisted-by: GPT-5.6 via Codex
Follow the current C++ naming and comment guidance, add reusable function programs to compiler and QC/QCO round-trip coverage, and keep local C++ lint diagnostics visible.

Assisted-by: GPT-5.6 via Codex
Drop trivial qubit predicates and document that iterator clients own callee traversal. Keep the recursion guard because straight-line unitary call cycles remain possible.

Verify nested operations before querying their interfaces, reject empty unitary bodies and cyclic SSA qubit flow, and cover malformed downstream calls with regression tests.

Assisted-by: GPT-5.6 via Codex
@burgholzer
burgholzer force-pushed the codex/qco-function-model branch from d2e592b to 1a68140 Compare September 3, 2026 21:05
@mergify mergify Bot removed the conflict label Sep 3, 2026
Preserve gate documentation in continued macros, trailing Doxygen member
comments, file summaries, and inline unused parameter names. Clarify the
comment policy without changing program behavior.

Assisted-by: Codex
@burgholzer

Copy link
Copy Markdown
Member Author

Alright, I believe this is as clean as it gets for now. Tagging this for auto-merge so that the other depending PRs can be updated over night.

@burgholzer
burgholzer enabled auto-merge (squash) September 3, 2026 22:05
@burgholzer
burgholzer merged commit f57b6c3 into main Sep 3, 2026
26 checks passed
@burgholzer
burgholzer deleted the codex/qco-function-model branch September 3, 2026 22:20
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 Core Anything related to the Core library and IR feature New feature or request MLIR Anything related to MLIR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants