Skip to content

MLIR Conversion(s) #880

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 129 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
129 commits
Select commit Hold shift + click to select a range
0589644
🚧 add conversions
flowerthrower Mar 19, 2025
34387f5
🚧 add former dummy.mlir test file
flowerthrower Mar 19, 2025
3543439
🎨 pre-commit fixes
pre-commit-ci[bot] Mar 19, 2025
15151e4
🚧 add plugin files
flowerthrower Mar 20, 2025
63ddd2f
🧪 update test
flowerthrower Mar 20, 2025
5eefc34
🚧 fix cmake config
flowerthrower Mar 20, 2025
6ef8276
🚧 add conversion passes to quantum-opt
flowerthrower Mar 20, 2025
35d781f
🎨 pre-commit fixes
pre-commit-ci[bot] Mar 20, 2025
54f1f19
🚧 clean up quantum-opt
flowerthrower Mar 20, 2025
12d8f11
🚧 add dialect dependency
flowerthrower Mar 20, 2025
9a0fb1c
🎨 pre-commit fixes
pre-commit-ci[bot] Mar 20, 2025
a46def1
Merge remote-tracking branch 'origin/main' into mlir-conversion
flowerthrower Mar 23, 2025
d8aed8f
🎨 pre-commit fixes
pre-commit-ci[bot] Mar 23, 2025
00b3d40
🚧 remove catalyst test
flowerthrower Mar 24, 2025
17291af
🚧 remove cmap
flowerthrower Mar 24, 2025
0d59f0a
🚧 add meas
flowerthrower Mar 24, 2025
4344df3
🚧 pre-commit
flowerthrower Mar 24, 2025
27cc84f
✅ add ghz example
flowerthrower Mar 24, 2025
d78e5db
🚧 add Hadamard conversion
flowerthrower Mar 24, 2025
839fb5b
🐛 fix duplicated struct names
flowerthrower Mar 24, 2025
e4c0196
🚧 add more tests
flowerthrower Mar 25, 2025
a019076
🎨 pre-commit fixes
pre-commit-ci[bot] Mar 25, 2025
1daaec1
🐛 fix ctrl qubits
flowerthrower Mar 25, 2025
c7deddd
🚧 add bool control
flowerthrower Mar 25, 2025
d3a42b3
🚧 imporve test files
flowerthrower Mar 25, 2025
e593baf
Merge commit 'a019076d1d364a42e8b9cd1c98f374d62e05141d' into mlir-con…
flowerthrower Mar 25, 2025
92b4742
✨ add Hadamard gate
flowerthrower Mar 26, 2025
ee108b7
🚧 update test
flowerthrower Mar 26, 2025
c3eea64
🚧 add lit test for plugin roundtrip
flowerthrower Mar 26, 2025
3fb5ce3
🔥 removed plugin test (not possible yet)
flowerthrower Mar 26, 2025
07e5130
🎨 per-commit
flowerthrower Mar 26, 2025
17c1e22
🔥 remove local use makefile
flowerthrower Mar 26, 2025
bb3cd4e
🚧 revert some changes
flowerthrower Mar 26, 2025
54d8064
➖ remove linklib
flowerthrower Mar 26, 2025
a6eb526
➖ remove linklib
flowerthrower Mar 26, 2025
de4b879
🐛 prevent Targets Defined nlohmann_json error
flowerthrower Mar 26, 2025
f9d6359
💡 add note
flowerthrower Mar 26, 2025
494f495
🔥 remove local makefile
flowerthrower Mar 26, 2025
39f9460
🚧 use only header files instead of full lib
flowerthrower Mar 26, 2025
e63f165
🎨 pre-commit
flowerthrower Mar 26, 2025
9f09e87
✅ fix all tests
flowerthrower Mar 26, 2025
4757068
🎨 align alloc conversion
flowerthrower Mar 26, 2025
38d3f6a
🎨 align extract conversion
flowerthrower Mar 26, 2025
f2e929d
🎨 align gate conversions
flowerthrower Mar 26, 2025
461845d
🔥 remove buggy measure conversion
flowerthrower Mar 26, 2025
bb31dd8
init
flowerthrower Mar 28, 2025
98f3da9
🐛 cherry pick: prevent Targets Defined nlohmann_json error
flowerthrower Mar 26, 2025
91cff38
🚧 fix cmakelists
flowerthrower Mar 28, 2025
2b460c8
🔥 remove unnecessary includes
flowerthrower Mar 28, 2025
684b5cf
✨ add ConvertMQTOptMeasure
flowerthrower Mar 28, 2025
562de94
✨ add ConvertQuantumMeasure
flowerthrower Mar 28, 2025
b8a7569
🚧 rename quantum names
flowerthrower Mar 31, 2025
903b5d7
🚧 finish renaming
flowerthrower Mar 31, 2025
39cf8e5
🎨 pre-commit
flowerthrower Mar 31, 2025
cef9047
Merge branch 'mlir-conversion' into mlir-conversion-plugin
flowerthrower Mar 31, 2025
f94019a
🚧 update names
flowerthrower Mar 31, 2025
4dbd59d
refactor(mlir): :recycle: update deprecated `applyPatternsAndFoldGree…
DRovara Apr 1, 2025
24cec28
test(mlir): :white_check_mark: improve quality of mqt-core-round-trip…
DRovara Apr 1, 2025
f238319
Merge commit '24cec28a66fdc99f6b07b9dec7d6c56f5efa467c' into mlir-con…
flowerthrower Apr 1, 2025
4a3bdf0
🚧 move pass options
flowerthrower Apr 1, 2025
6b8d7ad
fix(mlir): :bug: fix issue that causes `FromQuantumComputationPattern…
DRovara Apr 1, 2025
042d068
test(mlir): :white_check_mark: make test actually executable
DRovara Apr 1, 2025
3373c76
ci(mlir): :construction_worker: only use llvm-20 for testing
DRovara Apr 1, 2025
5e7d6c6
🚧 wip
flowerthrower Apr 1, 2025
7d12f7c
Revert "ci(mlir): :construction_worker: only use llvm-20 for testing"
DRovara Apr 1, 2025
beec847
fix(mlir): :recycle: go back to using applyPatternsAndFoldGreedily to…
DRovara Apr 1, 2025
4edf6f3
:bug: fixed conversion of static attributes and dynamic operands
BertiFlorea Apr 1, 2025
60f3ee8
🎨 pre-commit fixes
pre-commit-ci[bot] Apr 1, 2025
a8cd104
Merge commit 'beec84732414eb1fa9466eed8b266470db40d743' into mlir-con…
flowerthrower Apr 2, 2025
1ac55bc
🐛 fix undefined op access
flowerthrower Apr 2, 2025
0f8e199
save
flowerthrower Apr 8, 2025
893c2f3
Merge branch 'mlir-conversion' into mlir-conversion-plugin
flowerthrower Apr 8, 2025
ebbda74
🚧 save full roundtirp working
flowerthrower Apr 8, 2025
2b824d1
wip save
flowerthrower Apr 10, 2025
7199987
Merge commit 'cc1797ceb856785a5c21200d3aa7789276213fe9' into mlir-con…
flowerthrower Apr 11, 2025
d06c7f0
🚧 fix version
flowerthrower Apr 11, 2025
9246feb
add mapping roundtirp comparison
flowerthrower Apr 12, 2025
55485c0
🚧 add some stuff for PR
flowerthrower Apr 22, 2025
89336e2
Merge commit '55485c0831bf7781de8348fb5af9f125ccd7b333' into mlir-con…
flowerthrower Apr 22, 2025
8b09c68
🎨 pre-commit fixes
pre-commit-ci[bot] Apr 22, 2025
c1b5efa
cleanup: remove duplicate MQTOptDialect includes
flowerthrower Apr 22, 2025
166bca6
Merge branch 'main' into mlir-conversion
flowerthrower Apr 22, 2025
cffe6bb
refactor: update pattern application methods and improve includes
flowerthrower Apr 22, 2025
af534ff
refactor: revert changes that were moved to mlir-improve-roundtrip br…
flowerthrower Apr 22, 2025
956260c
Merge remote-tracking branch 'origin/mlir-conversion' into mlir-conve…
flowerthrower Apr 22, 2025
4df9fb8
style: format code for consistency and readability
flowerthrower Apr 22, 2025
4c721ae
refactor: update pattern application methods to use applyPatternsAndF…
flowerthrower Apr 22, 2025
cecd0d6
style: improve code formatting for readability
flowerthrower Apr 22, 2025
a6cb11e
refactor: remove deprecated cmake policies and add include guards in …
flowerthrower Apr 22, 2025
a3a651c
refactor: modify option to enable Catalyst conversion passes in CMake…
flowerthrower Apr 22, 2025
6bcf5cc
refactor: add support for Catalyst conversion passes in CMakeLists.tx…
flowerthrower Apr 22, 2025
e81af86
refactor: remove unnecessary hack for controlled gates in MQTOptToCat…
flowerthrower Apr 22, 2025
3f0775f
refactor: remove unused coupling map option from CatalystQuantumToMQTOpt
flowerthrower Apr 22, 2025
8e45ec1
refactor: make catalyst optional for quantum-opt
flowerthrower Apr 22, 2025
d3df8c1
refactor: update include directives for consistency
flowerthrower Apr 22, 2025
47258fe
refactor: enhance pass descriptions for Catalyst and MQTOpt conversions
flowerthrower Apr 22, 2025
5d7a702
refactor: introduce compatibility macros for MLIR pattern application
flowerthrower Apr 23, 2025
5d380d6
refactor: fix QuantumOpsDialect include to QuantumDialect
flowerthrower Apr 23, 2025
5abe9b1
refactor: consolidate legal operation declarations in Catalyst and MQ…
flowerthrower Apr 23, 2025
889ffd6
refactor: fix tests
flowerthrower Apr 23, 2025
8142225
refactor: fix tests
flowerthrower Apr 23, 2025
e60af0f
refactor: update CHECK comments for quantum operations in mqtopt.mlir…
flowerthrower Apr 23, 2025
cab888a
refactor: simplify operand extraction in conversion patterns for quan…
flowerthrower Apr 23, 2025
c1ec80c
refactor: replace push_back with emplace_back
flowerthrower Apr 23, 2025
0b084eb
add comments for boilerplate code
flowerthrower Apr 23, 2025
e905f08
Merge branch 'main' into mlir-conversion
flowerthrower Apr 23, 2025
7dde58e
refactor: remove unused includes in CatalystQuantumToMQTOpt.cpp
flowerthrower Apr 23, 2025
7841b33
Merge branch 'main' into mlir-conversion
flowerthrower Apr 25, 2025
d2213ea
update creation call for mqtopt operations
flowerthrower Apr 25, 2025
d1f480f
refactor: add missing includes for assert and cstddef
flowerthrower Apr 25, 2025
6166d72
refactor: remove unused includes and commented-out code
flowerthrower Apr 25, 2025
d97e5ef
Merge branch 'main' into mlir-conversion
flowerthrower Apr 28, 2025
1ac3384
update CHECKs in failing conversion tests
flowerthrower Apr 28, 2025
35236d2
Apply suggestions from code review
flowerthrower Apr 29, 2025
65ec200
:refactor: rename ENABLE_CATALYST to ENABLE_MQT_CORE_MLIR_CATALYST_PL…
flowerthrower Apr 29, 2025
fad43e4
:refactor: update pass name and related test commands to use 'catalys…
flowerthrower Apr 29, 2025
c45fadf
Refine dialect conversion summaries and test flags.
flowerthrower Apr 29, 2025
a8b32ac
remove stray whitespace
flowerthrower Apr 29, 2025
a5c0be4
Apply suggestions from code review
flowerthrower Apr 29, 2025
1f254f7
undo unrelated files
flowerthrower Apr 29, 2025
40845b9
Refactor MLIR version check for Catalyst compatibility
flowerthrower Apr 29, 2025
2134e36
Add initial CI configuration for Catalyst with MLIR testing
flowerthrower May 2, 2025
dbdf863
install llvm19 using Homebrew
flowerthrower May 2, 2025
08591a5
only clone Catalyst no submodules
flowerthrower May 2, 2025
f3d9ded
fix macos version
flowerthrower May 2, 2025
4620c18
fix macos version
flowerthrower May 2, 2025
472616b
fix macos version global
flowerthrower May 2, 2025
5289a0f
split ci pipeline test for debugging
flowerthrower May 2, 2025
02d3c2b
Merge branch 'main' into mlir-conversion
flowerthrower May 5, 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
122 changes: 122 additions & 0 deletions .github/workflows/ci_catalyst.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
name: Catalyst CI
on:
push:
branches:
- main
paths:
- "mlir/**"
pull_request:
paths:
- "mlir/**"
- ".github/workflows/ci_catalyst.yml"
merge_group:
workflow_dispatch:

concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
cancel-in-progress: true

jobs:
cpp-test-catalyst:
name: 🇨‌ Test MLIR with LLVM@${{ matrix.llvm-version }}
runs-on: macos-14
strategy:
matrix:
llvm-version: [19]
Comment on lines +22 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.

Would be interesting to see this work on macos-13 (x86 runners) as well as llvm-version: 20.
The current build pipeline seems to pass, which is great already!

Unrelated to this PR in particular, but what could be a nice byproduct in a separate PR is that this already represents a functional macOS-14 CI pipeline for MLIR, which would be part of #925.

env:
CMAKE_BUILD_PARALLEL_LEVEL: 4
CTEST_PARALLEL_LEVEL: 4
FORCE_COLOR: 3
steps:
# check out the repository
- uses: actions/checkout@v4
with:
fetch-depth: 0

# set up ccache for faster C++ builds
- name: Setup ccache
uses: Chocobo1/setup-ccache-action@v1
with:
prepend_symlinks_to_path: false
override_cache_key: c++-tests-mlir
Copy link
Member

Choose a reason for hiding this comment

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

fairly sure you need to use a different cache key here, otherwise there will be cache contention between the jobs.

Suggested change
override_cache_key: c++-tests-mlir
override_cache_key: c++-tests-mlir-catalyst

If we extend the matrix of CI workflows above, the cache key should also be updated.


# set up mold as linker for faster C++ builds
- name: Set up mold as linker
uses: rui314/setup-mold@v1

# set up uv for faster Python package management
- name: Install the latest version of uv
uses: astral-sh/setup-uv@v6
with:
python-version: 3.13
activate-environment: true

# make sure ninja is installed
- name: Install Ninja
run: uv tool install ninja

# make sure the lit test runner is installed
- name: Install lit
run: uv pip install lit

# install LLVM 19 and MLIR via Homebrew and set up environment variables
- name: Install LLVM and MLIR via Homebrew
run: |
brew install llvm@19
brew link --force --overwrite llvm@19
echo "CC=$(brew --prefix llvm@19)/bin/clang" >> $GITHUB_ENV
echo "CXX=$(brew --prefix llvm@19)/bin/clang++" >> $GITHUB_ENV
echo "MLIR_DIR=$(brew --prefix llvm@19)/lib/cmake/mlir" >> $GITHUB_ENV
echo "LLVM_DIR=$(brew --prefix llvm@19)/lib/cmake/llvm" >> $GITHUB_ENV
echo "$(brew --prefix llvm@19)/bin" >> $GITHUB_PATH

# clone PennyLane Catalyst (from patched branch) - excl. submodules
- name: Clone PennyLane Catalyst
run: |
git clone --branch mqt_integration --depth=1 https://github.com/flowerthrower/catalyst.git catalyst

- name: Set macOS deployment target for linker
run: echo "MACOSX_DEPLOYMENT_TARGET=14.0" >> $GITHUB_ENV
Comment on lines +78 to +79
Copy link
Member

Choose a reason for hiding this comment

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

This should not be necessary as you are running on macOS 14 already.

Comment on lines +78 to +79
Copy link
Member

Choose a reason for hiding this comment

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

This should not be necessary as you are running on macOS 14 already.


# configure only MLIRQuantum dialect (skip building tools)
- name: Configure MLIRQuantum dialect
run: |
cmake -G Ninja -S catalyst/mlir -B catalyst/mlir/build \
-DCMAKE_BUILD_TYPE=Release \
-DMLIR_DIR=$MLIR_DIR \
-DLLVM_DIR=$LLVM_DIR \
-DCATALYST_BUILD_TOOLS=OFF \
-DEnzyme_DIR="none"

# build MLIRQuantum
- name: Build MLIRQuantum dialect
run: |
ninja -C catalyst/mlir/build MLIRQuantum
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
ninja -C catalyst/mlir/build MLIRQuantum
cmake --build catalyst/mlir/build --target MLIRQuantum


- name: Check Catalyst CMake config
run: test -f catalyst/mlir/build/lib/cmake/catalyst/CatalystConfig.cmake

# configure the project with CMake
- name: Configure CMake for MLIR
run: |
cmake -G Ninja -S . -B build \
-DCMAKE_BUILD_TYPE=Release \
-DBUILD_MQT_CORE_MLIR=ON \
-DENABLE_MQT_CORE_MLIR_CATALYST_PLUGIN=ON \
-DCatalyst_DIR="$PWD/catalyst/mlir/build/lib/cmake/catalyst"

# build the project
- name: Build MLIR quantum-opt
run: cmake --build build --config Release --target quantum-opt

# run conversion pipeline
- name: Run conversion -> catalystquantum-to-mqtopt
run: |
./build/mlir/tools/quantum-opt/quantum-opt \
--pass-pipeline="builtin.module(catalystquantum-to-mqtopt)" \
mlir/test/Conversion/quantum.mlir
- name: Run conversion -> mqtopt-to-catalystquantum
run: |
./build/mlir/tools/quantum-opt/quantum-opt \
--pass-pipeline="builtin.module(mqtopt-to-catalystquantum)" \
mlir/test/Conversion/mqtopt.mlir
20 changes: 20 additions & 0 deletions cmake/ExternalDependencies.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,23 @@ endif()

# Make all declared dependencies available.
FetchContent_MakeAvailable(${FETCH_PACKAGES})

if(ENABLE_MQT_CORE_MLIR_CATALYST_PLUGIN)
# Manually detect the installed Catalyst Python and get its cmake directory.
execute_process(
COMMAND "${Python_EXECUTABLE}" -c
"import catalyst, os; print(os.path.dirname(catalyst.__file__))"
OUTPUT_STRIP_TRAILING_WHITESPACE
OUTPUT_VARIABLE Python_Catalyst_DIR
ERROR_QUIET)
message(STATUS "Found Catalyst package: ${Python_Catalyst_DIR}")

# TODO: once the Catalyst Python package provides the necessary files set(Catalyst_DIR
# "${Python_Catalyst_DIR}/mlir/build/lib/cmake/catalyst")
Comment on lines +78 to +88
Copy link
Member

Choose a reason for hiding this comment

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

Ideally, there would be no need to do something like set(Catalyst_DIR "${Python_Catalyst_DIR}/..., but Catalyst_DIR would already be a result of the execute_process call.
Either catalyst provides an entry point for that (similar to pybind, nanobind, or mqt-core), or we parse this somewhat from output similar to the existing command here by a simple Python script.

if(Catalyst_DIR)
list(APPEND CMAKE_PREFIX_PATH "${Catalyst_DIR}")
find_package(Catalyst REQUIRED)
else()
message(STATUS "Could not detect Catalyst CMake directory")
endif()
Comment on lines +89 to +94
Copy link
Member

Choose a reason for hiding this comment

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

This needs to fail hard if Catalyst cannot be found.

Suggested change
if(Catalyst_DIR)
list(APPEND CMAKE_PREFIX_PATH "${Catalyst_DIR}")
find_package(Catalyst REQUIRED)
else()
message(STATUS "Could not detect Catalyst CMake directory")
endif()
find_package(Catalyst REQUIRED)

Copy link
Member

Choose a reason for hiding this comment

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

Once a compatible version of Catalyst is released, this will probably also require a version specifier to indicate the minimum version required.

endif()
12 changes: 9 additions & 3 deletions mlir/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@ set(MQT_MLIR_MIN_VERSION 19.0)

# MLIR must be installed on the system
find_package(MLIR REQUIRED CONFIG)
if(MLIR_VERSION VERSION_LESS MQT_MLIR_MIN_VERSION)
message(FATAL_ERROR "MLIR version must be at least ${MQT_MLIR_MIN_VERSION}")
endif()
# if(MLIR_VERSION VERSION_LESS MQT_MLIR_MIN_VERSION) message(FATAL_ERROR "MLIR version must be at
# least ${MQT_MLIR_MIN_VERSION} but found ${MLIR_VERSION}") endif()
Comment on lines +15 to +16
Copy link
Member

Choose a reason for hiding this comment

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

Why was this commented out?

Suggested change
# if(MLIR_VERSION VERSION_LESS MQT_MLIR_MIN_VERSION) message(FATAL_ERROR "MLIR version must be at
# least ${MQT_MLIR_MIN_VERSION} but found ${MLIR_VERSION}") endif()
if(MLIR_VERSION VERSION_LESS MQT_MLIR_MIN_VERSION)
message(FATAL_ERROR "MLIR version must be at least ${MQT_MLIR_MIN_VERSION}")
endif()

message(STATUS "Using MLIRConfig.cmake in: ${MLIR_DIR}")
message(STATUS "Using LLVMConfig.cmake in: ${LLVM_DIR}")

Expand All @@ -26,6 +25,13 @@ string(REPLACE "." ";" MLIR_VERSION_COMPONENTS ${MLIR_VERSION})
list(GET MLIR_VERSION_COMPONENTS 0 MLIR_VERSION_MAJOR)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Just because I stumbe over it right now: Is this gymnastic with the version string necessary or can the VERSION_LESS operator of cmake be used directly? That might make the code cleaner here.

Copy link
Member

Choose a reason for hiding this comment

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

Seems reasonable to use VERSION_LESS 👍🏼

add_compile_definitions(MLIR_VERSION_MAJOR=${MLIR_VERSION_MAJOR})

option(ENABLE_MQT_CORE_MLIR_CATALYST_PLUGIN "Enable Catalyst conversion passes" OFF)
if(ENABLE_MQT_CORE_MLIR_CATALYST_PLUGIN)
message(STATUS "Found MLIR version ${MLIR_VERSION_MAJOR}.")
list(APPEND CMAKE_MODULE_PATH "${CATALYST_CMAKE_DIR}")
list(APPEND MLIR_INCLUDE_DIRS "${CATALYST_INCLUDE_DIRS}")
endif()

# Include the TableGen, LLVM and MLIR CMake modules.
include(TableGen)
include(AddLLVM)
Expand Down
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)
11 changes: 11 additions & 0 deletions mlir/include/mlir/Conversion/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

if(ENABLE_MQT_CORE_MLIR_CATALYST_PLUGIN)
add_subdirectory(Catalyst)
endif()
10 changes: 10 additions & 0 deletions mlir/include/mlir/Conversion/Catalyst/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(MQTOptToCatalystQuantum)
add_subdirectory(CatalystQuantumToMQTOpt)
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 CatalystQuantumToMQTOpt.td)
mlir_tablegen(CatalystQuantumToMQTOpt.h.inc -gen-pass-decls -name CatalystQuantumToMQTOpt)
add_public_tablegen_target(CatalystQuantumToMQTOptIncGen)

add_mlir_doc(CatalystQuantumToMQTOpt CatalystQuantumToMQTOpt ./ -gen-pass-doc)
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 mlir::mqt::ir::conversions {

#define GEN_PASS_DECL
#include "mlir/Conversion/Catalyst/CatalystQuantumToMQTOpt/CatalystQuantumToMQTOpt.h.inc"

#define GEN_PASS_REGISTRATION
#include "mlir/Conversion/Catalyst/CatalystQuantumToMQTOpt/CatalystQuantumToMQTOpt.h.inc"

} // namespace mlir::mqt::ir::conversions
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 CatalystQuantumToMQTOpt : Pass<"catalystquantum-to-mqtopt"> {
let summary = "Convert Catalyst's `Quantum` to MQT's `MQTOpt` dialect.";

let description = [{
This pass converts Catalyst's `Quantum` to MQT's `MQTOpt` dialect.
The following operations are currently NOT converted (and instead marked legal):
- DeviceInitOp
- DeviceReleaseOp
- NamedObsOp
- ExpvalOp
- FinalizeOp
- ComputationalBasisOp
- StateOp
- InitializeOp
}];

// Define dependent dialects
let dependentDialects = [
"catalyst::quantum::QuantumDialect",
"::mqt::ir::opt::MQTOptDialect"
];
}
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 MQTOptToCatalystQuantum.td)
mlir_tablegen(MQTOptToCatalystQuantum.h.inc -gen-pass-decls -name MQTOptToCatalystQuantum)
add_public_tablegen_target(MQTOptToCatalystQuantumIncGen)

add_mlir_doc(MQTOptToCatalystQuantum MQTOptToCatalystQuantum ./ -gen-pass-doc)
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 mlir::mqt::ir::conversions {

#define GEN_PASS_DECL
#include "mlir/Conversion/Catalyst/MQTOptToCatalystQuantum/MQTOptToCatalystQuantum.h.inc"

#define GEN_PASS_REGISTRATION
#include "mlir/Conversion/Catalyst/MQTOptToCatalystQuantum/MQTOptToCatalystQuantum.h.inc"

} // namespace mlir::mqt::ir::conversions
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// 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 MQTOptToCatalystQuantum : Pass<"mqtopt-to-catalystquantum"> {
let summary = "Convert MQT's `MQTOpt` to Catalyst's `Quantum` dialect.";

let description = [{
This pass converts MQT's `MQTOpt` to Catalyst's `Quantum` dialect.
The following operations are currently NOT converted (and instead marked legal):
- IOp
Copy link
Member

Choose a reason for hiding this comment

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

The identity gate is mapped to the Catalyst name "Identity". So this is definitely supported for conversion

- GPhaseOp
Copy link
Member

Choose a reason for hiding this comment

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

- BarrierOp
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 not quite sure we want to keep barriers around if we are translating between dialects. Ideally, we would want the conversion to be a true conversion in the sense that the whole circuit is translated.

- SOp, SdgOp
- TOp, TdgOp
Comment on lines +20 to +21
Copy link
Member

Choose a reason for hiding this comment

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

Both S and T are supported as gates in Catalyst. So are there inverses via the respective modifier.

- VOp, VdgOp
- UOp, U2Op
- SXOp, SXdgOp
Copy link
Member

Choose a reason for hiding this comment

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

This as well as the ECR gate are declared as not supported here https://github.com/PennyLaneAI/catalyst/blob/e89b83d393be158be499a95ce02b1312e7e89bbd/frontend/test/pytest/test_operations.py#L84-L85
It would be interesting to know, what is missing in order to enable the corresponding support.
If it turns out to be easy, it might be worth adding.

- iSWAPOp, iSWAPdgOp
Copy link
Member

Choose a reason for hiding this comment

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

ISWAP and, consequentially, its inverse are also directly supported in Catalyst.

- PeresOp, PeresdgOp
- DCXOp
Copy link
Member

Choose a reason for hiding this comment

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

Just to add another comment here: One could probably add support for these gates by specifying them as a unitary matrix, right?

- ECROp
- RXXOp, RYYOp, RZZOp, RZXOp
Copy link
Member

Choose a reason for hiding this comment

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

- XXminusYY, XXplusYY
Copy link
Member

Choose a reason for hiding this comment

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

One final comment here: For some of these gates, a single gate could be replaced by a decomposed version of the gate only using gates supported by the other dialect.
No one says that a roundtrip between dialects must be lossless.

}];
let dependentDialects = [
"catalyst::quantum::QuantumDialect",
"::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)
11 changes: 11 additions & 0 deletions mlir/lib/Conversion/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

if(ENABLE_MQT_CORE_MLIR_CATALYST_PLUGIN)
add_subdirectory(Catalyst)
endif()
10 changes: 10 additions & 0 deletions mlir/lib/Conversion/Catalyst/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(MQTOptToCatalystQuantum)
add_subdirectory(CatalystQuantumToMQTOpt)
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# 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(CatalystQuantumToMQTOpt ${CONVERSION_SOURCES} LINK_LIBS ${LIBRARIES} DEPENDS
CatalystQuantumToMQTOptIncGen)

target_link_libraries(CatalystQuantumToMQTOpt PRIVATE MLIRQuantum)
Loading
Loading