Skip to content

✨ Add OpenQASM-to-QC translation#1780

Merged
denialhaag merged 54 commits into
mainfrom
open-qasm
Jun 18, 2026
Merged

✨ Add OpenQASM-to-QC translation#1780
denialhaag merged 54 commits into
mainfrom
open-qasm

Conversation

@denialhaag

@denialhaag denialhaag commented Jun 11, 2026

Copy link
Copy Markdown
Member

Description

This is a rebased version of #1671 after #1671 was automatically closed when #1751 was merged.

Original description by @J4MMlE:

Description

This PR adds a direct OpenQASM-to-QC translation that bypasses the qc::QuantumComputation.

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 previously unsupported QASM3 features, such as gate modifiers, classical computations, and control flow structures.

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)

Current limitations

  • Gate parameters must be compile-time constants
  • pow modifier is unsupported (but will/should be once #1603 is merged)
  • Layout pragmas are unsupported (they have no equivalent in QC)

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.

@denialhaag denialhaag self-assigned this Jun 11, 2026
@denialhaag denialhaag added feature New feature or request MLIR Anything related to MLIR labels Jun 11, 2026
@denialhaag denialhaag added this to the MLIR Support milestone Jun 11, 2026
@codecov

codecov Bot commented Jun 11, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 81.62839% with 88 lines in your changes missing coverage. Please review.

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

📢 Thoughts on this report? Let us know!

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

This generally looks very good to me as a direct port of the QuantumComputation QASM Importer 🙌
I only have a couple of inline comments or requests for changes.
We should be able to merge this quickly.

A thought that came up while reviewing this: how much is the current architecture of the parser and the visitor implementation limiting us in terms of expanding the capabilities?
There are quite a few things from the OQ3 spec that we would want to support (loops being one of the most prominent ones).
Would it be interesting to define our own OpenQASM3 dialect (inspired by the qe-compiler one) that can directly parse in QASM files. And then we would write a conversion to MLIR standard dialects plus QC. Does that make sense? Is that overkill? To me it feels like this could generally make sense. What do you think?

Comment thread mlir/tools/mqt-cc/mqt-cc.cpp
Comment thread mlir/include/mlir/Dialect/QC/Translation/TranslateQASM3ToQC.h Outdated
Comment thread mlir/lib/Dialect/QC/Translation/TranslateQASM3ToQC.cpp Outdated
Comment thread mlir/lib/Dialect/QC/Translation/TranslateQASM3ToQC.cpp Outdated
Comment thread mlir/lib/Dialect/QC/Translation/TranslateQASM3ToQC.cpp Outdated
@denialhaag

Copy link
Copy Markdown
Member Author

A thought that came up while reviewing this: how much is the current architecture of the parser and the visitor implementation limiting us in terms of expanding the capabilities?
There are quite a few things from the OQ3 spec that we would want to support (loops being one of the most prominent ones).
Would it be interesting to define our own OpenQASM3 dialect (inspired by the qe-compiler one) that can directly parse in QASM files. And then we would write a conversion to MLIR standard dialects plus QC. Does that make sense? Is that overkill? To me it feels like this could generally make sense. What do you think?

I will think about this a bit and respond tomorrow!

@denialhaag denialhaag requested a review from burgholzer June 18, 2026 00:19
@denialhaag

Copy link
Copy Markdown
Member Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jun 18, 2026

Copy link
Copy Markdown
Contributor
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@mlir/include/mlir/Dialect/QC/Translation/TranslateQASM3ToQC.h`:
- Around line 13-26: The function translateQASM3ToQC uses OwningOpRef<ModuleOp>
as its return type but the header does not directly include the definition of
OwningOpRef, relying instead on transitive includes from BuiltinOps.h. Add
`#include` <mlir/IR/OwningOpRef.h> to the include section at the top of the file
along with the other mlir includes to make this header self-contained and
explicit about its dependencies.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 4b5a8e6b-daab-46b3-96dc-c6efd737f14b

📥 Commits

Reviewing files that changed from the base of the PR and between 40e31f7 and 86bbf4b.

📒 Files selected for processing (7)
  • mlir/include/mlir/Dialect/QC/Translation/TranslateQASM3ToQC.h
  • mlir/lib/Dialect/QC/Translation/TranslateQASM3ToQC.cpp
  • mlir/tools/mqt-cc/CMakeLists.txt
  • mlir/tools/mqt-cc/mqt-cc.cpp
  • mlir/unittests/Dialect/QC/Translation/test_qasm3_translation.cpp
  • mlir/unittests/programs/qasm_programs.cpp
  • mlir/unittests/programs/qasm_programs.h
💤 Files with no reviewable changes (1)
  • mlir/tools/mqt-cc/CMakeLists.txt

Comment thread mlir/include/mlir/Dialect/QC/Translation/TranslateQASM3ToQC.h Outdated

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

This is very close to being mergable 🙂

Comment thread mlir/tools/mqt-cc/CMakeLists.txt
@denialhaag denialhaag requested a review from burgholzer June 18, 2026 08:51
@denialhaag denialhaag merged commit 5a12960 into main Jun 18, 2026
32 of 33 checks passed
@denialhaag denialhaag deleted the open-qasm branch June 18, 2026 16:14
@denialhaag

Copy link
Copy Markdown
Member Author

Thanks a lot for getting this started, @J4MMlE! Your initial version was a great foundation! 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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