Skip to content

✨ Add MQTRef-QIR conversions #1091

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 122 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
122 commits
Select commit Hold shift + click to select a range
255d8bf
added conversion between mqtdyn to mqtopt dialect
Jun 13, 2025
8bce863
added conversion between mqtopt to mqtdyn dialect
Jun 13, 2025
ca62972
added test for mqtdyn-to-mqtopt conversion
Jun 16, 2025
cf2d5f9
added test for mqtopt-to-mqtdyn conversion
Jun 16, 2025
7998439
refactored code for dialect conversion
Jun 16, 2025
39cf9d3
Merge branch 'munich-quantum-toolkit:main' into mlir-mqt-dialect-conv…
li-mingbao Jun 16, 2025
a203019
added IWYU pragma to headerfiles
Jun 16, 2025
29e4456
🎨 pre-commit fixes
pre-commit-ci[bot] Jun 16, 2025
b0b237a
fixing some linter issues
Jun 17, 2025
7e0317d
applied requested changes and improved logic for mqtdyn-to-mqtopt
Jun 18, 2025
69ca321
fixed wrong header and reimplemented mqtdyn insertop conversion
Jun 18, 2025
c723299
refactored code and fixed measureOp for multiple qubits
Jun 18, 2025
4b11963
small changes to some variables
Jun 18, 2025
0abe8c1
fixing linter issues
Jun 19, 2025
53f4c2e
fixing unrealized conversion issues in llvm-19
Jun 20, 2025
84f6303
fixed bug with negCtrl qubits in mqtopt-to-mqtdyn conversion
Jun 20, 2025
0034340
added mqt type conversions for other operations
Jun 20, 2025
e5876a7
Merge branch 'main' into mlir-mqt-dialect-conversion
ystade Jun 21, 2025
7257887
fixed mqtopt-to-mqtdyn test
Jun 22, 2025
e422803
fixing mqtop conversion for multiple optValue users
Jun 22, 2025
3c58889
marking the vectors const
Jun 22, 2025
5679c1b
fixing mqtdyn-to-mqtopt test
Jun 24, 2025
b2789fa
Merge branch 'munich-quantum-toolkit:main' into mlir-mqt-dialect-conv…
li-mingbao Jun 26, 2025
29d863d
incorporate feedback
Jun 26, 2025
01389ae
replace global variables
Jun 26, 2025
f5c753a
update mqtdyn-to-mqtopt test
Jun 26, 2025
5f878e5
fix linter warning
Jun 27, 2025
f480833
improved description for mqtopt-to-mqtdyn pass
Jun 27, 2025
be0e353
replaced references with pointers
Jun 27, 2025
f3ccc10
incorporate some review feedback
Jul 3, 2025
a649ad0
refactored dialect conversion tests
Jul 3, 2025
1cd243f
Merge branch 'munich-quantum-toolkit:main' into mlir-mqt-dialect-conv…
li-mingbao Jul 3, 2025
1b4a8f5
changed variable names in tests
Jul 4, 2025
ceb8473
fixed test label
Jul 6, 2025
806c033
refactored code
Jul 6, 2025
bae4bbc
reworded pass descriptions
Jul 6, 2025
dfd6739
added tests for barrierOp and gphaseOp
Jul 6, 2025
2cd92fc
changed variable name in tests
Jul 6, 2025
7a40e53
changed CMakeLists
Jul 7, 2025
d259109
replaced eraseOp with replaceOp
Jul 7, 2025
9e3fe5a
fix linter issues
Jul 7, 2025
0ba823b
🎨 simplify CMake config
burgholzer Jul 7, 2025
6d30b7e
♻️ streamline conversion code
burgholzer Jul 7, 2025
9038e79
🚨 ignore uncheck optional clang-tidy rule (creates many false positives)
burgholzer Jul 7, 2025
450b344
🚨 address clang-tidy warnings
burgholzer Jul 7, 2025
28cb3ed
🚨 address last clang-tidy warning
burgholzer Jul 7, 2025
23d6a5e
initial setup
Jul 14, 2025
b205921
add more conversions
Jul 18, 2025
9e49c8f
add simple conversion test
Jul 18, 2025
3ab7428
rename test file
Jul 21, 2025
4295228
added workaround to differentiate types
Jul 28, 2025
0754157
Merge remote-tracking branch 'upstream/main' into mlir-qir-conversion
Jul 28, 2025
ff1a40c
insert blocks during conversion to QIR
Jul 28, 2025
56b4a81
inserted register allocation if needed
Jul 30, 2025
3b18af4
add conversion for single qubit gates
Jul 30, 2025
be37491
add conversion for simple qubit gates
Jul 30, 2025
6c357ee
add conversion for rotation gates
Jul 30, 2025
928a0c9
small fixes and added missing gates
Jul 30, 2025
25c08e9
add more conversions from mqtdyn to qir
Jul 31, 2025
4a560fb
clean up code
Jul 31, 2025
f8dfef6
adding tests and smaller fixes
Aug 1, 2025
d12748d
Merge branch 'munich-quantum-toolkit:main' into mlir-qir-conversion
li-mingbao Aug 1, 2025
b273c70
fix pass registration
Aug 1, 2025
8987287
fix placeholder test
Aug 1, 2025
c94d731
add more tests
Aug 5, 2025
e539be0
refactor some functions
Aug 6, 2025
8c05863
add standard dialect conversions
Aug 6, 2025
0fcfa10
fixing standard conversions
Aug 6, 2025
deca527
updated tests
Aug 6, 2025
8d99baf
add measure for multiple qubits
Aug 6, 2025
d26412f
Merge remote-tracking branch 'upstream/main' into mlir-qir-conversion
Aug 6, 2025
d05d7c2
fixing linter issues
Aug 6, 2025
688d203
add additional measure test
Aug 6, 2025
f28c417
remove unnecessary operations in qir measure conversion
Aug 7, 2025
545b661
remove not used header
Aug 7, 2025
e416e85
applying some feedback
Aug 11, 2025
8e1c26c
add statefulOpConversion pattern for MQTDynToQIR
Aug 11, 2025
56c1da9
streamline gate conversion
Aug 11, 2025
a6a6547
add tests for u1 and u3 gates
Aug 11, 2025
c879610
removed allocRegisterData
Aug 11, 2025
49fc5dd
add function to ensure different blocks for qir
Aug 11, 2025
267050d
add measureOp conversion without previous addressOfOp and globalOp
Aug 11, 2025
76d7708
fix more linter issues
Aug 11, 2025
dde79b4
Merge remote-tracking branch 'upstream/main' into mlir-qir-conversion
Aug 13, 2025
a298e04
fix measure operation conversion
Aug 13, 2025
78e2a48
add reset op conversion
Aug 13, 2025
b981692
Merge remote-tracking branch 'upstream/main' into mlir-qir-conversion
Aug 13, 2025
4beae2f
changed mqtdyn to mqtref
Aug 13, 2025
61018e6
refactor code
Aug 15, 2025
c732750
add pass descriptions
Aug 15, 2025
341b138
Merge remote-tracking branch 'upstream/main' into mlir-qir-conversion
Aug 15, 2025
467627c
fix operation names
Aug 15, 2025
1588dd8
fix measure tests
Aug 15, 2025
95d7ea8
remove unused headers
Aug 15, 2025
3d6aa5c
add support for static parameters
Aug 15, 2025
8d79f80
remove blocks in mqtref-to-qir tests
Aug 17, 2025
9725ae6
Merge remote-tracking branch 'upstream/main' into mlir-qir-conversion
Aug 17, 2025
ab4a2c1
fix linter issues
Aug 18, 2025
5ac8996
apply some review feedback
Aug 19, 2025
f3044b0
add proper conversion for negative controlled qubits
Aug 19, 2025
4a81350
add base support for static qubits
Aug 19, 2025
7c60238
refactored tests
Aug 19, 2025
d2f084c
add base support for static qubit addressing conversion from qir
Aug 19, 2025
ca1105e
add qir base profile attributes to conversion
Aug 19, 2025
e0d84be
increase blocks to 4 for mqtref to qir conversion
Aug 19, 2025
09a5d4c
add test for static addressing in qir
Aug 19, 2025
01854f9
Merge remote-tracking branch 'upstream/main' into mlir-qir-conversion
Aug 19, 2025
65eb705
fix linter issues
Aug 19, 2025
d79c998
fix order of inputs
Aug 19, 2025
d75d8b9
changed measurement conversion
Aug 20, 2025
ddeda6d
improve static parameter conversion
Aug 20, 2025
e97c595
Merge remote-tracking branch 'upstream/main' into mlir-qir-conversion
Aug 20, 2025
32e0178
add alloc and dealloc qubit conversion
Aug 20, 2025
6ae5b87
replace unordered map with stringmaps
Aug 21, 2025
4505696
update qir-to-memref tests
Aug 21, 2025
94dd9cf
add static qubit tests for mqtref to qir
Aug 21, 2025
0bc072c
add missing header
Aug 21, 2025
77ab501
trying to fix staticParam bug
Aug 21, 2025
db5cf03
another attempt to fix the bug
Aug 21, 2025
2da1f5a
small refactor for the static params
Aug 21, 2025
d772ba8
replace bool with auto
Aug 21, 2025
c46133d
Apply suggestions from code review
li-mingbao Aug 22, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions mlir/include/mlir/Conversion/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,5 @@

add_subdirectory(MQTRefToMQTOpt)
add_subdirectory(MQTOptToMQTRef)
add_subdirectory(MQTRefToQIR)
add_subdirectory(QIRToMQTRef)
13 changes: 13 additions & 0 deletions mlir/include/mlir/Conversion/MQTRefToQIR/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Copyright (c) 2023 - 2025 Chair for Design Automation, TUM
# Copyright (c) 2025 Munich Quantum Software Company GmbH
# All rights reserved.
#
# SPDX-License-Identifier: MIT
#
# Licensed under the MIT License

set(LLVM_TARGET_DEFINITIONS MQTRefToQIR.td)
mlir_tablegen(MQTRefToQIR.h.inc -gen-pass-decls -name MQTRefToQIR)
add_public_tablegen_target(MQTRefToQIRIncGen)

add_mlir_doc(MQTRefToQIR MLIRMQTRefToQIR Conversions/ -gen-pass-doc)
23 changes: 23 additions & 0 deletions mlir/include/mlir/Conversion/MQTRefToQIR/MQTRefToQIR.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* Copyright (c) 2023 - 2025 Chair for Design Automation, TUM
* Copyright (c) 2025 Munich Quantum Software Company GmbH
* All rights reserved.
*
* SPDX-License-Identifier: MIT
*
* Licensed under the MIT License
*/

#pragma once

#include <mlir/Pass/Pass.h> // from @llvm-project

namespace mqt::ir {

#define GEN_PASS_DECL
#include "mlir/Conversion/MQTRefToQIR/MQTRefToQIR.h.inc"

#define GEN_PASS_REGISTRATION
#include "mlir/Conversion/MQTRefToQIR/MQTRefToQIR.h.inc"

} // namespace mqt::ir
33 changes: 33 additions & 0 deletions mlir/include/mlir/Conversion/MQTRefToQIR/MQTRefToQIR.td
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Copyright (c) 2023 - 2025 Chair for Design Automation, TUM
// Copyright (c) 2025 Munich Quantum Software Company GmbH
// All rights reserved.
//
// SPDX-License-Identifier: MIT
//
// Licensed under the MIT License

include "mlir/Pass/PassBase.td"

def MQTRefToQIR : Pass<"mqtref-to-qir"> {
let summary = "Convert MQT's `Ref` dialect into the llvm dialect that adheres to the QIR specification";

let description = [{
This pass converts all operations to the llvm dialect. The quantum operations of the mqt ref dialect are converted
to an equivalent operation in the qir instruction set expressed with a function call in the llvm dialect. This requires a valid
input in the mqtref dialect where the main function is marked with the entry_point attribute. At the moment the pass only supports
simple quantum programs with a straight controlflow. In order to adhere to the base profile of QIR, the initial module is divided
into multiple blocks and an initialize operation is added. During the conversion both QubitType and RegisterType from mqtref are
replaced with llvm.ptr type to represent an opaque pointer in the llvm dialect.
The remaining operations from the standard dialects are lowered to the llvm dialect via built-in conversion passes from mlir.
This includes the following dialects at the moment: func, arith, cf

Once the module is converted fully in the llvm dialect, one can convert the resulting file into LLVM-IR with the following command:
mlir-translate --mlir-to-llvmir input.mlir > output.ll
Comment on lines +15 to +25
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am just putting this comment here as a note to remind us to iterate on this docstring once all other aspects in the PR are clarified.
This should, very clearly, state what the conversion pass can do and what it cannot do.

}];

// Define dependent dialects
let dependentDialects = [
"::mqt::ir::ref::MQTRefDialect",
"mlir::LLVM::LLVMDialect"
];
}
13 changes: 13 additions & 0 deletions mlir/include/mlir/Conversion/QIRToMQTRef/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Copyright (c) 2023 - 2025 Chair for Design Automation, TUM
# Copyright (c) 2025 Munich Quantum Software Company GmbH
# All rights reserved.
#
# SPDX-License-Identifier: MIT
#
# Licensed under the MIT License

set(LLVM_TARGET_DEFINITIONS QIRToMQTRef.td)
mlir_tablegen(QIRToMQTRef.h.inc -gen-pass-decls -name QIRToMQTRef)
add_public_tablegen_target(QIRToMQTRefIncGen)

add_mlir_doc(QIRToMQTRef MLIRQIRToMQTRef Conversions/ -gen-pass-doc)
23 changes: 23 additions & 0 deletions mlir/include/mlir/Conversion/QIRToMQTRef/QIRToMQTRef.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* Copyright (c) 2023 - 2025 Chair for Design Automation, TUM
* Copyright (c) 2025 Munich Quantum Software Company GmbH
* All rights reserved.
*
* SPDX-License-Identifier: MIT
*
* Licensed under the MIT License
*/

#pragma once

#include <mlir/Pass/Pass.h> // from @llvm-project

namespace mqt::ir {

#define GEN_PASS_DECL
#include "mlir/Conversion/QIRToMQTRef/QIRToMQTRef.h.inc"

#define GEN_PASS_REGISTRATION
#include "mlir/Conversion/QIRToMQTRef/QIRToMQTRef.h.inc"

} // namespace mqt::ir
32 changes: 32 additions & 0 deletions mlir/include/mlir/Conversion/QIRToMQTRef/QIRToMQTRef.td
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Copyright (c) 2023 - 2025 Chair for Design Automation, TUM
// Copyright (c) 2025 Munich Quantum Software Company GmbH
// All rights reserved.
//
// SPDX-License-Identifier: MIT
//
// Licensed under the MIT License

include "mlir/Pass/PassBase.td"

def QIRToMQTRef : Pass<"qir-to-mqtref"> {
let summary = "Convert llvm dialect that adheres to the QIR specification to MQT's `Ref` dialect";

let description = [{
This pass converts all llvm.mlir.call operation from the qir instruction set into quantum operations in the mqtref dialect.
The pass expects a valid mlir module in the llvm dialect that uses dynamic addressing for the qubit allocation and uses the
QIR base profile. At the moment the pass only supports simple quantum programs with a straight controlflow. The conversion
of the quantum operation is done checking the function name of the call operation and replacing it with an equivalent operation
from the mqtref dialect. Other operations from the llvm dialect like llvm.mlir.constants or function declarations are currently not
converted and persist after the conversion. At the moment quantum operations that do not have an equivalent operation in
the mqtref dialect are deleted during the conversion.

The initial .mlir module with the llvm dialect can be obtained by converting a .ll file with the following command:
mlir-translate --import-llvm input.ll -o output.mlir
}];

// Define dependent dialects
let dependentDialects = [
"::mqt::ir::ref::MQTRefDialect",
"mlir::LLVM::LLVMDialect"
];
}
2 changes: 2 additions & 0 deletions mlir/lib/Conversion/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,5 @@

add_subdirectory(MQTOptToMQTRef)
add_subdirectory(MQTRefToMQTOpt)
add_subdirectory(MQTRefToQIR)
add_subdirectory(QIRToMQTRef)
11 changes: 11 additions & 0 deletions mlir/lib/Conversion/MQTRefToQIR/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Copyright (c) 2023 - 2025 Chair for Design Automation, TUM
# Copyright (c) 2025 Munich Quantum Software Company GmbH
# All rights reserved.
#
# SPDX-License-Identifier: MIT
#
# Licensed under the MIT License

file(GLOB CONVERSION_SOURCES *.cpp)

add_mlir_library(MQTRefToQIR ${CONVERSION_SOURCES} DEPENDS MQTRefToQIRIncGen)
Loading
Loading