Skip to content

♻️ Define target compilation with payload specifications - #2219

Merged
simon1hofmann merged 11 commits into
mainfrom
codex/selected-payload-environment
Sep 8, 2026
Merged

simon1hofmann merged 11 commits into
mainfrom
codex/selected-payload-environment

Conversation

@burgholzer

@burgholzer burgholzer commented Aug 23, 2026

Copy link
Copy Markdown
Member

🤖 AI text below 🤖

Lead: @simon1hofmann. Cross-repository coordination: @burgholzer.

Description

Keep the compiler-only selected-program capability prototype independent of QDMI runtime adoption. Typed metadata and a cached target-environment analysis connect target selection to compilation without requiring unreleased QDMI APIs.

Compiler workstream: main → #2219#2162. QDMI adaptation remains the separate integration PR #2227. This compiler-only work targets Core 4.0, subject to Simon's compiler contract review and current CI. It does not require QDMI 1.4 or approval of the later QDMI metadata contract. #2131 tracks compiler requirements; #2365 coordinates the separate Core 4.1/QDMI 1.4 adaptation.

Retain the compiler behavior already released onto main through #2218/#2323/#2215: unknown topology or gate sets fail during inference, variadic controlled DDSIM gates and zero-arity global phase remain supported, and placement/decomposition retain their validated target. No driver replacement, batching or metadata cleanup is included.

Local validation

  • Independent release build and CTest: 3,879 passed, one existing optional-device skip.
  • Targeted Python compiler/QDMI tests: 558 passed.
  • Stub generation, repository lint and full changed-file C++ lint passed.
  • Hosted CI must be checked separately on this final head.

AI-assisted restructuring; human design review remains required.

Compiler contract review

Model the capabilities of the selected program/target combination rather than assuming a format's full language is executable. Keep the initial feature vocabulary bounded and informed by OpenQASM and QIR. Validate representative benchmark targets without requiring a QDMI 1.4 device. The later QDMI adapter may expose only a subset until its independent contract is ready.

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 added feature New feature or request c++ Anything related to C++ code python Anything related to Python code MLIR Anything related to MLIR QDMI Anything related to QDMI labels Aug 23, 2026
@burgholzer burgholzer self-assigned this Aug 23, 2026
@burgholzer
burgholzer force-pushed the codex/selected-payload-environment branch from b53e303 to c62e088 Compare August 23, 2026 19:10
@codecov

codecov Bot commented Aug 23, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 93.11295% with 25 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
mlir/tools/mqt-cc/mqt-cc.cpp 76.7% 13 Missing ⚠️
mlir/lib/Compiler/TargetEnvironment.cpp 93.4% 12 Missing ⚠️

📢 Thoughts on this report? Let us know!

@burgholzer burgholzer left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This one will likely still need a bit of work to iron out the details.

Comment thread .agent/plans/selected-payload-target-environment.md Outdated
Comment thread .agent/plans/selected-payload-target-environment.md Outdated
Comment thread .agent/plans/selected-payload-target-environment.md Outdated
Comment thread bindings/mlir/register_mlir.cpp
Comment thread docs/mlir/target_compilation.md Outdated
@mergify mergify Bot added the conflict label Aug 24, 2026
@burgholzer
burgholzer force-pushed the codex/selected-payload-environment branch from ae5b72f to b0dd192 Compare August 24, 2026 13:31
@burgholzer burgholzer changed the title ✨ Select exact payload environments for target compilation ♻️ Define target compilation with payload specifications Aug 24, 2026
@burgholzer burgholzer removed QDMI Anything related to QDMI conflict labels Aug 24, 2026
@coderabbitai

coderabbitai Bot commented Aug 24, 2026

Copy link
Copy Markdown
Contributor

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.

@burgholzer

Copy link
Copy Markdown
Member Author

This looks much cleaner now. And should also be ready.

@burgholzer
burgholzer force-pushed the codex/selected-payload-environment branch from bb0240b to 28284fa Compare August 24, 2026 23:47
@burgholzer

Copy link
Copy Markdown
Member Author

@simon1hofmann @denialhaag any feedback on this one from your side?
I looked through this yesterday night already and it looked pretty clean to me.

@simon1hofmann

Copy link
Copy Markdown
Contributor

@simon1hofmann @denialhaag any feedback on this one from your side? I looked through this yesterday night already and it looked pretty clean to me.

Going through this now and will provide feedback in around 15min.

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

Also went through the changes here and they look really clean 👍

@mergify mergify Bot removed the conflict label Sep 7, 2026
@simon1hofmann
simon1hofmann marked this pull request as ready for review September 7, 2026 13:13

@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 the continued improvements, @simon1hofmann! 🙂 Overall, this looks pretty good to me. I only have a few remarks:

Comment thread mlir/include/mlir/Compiler/TargetEnvironment.h
Comment thread mlir/include/mlir/Compiler/TargetEnvironment.h Outdated
Comment thread mlir/include/mlir/Compiler/TargetEnvironment.h
Comment thread mlir/include/mlir/Dialect/MQT/IR/MQTDialect.td
Comment thread mlir/include/mlir/Dialect/QCO/Transforms/Passes.h Outdated
Comment thread mlir/lib/Dialect/MQT/IR/MQTDialect.cpp
Comment thread mlir/unittests/Compiler/test_compiler_pipeline.cpp Outdated
burgholzer and others added 10 commits September 8, 2026 15:25
Record complete compiler-target facts and one exact payload execution contract as typed module metadata.

Assisted-by: GPT-5.6 Sol via Codex
Represent the selected hardware target and payload specification as one validated target environment. Cache that value through the MLIR analysis manager for mapping, native synthesis, and conformance.

Derive targeted compiler output from the selected payload format in the C++, Python, and mqt-cc APIs. Keep untargeted output selection independent.

Assisted-by: GPT-5.6 Sol via Codex
Declare the dialect used by runtime-angle synthesis and cover a fresh context that does not preload it.

Assisted-by: GPT-6 via Codex
Zero-fill omitted numeric components at the payload snapshot boundary. Accept the same syntax in typed MLIR and keep compiler output selection exact.

Assisted-by: GPT-6 via Codex
Use DDSIM for executable QIR examples and state the environment required by the C++ pipeline builder.

Assisted-by: GPT-6 via Codex
Co-authored-by: Daniel Haag <121057143+denialhaag@users.noreply.github.com>
Signed-off-by: simon1hofmann <119581649+simon1hofmann@users.noreply.github.com>
Assisted-by: OpenAI via Codex
Preserve upstream regressions after rebasing onto main by using the existing target-environment helpers.

Assisted-by: OpenAI via Codex
@simon1hofmann
simon1hofmann force-pushed the codex/selected-payload-environment branch from 245a55f to 8a050a0 Compare September 8, 2026 13:34
@mergify mergify Bot removed the conflict label Sep 8, 2026

@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 addressing all of my comments, @simon1hofmann! I'll leave the final comment open for now, but I'll not die on that hill; you can resolve it whenever we have come to any conclusion. I'm approving for now. Feel free to request another review if there are new changes I can have a look at! 🙂

@simon1hofmann

Copy link
Copy Markdown
Contributor

Also looks good to me, will leave the final check to @burgholzer before merging.

@burgholzer

Copy link
Copy Markdown
Member Author

I'll tackle this one next

Make the pipeline take one environment and reuse its prepared target in the
cached analysis. Standalone passes decode the typed pair on demand. Remove
the unused DLTI extension and query layer.

Assisted-by: GPT-6 via Codex

@burgholzer burgholzer left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I ran this through another iteration with the goal of simplifying the implementation, which was pretty successful I believe.
I'd vote for getting this in now and looking at the fallout in subsequent audits until the release.

Comment thread mlir/include/mlir/Compiler/TargetEnvironment.h
@simon1hofmann
simon1hofmann merged commit 784519c into main Sep 8, 2026
26 checks passed
@simon1hofmann
simon1hofmann deleted the codex/selected-payload-environment branch September 8, 2026 19:13
simon1hofmann added a commit that referenced this pull request Sep 9, 2026
Move the #2162 reference beside #2219 and describe payload-aware
control-flow legalization in the existing target-compilation entry.

Assisted-by: OpenAI Codex
burgholzer added a commit that referenced this pull request Sep 9, 2026
* ✨ Legalize control flow for selected payloads

Use stock MLIR normalization, bounded static loop unrolling, and dialect conversion to match residual structured control flow to the selected payload specification.

Co-authored-by: Simon Hofmann <simon.t.hofmann@tum.de>

Assisted-by: GPT-5.6 Sol via Codex

* ♻️ Remove redundant modifier legality exemptions

QCO modifiers do not implement branch interfaces, so the existing fallback already accepts them.

Assisted-by: GPT-6 via Codex

* 📝 Align control flow release scope

Preserve the capability snapshot while distinguishing Core 4.0 compiler review from the separate QDMI 1.4 adaptation.

Assisted-by: GPT-6 via Codex

* ♻️ Simplify structured payload legalization

Use native static trip counts while retaining literal-bound proofs and full
unroll safety limits. Accept single-case switches with multiway support.
Require structured input at pipeline entry and remove CFG lifting and the
redundant cleanup after control legalization.

Assisted-by: GPT-6 via Codex

* ♻️ Validate loop inputs before legalization

Check the supported SCF loop input form at both pass entry points, so
loop legalization can rely on explicit iteration arguments. Keep branch
checks after unrolling and leave the QCO linearity contract unchanged.

Assisted-by: OpenAI Codex

* ♻️ Clarify control-flow pass names

Keep payload-loop unrolling separate from residual control-flow checks
so constant propagation and QCO cleanup can run between them. Leave the
factor-based quantum-loop optimization unchanged.

Assisted-by: OpenAI Codex

* ♻️ Centralize control-flow capability IDs

Keep the compiler snapshot identifiers beside ProgramCapability and
ProgramConstraint so producers and legalization share their spellings.
Do not depend on the draft QDMI capability API.

Assisted-by: OpenAI Codex

* 🧪 Keep control fixtures allocation-independent

Exercise control-flow rejection with valid quantum inputs and remove unrelated quantum operations from classical fixtures.

Assisted-by: OpenAI Codex

* 🐛 Check the width of fully unrolled loop steps

Reject signed step truncation before native unrolling mutates the loop. Preserve safe signed and unsigned narrow-integer loops, and check their observed induction values.

Assisted-by: OpenAI Codex

* 🐛 Bound switch expansion before rewriting

Check payload depth and a compiler nesting ceiling before moving case regions. Build accepted chains iteratively and retain native multiway switches. Cover expansion boundaries, moved control, state selection, and cumulative loop cloning.

Assisted-by: OpenAI Codex

* ♻️ Reuse native trivial-loop promotion

Reuse the native zero/one-trip utility, apply required C++ initializer style, and replace stale local handoff notes with scoped validation. Keep the switch safety comment purely technical.

Assisted-by: OpenAI Codex

* 🧪 Exercise payload limits through frontends

Replace three handwritten positive fixtures with OpenQASM imports and
test a live Qiskit classical switch against selected capabilities.
Keep the focused raw-MLIR safety regressions and production contract
unchanged.

Assisted-by: OpenAI Codex

* 📝 Group payload legalization with target compilation

Move the #2162 reference beside #2219 and describe payload-aware
control-flow legalization in the existing target-compilation entry.

Assisted-by: OpenAI Codex

* 🐛 Legalize empty and unsigned counted loops

Reuse LLVM's state and induction-value remapping for terminator-only
loops within the existing clone budget. Zero-extend unsigned bounds
before checking whether full unrolling is safe.

Add frontend state-permutation and direct induction-value regressions,
and cover unsigned bounds above the signed range of their type.

Assisted-by: GPT-6 via Codex

---------

Co-authored-by: Lukas Burgholzer <burgholzer@me.com>
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 python Anything related to Python code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants