Skip to content

✨ Add direct OpenQASM to QC translation#1671

Draft
J4MMlE wants to merge 7 commits intomunich-quantum-toolkit:mainfrom
J4MMlE:open-qasm
Draft

✨ Add direct OpenQASM to QC translation#1671
J4MMlE wants to merge 7 commits intomunich-quantum-toolkit:mainfrom
J4MMlE:open-qasm

Conversation

@J4MMlE
Copy link
Copy Markdown
Contributor

@J4MMlE J4MMlE commented Apr 27, 2026

Description

This PR adds a direct QASM3 → QC dialect translation, bypassing QuantumComputation.

Previous flow:
OpenQASM -> AST -> QuantumComputation -> QC dialect
New flow:
OpenQASM -> AST -> QC dialect

The new flow reuses the existing parser and walks the AST directly to emit QC dialect ops. Skipping QuantumComputation removes an intermediate step and enables QASM3 features previously unsupported, such as gate modifiers, classical computations and control flow structures.

For now i added a --direct-import flag to invoke the new direct translation - this will eventually be dropped, so that this direct translation becomes the new default.

What works

  • All standard gates plus Qiskit-style MCX variants
  • Gate modifiers: ctrl @, negctrl @, inv @, nested combinations
  • Register declarations, qubit/bit allocation
  • Measure, reset, barrier
  • if/else over quantum statements
  • Hardware qubits convert to qc.static
  • Broadcasting (register-width gate calls)
  • User-defined compound gates (inline expansion)

Current limitations

  • Gate parameters must be compile-time constants. Adding Values is a requirement to also support classical computations.
  • pow modifier is unsupported (but will/should be, once it gets merged into main)
  • Layout pragmas are unsupported (they have no equivalent in QC)
  • classical computations and control flow unsupported (these require extension on the parser)
  • if only works up to qc but should work for the whole pipeline once the scf conversion PR is in

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:

  • I have disclosed the use of AI tools in the PR description as per our AI Usage Guidelines.
  • 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.

@mergify mergify Bot added the conflict label Apr 27, 2026
@burgholzer burgholzer added feature New feature or request c++ Anything related to C++ code MLIR Anything related to MLIR labels Apr 28, 2026
@burgholzer burgholzer added this to the MLIR Support milestone Apr 28, 2026
denialhaag and others added 2 commits April 29, 2026 12:59
Signed-off-by: Daniel Haag <121057143+denialhaag@users.noreply.github.com>
@mergify mergify Bot removed the conflict label Apr 29, 2026
Comment on lines +76 to +79
static cl::opt<bool> directImport(
"direct-import",
cl::desc("Use direct QASM3 → QC import (bypasses QuantumComputation)"),
cl::init(false));
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.

Is there currently any significant feature that requires the legacy loader? If not, I'd say we can drop this flag and remove the legacy function already in this PR. 🤔

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.

Yeah. There is no need for any kind of deprecation period here. Let's just use the new functionality 👍🏻

@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 29, 2026

Codecov Report

❌ Patch coverage is 0% with 559 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
.../lib/Dialect/QC/Translation/TranslateQASM3ToQC.cpp 0.0% 559 Missing ⚠️

📢 Thoughts on this report? Let us know!

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants