Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
149 commits
Select commit Hold shift + click to select a range
789654d
:test_tube: Added tests for Hadamard lifting
LiRem101 Mar 26, 2026
e05e2fe
:test_tube: Added test cases for controlled Pauli Z lifting
LiRem101 Mar 27, 2026
fc10555
:twisted_rightwards_arrows: Merge branch 'main' into mlir/hadamard-li…
LiRem101 Mar 27, 2026
fa877c6
:construction: Added framework for hadamard lifting pass
LiRem101 Mar 27, 2026
d784d01
:construction: Started exchange of Hadamard and Pauli
LiRem101 Mar 30, 2026
e1b6b37
:construction: Lifting uncontrolled Hadamard gates above Pauli
LiRem101 Mar 31, 2026
59739f1
:twisted_rightwards_arrows: Merge branch 'main' into mlir/hadamard-li…
LiRem101 Mar 31, 2026
9dc386e
:white_check_mark: Added canonicalization to references
LiRem101 Mar 31, 2026
5653b9a
:white_check_mark: Corrected gates
LiRem101 Mar 31, 2026
67d3c7c
:construction: Added handling of controlled gates
LiRem101 Apr 1, 2026
95e3604
:recycle: Refactored handling of controlled gates
LiRem101 Apr 1, 2026
e01a8b9
:construction: Added handling of controlled Pauli Z gates
LiRem101 Apr 1, 2026
798c514
:recycle: Refactored handling of controlled Pauli Z gates
LiRem101 Apr 1, 2026
baf731c
:construction: Added CNOT Hadamard handling
LiRem101 Apr 1, 2026
a43b158
✅ Corrected test
LiRem101 Apr 2, 2026
7fd4f75
:rotating_light: Fixed linter warnings
LiRem101 Apr 2, 2026
9c43526
:twisted_rightwards_arrows: Merge branch 'main' into mlir/hadamard-li…
LiRem101 Apr 2, 2026
18382b3
:rotating_light: Fixed linter warnings
LiRem101 Apr 2, 2026
7a89811
:fire: Removed statistics
LiRem101 Apr 2, 2026
cc5f15c
:construction: Added infrastructure to use hadamard lifting
LiRem101 Apr 2, 2026
a682420
:construction: Added infrastructure to use hadamard lifting
LiRem101 Apr 2, 2026
2c298bf
🎨 pre-commit fixes
pre-commit-ci[bot] Apr 2, 2026
e3da07f
:memo: Added information to CHANGELOG.md
LiRem101 Apr 2, 2026
b3bf966
:pencil2: Changed Preceeding to preceding
LiRem101 Apr 2, 2026
b2862e8
:twisted_rightwards_arrows: Merge branch 'mlir/hadamard-lifting' of g…
LiRem101 Apr 2, 2026
e9c66b3
:rotating_light: Fixed linter warnings
LiRem101 Apr 7, 2026
13c046d
:rotating_light: Optimized imports
LiRem101 Apr 7, 2026
db8491e
:rotating_light: Changed dyn_cast to llvm
LiRem101 Apr 7, 2026
f95eeb0
🔀 Merge branch 'main' into mlir/hadamard-lifting
LiRem101 Apr 7, 2026
18cb1b0
:twisted_rightwards_arrows: Merged 'main' and resolved merge conflicts
LiRem101 Apr 8, 2026
fb70183
🎨 pre-commit fixes
pre-commit-ci[bot] Apr 8, 2026
d785bdb
:construction: Fixed branching for optimization passes
LiRem101 Apr 8, 2026
74edb2e
:twisted_rightwards_arrows: Merge branch 'mlir/hadamard-lifting' of g…
LiRem101 Apr 8, 2026
cc97cfd
:memo: Updated Hadamard lifting documentation and fixed typos
LiRem101 Apr 8, 2026
26ca2ed
:construction: Removed double MLIRParser in CMakeLists
LiRem101 Apr 8, 2026
a15d2c1
:white_check_mark: Apply only canonicalizer to reference code
LiRem101 Apr 8, 2026
233da3f
:recycle: use is_permutation
LiRem101 Apr 8, 2026
6af2a96
:bug: Controlled Pauli Y cannot be lifted
LiRem101 Apr 8, 2026
664abad
🎨 pre-commit fixes
pre-commit-ci[bot] Apr 8, 2026
cf245b1
:recycle: Refactored runCanonicalizerPass method
LiRem101 Apr 8, 2026
4ab38c1
:twisted_rightwards_arrows: Merge branch 'mlir/hadamard-lifting' of g…
LiRem101 Apr 8, 2026
57159ae
:rotating_light: Optimized imports and test naming
LiRem101 Apr 8, 2026
c966623
:construction: Apply suggestions from code review
LiRem101 Apr 15, 2026
8d32188
:construction: Adapated code to suggestions from code review
LiRem101 Apr 15, 2026
edc59a2
:memo: Adapted documentation according to review
LiRem101 Apr 15, 2026
cdfc8ed
:construction: Implemented changes suggested by review, removed handl…
LiRem101 Apr 15, 2026
de726cb
:construction: Added global phase for Y-H commutation
LiRem101 Apr 16, 2026
500b0d1
:construction: Added TypeSwitch
LiRem101 Apr 16, 2026
b67a26f
:memo: Improved documentation
LiRem101 Apr 16, 2026
928f6c5
:recycle: Removed temporary value and branchings, assisted-by: GPT 5 …
LiRem101 Apr 16, 2026
9b2397e
:construction: Implemented changes requested in review
LiRem101 Apr 16, 2026
20b6580
:white_check_mark: Added test for measurement after target of CNOT
LiRem101 Apr 16, 2026
3b430d4
:construction: Implemented changes requested in review
LiRem101 Apr 17, 2026
ee2f941
:twisted_rightwards_arrows: Merge with main
LiRem101 Apr 17, 2026
f3cb1d7
🎨 pre-commit fixes
pre-commit-ci[bot] Apr 17, 2026
e5ba050
:pencil2: Fixed typos
LiRem101 Apr 17, 2026
afdb6b0
:twisted_rightwards_arrows: Merge with origin
LiRem101 Apr 17, 2026
44d8c98
🎨 pre-commit fixes
pre-commit-ci[bot] Apr 17, 2026
1ca77fa
:rotating_light: Fix linter errors
LiRem101 Apr 17, 2026
10b21ed
:rotating_light: Fix linter errors
LiRem101 Apr 17, 2026
f183f63
:rotating_light: Fix linter errors
LiRem101 Apr 17, 2026
89da08c
:rotating_light: Fix linter errors
LiRem101 Apr 17, 2026
2f0dbe6
:rotating_light: Fix linter errors
LiRem101 Apr 17, 2026
31995a8
:bug: Fix dangling range, assisted-by: GPT 5 via KI:connect
LiRem101 Apr 20, 2026
3750513
:white_check_mark: Adapated tests to removal of controlled cases
LiRem101 Apr 20, 2026
0da58cf
:bug: Fixed dangling hadamard gate object
LiRem101 Apr 20, 2026
1c2a5a8
:twisted_rightwards_arrows: Merge with main
LiRem101 Apr 22, 2026
fce739b
🎨 pre-commit fixes
pre-commit-ci[bot] Apr 22, 2026
3331f0c
Merge branch 'main' into mlir/hadamard-lifting
denialhaag Apr 29, 2026
7f1256b
Simplify diff
denialhaag Apr 29, 2026
3084ec4
Adapt to new include style
denialhaag Apr 29, 2026
615bbd4
Merge branch 'main' into fork/LiRem101/mlir/hadamard-lifting
burgholzer May 6, 2026
9afaacd
♻️ Simplify pass implementation
burgholzer May 6, 2026
43452ee
:twisted_rightwards_arrows: Merge branch 'main' into mlir/hadamard-li…
LiRem101 May 7, 2026
0fcf1e6
:memo: Adapted documentation
LiRem101 May 7, 2026
6b4f865
Merge branch 'main' into fork/LiRem101/mlir/hadamard-lifting
burgholzer May 11, 2026
413585b
Merge branch 'main' into mlir/hadamard-lifting
burgholzer May 11, 2026
06c681f
:bricks: Add files for tracking QuantumStates
LiRem101 Jun 9, 2026
4bd6f65
:construction: Added GateToMap.h
LiRem101 Jun 10, 2026
87ddcde
:recycle: Refactored GateToMap.h, Assisted-by: GPT OSS via KI:connect
LiRem101 Jun 10, 2026
992c0f6
📝 Added Docstring
LiRem101 Jun 10, 2026
3954213
:construction: Added Header File for QuantumState
LiRem101 Jun 10, 2026
549e786
:recycle: Refactored QuantumState.hpp, assisted-by GPT OSS via KI:con…
LiRem101 Jun 10, 2026
060c7c7
:construction: Added QuantumState class
LiRem101 Jun 11, 2026
fca5829
:recycle: Refactored QuantumState.hpp and QuantumState.cpp, assisted-…
LiRem101 Jun 11, 2026
dfb3c79
✅ Added tests for QuantumState
LiRem101 Jun 11, 2026
edbde78
:white_check_mark: Passes first test
LiRem101 Jun 12, 2026
24903c1
:white_check_mark: Passed tests
LiRem101 Jun 12, 2026
4c8b2bf
:recycle: Refactored QuantumState.hpp
LiRem101 Jun 12, 2026
37df86d
:recycle: Refactored QuantumState.hpp, assisted-by GPT-OSS va KI:connect
LiRem101 Jun 12, 2026
515928d
:construction: Corrected macros
LiRem101 Jun 12, 2026
9e5d051
:rotating_light: Corrected clang errors
LiRem101 Jun 12, 2026
2fc9805
🚧 Created HybridState.hpp
LiRem101 Jun 12, 2026
eeec576
🚧 Adapted HybridState and created ClassicalArithOperation
LiRem101 Jun 16, 2026
fa6667b
🚧 Added HybridState implementation
LiRem101 Jun 17, 2026
af69c0c
🚧 Added tests for HybridState
LiRem101 Jun 17, 2026
c77bb06
:white_check_mark: Added tests for classical operations
LiRem101 Jun 18, 2026
2cbc8ae
:recycle: Refactored HybridState
LiRem101 Jun 18, 2026
8b23135
:construction: Added UnionTable infrastructure
LiRem101 Jun 18, 2026
e8b170d
:white_check_mark: Added UnionTable tests
LiRem101 Jun 18, 2026
e8dabcb
:construction: Added UnionTable methods
LiRem101 Jun 19, 2026
1607ddb
:construction: Added UnionTable methods
LiRem101 Jun 19, 2026
c3fd47c
:construction: Corrected handling of maps
LiRem101 Jun 19, 2026
3300fe6
:construction: Corrected handling of maps
LiRem101 Jun 19, 2026
056af2e
:construction: Corrected several test problems
LiRem101 Jun 22, 2026
b3269eb
:construction: Added additional tests for UnionTable
LiRem101 Jun 22, 2026
aecb3a0
:construction: Added getValueThatIsEquivalentToQubit
LiRem101 Jun 23, 2026
fefdc7e
:construction: Added UnionTableFunctionality
LiRem101 Jun 24, 2026
1a93171
:construction: Fixed test results
LiRem101 Jun 24, 2026
d7bfb19
:construction: Fixed tests
LiRem101 Jun 25, 2026
2cc0545
:construction: Added infrastructure for constant propagation passes
LiRem101 Jun 26, 2026
500ada9
:test_tube: Added first test for constant propagation
LiRem101 Jun 26, 2026
9c47ebf
:construction: Continued constant propagation infrastructure
LiRem101 Jun 26, 2026
ab7ba5b
:test_tube: Added constant propagation test
LiRem101 Jun 29, 2026
a0341a7
:construction: Global phase as double
LiRem101 Jun 29, 2026
e0f9a98
:construction: Handling of global phases without control
LiRem101 Jun 29, 2026
d4690b1
:construction: Ctrl qubits changed after gate
LiRem101 Jun 29, 2026
32dde57
:construction: Start of ctrl handling
LiRem101 Jun 29, 2026
4e8463d
:construction: Handling of ctrl continued
LiRem101 Jun 30, 2026
9f15fb1
:construction: Handling of ctrl
LiRem101 Jun 30, 2026
af40f05
:memo: Added docstrings
LiRem101 Jun 30, 2026
27e9da3
:construction: Added creation of classical value inside measurement
LiRem101 Jun 30, 2026
1819c07
:construction: Added reset and measurement handling
LiRem101 Jun 30, 2026
eb0f2fb
:construction: Started removal of ctrl of always executed gates
LiRem101 Jun 30, 2026
99850ff
:construction: Removal of ctrl of always executed gates
LiRem101 Jun 30, 2026
64619cc
:construction: Started removal of ctrls that are superfluous
LiRem101 Jun 30, 2026
0d440a2
✅ Fixed test
LiRem101 Jun 30, 2026
ef60703
:memo: Added docstring
LiRem101 Jul 1, 2026
6397001
:construction: Continued removal of ctrls in CtrlOp
LiRem101 Jul 1, 2026
c527209
:construction: Fixed creation of uncontrolled gates
LiRem101 Jul 1, 2026
80c6b82
:test_tube: Added test to check propagation in classical branching
LiRem101 Jul 1, 2026
dd691d1
:construction: Added propagation of classical branching
LiRem101 Jul 1, 2026
3ec5f72
:test_tube: Extended test for removal of classical condition
LiRem101 Jul 2, 2026
22e02a9
:construction: Removal of branch if condition is one
LiRem101 Jul 2, 2026
aea9d47
:construction: Added handling to remove classical branches
LiRem101 Jul 2, 2026
cd1ff0a
:construction: First draft of creating branches
LiRem101 Jul 2, 2026
e05c433
:construction: Create branches during constant propagation
LiRem101 Jul 2, 2026
4c3f9cc
:test_tube: Added tests for movement of measurement
LiRem101 Jul 2, 2026
bf7b1af
:construction: Added moving measurement in front
LiRem101 Jul 2, 2026
ffe6293
:construction: Added handling of classical operations
LiRem101 Jul 2, 2026
774e859
:construction: Creating then and else branches
LiRem101 Jul 2, 2026
e83acbd
:construction: Added usage of parameters
LiRem101 Jul 2, 2026
a87875a
:construction: Added pipeline frame
LiRem101 Jul 2, 2026
fb56ef0
:twisted_rightwards_arrows: Merged with main
LiRem101 Jul 2, 2026
74d198b
:construction: Adapted to changes from main
LiRem101 Jul 2, 2026
edd955c
🎨 pre-commit fixes
pre-commit-ci[bot] Jul 2, 2026
4420939
:memo: Added change information to CHANGELOG.md
LiRem101 Jul 2, 2026
b096acf
Merge branch 'mlir/constant-propagation' of github.com:LiRem101/mqt-c…
LiRem101 Jul 2, 2026
c26efd8
🎨 pre-commit fixes
pre-commit-ci[bot] Jul 2, 2026
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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ releases may include breaking changes.

### Added

- ✨ Add a `constant propagation` pass for reducing superfluous quantum
resources by propagating the quantum machine state ([#1845]) ([**@lirem101])
- 🚸 Add `const` version of the `CompoundOperation`'s `getOps()` function
([#1826]) ([**@ystade])
- 🐳 Add dev container configuration for consistent local development
Expand Down Expand Up @@ -594,6 +596,7 @@ changelogs._

<!-- PR links -->

[#1845]: https://github.com/munich-quantum-toolkit/core/pull/1845
[#1842]: https://github.com/munich-quantum-toolkit/core/pull/1842
[#1830]: https://github.com/munich-quantum-toolkit/core/pull/1830
[#1828]: https://github.com/munich-quantum-toolkit/core/pull/1828
Expand Down
3 changes: 3 additions & 0 deletions mlir/include/mlir/Compiler/CompilerPipeline.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ struct QuantumCompilerConfig {

/// Enable Hadamard lifting
bool enableHadamardLifting = false;

/// Enable constant propagation
bool enableConstantPropagation = false;
};

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
/*
* Copyright (c) 2023 - 2026 Chair for Design Automation, TUM
* Copyright (c) 2025 - 2026 Munich Quantum Software Company GmbH
* All rights reserved.
*
* SPDX-License-Identifier: MIT
*
* Licensed under the MIT License
*/

#pragma once

#ifndef MQT_CORE_CLASSICALARITHOPERATION_H
#define MQT_CORE_CLASSICALARITHOPERATION_H

#include "mlir/Dialect/QCO/IR/QCOOps.h"
#include "mlir/Dialect/QCO/Utils/Drivers.h"

#include <mlir/Dialect/Arith/IR/Arith.h>
#include <mlir/IR/BuiltinTypes.h>
#include <mlir/IR/Operation.h>

#include <cmath>
#include <stdexcept>

/**
* This file provides information of available arith operations. It calculates
* the result of valid arith operations. Operations are only valid with one to
* two operands, not if they are applied to sequences.
*/
inline int64_t getArithIntegerOpResult(mlir::Operation* operation,
int64_t value1, int64_t value2 = 0,
int64_t value3 = 0) {

for (mlir::Value operand : operation->getOperands()) {
if (isa<mlir::VectorType>(operand.getType())) {
throw std::runtime_error(
"Constant propagation does not support vectors as classical types.");
}
}

return mlir::TypeSwitch<mlir::Operation*, int64_t>(operation)
.Case<mlir::arith::AddIOp>([&](auto) { return value1 + value2; })
.Case<mlir::arith::AndIOp>([&](auto) { return value1 & value2; })
.Case<mlir::arith::CeilDivSIOp>([&](auto) {
// Division that rounds to positive infinity
return ceil(1.0 * value1 / value2);
})
.Case<mlir::arith::DivSIOp>([&](auto) {
// Division that rounds towards zero
return value1 / value2;
})
.Case<mlir::arith::FloorDivSIOp>([&](auto) {
// Division that rounds to negative infinity
return floor(1.0 * value1 / value2);
})
.Case<mlir::arith::MaxSIOp>(
[&](auto) { return value1 > value2 ? value1 : value2; })
.Case<mlir::arith::MinSIOp>(
[&](auto) { return value1 < value2 ? value1 : value2; })
.Case<mlir::arith::MulIOp>([&](auto) { return value1 * value2; })
.Case<mlir::arith::OrIOp>([&](auto) { return value1 | value2; })
.Case<mlir::arith::RemSIOp>(
[&](auto) { return remainder(value1, value2); })
.Case<mlir::arith::ShLIOp>([&](auto) { return value1 << value2; })
.Case<mlir::arith::ShRSIOp>([&](auto) { return value1 >> value2; })
.Case<mlir::arith::SubIOp>([&](auto) { return value1 - value2; })
.Case<mlir::arith::XOrIOp>([&](auto) { return value1 ^ value2; })
.Case<mlir::arith::SelectOp>(
[&](auto) { return value1 == 0 ? value3 : value2; })
.Default([&](auto) -> int64_t {
throw std::runtime_error("Unsupported integer operation in "
"mlir::qco::classicalarithoperation");
});
}

inline double getArithDoubleOpResult(mlir::Operation* operation, double value1,
double value2 = 0.0) {

for (mlir::Value operand : operation->getOperands()) {
if (isa<mlir::VectorType>(operand.getType())) {
throw std::runtime_error(
"Constant propagation does not support vectors as classical types.");
}
}

return mlir::TypeSwitch<mlir::Operation*, double>(operation)
.Case<mlir::arith::AddFOp>([&](auto) { return value1 + value2; })
.Case<mlir::arith::DivFOp>([&](auto) { return value1 / value2; })
.Case<mlir::arith::MaximumFOp>(
[&](auto) { return value1 > value2 ? value1 : value2; })
.Case<mlir::arith::MaxNumFOp>(
[&](auto) { return value1 > value2 ? value1 : value2; })
.Case<mlir::arith::MinimumFOp>(
[&](auto) { return value1 < value2 ? value1 : value2; })
.Case<mlir::arith::MinNumFOp>(
[&](auto) { return value1 < value2 ? value1 : value2; })
.Case<mlir::arith::MulFOp>([&](auto) { return value1 * value2; })
.Case<mlir::arith::NegFOp>([&](auto) { return -value1; })
.Case<mlir::arith::RemFOp>(
[&](auto) { return remainder(value1, value2); })
.Case<mlir::arith::SubFOp>([&](auto) { return value1 - value2; })
.Default([&](auto) -> double {
throw std::runtime_error("Unsupported floating-point operation in "
"mlir::qco::classicalarithoperation");
});
}

#endif // MQT_CORE_MQT_CORE_CLASSICALARITHOPERATION_H
Original file line number Diff line number Diff line change
@@ -0,0 +1,229 @@
/*
* Copyright (c) 2023 - 2026 Chair for Design Automation, TUM
* Copyright (c) 2025 - 2026 Munich Quantum Software Company GmbH
* All rights reserved.
*
* SPDX-License-Identifier: MIT
*
* Licensed under the MIT License
*/

#pragma once

#include <mlir/IR/Operation.h>
#ifndef MQT_CORE_GATETOMAP_H
#define MQT_CORE_GATETOMAP_H

#include "mlir/Dialect/QCO/IR/QCOOps.h"
#include "mlir/Dialect/QCO/Utils/Drivers.h"

#include <cmath>
#include <complex>
#include <numbers>
#include <span>
#include <stdexcept>
#include <unordered_map>

/**
* This file provides information of available quantum gates as mappings. It is
* used in constant propagation to get the factors each amplitude has to be
* multiplied with to get the new amplitudes after a gate application.
*/

using Complex = std::complex<double>;

using ResultMap =
std::unordered_map<unsigned int, std::unordered_map<unsigned int, Complex>>;

constexpr double inv_sqrt2 = 1.0 / std::numbers::sqrt2;

inline std::unordered_map<unsigned int,
std::unordered_map<unsigned int, Complex>>
getQubitMappingOfGates(mlir::Operation* gate, const std::span<double>& params) {

return mlir::TypeSwitch<
mlir::Operation*,
std::unordered_map<unsigned int,
std::unordered_map<unsigned int, Complex>>>(
gate)
.Case<mlir::qco::IdOp>([&](auto) {
return ResultMap{{0, {{0, Complex(1, 0)}}}, {1, {{1, Complex(1, 0)}}}};
})
.Case<mlir::qco::HOp>([&](auto) {
return ResultMap{
{{0, {{0, Complex(inv_sqrt2, 0)}, {1, Complex(inv_sqrt2, 0)}}},
{1, {{0, Complex(inv_sqrt2, 0)}, {1, Complex(-inv_sqrt2, 0)}}}}};
})
.Case<mlir::qco::XOp>([&](auto) {
return ResultMap{
{{0, {{1, Complex(1, 0)}}}, {1, {{0, Complex(1, 0)}}}}};
})
.Case<mlir::qco::YOp>([&](auto) {
return ResultMap{
{{0, {{1, Complex(0, 1)}}}, {1, {{0, Complex(0, -1)}}}}};
})
.Case<mlir::qco::ZOp>([&](auto) {
return ResultMap{
{{0, {{0, Complex(1, 0)}}}, {1, {{1, Complex(-1, 0)}}}}};
})
.Case<mlir::qco::SOp>([&](auto) {
return ResultMap{
{{0, {{0, Complex(1, 0)}}}, {1, {{1, Complex(0, 1)}}}}};
})
.Case<mlir::qco::SdgOp>([&](auto) {
return ResultMap{
{{0, {{0, Complex(1, 0)}}}, {1, {{1, Complex(0, -1)}}}}};
})
.Case<mlir::qco::TOp>([&](auto) {
return ResultMap{{{0, {{0, Complex(1, 0)}}},
{1, {{1, Complex(inv_sqrt2, inv_sqrt2)}}}}};
})
.Case<mlir::qco::TdgOp>([&](auto) {
return ResultMap{{{0, {{0, Complex(1, 0)}}},
{1, {{1, Complex(inv_sqrt2, -inv_sqrt2)}}}}};
})
.Case<mlir::qco::SXOp>([&](auto) {
return ResultMap{
{{0, {{0, Complex(0.5, 0.5)}, {1, Complex(0.5, -0.5)}}},
{1, {{0, Complex(0.5, -0.5)}, {1, Complex(0.5, 0.5)}}}}};
})
.Case<mlir::qco::SXdgOp>([&](auto) {
return ResultMap{
{{0, {{0, Complex(0.5, -0.5)}, {1, Complex(0.5, 0.5)}}},
{1, {{0, Complex(0.5, 0.5)}, {1, Complex(0.5, -0.5)}}}}};
})
.Case<mlir::qco::RXOp>([&](auto) {
const double c = cos(0.5 * params[0]);
const double s = sin(0.5 * params[0]);
return ResultMap{{{0, {{0, Complex(c, 0)}, {1, Complex(0, -s)}}},
{1, {{0, Complex(0, -s)}, {1, Complex(c, 0)}}}}};
})
.Case<mlir::qco::RYOp>([&](auto) {
const double c = cos(0.5 * params[0]);
const double s = sin(0.5 * params[0]);
return ResultMap{{{0, {{0, Complex(c, 0)}, {1, Complex(s, 0)}}},
{1, {{0, Complex(-s, 0)}, {1, Complex(c, 0)}}}}};
})
.Case<mlir::qco::RZOp>([&](auto) {
const double halfParameter = 0.5 * params[0];
return ResultMap{{{0, {{0, exp(Complex(0, -halfParameter))}}},
{1, {{1, exp(Complex(0, halfParameter))}}}}};
})
.Case<mlir::qco::POp>([&](auto) {
return ResultMap{{{0, {{0, Complex(1, 0)}}},
{1, {{1, exp(Complex(0, params[0]))}}}}};
})
.Case<mlir::qco::ROp>([&](auto) {
const double c = cos(0.5 * params[0]);
const double s = sin(0.5 * params[0]);
return ResultMap{{{0,
{{0, Complex(c, 0)},
{1, exp(Complex(0, params[1])) * Complex(0, -s)}}},
{1,
{{0, exp(Complex(0, -params[1])) * Complex(0, -s)},
{1, Complex(c, 0)}}}}};
})
.Case<mlir::qco::U2Op>([&](auto) {
return ResultMap{
{{0, {{0, Complex(inv_sqrt2, 0)}, {1, exp(Complex(0, params[0]))}}},
{1,
{{0, -exp(Complex(0, params[1]))},
{1, exp(Complex(0, params[0] + params[1]))}}}}};
})
.Case<mlir::qco::UOp>([&](auto) {
const double c = cos(0.5 * params[0]);
const double s = sin(0.5 * params[0]);
return ResultMap{
{{0, {{0, Complex(c, 0)}, {1, exp(Complex(0, params[1])) * s}}},
{1,
{{0, -exp(Complex(0, params[2])) * s},
{1, exp(Complex(0, params[1] + params[2])) * c}}}}};
})
.Case<mlir::qco::SWAPOp>([&](auto) {
return ResultMap{{{0, {{0, Complex(1, 0)}}},
{1, {{2, Complex(1, 0)}}},
{2, {{1, Complex(1, 0)}}},
{3, {{3, Complex(1, 0)}}}}};
})
.Case<mlir::qco::iSWAPOp>([&](auto) {
return ResultMap{{{0, {{0, Complex(1, 0)}}},
{1, {{2, Complex(0, -1)}}},
{2, {{1, Complex(0, -1)}}},
{3, {{3, Complex(1, 0)}}}}};
})
.Case<mlir::qco::DCXOp>([&](auto) {
return ResultMap{{{0, {{0, Complex(1, 0)}}},
{1, {{2, Complex(1, 0)}}},
{2, {{3, Complex(1, 0)}}},
{3, {{1, Complex(1, 0)}}}}};
})
.Case<mlir::qco::ECROp>([&](auto) {
return ResultMap{
{{0, {{2, Complex(inv_sqrt2, 0)}, {3, Complex(0, -inv_sqrt2)}}},
{1, {{2, Complex(0, -inv_sqrt2)}, {3, Complex(inv_sqrt2, 0)}}},
{2, {{0, Complex(inv_sqrt2, 0)}, {1, Complex(0, inv_sqrt2)}}},
{3, {{0, Complex(0, inv_sqrt2)}, {1, Complex(inv_sqrt2, 0)}}}}};
})
.Case<mlir::qco::RXXOp>([&](auto) {
const double c = cos(0.5 * params[0]);
const double s = sin(0.5 * params[0]);
return ResultMap{{{0, {{0, Complex(c, 0)}, {3, Complex(0, -s)}}},
{1, {{1, Complex(c, 0)}, {2, Complex(0, -s)}}},
{2, {{1, Complex(0, -s)}, {2, Complex(c, 0)}}},
{3, {{0, Complex(0, -s)}, {3, Complex(c, 0)}}}}};
})
.Case<mlir::qco::RYYOp>([&](auto) {
const double c = cos(0.5 * params[0]);
const double s = sin(0.5 * params[0]);
return ResultMap{{{0, {{0, Complex(c, 0)}, {3, Complex(0, s)}}},
{1, {{1, Complex(c, 0)}, {2, Complex(0, -s)}}},
{2, {{1, Complex(0, -s)}, {2, Complex(c, 0)}}},
{3, {{0, Complex(0, s)}, {3, Complex(c, 0)}}}}};
})
.Case<mlir::qco::RZXOp>([&](auto) {
const double c = cos(0.5 * params[0]);
const double s = sin(0.5 * params[0]);
return ResultMap{{{0, {{0, Complex(c, 0)}, {1, Complex(0, -s)}}},
{1, {{0, Complex(0, -s)}, {1, Complex(c, 0)}}},
{2, {{2, Complex(c, 0)}, {3, Complex(0, s)}}},
{3, {{2, Complex(0, s)}, {3, Complex(c, 0)}}}}};
})
.Case<mlir::qco::RZZOp>([&](auto) {
const double halfParam = 0.5 * params[0];
Complex ePos = exp(Complex(0, halfParam));
Complex eNeg = exp(Complex(0, -halfParam));
return ResultMap{{{0, {{0, eNeg}}},
{1, {{1, ePos}}},
{2, {{2, ePos}}},
{3, {{3, eNeg}}}}};
})
.Case<mlir::qco::XXPlusYYOp>([&](auto) {
const double c = cos(0.5 * params[0]);
const double s = sin(0.5 * params[0]);
return ResultMap{{{0, {{0, Complex(1, 0)}}},
{1,
{{1, Complex(c, 0)},
{2, Complex(0, -s) * exp(Complex(0, params[1]))}}},
{2,
{{1, Complex(0, -s) * exp(Complex(0, -params[1]))},
{2, Complex(c, 0)}}},
{3, {{3, Complex(1, 0)}}}}};
})
.Case<mlir::qco::XXMinusYYOp>([&](auto) {
const double c = cos(0.5 * params[0]);
const double s = sin(0.5 * params[0]);
return ResultMap{{{0,
{{0, Complex(c, 0)},
{3, Complex(0, -s) * exp(Complex(0, params[1]))}}},
{1, {{1, Complex(1, 0)}}},
{2, {{2, Complex(1, 0)}}},
{3,
{{0, Complex(0, -s) * exp(Complex(0, -params[1]))},
{3, Complex(c, 0)}}}}};
})
.Default([&](auto) -> ResultMap {
throw std::runtime_error("Unsupported gate in mlir::qco::gatetomap");
});
}

#endif // MQT_CORE_GATETOMAP_H
Loading
Loading