Skip to content

Commit c4f6399

Browse files
🎨 pre-commit fixes
1 parent 4bc6f15 commit c4f6399

7 files changed

Lines changed: 78 additions & 47 deletions

File tree

CMakeLists.txt

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,22 +24,15 @@ include(PackageAddTest)
2424
include(Cache)
2525
include(AddMQTCoreLibrary)
2626

27-
# include(FetchContent)
28-
# FetchContent_Declare(
29-
# armadillo
30-
# GIT_REPOSITORY https://gitlab.com/conradsnicta/armadillo-code.git
31-
# GIT_TAG 15.0.1
32-
# )
27+
# include(FetchContent) FetchContent_Declare( armadillo GIT_REPOSITORY
28+
# https://gitlab.com/conradsnicta/armadillo-code.git GIT_TAG 15.0.1 )
3329
# FetchContent_MakeAvailable(armadillo)
3430
find_package(Armadillo 15 REQUIRED)
3531
if(Armadillo_FOUND AND NOT TARGET Armadillo::Armadillo)
3632
add_library(Armadillo::Armadillo INTERFACE IMPORTED)
3733
set_target_properties(
38-
Armadillo::Armadillo
39-
PROPERTIES
40-
INTERFACE_LINK_LIBRARIES "${ARMADILLO_LIBRARIES}"
41-
INTERFACE_INCLUDE_DIRECTORIES "${ARMADILLO_INCLUDE_DIRS}"
42-
)
34+
Armadillo::Armadillo PROPERTIES INTERFACE_LINK_LIBRARIES "${ARMADILLO_LIBRARIES}"
35+
INTERFACE_INCLUDE_DIRECTORIES "${ARMADILLO_INCLUDE_DIRS}")
4336
endif()
4437

4538
option(BUILD_MQT_CORE_BINDINGS "Build the MQT Core Python bindings" OFF)

mlir/lib/Dialect/MQTOpt/Transforms/GateDecomposition.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ struct GateDecomposition final
4040
config.setUseTopDownTraversal(true);
4141

4242
// Apply patterns in an iterative and greedy manner.
43-
if (mlir::failed(mlir::applyPatternsGreedily(op, std::move(patterns), config))) {
43+
if (mlir::failed(
44+
mlir::applyPatternsGreedily(op, std::move(patterns), config))) {
4445
signalPassFailure();
4546
}
4647
}

mlir/lib/Dialect/MQTOpt/Transforms/GateDecompositionPattern.cpp

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
*/
1010

1111
#include "Helpers.h"
12+
#include "d.h"
1213
#include "mlir/Dialect/MQTOpt/IR/MQTOptDialect.h"
1314
#include "mlir/Dialect/MQTOpt/Transforms/Passes.h"
1415

@@ -25,8 +26,6 @@
2526
#include <mlir/Support/LogicalResult.h>
2627
#include <string>
2728

28-
#include "d.h"
29-
3029
namespace mqt::ir::opt {
3130

3231
/**
@@ -48,7 +47,8 @@ struct GateDecompositionPattern final
4847
return mlir::failure();
4948
}
5049

51-
matrix4x4 unitaryMatrix = helpers::kroneckerProduct(identityGate, identityGate);
50+
matrix4x4 unitaryMatrix =
51+
helpers::kroneckerProduct(identityGate, identityGate);
5252
for (auto&& gate : series) {
5353
auto gateMatrix = getTwoQubitMatrix({.type = helpers::getQcType(gate),
5454
.parameter = {/*TODO*/},
@@ -329,10 +329,10 @@ struct GateDecompositionPattern final
329329

330330
static std::tuple<matrix2x2, matrix2x2, fp>
331331
decompose_two_qubit_product_gate(matrix4x4 special_unitary) {
332-
using helpers::dot;
333-
using helpers::kroneckerProduct;
334-
using helpers::transpose_conjugate;
335-
using helpers::determinant;
332+
using helpers::determinant;
333+
using helpers::dot;
334+
using helpers::kroneckerProduct;
335+
using helpers::transpose_conjugate;
336336
// first quadrant
337337
matrix2x2 r = {special_unitary[0 * 4 + 0], special_unitary[0 * 4 + 1],
338338
special_unitary[1 * 4 + 0], special_unitary[1 * 4 + 1]};
@@ -375,7 +375,7 @@ struct GateDecompositionPattern final
375375

376376
static matrix4x4 magic_basis_transform(const matrix4x4& unitary,
377377
MagicBasisTransform direction) {
378-
using helpers::dot;
378+
using helpers::dot;
379379
constexpr matrix4x4 B_NON_NORMALIZED = {
380380
C_ONE, IM, C_ZERO, C_ZERO, C_ZERO, C_ZERO, IM, C_ONE,
381381
C_ZERO, C_ZERO, IM, C_M_ONE, C_ONE, M_IM, C_ZERO, C_ZERO,
@@ -545,10 +545,10 @@ struct GateDecompositionPattern final
545545
static TwoQubitWeylDecomposition
546546
new_inner(matrix4x4 unitary_matrix, std::optional<fp> fidelity,
547547
std::optional<Specialization> _specialization) {
548-
using helpers::dot;
549548
using helpers::determinant;
550-
using helpers::transpose;
551549
using helpers::diagonal;
550+
using helpers::dot;
551+
using helpers::transpose;
552552
auto& u = unitary_matrix;
553553
auto det_u = determinant(u);
554554
auto det_pow = std::pow(det_u, static_cast<fp>(-0.25));
@@ -565,11 +565,11 @@ struct GateDecompositionPattern final
565565
helpers::print(m2);
566566

567567
arma::Mat<qfp> U(4, 4);
568-
for (int i = 0; i < 4; ++i) {
569-
for (int j = 0; j < 4; ++j) {
570-
U.at(j, i) = u_p[j * 4 + i];
571-
}
572-
}
568+
for (int i = 0; i < 4; ++i) {
569+
for (int j = 0; j < 4; ++j) {
570+
U.at(j, i) = u_p[j * 4 + i];
571+
}
572+
}
573573
auto x = U.st() * U;
574574
std::cerr << "ARMA\n" << U.t() << "\n\n" << U << "\n\n" << x << std::endl;
575575

@@ -1407,7 +1407,7 @@ struct GateDecompositionPattern final
14071407
decomp0_inner(const TwoQubitWeylDecomposition& target) const {
14081408
using helpers::dot;
14091409
return {
1410-
dot(target.K1r, target.K2r),
1410+
dot(target.K1r, target.K2r),
14111411
dot(target.K1l, target.K2l),
14121412
};
14131413
}

mlir/lib/Dialect/MQTOpt/Transforms/Helpers.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ constexpr qfp M_IM{0., -1.};
4040
namespace mqt::ir::opt::helpers {
4141

4242
// TODO: remove
43-
template <std::size_t N> void print(std::array<std::complex<fp>, N> matrix, std::string s = "") {
43+
template <std::size_t N>
44+
void print(std::array<std::complex<fp>, N> matrix, std::string s = "") {
4445
int i{};
4546
if (!s.empty()) {
4647
llvm::errs() << "=== " << s << " ===\n";
@@ -54,7 +55,8 @@ template <std::size_t N> void print(std::array<std::complex<fp>, N> matrix, std:
5455
llvm::errs() << '\n';
5556
}
5657

57-
template <std::size_t N> void print(std::array<fp, N> matrix, std::string s = "") {
58+
template <std::size_t N>
59+
void print(std::array<fp, N> matrix, std::string s = "") {
5860
int i{};
5961
if (!s.empty()) {
6062
llvm::errs() << "=== " << s << " ===\n";
@@ -375,7 +377,8 @@ auto submatrix(Container&& matrix, int rowStart, int columnStart, int numRows,
375377
std::vector<ValueType<Container>> result(numRows * numColumns);
376378
for (int i = 0; i < numColumns; ++i) {
377379
for (int j = 0; j < numRows; ++j) {
378-
result[j * numColumns + i] = matrix[(rowStart + j) * n + (columnStart + i)];
380+
result[j * numColumns + i] =
381+
matrix[(rowStart + j) * n + (columnStart + i)];
379382
}
380383
}
381384
return result;

mlir/lib/Dialect/MQTOpt/Transforms/a.cpp

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
/*
2+
* Copyright (c) 2023 - 2025 Chair for Design Automation, TUM
3+
* Copyright (c) 2025 Munich Quantum Software Company GmbH
4+
* All rights reserved.
5+
*
6+
* SPDX-License-Identifier: MIT
7+
*
8+
* Licensed under the MIT License
9+
*/
10+
111
#include <array>
212
#include <complex>
313
#include <iomanip>
@@ -32,7 +42,7 @@ matrix4x4 zgemm2(matrix4x4 a, matrix4x4 b) {
3242
qfp z__1;
3343
qfp z__2;
3444
qfp temp;
35-
qfp alpha {1.0, 0.0};
45+
qfp alpha{1.0, 0.0};
3646
for (auto j = 0; j < i__1; ++j) {
3747
for (auto i__ = 0; i__ < 4; ++i__) {
3848
auto i__3 = i__ + j * 4;
@@ -71,18 +81,17 @@ matrix4x4 zgemm2(matrix4x4 a, matrix4x4 b) {
7181
}
7282

7383
int zgemm_(char* transa, char* transb, integer* m, integer* n, integer* k,
74-
doublecomplex* alpha, matrix4x4 a, integer* lda,
75-
matrix4x4 b, integer* ldb, doublecomplex* beta,
76-
matrix4x4& c__, integer* ldc);
84+
doublecomplex* alpha, matrix4x4 a, integer* lda, matrix4x4 b,
85+
integer* ldb, doublecomplex* beta, matrix4x4& c__, integer* ldc);
7786
matrix4x4 zgemm(matrix4x4 a, matrix4x4 b) {
7887
qfp alpha{1.0, 0.0};
7988
qfp beta{1.0, 0.0};
8089
int dimension = 4;
8190
matrix4x4 result{};
8291
// zgemm_("n", "n", &dimension, &dimension, &dimension, &alpha, a.data(),
8392
// &dimension, b.data(), &dimension, &beta, result.data(), &dimension);
84-
zgemm_("N", "N", &dimension, &dimension, &dimension, &alpha, a,
85-
&dimension, b, &dimension, &beta, result, &dimension);
93+
zgemm_("N", "N", &dimension, &dimension, &dimension, &alpha, a, &dimension, b,
94+
&dimension, &beta, result, &dimension);
8695
return result;
8796
}
8897

@@ -91,8 +100,7 @@ void d_cnjg(doublecomplex* r, doublecomplex* z) { *r = std::conj(*z); }
91100
/* Subroutine */ int zgemm_(char* transa, char* transb, integer* m, integer* n,
92101
integer* k, doublecomplex* alpha, matrix4x4 a,
93102
integer* lda, matrix4x4 b, integer* ldb,
94-
doublecomplex* beta, matrix4x4& c__,
95-
integer* ldc) {
103+
doublecomplex* beta, matrix4x4& c__, integer* ldc) {
96104
/* System generated locals */
97105
integer a_dim1, a_offset, b_dim1, b_offset, c_dim1, c_offset, i__1, i__2,
98106
i__3, i__4, i__5, i__6;
@@ -360,14 +368,16 @@ void d_cnjg(doublecomplex* r, doublecomplex* z) { *r = std::conj(*z); }
360368
beta->imag() * c__[i__4 - c_offset].imag()),
361369
z__1.imag(beta->real() * c__[i__4 - c_offset].imag() +
362370
beta->imag() * c__[i__4 - c_offset].real());
363-
c__[i__3 - c_offset].real(z__1.real()), c__[i__3 - c_offset].imag(z__1.imag());
371+
c__[i__3 - c_offset].real(z__1.real()),
372+
c__[i__3 - c_offset].imag(z__1.imag());
364373
/* L60: */
365374
}
366375
}
367376
i__2 = *k;
368377
for (l = 1; l <= i__2; ++l) {
369378
i__3 = l + j * b_dim1;
370-
if (b[i__3 - b_offset].real() != 0. || b[i__3 - b_offset].imag() != 0.) {
379+
if (b[i__3 - b_offset].real() != 0. ||
380+
b[i__3 - b_offset].imag() != 0.) {
371381
i__3 = l + j * b_dim1;
372382
z__1.real(alpha->real() * b[i__3 - b_offset].real() -
373383
alpha->imag() * b[i__3 - b_offset].imag()),
@@ -385,7 +395,8 @@ void d_cnjg(doublecomplex* r, doublecomplex* z) { *r = std::conj(*z); }
385395
temp.imag() * a[i__6 - a_offset].real());
386396
z__1.real(c__[i__5 - c_offset].real() + z__2.real()),
387397
z__1.imag(c__[i__5 - c_offset].imag() + z__2.imag());
388-
c__[i__4 - c_offset].real(z__1.real()), c__[i__4 - c_offset].imag(z__1.imag());
398+
c__[i__4 - c_offset].real(z__1.real()),
399+
c__[i__4 - c_offset].imag(z__1.imag());
389400
/* L70: */
390401
}
391402
}
@@ -421,7 +432,8 @@ void d_cnjg(doublecomplex* r, doublecomplex* z) { *r = std::conj(*z); }
421432
alpha->imag() * temp.imag()),
422433
z__1.imag(alpha->real() * temp.imag() +
423434
alpha->imag() * temp.real());
424-
c__[i__3 - c_offset].real(z__1.real()), c__[i__3 - c_offset].imag(z__1.imag());
435+
c__[i__3 - c_offset].real(z__1.real()),
436+
c__[i__3 - c_offset].imag(z__1.imag());
425437
} else {
426438
i__3 = i__ + j * c_dim1;
427439
z__2.real(alpha->real() * temp.real() -
@@ -435,7 +447,8 @@ void d_cnjg(doublecomplex* r, doublecomplex* z) { *r = std::conj(*z); }
435447
beta->imag() * c__[i__4 - c_offset].real());
436448
z__1.real(z__2.real() + z__3.real()),
437449
z__1.imag(z__2.imag() + z__3.imag());
438-
c__[i__3 - c_offset].real(z__1.real()), c__[i__3 - c_offset].imag(z__1.imag());
450+
c__[i__3 - c_offset].real(z__1.real()),
451+
c__[i__3 - c_offset].imag(z__1.imag());
439452
}
440453
/* L110: */
441454
}

mlir/lib/Dialect/MQTOpt/Transforms/b.h

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
/*
2+
* Copyright (c) 2023 - 2025 Chair for Design Automation, TUM
3+
* Copyright (c) 2025 Munich Quantum Software Company GmbH
4+
* All rights reserved.
5+
*
6+
* SPDX-License-Identifier: MIT
7+
*
8+
* Licensed under the MIT License
9+
*/
10+
111
#pragma once
212

313
#include "Helpers.h"
@@ -140,7 +150,8 @@ void tridiagonalization_inplace(rmatrix4x4& mat, rdiagonal4x4& hCoeffs) {
140150
auto updatedMatrix = bottomRightCorner(mat, remainingSize, remainingSize);
141151
updatedMatrix = lowerSelfadjointView(updatedMatrix);
142152
updatedMatrix = rankUpdate(
143-
updatedMatrix, helpers::submatrix(mat, n - remainingSize, i, remainingSize, 1),
153+
updatedMatrix,
154+
helpers::submatrix(mat, n - remainingSize, i, remainingSize, 1),
144155
std::vector<fp>{hCoeffs.begin() + (n - remainingSize), hCoeffs.end()},
145156
-1.0);
146157
// update bottom right corner
@@ -369,8 +380,8 @@ void householderSequenceEval(rmatrix4x4& m_vectors,
369380
llvm::copy(tmp2, matrix.begin());
370381

371382
tmp2 = helpers::add(
372-
bottom, helpers::multiply(-tau, helpers::multiply(essential, tmp,
373-
1)));
383+
bottom,
384+
helpers::multiply(-tau, helpers::multiply(essential, tmp, 1)));
374385
// insert all rows except first row
375386
llvm::copy(tmp2, matrix.begin() + n);
376387
}

mlir/lib/Dialect/MQTOpt/Transforms/d.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
/*
2+
* Copyright (c) 2023 - 2025 Chair for Design Automation, TUM
3+
* Copyright (c) 2025 Munich Quantum Software Company GmbH
4+
* All rights reserved.
5+
*
6+
* SPDX-License-Identifier: MIT
7+
*
8+
* Licensed under the MIT License
9+
*/
10+
111
#pragma once
212

313
#include "Helpers.h"

0 commit comments

Comments
 (0)