Skip to content

Commit 5a12960

Browse files
denialhaagJ4MMlEburgholzer
authored
✨ Add OpenQASM-to-QC translation (#1780)
## 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](#1603) is merged) > - Layout pragmas are unsupported (they have no equivalent in `QC`) ## Checklist - [x] The pull request only contains commits that are focused and relevant to this change. - [x] I have added appropriate tests that cover the new/changed functionality. - [x] ~~I have updated the documentation to reflect these changes.~~ - [x] I have added entries to the changelog for any noteworthy additions, changes, fixes, or removals. - [x] ~~I have added migration instructions to the upgrade guide (if needed).~~ - [x] The changes follow the project's style guidelines and introduce no new warnings. - [x] The changes are fully tested and pass the CI checks. - [x] I have reviewed my own code changes. --------- Signed-off-by: Daniel Haag <121057143+denialhaag@users.noreply.github.com> Co-authored-by: Anatol Bussejahn <anatol.bussejahn@tum.de> Co-authored-by: Lukas Burgholzer <burgholzer@me.com>
1 parent 89448cf commit 5a12960

12 files changed

Lines changed: 2714 additions & 48 deletions

File tree

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ with the exception that minor releases may include breaking changes.
4242
[#1569], [#1570], [#1572], [#1573], [#1580], [#1602], [#1620], [#1623],
4343
[#1624], [#1626], [#1627], [#1635], [#1638], [#1673], [#1675], [#1700],
4444
[#1710], [#1717], [#1728], [#1730], [#1749], [#1751], [#1762], [#1765],
45-
[#1774], [#1781], [#1782], [#1787])
45+
[#1774], [#1780], [#1781], [#1782], [#1787])
4646
([**@burgholzer**], [**@denialhaag**], [**@taminob**], [**@DRovara**],
4747
[**@li-mingbao**], [**@Ectras**], [**@MatthiasReumann**],
4848
[**@simon1hofmann**])
@@ -601,6 +601,7 @@ changelogs._
601601
[#1787]: https://github.com/munich-quantum-toolkit/core/pull/1787
602602
[#1782]: https://github.com/munich-quantum-toolkit/core/pull/1782
603603
[#1781]: https://github.com/munich-quantum-toolkit/core/pull/1781
604+
[#1780]: https://github.com/munich-quantum-toolkit/core/pull/1780
604605
[#1776]: https://github.com/munich-quantum-toolkit/core/pull/1776
605606
[#1774]: https://github.com/munich-quantum-toolkit/core/pull/1774
606607
[#1766]: https://github.com/munich-quantum-toolkit/core/pull/1766
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
* Copyright (c) 2023 - 2026 Chair for Design Automation, TUM
3+
* Copyright (c) 2025 - 2026 Munich Quantum Software Company GmbH
4+
* All rights reserved.
5+
*
6+
* SPDX-License-Identifier: MIT
7+
*
8+
* Licensed under the MIT License
9+
*/
10+
11+
#pragma once
12+
13+
#include <llvm/Support/SourceMgr.h>
14+
#include <mlir/IR/OwningOpRef.h>
15+
#include <mlir/Support/LLVM.h>
16+
17+
namespace mlir {
18+
19+
// Forward declarations
20+
class MLIRContext;
21+
class ModuleOp;
22+
23+
namespace qc {
24+
25+
/**
26+
* @brief Translate an OpenQASM 3 program to a QC program.
27+
*
28+
* @param sourceMgr Source manager containing the OpenQASM3 program.
29+
* @param context MLIRContext to create the module in.
30+
*/
31+
[[nodiscard]] OwningOpRef<ModuleOp>
32+
translateQASM3ToQC(llvm::SourceMgr& sourceMgr, MLIRContext* context);
33+
34+
/**
35+
* @brief Translate an OpenQASM 3 program to a QC program.
36+
*
37+
* @param source String containing the OpenQASM3 program.
38+
* @param context MLIRContext to create the module in.
39+
*/
40+
[[nodiscard]] OwningOpRef<ModuleOp> translateQASM3ToQC(StringRef source,
41+
MLIRContext* context);
42+
43+
} // namespace qc
44+
45+
} // namespace mlir

mlir/lib/Dialect/QC/Translation/CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,15 @@
99
add_mlir_library(
1010
MLIRQCTranslation
1111
TranslateQuantumComputationToQC.cpp
12+
TranslateQASM3ToQC.cpp
1213
LINK_LIBS
1314
MLIRArithDialect
1415
MLIRFuncDialect
1516
MLIRSCFDialect
1617
MLIRQCDialect
1718
MLIRQCProgramBuilder
18-
MQT::CoreIR)
19+
MQT::CoreIR
20+
MQT::CoreQASM)
1921

2022
mqt_mlir_target_use_project_options(MLIRQCTranslation)
2123

0 commit comments

Comments
 (0)