-
-
Notifications
You must be signed in to change notification settings - Fork 42
✨ 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
li-mingbao
wants to merge
122
commits into
munich-quantum-toolkit:main
Choose a base branch
from
li-mingbao:mlir-qir-conversion
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+3,296
−1
Open
Changes from 121 commits
Commits
Show all changes
122 commits
Select commit
Hold shift + click to select a range
255d8bf
added conversion between mqtdyn to mqtopt dialect
8bce863
added conversion between mqtopt to mqtdyn dialect
ca62972
added test for mqtdyn-to-mqtopt conversion
cf2d5f9
added test for mqtopt-to-mqtdyn conversion
7998439
refactored code for dialect conversion
39cf9d3
Merge branch 'munich-quantum-toolkit:main' into mlir-mqt-dialect-conv…
li-mingbao a203019
added IWYU pragma to headerfiles
29e4456
🎨 pre-commit fixes
pre-commit-ci[bot] b0b237a
fixing some linter issues
7e0317d
applied requested changes and improved logic for mqtdyn-to-mqtopt
69ca321
fixed wrong header and reimplemented mqtdyn insertop conversion
c723299
refactored code and fixed measureOp for multiple qubits
4b11963
small changes to some variables
0abe8c1
fixing linter issues
53f4c2e
fixing unrealized conversion issues in llvm-19
84f6303
fixed bug with negCtrl qubits in mqtopt-to-mqtdyn conversion
0034340
added mqt type conversions for other operations
e5876a7
Merge branch 'main' into mlir-mqt-dialect-conversion
ystade 7257887
fixed mqtopt-to-mqtdyn test
e422803
fixing mqtop conversion for multiple optValue users
3c58889
marking the vectors const
5679c1b
fixing mqtdyn-to-mqtopt test
b2789fa
Merge branch 'munich-quantum-toolkit:main' into mlir-mqt-dialect-conv…
li-mingbao 29d863d
incorporate feedback
01389ae
replace global variables
f5c753a
update mqtdyn-to-mqtopt test
5f878e5
fix linter warning
f480833
improved description for mqtopt-to-mqtdyn pass
be0e353
replaced references with pointers
f3ccc10
incorporate some review feedback
a649ad0
refactored dialect conversion tests
1cd243f
Merge branch 'munich-quantum-toolkit:main' into mlir-mqt-dialect-conv…
li-mingbao 1b4a8f5
changed variable names in tests
ceb8473
fixed test label
806c033
refactored code
bae4bbc
reworded pass descriptions
dfd6739
added tests for barrierOp and gphaseOp
2cd92fc
changed variable name in tests
7a40e53
changed CMakeLists
d259109
replaced eraseOp with replaceOp
9e3fe5a
fix linter issues
0ba823b
🎨 simplify CMake config
burgholzer 6d30b7e
♻️ streamline conversion code
burgholzer 9038e79
🚨 ignore uncheck optional clang-tidy rule (creates many false positives)
burgholzer 450b344
🚨 address clang-tidy warnings
burgholzer 28cb3ed
🚨 address last clang-tidy warning
burgholzer 23d6a5e
initial setup
b205921
add more conversions
9e49c8f
add simple conversion test
3ab7428
rename test file
4295228
added workaround to differentiate types
0754157
Merge remote-tracking branch 'upstream/main' into mlir-qir-conversion
ff1a40c
insert blocks during conversion to QIR
56b4a81
inserted register allocation if needed
3b18af4
add conversion for single qubit gates
be37491
add conversion for simple qubit gates
6c357ee
add conversion for rotation gates
928a0c9
small fixes and added missing gates
25c08e9
add more conversions from mqtdyn to qir
4a560fb
clean up code
f8dfef6
adding tests and smaller fixes
d12748d
Merge branch 'munich-quantum-toolkit:main' into mlir-qir-conversion
li-mingbao b273c70
fix pass registration
8987287
fix placeholder test
c94d731
add more tests
e539be0
refactor some functions
8c05863
add standard dialect conversions
0fcfa10
fixing standard conversions
deca527
updated tests
8d99baf
add measure for multiple qubits
d26412f
Merge remote-tracking branch 'upstream/main' into mlir-qir-conversion
d05d7c2
fixing linter issues
688d203
add additional measure test
f28c417
remove unnecessary operations in qir measure conversion
545b661
remove not used header
e416e85
applying some feedback
8e1c26c
add statefulOpConversion pattern for MQTDynToQIR
56c1da9
streamline gate conversion
a6a6547
add tests for u1 and u3 gates
c879610
removed allocRegisterData
49fc5dd
add function to ensure different blocks for qir
267050d
add measureOp conversion without previous addressOfOp and globalOp
76d7708
fix more linter issues
dde79b4
Merge remote-tracking branch 'upstream/main' into mlir-qir-conversion
a298e04
fix measure operation conversion
78e2a48
add reset op conversion
b981692
Merge remote-tracking branch 'upstream/main' into mlir-qir-conversion
4beae2f
changed mqtdyn to mqtref
61018e6
refactor code
c732750
add pass descriptions
341b138
Merge remote-tracking branch 'upstream/main' into mlir-qir-conversion
467627c
fix operation names
1588dd8
fix measure tests
95d7ea8
remove unused headers
3d6aa5c
add support for static parameters
8d79f80
remove blocks in mqtref-to-qir tests
9725ae6
Merge remote-tracking branch 'upstream/main' into mlir-qir-conversion
ab4a2c1
fix linter issues
5ac8996
apply some review feedback
f3044b0
add proper conversion for negative controlled qubits
4a81350
add base support for static qubits
7c60238
refactored tests
d2f084c
add base support for static qubit addressing conversion from qir
ca1105e
add qir base profile attributes to conversion
e0d84be
increase blocks to 4 for mqtref to qir conversion
09a5d4c
add test for static addressing in qir
01854f9
Merge remote-tracking branch 'upstream/main' into mlir-qir-conversion
65eb705
fix linter issues
d79c998
fix order of inputs
d75d8b9
changed measurement conversion
ddeda6d
improve static parameter conversion
e97c595
Merge remote-tracking branch 'upstream/main' into mlir-qir-conversion
32e0178
add alloc and dealloc qubit conversion
6ae5b87
replace unordered map with stringmaps
4505696
update qir-to-memref tests
94dd9cf
add static qubit tests for mqtref to qir
0bc072c
add missing header
77ab501
trying to fix staticParam bug
db5cf03
another attempt to fix the bug
2da1f5a
small refactor for the static params
d772ba8
replace bool with auto
c46133d
Apply suggestions from code review
li-mingbao File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
}]; | ||
|
||
// Define dependent dialects | ||
let dependentDialects = [ | ||
"::mqt::ir::ref::MQTRefDialect", | ||
"mlir::LLVM::LLVMDialect" | ||
]; | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. | ||
li-mingbao marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
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" | ||
]; | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.