Skip to content

Commit fb19be3

Browse files
committed
move GateDecompositionPass to new QCO dialect
1 parent 2b4e10b commit fb19be3

25 files changed

Lines changed: 248 additions & 705 deletions

mlir/include/mlir/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,6 @@
66
#
77
# Licensed under the MIT License
88

9-
add_subdirectory(Dialect)
109
add_subdirectory(Conversion)
10+
add_subdirectory(Dialect)
11+
add_subdirectory(Passes)

mlir/include/mlir/Dialect/MQTOpt/Transforms/Passes.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ enum class PlacementStrategy : std::uint8_t { Random, Identity };
3434
#include "mlir/Dialect/MQTOpt/Transforms/Passes.h.inc" // IWYU pragma: export
3535

3636
void populateGateEliminationPatterns(mlir::RewritePatternSet& patterns);
37-
void populateGateDecompositionPatterns(mlir::RewritePatternSet& patterns);
3837
void populateMergeRotationGatesPatterns(mlir::RewritePatternSet& patterns);
3938
void populateSwapReconstructionAndElisionPatterns(
4039
mlir::RewritePatternSet& patterns);

mlir/include/mlir/Dialect/MQTOpt/Transforms/Passes.td

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,6 @@ def GateElimination : Pass<"gate-elimination", "mlir::ModuleOp"> {
4343
}];
4444
}
4545

46-
def GateDecomposition : Pass<"gate-decomposition", "mlir::ModuleOp"> {
47-
let dependentDialects = [ "mlir::arith::ArithDialect", "mqt::ir::opt::MQTOptDialect" ];
48-
let summary = "This pass performs various gate decompositions to translate quantum gates being used.";
49-
let description = [{
50-
Decomposes series of operations that operate on up to two qubits into a sequence of up to three
51-
two-qubit basis gates and single-qubit operations.
52-
}];
53-
}
54-
5546
def MergeRotationGates : Pass<"merge-rotation-gates", "mlir::ModuleOp"> {
5647
let summary = "This pass searches for consecutive applications of rotation gates that can be merged.";
5748
let description = [{
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Copyright (c) 2023 - 2025 Chair for Design Automation, TUM
2+
# Copyright (c) 2025 Munich Quantum Software Company GmbH
3+
# All rights reserved.
4+
#
5+
# SPDX-License-Identifier: MIT
6+
#
7+
# Licensed under the MIT License
8+
9+
set(LLVM_TARGET_DEFINITIONS Passes.td)
10+
mlir_tablegen(Passes.h.inc -gen-pass-decls -name QCO)
11+
add_public_tablegen_target(QcoPassesIncGen)
12+
add_mlir_doc(Passes QcoPasses Passes/ -gen-pass-doc)

mlir/include/mlir/Dialect/MQTOpt/Transforms/Decomposition/BasisDecomposer.h renamed to mlir/include/mlir/Passes/Decomposition/BasisDecomposer.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
#include <optional>
3939
#include <utility>
4040

41-
namespace mqt::ir::opt::decomposition {
41+
namespace mlir::qco::decomposition {
4242

4343
/**
4444
* Decomposer that must be initialized with a two-qubit basis gate that will
@@ -544,4 +544,4 @@ class TwoQubitBasisDecomposer {
544544
matrix2x2 q2r;
545545
};
546546

547-
} // namespace mqt::ir::opt::decomposition
547+
} // namespace mlir::qco::decomposition

mlir/include/mlir/Dialect/MQTOpt/Transforms/Decomposition/EulerBasis.h renamed to mlir/include/mlir/Passes/Decomposition/EulerBasis.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
#include <cstdint>
1414

15-
namespace mqt::ir::opt::decomposition {
15+
namespace mlir::qco::decomposition {
1616
/**
1717
* Largest number that will be assumed as zero for the euler decompositions.
1818
*/
@@ -37,4 +37,4 @@ enum class EulerBasis : std::uint8_t {
3737
ZSXX = 10,
3838
ZSX = 11,
3939
};
40-
} // namespace mqt::ir::opt::decomposition
40+
} // namespace mlir::qco::decomposition

mlir/include/mlir/Dialect/MQTOpt/Transforms/Decomposition/EulerDecomposition.h renamed to mlir/include/mlir/Passes/Decomposition/EulerDecomposition.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
#include <mlir/Support/LogicalResult.h>
3333
#include <optional>
3434

35-
namespace mqt::ir::opt::decomposition {
35+
namespace mlir::qco::decomposition {
3636

3737
/**
3838
* Decomposition of single-qubit matrices into rotation gates using a KAK
@@ -210,4 +210,4 @@ class EulerDecomposition {
210210
return sequence;
211211
}
212212
};
213-
} // namespace mqt::ir::opt::decomposition
213+
} // namespace mlir::qco::decomposition

mlir/include/mlir/Dialect/MQTOpt/Transforms/Decomposition/Gate.h renamed to mlir/include/mlir/Passes/Decomposition/Gate.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
#include <llvm/ADT/SmallVector.h>
1717

18-
namespace mqt::ir::opt::decomposition {
18+
namespace mlir::qco::decomposition {
1919

2020
using QubitId = std::size_t;
2121

@@ -29,4 +29,4 @@ struct Gate {
2929
llvm::SmallVector<QubitId, 2> qubitId = {0};
3030
};
3131

32-
} // namespace mqt::ir::opt::decomposition
32+
} // namespace mlir::qco::decomposition

mlir/include/mlir/Dialect/MQTOpt/Transforms/Decomposition/GateSequence.h renamed to mlir/include/mlir/Passes/Decomposition/GateSequence.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
#include "Helpers.h"
1616
#include "UnitaryMatrices.h"
1717
#include "ir/operations/OpType.hpp"
18-
#include "mlir/Dialect/MQTOpt/Transforms/Decomposition/Helpers.h"
1918

2019
#include <Eigen/Core>
2120
#include <cassert>
@@ -32,7 +31,7 @@
3231
#include <mlir/Support/LLVM.h>
3332
#include <mlir/Support/LogicalResult.h>
3433

35-
namespace mqt::ir::opt::decomposition {
34+
namespace mlir::qco::decomposition {
3635
/**
3736
* Gate sequence of single-qubit and/or two-qubit gates.
3837
*/
@@ -96,4 +95,4 @@ using OneQubitGateSequence = QubitGateSequence;
9695
*/
9796
using TwoQubitGateSequence = QubitGateSequence;
9897

99-
} // namespace mqt::ir::opt::decomposition
98+
} // namespace mlir::qco::decomposition

mlir/include/mlir/Dialect/MQTOpt/Transforms/Decomposition/Helpers.h renamed to mlir/include/mlir/Passes/Decomposition/Helpers.h

Lines changed: 13 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
#include "ir/Definitions.hpp"
1414
#include "ir/operations/OpType.hpp"
15-
#include "mlir/Dialect/MQTOpt/IR/MQTOptDialect.h"
15+
#include "mlir/Dialect/QCO/IR/QCODialect.h"
1616

1717
#include <Eigen/Core> // NOLINT(misc-include-cleaner)
1818
#include <Eigen/Eigenvalues> // NOLINT(misc-include-cleaner)
@@ -30,7 +30,7 @@
3030
#include <string>
3131
#include <unsupported/Eigen/KroneckerProduct> // TODO: unstable, NOLINT(misc-include-cleaner)
3232

33-
namespace mqt::ir::opt {
33+
namespace mlir::qco {
3434
using fp = qc::fp;
3535
using qfp = std::complex<fp>;
3636
// NOLINTBEGIN(misc-include-cleaner)
@@ -47,9 +47,9 @@ constexpr qfp C_M_ONE{-1., 0.};
4747
constexpr qfp IM{0., 1.};
4848
constexpr qfp M_IM{0., -1.};
4949

50-
} // namespace mqt::ir::opt
50+
} // namespace mlir::qco
5151

52-
namespace mqt::ir::opt::helpers {
52+
namespace mlir::qco::helpers {
5353

5454
std::optional<fp> mlirValueToFp(mlir::Value value);
5555

@@ -136,17 +136,17 @@ template <typename T, typename Func>
136136
}
137137

138138
[[nodiscard]] inline llvm::SmallVector<fp, 3>
139-
getParameters(UnitaryInterface op) {
139+
getParameters(UnitaryOpInterface op) {
140140
llvm::SmallVector<fp, 3> parameters;
141-
for (auto&& param : op.getParams()) {
142-
if (auto value = helpers::mlirValueToFp(param)) {
141+
for (std::size_t i = 0; i < op.getNumParams(); ++i) {
142+
if (auto value = helpers::mlirValueToFp(op.getParameter(i))) {
143143
parameters.push_back(*value);
144144
}
145145
}
146146
return parameters;
147147
}
148148

149-
[[nodiscard]] inline qc::OpType getQcType(UnitaryInterface op) {
149+
[[nodiscard]] inline qc::OpType getQcType(UnitaryOpInterface op) {
150150
try {
151151
const std::string type = op->getName().stripDialect().str();
152152
return qc::opTypeFromString(type);
@@ -155,27 +155,12 @@ getParameters(UnitaryInterface op) {
155155
}
156156
}
157157

158-
[[nodiscard]] inline bool isSingleQubitOperation(UnitaryInterface op) {
159-
auto&& inQubits = op.getInQubits();
160-
auto&& outQubits = op.getOutQubits();
161-
const bool isSingleQubitOp =
162-
inQubits.size() == 1 && outQubits.size() == 1 && !op.isControlled();
163-
return isSingleQubitOp;
158+
[[nodiscard]] inline bool isSingleQubitOperation(UnitaryOpInterface op) {
159+
return op.isSingleQubit();
164160
}
165161

166-
[[nodiscard]] inline bool isTwoQubitOperation(UnitaryInterface op) {
167-
auto&& inQubits = op.getInQubits();
168-
auto&& inPosCtrlQubits = op.getPosCtrlInQubits();
169-
auto&& inNegCtrlQubits = op.getNegCtrlInQubits();
170-
auto inQubitSize =
171-
inQubits.size() + inPosCtrlQubits.size() + inNegCtrlQubits.size();
172-
auto&& outQubits = op.getOutQubits();
173-
auto&& outPosCtrlQubits = op.getPosCtrlOutQubits();
174-
auto&& outNegCtrlQubits = op.getNegCtrlOutQubits();
175-
auto outQubitSize =
176-
outQubits.size() + outPosCtrlQubits.size() + outNegCtrlQubits.size();
177-
const bool isTwoQubitOp = inQubitSize == 2 && outQubitSize == 2;
178-
return isTwoQubitOp;
162+
[[nodiscard]] inline bool isTwoQubitOperation(UnitaryOpInterface op) {
163+
return op.isTwoQubit();
179164
}
180165

181166
// NOLINTBEGIN(misc-include-cleaner)
@@ -235,4 +220,4 @@ template <typename T, int N, int M>
235220
return 1;
236221
}
237222

238-
} // namespace mqt::ir::opt::helpers
223+
} // namespace mlir::qco::helpers

0 commit comments

Comments
 (0)