Skip to content

♻️ Generalize MLIR compiler target facts - #2218

Open
burgholzer wants to merge 6 commits into
mainfrom
codex/generalize-compiler-target
Open

♻️ Generalize MLIR compiler target facts#2218
burgholzer wants to merge 6 commits into
mainfrom
codex/generalize-compiler-target

Conversation

@burgholzer

@burgholzer burgholzer commented Aug 23, 2026

Copy link
Copy Markdown
Member

🤖 AI text below 🤖

Description

Generalize the unreleased MLIR compiler target contract before serializing it in mqt.target_env.

  • Distinguish unknown, unrestricted, and explicit connectivity and native-operation facts.
  • Use site and operation-arity vocabulary throughout the C++ and Python APIs.
  • Make mapping, synthesis, and conformance request facts only when the residual program needs them.
  • Keep missing QDMI topology or operation applicability unknown instead of granting support.
  • Preserve cheap CompilerTarget copies and move target metadata into immutable storage.

This is the context-free target prerequisite for #2215. It deliberately does not add payload capabilities or depend on the WIP QDMI v1.4 API.

Validation:

  • Compiler unit tests: 131 passed.
  • Mapping unit tests: 83 passed.
  • Native-synthesis unit tests: 24 passed.
  • Focused Python tests: 223 passed.
  • Generated stubs are current.
  • Focused clang-tidy, uvx nox -s lint, and git diff --check pass.

Implementation and pull-request text were prepared with OpenAI Codex.

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 refactor Anything related to code refactoring c++ Anything related to C++ code python Anything related to Python code MLIR Anything related to MLIR labels Aug 23, 2026
@burgholzer burgholzer self-assigned this Aug 23, 2026
@codecov

codecov Bot commented Aug 23, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 92.30769% with 12 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
mlir/lib/Compiler/Target.cpp 88.9% 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 feels close to ready.

Comment thread docs/qdmi/ddsim_device.md Outdated
Comment thread docs/qdmi/ddsim_device.md Outdated
Comment thread mlir/include/mlir/Compiler/Target.h Outdated
Comment thread mlir/include/mlir/Compiler/Target.h Outdated
Comment thread mlir/include/mlir/Compiler/Target.h Outdated
@coderabbitai

coderabbitai Bot commented Aug 24, 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.

@burgholzer
burgholzer force-pushed the codex/generalize-compiler-target branch from 9b961b2 to 8fafa97 Compare August 24, 2026 13:52
@mergify mergify Bot added the conflict label Aug 24, 2026
burgholzer and others added 6 commits August 24, 2026 23:33
Represent unknown, unrestricted, and explicit connectivity and native-operation facts separately. Use site and arity vocabulary, and make target passes request facts only when needed.

Assisted-by: OpenAI Codex
Keep unavailable QDMI v1.3 properties unknown while preserving the compile-and-execute integration with explicit simulator capabilities.

Assisted-by: OpenAI Codex
Replace ordered sets with the project's LLVM containers and in-place canonicalization.

Assisted-by: OpenAI Codex
Copy public collection views into compact LLVM storage and document the explicit DDSIM synthesis basis used until QDMI v1.4 reports all-to-all connectivity.

Assisted-by: GPT-5.6 Sol via Codex
@burgholzer
burgholzer force-pushed the codex/generalize-compiler-target branch from 8fafa97 to a6f7fd1 Compare August 24, 2026 23:47

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

I just had a free minute to go through this, and it looks really clean to me! :shipit:

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

This also looks quite good, just a few comments about the documentation and two concerns flagged by another LLM review run.

```

Use `CompilerTarget.Connectivity.all_to_all()` for an all-to-all target. An
empty `CompilerTarget.NativeOperations([])` means that no operation is native.

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.

Does that mean native synthesis is not called at all? Should we add an example for a target with a specific set of native operations?

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'd rather argue that "no operation is native" is a misconfiguration as this essentially means that you cannot compile to the target (it lacks an ISA).
Maybe this part of the documentation should make this more explicit (and the code should likely fail early on such targets)

Comment thread docs/qdmi/ddsim_device.md
target = CompilerTarget(
device.qubits_num(),
connectivity=CompilerTarget.Connectivity.all_to_all(),
native_operations=CompilerTarget.NativeOperations([

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.

An example like this in target_compilation.md.

Comment thread docs/qdmi/ddsim_device.md
CompilerTarget.Operation("u", 1, 3),
CompilerTarget.Operation("cx", 2, 0),
CompilerTarget.Operation("measure", 1, 0),
CompilerTarget.Operation("reset", 1, 0),

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.

Is it clear/explained somewhere what the second and third argument in Operation represent?

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.

Likely no really. Maybe it would help to add keyword arguments here in the docs to make this more explicit.

"""
target = CompilerTarget.from_device(ddsim_device)
target = CompilerTarget(
ddsim_device.qubits_num(),

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.

Unrelated to this PR, but is there any reason why it is called qubits_num and not num_qubits?

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.

None that I could think of. We can happily rename consistently.

signalPassFailure();
return;
}
if (comp->hasTwoQubitOperations &&

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.

This permits unknown connectivity without two-qubit gates, but control-flow reconciliation still queries topology at Mapping.cpp:899-908, reaching the fatal branch at Target.cpp:753-758.

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.

Thanks for pointing that out. We should definitely fix this!

const std::optional<uint64_t> duration,
const std::optional<double> fidelity) {
std::set<SiteId> uniqueSites;
llvm::SmallDenseSet<SiteId> uniqueSites;

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.

This stores nonnegative int64_t IDs in SmallDenseSet, whose sentinel values overlap the advertised domain (INT64_MAX, and on LP64 also INT64_MAX-1)

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.

Thanks. I think we could be limiting the sites to 32bits. IIRC site IDs should also be non-negative (might be worth double-checking).
Reducing to 32-bits may even increase efficiency throughout the implementation.

@burgholzer

Copy link
Copy Markdown
Member Author

Thanks @denialhaag and @simon1hofmann 🙏🏼
Given how this is at the very bottom of an 11 PR stack, I'd like to only touch this once more and freeze the implementation afterwards. Are there any further comments on the above from your side?
Quick signal would be good. Then I'll kick off the implementation and the rebase.

@simon1hofmann

Copy link
Copy Markdown
Contributor

Thanks @denialhaag and @simon1hofmann 🙏🏼

Given how this is at the very bottom of an 11 PR stack, I'd like to only touch this once more and freeze the implementation afterwards. Are there any further comments on the above from your side?

Quick signal would be good. Then I'll kick off the implementation and the rebase.

Thanks for addressing my comments, I agree with all your answers.

@denialhaag

Copy link
Copy Markdown
Member

Thanks @denialhaag and @simon1hofmann 🙏🏼
Given how this is at the very bottom of an 11 PR stack, I'd like to only touch this once more and freeze the implementation afterwards. Are there any further comments on the above from your side?
Quick signal would be good. Then I'll kick off the implementation and the rebase.

Thanks for addressing my comments, I agree with all your answers.

Go also from my side!

@mergify mergify Bot added the conflict label Aug 26, 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 conflict MLIR Anything related to MLIR python Anything related to Python code refactor Anything related to code refactoring

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants