-
-
Notifications
You must be signed in to change notification settings - Fork 44
MLIR Plugin #881
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
flowerthrower
wants to merge
306
commits into
main
Choose a base branch
from
mlir-plugin
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.
Open
MLIR Plugin #881
Changes from 1 commit
Commits
Show all changes
306 commits
Select commit
Hold shift + click to select a range
09ea22c
⬆️ Update catalyst dep
ystade 74231a1
♻️ Clean-up CMakeLists
ystade 2c15f70
Merge branch 'main' into mlir-plugin
burgholzer 76cb1dc
🎨 remove stray changes
burgholzer cbc5cba
🔥 remove duplicate file
burgholzer 8a8f01d
🔥 remove further stray change
burgholzer 9f17863
🎨 add entry point for mqt.passes in pyproject.toml
flowerthrower 76535cb
add python guard
flowerthrower e69b0e1
Apply suggestions from code review
flowerthrower 3626013
🎨 pre-commit fixes
pre-commit-ci[bot] 5861960
Merge branch 'mlir-plugin' of https://github.com/cda-tum/mqt-core int…
flowerthrower 01b139c
🎨 update CMakeLists.txt to improve RPATH handling and installation di…
flowerthrower 816ac83
🎨 update CI configuration to enable BUILD_MQT_CORE_CATALYST_PLUGIN fo…
flowerthrower 217305d
🎨 update pyproject.toml to set version and clean up dependencies
flowerthrower 160c62e
🎨 pre-commit fixes
pre-commit-ci[bot] 2b01fde
add environment markers
flowerthrower 9d5f2eb
add ci for macos plugin test
flowerthrower d9d3028
fix ci
flowerthrower 91304bf
fix ci
flowerthrower e23edb5
fix ci
flowerthrower c5242e3
fix ci
flowerthrower 8db1931
fix ci
flowerthrower 4cc18b0
fix ci
flowerthrower 8c69fbd
fix ci
flowerthrower 2a04dd5
dynamic path finding
flowerthrower 65f34e7
calm down ruff
flowerthrower c2e0cda
remove version file
flowerthrower 203049f
🚚 rename test file
flowerthrower 270fd6d
🚧 use rpath
flowerthrower 74a7ce9
🚧 use matchAndRewrite
flowerthrower cec21b4
add path in ci to find dylib
flowerthrower ffedad9
Merge commit '08e61d14291da0e7e39af3f5e6c46a6641635eb7' into mlir-plugin
flowerthrower 95b7951
debug ci
flowerthrower 8167e6f
🎨 pre-commit fixes
pre-commit-ci[bot] 35c01bf
debug ci
flowerthrower c230d99
✅ add test for plugin execution
flowerthrower 705ac5d
🎨 pre-commit fixes
pre-commit-ci[bot] 116bb7f
➕ install pytest in ci
flowerthrower d5471b9
💚 fix urllib3 to stable version
flowerthrower 4bd1af9
⚡️ improve ci
flowerthrower 8c42d30
💚 improve ci
flowerthrower 2680a1e
🐛 fix dialect roundtrip tests
flowerthrower ec8bedd
enable full round-trip-test
flowerthrower 43f2bc2
add platform markers
flowerthrower 294272f
Merge branch 'main' into mlir-plugin
burgholzer 9ab3ef4
⏪ revert a couple of unrelated changes
burgholzer c43b7cc
♻️ restructure plugin package
burgholzer c0ee59f
🚧 work in progress that does not work yet
burgholzer 388acf3
🩹 fix sdist for mqt-core
burgholzer 54d4dec
➕ update dependencies
burgholzer ea57507
🚚 rename to `mqt-core-catalyst-plugin`
burgholzer 7015cf3
🔧 do not explicitly register plugins
burgholzer 745b26a
🔧 add target specific CMake settings
burgholzer 7dda34a
♻️ turn into standalone plugin package
burgholzer 624b5fa
🩹 do not register passes in dialect plugin
burgholzer 4b69fa2
🎨 miscellaneous fixes in pyproject.toml configuration
burgholzer cbc97e9
🚨 run pre-commit
burgholzer 7a97880
Merge remote-tracking branch 'refs/remotes/munich-quantum-toolkit/mai…
burgholzer fa3e096
⬆️ update mqt-core plugin dependency
burgholzer 9900215
🔧 do not run cpp-linter on catalyst plugin for now.
burgholzer 77266d3
👷 set up dedicated plugin CI
burgholzer 4d76e3b
🩹 activate virtual environment in CI
burgholzer 3d082df
🩹 enable PIC for MQT Core in plugin
burgholzer cd575bf
🔧 decouple plugin from main CMake build to avoid endless loop
burgholzer e3fe319
✏️ disambiguate workflow names
burgholzer ad33833
🔧 tweak workflow triggers
burgholzer 8124ce3
Merge branch 'main' into mlir-plugin
flowerthrower 70afd91
⏪ revert non plugin specific changes
flowerthrower 173e971
⏪ revert non-plugin specific changes
flowerthrower 3feaa26
⏪ revert non-plugin specific changes
flowerthrower aaa2188
🩹 properly run pytest
burgholzer d7d1783
🔧 only build catalyst MLIR component
burgholzer f1b333f
🩹 use active environment
burgholzer 4b0d47e
⚗️ try building with clang-19 on Ubuntu
burgholzer e385ea5
Merge branch 'main' into mlir-plugin
burgholzer a314f38
⚗️ try Catalyst MLIR commit
burgholzer 90dcb7b
🩹 set build type
burgholzer e80f154
⚗️ tweak LLVM installation
burgholzer 29b121d
🩹 fix the mqt-core version
burgholzer 8f804a2
🙈 simplify gitignore
burgholzer 962802b
⏪ revert unnecessary config
burgholzer e9a3b56
⏪ don't explicitly install clang version that will not be used
burgholzer 098c174
Merge branch 'main' into mlir-plugin
burgholzer 43333de
⚗️ disable mold as a linker for catalyst build
burgholzer 9179a40
♻️ one more `match` and `rewrite` replacement
burgholzer d9957f0
🔧 use mqt-core from the source tree
burgholzer 989adfd
⬆️ update catalyst dependency
burgholzer 14e5732
♻️ streamline Python plugin code
burgholzer 106fa7d
🚨 address some clang-tidy warnings
burgholzer 68142d6
🔧 tweak Catalyst installation on Linux
burgholzer 9255e49
🔊 print more test output
burgholzer f7dce4c
⚗️ try with LLVM 21
burgholzer 04a43f3
📦 only build the targets necessary for the plugin
burgholzer 063b184
⚗️ experiment with the RPATH settings
burgholzer e7aed92
🔧 exclude macos and llvm@21
burgholzer 610a8d9
⚗️ try compiling with gcc on Linux
burgholzer 039cffc
🩹 disable LLD for catalyst build
burgholzer 337ed02
🔧 only build the check-mlir target
burgholzer 78e6291
⚗️ try an explicit repair wheel step
burgholzer 7d874be
🔧 modify LLVM install configuration to maybe fix the Linux build
burgholzer e178ed8
🩹 fix CI configuration
burgholzer bec9939
⬆️ update to release version of Catalyst
burgholzer e045f05
🩹 also install the catalyst dependency group
burgholzer dd8cfb3
➕ add catalyst as a runtime dependency
burgholzer 1afa51a
⏪ remove the wheel repair step again for now
burgholzer 3b2c9dd
🔧 run without mold as a linker
burgholzer 04f134d
🔊 print shared library information logs
burgholzer 7668673
:refactor: added missing conversions from the separate PR #880
BertiFlorea 60f7c22
:memo: update pass description with the remaining op conversions
BertiFlorea e2fde36
:bug: fix missing patterns of existing conversions
BertiFlorea 3de0827
:recycle: add missing PeresOp conversion
BertiFlorea 8686445
:memo: update MQTOptToCatalystQuantum pass description
BertiFlorea 8fa8c0d
:green_heart: update include paths to prevent c lint error
BertiFlorea dfa1d9d
🎨 pre-commit fixes
pre-commit-ci[bot] f80355e
:rewind: :green_heart: revert include paths and update cmake file in …
BertiFlorea a682d93
:construction: try to explicitly point clang to see the includes
BertiFlorea d641451
🎨 pre-commit fixes
pre-commit-ci[bot] 81b0e36
:recycle: revert catalyst/lib/CMakeLists.txt and catalyst/CMakeLists.txt
BertiFlorea ea46083
🐛 add arith includes and fix arith div logic
flowerthrower 810ad4b
🐛 fix adjoint parameter handling in quantum gate conversions
flowerthrower 48802d4
Merge remote-tracking branch 'munich-quantum-toolkit/main' into mlir-…
burgholzer 5532a39
🔧 streamline CI configuration
burgholzer 6358288
📦 make uv resolution more precise and update lockfile
burgholzer 5953de0
🔧 match Catalyst macOS deployment target
burgholzer a83ecf6
⬆️ update C++ standard to C++20
burgholzer 163d7d1
⬆️ update mqt-core version
burgholzer 0b0b6d8
🔧 move prerelease config to comments
burgholzer fbfcf8c
🔥 remove unused CMake file
burgholzer 41ad6a7
🔥 remove unused variable
burgholzer 1667c4a
🚸 enable optional coverage collection
burgholzer 5b1f072
🔧 optimize CMake configuration with header file sets
burgholzer 32c4fdf
🎨 add format and linting config to plugin
burgholzer 48ea811
♻️ first round of plugin code cleanup
burgholzer 6a6c59f
🔥 remove LLVM 21 from the testing matrix
burgholzer ee084fd
👷 add Linux ARM to test matrix for plugin
burgholzer f9b32a2
♻️ simplify conversion patterns
burgholzer db60591
🐛 fix control and target ordering in MQTOpt to Catalyst translation
burgholzer 6e829f2
🐛 fix pattern for `XXminusYY`
burgholzer 54859f9
🔥 Comment out CI runs not using exact LLVM commit
burgholzer d2c7fec
✨ enable support for `CSWAP` from catalyst
burgholzer ee20add
✨ enable support for `S` and `T` from catalyst
burgholzer aa6bce6
✨ enable support for `ISWAP` from catalyst
burgholzer 9daf5d3
✨ enable support for `Identity` from catalyst
burgholzer 87ab895
✨ enable support for `SX` from catalyst
burgholzer ed9a3f3
✨ enable support for `ECR` from catalyst
burgholzer 2374378
🎨 directly use string comparisons
burgholzer fec7946
🎨 reduce boilerplate code
burgholzer d80d1e4
⏪ restore boilerplate code for unresolved materialization
burgholzer 12c47bf
♻️ streamline conversion to catalyst
burgholzer 9a52a78
♻️ assume `SX` and `ECR` to be legal and supported
burgholzer 857b368
✨ add support for CSWAP in conversion to catalyst
burgholzer 4a7bf6e
♻️ simplify `V` and `Vdg` gate sequence
burgholzer 778ae8f
🐛 fix DCX implementation
burgholzer b053818
🚨 fix missing header
burgholzer dbb2bb0
Merge branch 'main' into mlir-plugin
flowerthrower 45ee5e1
add getting started example
flowerthrower 11c308e
🎨 pre-commit fixes
pre-commit-ci[bot] f4580a3
💚 add ci for plugin lit tests
flowerthrower f84706e
🐛 fix tests
flowerthrower df10af6
🐛 fix control order in conversion test
flowerthrower f8215ca
🎨 pre-commit fixes
pre-commit-ci[bot] 541c7ca
🚧 debug failing conversion
flowerthrower 52023c1
🐛 fix test
flowerthrower 5e46c40
🐛 fix operation names
flowerthrower 5d3df91
✅ add conversion and test for xxplusyy gate
flowerthrower be0ba8e
🐛 fix lit setup
flowerthrower 3f11c3c
🎨 remove debugging lines
flowerthrower 1250676
✅ fix and test rzx gate conversion
flowerthrower b10f91b
🐛 fix include directories for Catalyst installation from PyPI
flowerthrower fca7d10
🎨 pre-commit fixes
pre-commit-ci[bot] a876914
🎨 clean up CI configuration by removing commented-out jobs and updati…
flowerthrower 108bb60
🐛 update Python executable references to Python3 in CMake files
flowerthrower 0fbdcfc
🐛 fix constant values in MQTOptToCatalystQuantum conversion for corre…
flowerthrower d48decf
📝 update README.md with installation instructions and system requirem…
flowerthrower 8142c08
🎨 pre-commit fixes
pre-commit-ci[bot] 906ca09
Merge commit '8bb58888948246ab3486c678a595ca670c2eddc7' into mlir-plugin
flowerthrower e7d8109
🚧 fix conversion patterns
flowerthrower ac126cd
🎨 imporve tests
flowerthrower b31f55e
✨ Update clang-tidy configurations and add clang-tidy to ci for the C…
flowerthrower 00b2661
🎨 pre-commit fixes
pre-commit-ci[bot] 5e642d7
🎨 pre-commit
flowerthrower 3bcc78a
🎨 improve lit test coverage
flowerthrower bca11f7
🎨 reduce code duplication
flowerthrower 7a4c649
Merge branch 'mlir-plugin' of https://github.com/cda-tum/mqt-core int…
flowerthrower a92555a
🎨 update parameter handling in ConvertMQTOptSimpleGate for VOp
flowerthrower 3110870
Merge branch 'main' into mlir-plugin
flowerthrower e1193f5
Merge branch 'mlir-plugin' of https://github.com/cda-tum/mqt-core int…
flowerthrower 0acca05
fix checks
flowerthrower 23c1fd7
add pauli gates conversion lit test
flowerthrower 559648d
add clifford gates conversion lit test
flowerthrower 708f2c8
add swap gates conversion lit test
flowerthrower 59bcd6e
add ising gates conversion lit test
flowerthrower fcf3f5d
add parameterized gates conversion lit test
flowerthrower 81ee0af
remove xxminusyy conversion
flowerthrower 1496eb8
remove duplicate tests
flowerthrower c9e0c9f
add quantum conversion tests
flowerthrower bad986e
🎨 make style consistent with other tests
flowerthrower ef302a7
Merge remote-tracking branch 'origin/main' into mlir-plugin
flowerthrower 2e7dc88
update tests
flowerthrower cd7916c
🎨 pre-commit fixes
pre-commit-ci[bot] ac029e8
fix tests
flowerthrower 2ea817b
Merge commit 'cd7916c2e194a709ae71c19aadd1ab3f99250e82' into mlir-plugin
flowerthrower dd33fbf
Merge branch 'main' into mlir-plugin
flowerthrower cec133f
first adaptions to work with new mref
flowerthrower 2830e66
🎨 pre-commit fixes
pre-commit-ci[bot] 1a49e72
make work with older llvm
flowerthrower f273fa4
Merge commit '2830e66c823f742f46bc19a356ddfaba6e73c422' into mlir-plugin
flowerthrower 08a5565
update ising
flowerthrower 0d79329
update entangling tests
flowerthrower 0755907
finish update all mqtopt tests
flowerthrower fd2c784
fix quantum pauli test
flowerthrower e3ef2e9
update quantum to mqt conversion to account for mref
flowerthrower 3fe4e05
use mlir isa
flowerthrower 70be761
standardize tests
flowerthrower 54c1dd7
calm down warnings
flowerthrower abc676d
Merge remote-tracking branch 'origin/main' into mlir-plugin
flowerthrower 1906761
fix fialing tests
flowerthrower fe20c95
🚧 wip
flowerthrower 54a4ec1
all lit tests succeed
flowerthrower b50d557
fix conversion dynamic index from operand
flowerthrower 7443c3a
Merge commit '1e22f589e0531e4693a22beb6ae8eb5a53a85eb5' into mlir-plugin
flowerthrower c8af436
fix: update greedy driver configuration for MLIR version compatibility
flowerthrower c789e97
fix: streamline top-down traversal configuration for MLIR compatibility
flowerthrower 443ea2f
fix: add conversion pattern for GlobalPhaseOp in Catalyst to MQTOpt
flowerthrower 349e952
fix: remove unnecessary comments in ConvertQuantumGlobalPhase struct
flowerthrower e1e300c
fix: enhance gate conversion logic for RX, RY, RZ, CRX, CRY, CRZ, and…
flowerthrower 8eec5c7
fix: implement conversion pattern for XXplusYYOp with parameter handl…
flowerthrower 3721891
fix: update Ising gate conversion test to correctly handle new RZ par…
flowerthrower fd43fba
fix: add device configuration utilities to prevent gate decomposition…
flowerthrower 36a5d50
fix: add python test cases for MQT plugin to ensure correct roundtrip…
flowerthrower 886e71d
🎨 pre-commit fixes
pre-commit-ci[bot] 2032b9e
fix: update Ising gate tests to use correct angle parameter and add P…
flowerthrower b071000
fix: update C++ linter configuration to use input from caller and ign…
flowerthrower 3d44546
fix: add type hint for kwargs in get_device function and update docst…
flowerthrower f518011
Merge branch 'main' into mlir-plugin
flowerthrower 71065ab
fix: update cpp-linter workflow commit
flowerthrower d6fec59
fix: reorder includes and improve type conversion comments in Catalys…
flowerthrower 36b52da
Merge branch 'mlir-plugin' of https://github.com/cda-tum/mqt-core int…
flowerthrower f7f806b
fix: update MLIR and Catalyst dependencies and adjust Python version …
flowerthrower 38c779c
Merge branch 'main' into mlir-plugin
flowerthrower d40fa29
fix: clean up README.md by removing TODO comments and improving wording
flowerthrower f79d5a9
Merge branch 'mlir-plugin' of https://github.com/cda-tum/mqt-core int…
flowerthrower 465242a
fix: add explicit constructor to QubitInfo for gcc-14 compatibility
flowerthrower 70c4596
fix: enhance ising gates roundtrip test with custom MLIR pipelines an…
flowerthrower cc88071
Refactor code structure for improved readability
flowerthrower 7b95c7b
Apply suggestions from code review
flowerthrower 90c25d1
fix: correct variable usage in ExternalDependencies.cmake and improve…
flowerthrower 3fe4813
🎨 pre-commit fixes
pre-commit-ci[bot] 2239690
feat: implement XXminusYY gate conversion and update test cases for I…
flowerthrower 153b6e6
Merge branch 'mlir-plugin' of https://github.com/cda-tum/mqt-core int…
flowerthrower 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| .PHONY: plugin | ||
|
|
||
| CATALYST_BASE_DIR := /Users/patrickhopf/Code/catalyst/mlir | ||
| CATALYST_BUILD_DIR := $(CATALYST_BASE_DIR)/build | ||
| LLVM_BUILD_DIR := $(CATALYST_BASE_DIR)/llvm-project/build | ||
| LLVM_EXTERNAL_LIT := $(LLVM_BUILD_DIR)/bin/llvm-lit | ||
| CATALYST_TOOLS_DIR := $(LLVM_BUILD_DIR)/bin | ||
|
|
||
| plugin: | ||
| cmake -B build -G Ninja \ | ||
| -DCatalyst_DIR=$(CATALYST_BUILD_DIR)/lib/cmake/catalyst \ | ||
| -DMLIR_DIR=$(LLVM_BUILD_DIR)/lib/cmake/mlir \ | ||
| -DBUILD_MQT_CORE_MLIR=ON \ | ||
|
|
||
| cmake --build build | ||
| cmake --build build --target quantum-opt |
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
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 |
|---|---|---|
|
|
@@ -6,3 +6,4 @@ | |
| # Licensed under the MIT License | ||
|
|
||
| add_subdirectory(quantum-opt) | ||
| add_subdirectory(mqt-plugin) | ||
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,28 @@ | ||
| # Copyright (c) 2025 Chair for Design Automation, TUM | ||
| # All rights reserved. | ||
| # | ||
| # SPDX-License-Identifier: MIT | ||
| # | ||
| # Licensed under the MIT License | ||
|
|
||
| set(PLUGIN_OUTPUT_DIR "${CMAKE_SOURCE_DIR}/mqt_plugin_wheel/mqt_plugin") | ||
| add_compile_options(-fexceptions) | ||
|
|
||
| add_llvm_library( | ||
| MQTPlugin | ||
| MODULE | ||
| BUILDTREE_ONLY | ||
| mqt-plugin.cpp | ||
| DEPENDS | ||
| MLIRMQTOpt | ||
| MLIRMQTOptTransforms | ||
| PLUGIN_TOOL | ||
| catalyst-cli | ||
| LINK_LIBS | ||
| MLIRMQTOpt | ||
| MLIRMQTOptTransforms | ||
| ${MLIRQuantum_LIB} # Link directly to the static library | ||
| ) | ||
|
|
||
| # Set output directory for the plugin to be shipped with the wheel | ||
| set_target_properties(MQTPlugin PROPERTIES LIBRARY_OUTPUT_DIRECTORY "${PLUGIN_OUTPUT_DIR}") |
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,45 @@ | ||
| /* | ||
| * Copyright (c) 2025 Chair for Design Automation, TUM | ||
| * All rights reserved. | ||
| * | ||
| * SPDX-License-Identifier: MIT | ||
| * | ||
| * Licensed under the MIT License | ||
| */ | ||
|
|
||
| //===- mqt-plugin.cpp ------------------------------------*- C++ -*-===// | ||
| // | ||
| // This file is licensed under the Apache License v2.0 with LLVM Exceptions. | ||
| // See https://llvm.org/LICENSE.txt for license information. | ||
| // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| #include "mlir/Dialect/MQTOpt/IR/MQTOptDialect.h" | ||
| #include "mlir/Dialect/MQTOpt/Transforms/Passes.h" | ||
| #include "mlir/IR/MLIRContext.h" | ||
| #include "mlir/Tools/Plugins/DialectPlugin.h" | ||
| #include "mlir/Tools/Plugins/PassPlugin.h" | ||
|
|
||
| #include "llvm/Config/llvm-config.h" | ||
| #include "llvm/Support/Compiler.h" | ||
|
|
||
| using namespace mlir; | ||
|
|
||
| /// Dialect plugin registration mechanism. | ||
| /// Observe that it also allows to register passes. | ||
| /// Necessary symbol to register the dialect plugin. | ||
| extern "C" LLVM_ATTRIBUTE_WEAK DialectPluginLibraryInfo | ||
| mlirGetDialectPluginInfo() { | ||
| return {MLIR_PLUGIN_API_VERSION, "MQTOpt", LLVM_VERSION_STRING, | ||
| [](DialectRegistry* registry) { | ||
| registry->insert<::mqt::ir::opt::MQTOptDialect>(); | ||
| }}; | ||
| } | ||
|
|
||
| /// Pass plugin registration mechanism. | ||
| /// Necessary symbol to register the pass plugin. | ||
| extern "C" LLVM_ATTRIBUTE_WEAK PassPluginLibraryInfo mlirGetPassPluginInfo() { | ||
| return {MLIR_PLUGIN_API_VERSION, "MQTOptPasses", LLVM_VERSION_STRING, | ||
| []() { mqt::ir::opt::registerMQTOptPasses(); }}; | ||
| } |
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,9 @@ | ||
| # Copyright (c) 2025 Chair for Design Automation, TUM | ||
| # All rights reserved. | ||
| # | ||
| # SPDX-License-Identifier: MIT | ||
| # | ||
| # Licensed under the MIT License | ||
|
|
||
| include mqt_plugin/lib/* | ||
| include mqt_plugin/test/*.py |
Binary file not shown.
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,84 @@ | ||
| # Copyright (c) 2025 Chair for Design Automation, TUM | ||
| # All rights reserved. | ||
| # | ||
| # SPDX-License-Identifier: MIT | ||
| # | ||
| # Licensed under the MIT License | ||
|
|
||
| # Copyright 2024 Xanadu Quantum Technologies Inc. | ||
|
|
||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
|
|
||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
|
|
||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| """MQT Plugin interface.""" | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| from pathlib import Path | ||
|
|
||
| import pennylane as qml | ||
| from catalyst.passes import PassPlugin | ||
|
|
||
|
|
||
| def getMQTPluginAbsolutePath(): | ||
| """Returns the absolute path to the MQT plugin.""" | ||
| ext = "dylib" # TODO: we should provide "so" as well | ||
| # ext = "so" if platform.system() == "Linux" else "dylib" | ||
| return Path(Path(__file__).parent.absolute(), f"MQTPlugin.{ext}") | ||
|
|
||
|
|
||
| def name2pass(_name): | ||
| """Example entry point for MQT plugin.""" | ||
| return getMQTPluginAbsolutePath(), "mqt-core-round-trip" | ||
|
|
||
|
|
||
| def MQTCoreRoundTrip(*flags, **valued_options): | ||
| """Applies the "mqt-core-round-trip" pass.""" | ||
|
|
||
| def add_pass_to_pipeline(**kwargs): | ||
| pass_pipeline = kwargs.get("pass_pipeline", []) | ||
| pass_pipeline.append( | ||
| PassPlugin( | ||
| getMQTPluginAbsolutePath(), | ||
| "mqt-core-round-trip", | ||
| *flags, | ||
| **valued_options, | ||
| ) | ||
| ) | ||
| return pass_pipeline | ||
|
|
||
| def decorator(qnode): | ||
| if not isinstance(qnode, qml.QNode): | ||
| # Technically, this apply pass is general enough that it can apply to | ||
| # classical functions too. However, since we lack the current infrastructure | ||
| # to denote a function, let's limit it to qnodes | ||
| msg = f"A QNode is expected, got the classical function {qnode}" | ||
| raise TypeError(msg) | ||
|
|
||
| def qnode_call(*args, **kwargs): | ||
| kwargs["pass_pipeline"] = add_pass_to_pipeline(**kwargs) | ||
| return qnode(*args, **kwargs) | ||
|
|
||
| return qnode_call | ||
|
|
||
| # When the decorator is used without () | ||
| if len(flags) == 1 and isinstance(flags[0], qml.QNode): | ||
| qnode = flags[0] | ||
|
|
||
| def qnode_call(*args, **kwargs): | ||
| kwargs["pass_pipeline"] = add_pass_to_pipeline(**kwargs) | ||
| return qnode(*args, **kwargs) | ||
|
|
||
| return qnode_call | ||
|
|
||
| # When the decorator is used with () | ||
| return decorator |
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,6 @@ | ||
| # PennyLane dvice configuration file | ||
|
|
||
| ["main"] | ||
| shots = 1024 | ||
| wires = 2 | ||
| cmap = [[0, 1], [1, 0]] |
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,168 @@ | ||
| # Copyright (c) 2025 Chair for Design Automation, TUM | ||
| # All rights reserved. | ||
| # | ||
| # SPDX-License-Identifier: MIT | ||
| # | ||
| # Licensed under the MIT License | ||
|
|
||
| # Copyright 2024 Xanadu Quantum Technologies Inc. | ||
|
|
||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
|
|
||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
|
|
||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| """This file performs the frontend lit tests that the peephole transformations are correctly lowered. | ||
|
|
||
| We check the transform jax primitives for each pass is correctly injected | ||
| during tracing, and these transform primitives are correctly lowered to the mlir before | ||
| running -apply-transform-sequence. | ||
| """ | ||
|
|
||
| # RUN: %PYTHON %s | FileCheck %s | ||
|
|
||
| # pylint: disable=line-too-long | ||
| from __future__ import annotations | ||
|
|
||
| from pathlib import Path | ||
|
|
||
| import pennylane as qml | ||
| from catalyst import CompileError, pipeline | ||
| from pennylane.configuration import Configuration | ||
| from utils import print_jaxpr, print_mlir | ||
| from utils import qjit_for_tests as qjit | ||
|
|
||
|
|
||
| def flush_peephole_opted_mlir_to_iostream(QJIT) -> None: | ||
| """The QJIT compiler does not offer a direct interface to access an intermediate mlir in the pipeline. | ||
| The `QJIT.mlir` is the mlir before any passes are run, i.e. the "0_<qnode_name>.mlir". | ||
| Since the QUANTUM_COMPILATION_PASS is located in the middle of the pipeline, we need | ||
| to retrieve it with keep_intermediate=True and manually access the "2_QuantumCompilationPass.mlir". | ||
| Then we delete the kept intermediates to avoid pollution of the workspace. | ||
| """ | ||
|
|
||
|
|
||
| # | ||
| # pipeline | ||
| # | ||
|
|
||
|
|
||
| def test_pipeline_lowering() -> None: | ||
| """Basic pipeline lowering on one qnode.""" | ||
| my_pipeline = { | ||
| "cancel_inverses": {}, | ||
| "merge_rotations": {}, | ||
| } | ||
|
|
||
| @qjit(keep_intermediate=True, verbose=True) | ||
| @pipeline(my_pipeline) | ||
| @qml.qnode(qml.device("lightning.qubit", wires=2)) | ||
| def test_pipeline_lowering_workflow(x): | ||
| qml.RX(x, wires=[0]) | ||
| qml.Hadamard(wires=[1]) | ||
| qml.Hadamard(wires=[1]) | ||
| return qml.expval(qml.PauliY(wires=0)) | ||
|
|
||
| # CHECK: pipeline=(remove-chained-self-inverse, merge-rotations) | ||
| print_jaxpr(test_pipeline_lowering_workflow, 1.2) | ||
|
|
||
| # CHECK: transform.named_sequence @__transform_main | ||
| # CHECK-NEXT: {{%.+}} = transform.apply_registered_pass "remove-chained-self-inverse" to {{%.+}} | ||
| # CHECK-NEXT: {{%.+}} = transform.apply_registered_pass "merge-rotations" to {{%.+}} | ||
| # CHECK-NEXT: transform.yield | ||
| print_mlir(test_pipeline_lowering_workflow, 1.2) | ||
|
|
||
| # CHECK: {{%.+}} = call @test_pipeline_lowering_workflow_transformed_0( | ||
| # CHECK: func.func public @test_pipeline_lowering_workflow_transformed_0( | ||
| # CHECK: {{%.+}} = quantum.custom "RX"({{%.+}}) {{%.+}} : !quantum.bit | ||
| # CHECK-NOT: {{%.+}} = quantum.custom "Hadamard"() {{%.+}} : !quantum.bit | ||
| # CHECK-NOT: {{%.+}} = quantum.custom "Hadamard"() {{%.+}} : !quantum.bit | ||
| test_pipeline_lowering_workflow(42.42) | ||
| flush_peephole_opted_mlir_to_iostream(test_pipeline_lowering_workflow) | ||
|
|
||
|
|
||
| def test_MQT_plugin() -> bool | None: | ||
| """Generate MLIR for the MQT plugin via entry-point. | ||
|
|
||
| HACK required to make this test work! | ||
|
|
||
| 1. in catalyst/pipelines.py, add the following line: | ||
|
|
||
| def get_enforce_runtime_invariants_stage(_options: CompileOptions) -> List[str]: | ||
| ... | ||
| enforce_runtime_invariants = [ | ||
| ... | ||
| "builtin.module(mqt-core-round-trip)", # HACK | ||
| "builtin.module(apply-transform-sequence)", | ||
| ... | ||
| ] | ||
|
|
||
| 2. in catalyst/compiler.py, add the following line: | ||
|
|
||
| def run_from_ir(self, ir: str, module_name: str, workspace: Directory): | ||
| ... | ||
| cmd = self.get_cli_command(tmp_infile_name, output_ir_name, module_name, workspace) | ||
| cmd += ["--debug"] # HACK | ||
| try: | ||
| ... | ||
|
|
||
| """ | ||
| my_pipeline = { | ||
| "mqt.mqt-core-round-trip": {"cmap": [[0, 1], [1, 0]]}, | ||
| # "mqt.mqt-core-round-trip": {}, | ||
| } | ||
|
|
||
| config_path = Path(__file__).parent / "dev_config.toml" | ||
| Configuration(config_path) | ||
| dev = qml.device( | ||
| name="lightning.qubit", wires=2 | ||
| ) # config=conf)#"lightning.qubit", {'wires': 2, 'cmap': [[0, 1], [1, 0]]}) | ||
|
|
||
| try: | ||
|
|
||
| @qjit(keep_intermediate=True, verbose=True) | ||
| @pipeline(my_pipeline) | ||
| @qml.qnode(dev) | ||
| def test_pipeline_mqtplugin_workflow() -> None: | ||
| qml.Hadamard(wires=[0]) | ||
|
|
||
| test_pipeline_mqtplugin_workflow() | ||
| flush_peephole_opted_mlir_to_iostream(test_pipeline_mqtplugin_workflow) | ||
|
|
||
| except CompileError as error: # Expecting failure, because MQT plugin does not cover full roundtrip (yet) | ||
| error_msg = str(error) # Recover the output after application of the MQT conversion pass | ||
| try: | ||
| mlir_str = error_msg.split("module @module_test_pipeline_mqtplugin_workflow_transformed {")[1] | ||
| mlir_str = error_msg.split("}\n}")[0] | ||
| except: | ||
|
||
| return False | ||
|
|
||
| transformed = [ | ||
| r"%c = stablehlo.constant dense<0> : tensor<i64>", | ||
| r"%extracted = tensor.extract %c[] : tensor<i64>", | ||
| r"quantum.device shots(%extracted) ", # ... there is more in this line | ||
| r"%c_0 = stablehlo.constant dense<1> : tensor<i64>", | ||
| r'%0 = "mqtopt.allocQubitRegister"() <{size_attr = 1 : i64}> : () -> !mqtopt.QubitRegister', | ||
| r"%c_1 = stablehlo.constant dense<0> : tensor<i64>", | ||
| r"%extracted_2 = tensor.extract %c_1[] : tensor<i64>", | ||
| r'%out_qureg, %out_qubit = "mqtopt.extractQubit"(%0, %extracted_2) : (!mqtopt.QubitRegister, i64) -> (!mqtopt.QubitRegister, !mqtopt.Qubit)', | ||
| r"%1 = mqtopt.H() %out_qubit : !mqtopt.Qubit", | ||
| r"%c_3 = stablehlo.constant dense<0> : tensor<i64>", | ||
| r"%extracted_4 = tensor.extract %c_3[] : tensor<i64>", | ||
| r'%2 = "mqtopt.insertQubit"(%out_qureg, %1, %extracted_4) : (!mqtopt.QubitRegister, !mqtopt.Qubit, i64) -> !mqtopt.QubitRegister', | ||
| r'"mqtopt.deallocQubitRegister"(%2) : (!mqtopt.QubitRegister) -> ()', | ||
| r"quantum.device_release", | ||
| r"return", | ||
| ] | ||
|
|
||
| return all(t in mlir_str for t in transformed) | ||
|
|
||
|
|
||
| test_MQT_plugin() | ||
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.
Uh oh!
There was an error while loading. Please reload this page.