Skip to content

Commit 5e8d0d0

Browse files
committed
Cleanup to satisfy coderabittai
1 parent 62a7eed commit 5e8d0d0

6 files changed

Lines changed: 17 additions & 39 deletions

File tree

CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ include(PreventInSourceBuilds)
2323
include(PackageAddTest)
2424
include(Cache)
2525
include(AddMQTCoreLibrary)
26-
include(FetchContent)
2726

2827
option(BUILD_MQT_CORE_BINDINGS "Build the MQT Core Python bindings" OFF)
2928
if(BUILD_MQT_CORE_BINDINGS)

cmake/ExternalDependencies.cmake

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,10 @@ if(BUILD_MQT_CORE_MLIR)
2727
Eigen
2828
GIT_REPOSITORY https://gitlab.com/libeigen/eigen.git
2929
GIT_TAG 5.0.1
30-
GIT_SHALLOW TRUE)
31-
FetchContent_MakeAvailable(Eigen)
30+
GIT_SHALLOW TRUE
31+
FIND_PACKAGE_ARGS 3.4.0 # minimum version for locally installed package
32+
)
33+
list(APPEND FETCH_PACKAGES Eigen)
3234
endif()
3335

3436
set(JSON_VERSION

mlir/include/mlir/Dialect/QCO/IR/QCODialect.h

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
#include <mlir/Interfaces/SideEffectInterfaces.h>
3030
#include <optional>
3131
#include <string>
32-
#include <unsupported/Eigen/KroneckerProduct>
3332
#include <variant>
3433

3534
#define DIALECT_NAME_QCO "qco"
@@ -55,13 +54,6 @@
5554

5655
namespace mlir::qco {
5756

58-
/**
59-
* @brief Retrieve C++ type of static mlir::Value.
60-
* @details The returned float attribute can be used to get the value of the
61-
* given parameter as a C++ type.
62-
*/
63-
[[nodiscard]] inline std::optional<double>
64-
tryGetParameterAsDouble(UnitaryOpInterface op, size_t i);
6557
/**
6658
* @brief Trait for operations with a fixed number of target qubits and
6759
* parameters
@@ -71,11 +63,6 @@ tryGetParameterAsDouble(UnitaryOpInterface op, size_t i);
7163
* verification and code generation optimizations.
7264
* @tparam T The target arity.
7365
* @tparam P The parameter arity.
74-
* @tparam MatrixDefinition A function returning the matrix definition of the
75-
* operation. The operation will be provided as the
76-
* only argument of the function. If the operation does
77-
* not have a matrix definition, set this value to
78-
* nullptr.
7966
*/
8067
template <size_t T, size_t P> class TargetAndParameterArityTrait {
8168
public:
@@ -144,14 +131,6 @@ template <size_t T, size_t P> class TargetAndParameterArityTrait {
144131
llvm::reportFatalUsageError(
145132
"Given qubit is not an input of the operation");
146133
}
147-
148-
protected:
149-
[[nodiscard]] const Operation* getConstOperation() const {
150-
auto* concrete = static_cast<const ConcreteType*>(this);
151-
// use dereference operator instead of getOperation() of mlir::Op; the
152-
// operator provides a const overload, getOperation() does not
153-
return *concrete;
154-
}
155134
};
156135
};
157136

@@ -163,11 +142,3 @@ template <size_t T, size_t P> class TargetAndParameterArityTrait {
163142

164143
#define GET_OP_CLASSES
165144
#include "mlir/Dialect/QCO/IR/QCOOps.h.inc" // IWYU pragma: export
166-
167-
namespace mlir::qco {
168-
169-
[[nodiscard]] inline UnitaryOpInterface getControlledOp(UnitaryOpInterface op) {
170-
return llvm::cast<CtrlOp>(op).getBodyUnitary();
171-
}
172-
173-
} // namespace mlir::qco

mlir/include/mlir/Dialect/QCO/IR/QCOInterfaces.td

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ def UnitaryOpInterface : OpInterface<"UnitaryOpInterface"> {
2828

2929
let cppNamespace = "::mlir::qco";
3030

31-
// TODO: fix const correctness?
3231
let methods = [
3332
// Qubit accessors
3433
InterfaceMethod<
@@ -146,12 +145,20 @@ def UnitaryOpInterface : OpInterface<"UnitaryOpInterface"> {
146145

147146
if constexpr (std::is_same_v<std::remove_cvref_t<MatrixType>, Eigen::MatrixXcd>) {
148147
// cast to Eigen::MatrixXcd via visitor pattern
149-
auto&& visitor = [](auto&& m) -> std::optional<MatrixType> { return m; };
148+
auto&& visitor = [](auto&& m) -> std::optional<MatrixType> {
149+
// implicit cast to Eigen::MatrixXcd if variant holds a matrix type;
150+
// if variant holds std::nullopt_t, std::optional will be initialized with
151+
// the std::nullopt_t instance, so std::nullopt
152+
return m;
153+
};
150154
return std::visit(visitor, matrix);
151155
} else {
152156
// if an explicit size has been requested, use checked access to variant
153-
// to return the correct type (throws on wrong type)
154-
return std::get<MatrixType>(matrix);
157+
// to try to return the correct type
158+
if (auto* ptr = std::get_if<MatrixType>(matrix)) {
159+
return *ptr;
160+
}
161+
return std::nullopt;
155162
}
156163
}
157164
}];

mlir/include/mlir/Dialect/QCO/IR/QCOOps.td

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,6 @@ class TargetAndParameterArityTrait<int T, int P>
243243
let cppNamespace = "::mlir::qco";
244244
}
245245

246-
def ZeroTargetZeroParameter : TargetAndParameterArityTrait<0, 0>;
247246
def ZeroTargetOneParameter : TargetAndParameterArityTrait<0, 1>;
248247
def OneTargetZeroParameter : TargetAndParameterArityTrait<1, 0>;
249248
def OneTargetOneParameter : TargetAndParameterArityTrait<1, 1>;
@@ -1004,7 +1003,7 @@ def XXMinusYYOp : QCOOp<"xx_minus_yy", traits = [UnitaryOpInterface, TwoTargetTw
10041003
let hasCanonicalizer = 1;
10051004
}
10061005

1007-
def BarrierOp : QCOOp<"barrier", traits = [UnitaryOpInterface, ZeroTargetZeroParameter]> {
1006+
def BarrierOp : QCOOp<"barrier", traits = [UnitaryOpInterface]> {
10081007
let summary = "Apply a barrier gate to a set of qubits";
10091008
let description = [{
10101009
Applies a barrier gate to a set of qubits and returns the transformed qubits.

mlir/lib/Dialect/QCO/IR/Modifiers/CtrlOp.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,7 @@ std::optional<Eigen::MatrixXcd> CtrlOp::getUnitaryMatrix() {
375375
assert(targetMatrix->cols() == targetMatrix->rows());
376376

377377
// define dimensions and type of output matrix
378-
const auto dim = static_cast<int64_t>((1 << getNumControls()) * targetDim);
378+
const auto dim = static_cast<int64_t>((1ULL << getNumControls()) * targetDim);
379379

380380
// initialize result with identity
381381
Eigen::MatrixXcd matrix = Eigen::MatrixXcd::Identity(dim, dim);

0 commit comments

Comments
 (0)