Skip to content

MLIR mqt dialect conversion #1001

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 26 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 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
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
1 change: 1 addition & 0 deletions mlir/include/mlir/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@
# Licensed under the MIT License

add_subdirectory(Dialect)
add_subdirectory(Conversion)
10 changes: 10 additions & 0 deletions mlir/include/mlir/Conversion/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# 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

add_subdirectory(MQTDynToMQTOpt)
add_subdirectory(MQTOptToMQTDyn)
13 changes: 13 additions & 0 deletions mlir/include/mlir/Conversion/MQTDynToMQTOpt/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 MQTDynToMQTOpt.td)
mlir_tablegen(MQTDynToMQTOpt.h.inc -gen-pass-decls -name MQTDynToMQTOpt)
add_public_tablegen_target(MQTDynToMQTOptIncGen)

add_mlir_doc(MQTDynToMQTOpt MLIRMQTDynToMQTOpt Conversions/ -gen-pass-doc)
23 changes: 23 additions & 0 deletions mlir/include/mlir/Conversion/MQTDynToMQTOpt/MQTDynToMQTOpt.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/MQTDynToMQTOpt/MQTDynToMQTOpt.h.inc"

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

} // namespace mqt::ir
28 changes: 28 additions & 0 deletions mlir/include/mlir/Conversion/MQTDynToMQTOpt/MQTDynToMQTOpt.td
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// 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 MQTDynToMQTOpt : Pass<"mqtdyn-to-mqtopt"> {
let summary = "Convert MQT's `MQTDyn` to MQT's `MQTOpt` dialect.";

let description = [{
This pass converts all current mqtdyn operations to an equivalent mqtopt operation.
To convert them to the opt dialect, the conversion pass keeps an updated map that tracks each dyn qubit
and dyn qubit register to its latest state value when replacing them with an opt operation. These state values
are obtained by updating the map with the return values of the newly created opt operations. The mqtopt insert
operation is added when matching the dealloc operation of any qubit register. A mqtopt insert operation is then
created for each qubit that was extracted from the qubit register and placed before the dealloc operation.
}];

// Define dependent dialects
let dependentDialects = [
"::mqt::ir::dyn::MQTDynDialect",
"::mqt::ir::opt::MQTOptDialect"
];
}
13 changes: 13 additions & 0 deletions mlir/include/mlir/Conversion/MQTOptToMQTDyn/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 MQTOptToMQTDyn.td)
mlir_tablegen(MQTOptToMQTDyn.h.inc -gen-pass-decls -name MQTOptToMQTDyn)
add_public_tablegen_target(MQTOptToMQTDynIncGen)

add_mlir_doc(MQTOptToMQTDyn MQTOptToMQTDyn Conversions/ -gen-pass-doc)
23 changes: 23 additions & 0 deletions mlir/include/mlir/Conversion/MQTOptToMQTDyn/MQTOptToMQTDyn.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/MQTOptToMQTDyn/MQTOptToMQTDyn.h.inc"

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

} // namespace mqt::ir
28 changes: 28 additions & 0 deletions mlir/include/mlir/Conversion/MQTOptToMQTDyn/MQTOptToMQTDyn.td
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// 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 MQTOptToMQTDyn : Pass<"mqtopt-to-mqtdyn"> {
let summary = "Convert MQT's `MQTOpt` to MQT's `MQTDyn` dialect.";

let description = [{
This pass converts all current mqtopt operations to an equivalent mqtdyn operation.
The result of the converted mqtdyn alloc operation acts as a qubit register reference and replaces the operand of the operation
that uses the initial mqtopt qubit register. This reference is then propagated to all subsequent operations that use the state
of the initial mqtopt register and replaces their operand. The same applies to the result of the extract operation that acts as a qubit
reference and is propagated to all later uses of this qubit. The mqtopt insert operation is deleted as there is no equivalent
operation in the mqtdyn dialect and any subsequent operation that uses the result of this operation acts on the qubit register reference.
}];

// Define dependent dialects
let dependentDialects = [
"::mqt::ir::dyn::MQTDynDialect",
"::mqt::ir::opt::MQTOptDialect"
];
}
1 change: 1 addition & 0 deletions mlir/lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@
# Licensed under the MIT License

add_subdirectory(Dialect)
add_subdirectory(Conversion)
10 changes: 10 additions & 0 deletions mlir/lib/Conversion/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# 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

add_subdirectory(MQTOptToMQTDyn)
add_subdirectory(MQTDynToMQTOpt)
16 changes: 16 additions & 0 deletions mlir/lib/Conversion/MQTDynToMQTOpt/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# 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

get_property(CONVERSION_LIBS GLOBAL PROPERTY MLIR_CONVERSION_LIBS)
list(APPEND CONVERSION_LIBS MQT::CoreIR)
add_compile_options(-fexceptions)

file(GLOB CONVERSION_SOURCES *.cpp)

add_mlir_library(MQTDynToMQTOpt ${CONVERSION_SOURCES} LINK_LIBS ${LIBRARIES} DEPENDS
MQTDynToMQTOptIncGen)
Loading
Loading