Skip to content

✨ Expose native target mapping controls - #2551

Open
simon1hofmann wants to merge 10 commits into
mainfrom
feat/target-mapping-controls
Open

✨ Expose native target mapping controls#2551
simon1hofmann wants to merge 10 commits into
mainfrom
feat/target-mapping-controls

Conversation

@simon1hofmann

@simon1hofmann simon1hofmann commented Sep 12, 2026

Copy link
Copy Markdown
Contributor

🤖 AI text below 🤖

Description

Add shared CompilationOptions for timing, statistics, a compilation-wide seed,
and native mapping trials, refinement iterations, and routing lookahead. C++,
Python, and mqt-cc use the same controls through target compilation, synthesis,
custom pass pipelines, and QDMI source submission.
Compiler settings are accepted only through CompilationOptions; separate
timing/statistics arguments are removed.

An explicit seed controls Core's mapper, Pauli twirling, and numerical synthesis
retries. It overrides pass-local seeds, including nested pipelines. The scoped
seed is captured in MLIR crash reproducers and restored after success or failure.
The new CLI tests use GoogleTest and check both exit status and diagnostics.

Usage

from mqt.core.mlir import CompilationOptions, MappingOptions, compile_program

options = CompilationOptions(
    seed=7,
    enable_timing=True,
    enable_statistics=True,
    mapping=MappingOptions(trials=4, iterations=2, lookahead=10),
)
compiled = compile_program(source, target=device, options=options)
# The same options work with submit_program(source, target=device, options=options).

Typed programs accept options on compile_for_target, synthesize_for_target,
and run_pass_pipeline. C++ compiler entry points accept a final
const CompilationOptions&. Low-level target pipeline builders accept
MappingOptions; execute their pass managers with runWithCompilationOptions
to apply the seed and instrumentation with the same precedence as the compiler API.

mqt-cc input.qasm --qdmi-device mqt.sc.iqm.garnet \
  '--payload-spec=#mqt.payload_spec<format = <id = "qir", version = "2.1.0", profile = "base", encoding = text>, capabilities = [], optional_capabilities_known = false>' \
  --seed 7 --mapping-trials 4 --mapping-iterations 2 --mapping-lookahead 10

--seed also works without a device and with custom or isolated pass pipelines.

Limitations

  • seed=None preserves each pass's default or explicit seed. Execution sampling has a separate seed.
  • Omitted trials use the available logical CPU count. Set seed and trials for repeatable mapping with a fixed build, input, and target; layouts may change between releases.
  • Trials and iterations must be positive. Iterations default to one forward/backward refinement round. Lookahead defaults to 20 additional two-qubit gates; zero considers only the current gate. Lookahead storage follows actual gates, including when the ceiling is SIZE_MAX. All-to-all placement ignores valid mapping controls. The mapper may also consider deterministic candidates.
  • Target compilation still requires structured QCO/SCF input and the existing native-synthesis input subset. These controls do not prescribe a layout; ✨ Preserve and control compiler qubit layouts #2553 adds layout selection and reporting.
  • Compilation options do not apply to an already compiled payload. Source submission accepts options=None to mean no supplied compiler settings; other compiler entry points take CompilationOptions directly.

Breaking API change

Replace Python enable_timing=True, enable_statistics=True keywords with
options=CompilationOptions(enable_timing=True, enable_statistics=True).
In C++, replace trailing timing/statistics booleans with
CompilationOptions{.enableTiming = true, .enableStatistics = true}.
For source submitProgram, the options object follows the custom job parameters.
Omit options when defaults are sufficient; for compilation and typed methods,
replace explicit options=None with omission or CompilationOptions().

Validation

  • 158 Python compiler/QDMI tests pass, including exact mapping diagnostics through every public target entry point.
  • 228 native compiler, 115 mapping, and 61 target-synthesis tests pass, including stored-seed precedence and restoration and maximum-lookahead compilation.
  • Three CLI CTests pass; the documented target command also succeeds with normal and SIZE_MAX lookahead.
  • Stub generation, repository lint, and full-file C++ lint pass.

CI for the latest push is pending.

Release documentation follows the current release-preparation policy. This PR adds no changelog or upgrade-guide entry.

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

@codecov

codecov Bot commented Sep 12, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 96.40288% with 5 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
mlir/lib/Compiler/TargetCompilation.cpp 72.2% 5 Missing ⚠️

📢 Thoughts on this report? Let us know!

@simon1hofmann simon1hofmann added feature New feature or request MLIR Anything related to MLIR c++ Anything related to C++ code python Anything related to Python code QDMI Anything related to QDMI labels Sep 12, 2026
@simon1hofmann
simon1hofmann added this pull request to stack #2555 September 13, 2026 11:25
@simon1hofmann simon1hofmann self-assigned this Sep 13, 2026
@simon1hofmann
simon1hofmann marked this pull request as ready for review September 13, 2026 11:42

@burgholzer burgholzer 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 have a couple of broader questions on the design here.
I believe we should spend a bit of effort to come up with a good system for these options.
The general addition here makes sense to me.

Comment thread bindings/mlir/register_mlir.cpp Outdated
Comment thread bindings/mlir/register_mlir.cpp Outdated
Comment thread docs/mlir/target_compilation.md
Comment thread mlir/unittests/Compiler/mqt-cc/verify_mapping.cmake Outdated
Comment thread CHANGELOG.md
simon1hofmann added a commit that referenced this pull request Sep 13, 2026
🤖 *AI text below* 🤖

Merge the compiler-wide options from #2551 and use the same options argument
for layout compilation. Preserve explicit input assignments, detached results,
metadata invalidation, and saved-pipeline replay. Update usage and tests for
the shared seed, timing, statistics, and mapping controls.

Assisted-by: GPT-6 via Codex
simon1hofmann added a commit that referenced this pull request Sep 14, 2026
🤖 *AI text below* 🤖

Align the stacked layout branch with #2551's simplified compiler API.
Remove separate timing/statistics arguments from the layout method too.

Assisted-by: GPT-6 via Codex
@simon1hofmann
simon1hofmann force-pushed the feat/target-mapping-controls branch from 5d3f16c to 8f00093 Compare September 14, 2026 09:36
simon1hofmann and others added 10 commits September 14, 2026 19:49
🤖 *AI text below* 🤖

Thread the native mapper seed and trial count through C++, Python, device compilation, and mqt-cc. Preserve existing defaults and validate zero trials before rewriting the program.

Assisted-by: GPT-6 via Codex
🤖 *AI text below* 🤖

Assisted-by: GPT-6 via Codex
🤖 *AI text below* 🤖

Group timing, statistics, mapping trials, and an optional compiler seed in
CompilationOptions. Preserve legacy flag calls and propagate explicit seeds
through mapping, custom pipelines, and numerical synthesis. Capture scoped
seed metadata in crash reproducers and validate its module-level contract.

Replace the mapping CLI script with native checks and cover seed precedence,
wide seeds, numerical retries, compatibility, and failure cleanup.

Assisted-by: GPT-6 via Codex
🤖 *AI text below* 🤖

Pass synthesis mapping options to the shared preparation pass so invalid
trial counts fail before rewriting the input. Cover synthesis alongside
both target compilation connectivity modes in the existing regression.

Assisted-by: GPT-6 via Codex
🤖 *AI text below* 🤖

Remove the timing/statistics overloads and Python keyword compatibility
layer. Compiler entry points now take CompilationOptions directly, with
binding arguments copied before releasing the GIL. Keep omitted options
distinct for submission so compiled payloads reject compiler settings.

Update native callers, instrumentation tests, documentation, and generated
stubs. This intentionally breaks callers that use the separate flags.

Assisted-by: GPT-6 via Codex
🤖 *AI text below* 🤖

Keep the plan scoped to Core's compiler API, remove the obsolete flag
compatibility statement, and record the current validation results.

Assisted-by: GPT-6 via Codex
🤖 *AI text below* 🤖

Add layout refinement iterations and routing lookahead to MappingOptions
and the CLI. Preserve the defaults of one refinement round and twenty
additional gates; permit zero lookahead and reject zero iterations before
target compilation or synthesis changes the program.

Extend forwarding, repeatability, and CLI validation coverage. Keep all
compiler settings grouped in CompilationOptions.

Assisted-by: GPT-6 via Codex
🤖 *AI text below* 🤖

Regenerate the Python interface, apply initializer conventions, and record
validation for the added mapping controls.

Assisted-by: GPT-6 via Codex
Bound routing lookahead storage by actual gates and keep compilation-wide
settings in the shared pass-manager runner. Narrow target builders to
mapping options, remove duplicate seed plumbing, and check seed precedence
and mapping diagnostics at execution boundaries. Fix the CLI example.

Assisted-by: GPT-6 via Codex
@burgholzer
burgholzer force-pushed the feat/target-mapping-controls branch from 8f00093 to 5796ad8 Compare September 14, 2026 20:12
@burgholzer burgholzer self-assigned this Sep 14, 2026

@burgholzer burgholzer 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 pushed a couple of changes and simplifications here. These look pretty decent to me 🙌🏼
I'll quickly explore one last thing, then I'll likely merge this!

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 QDMI Anything related to QDMI

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants