Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions .clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Checks: |
-cppcoreguidelines-macro-usage,
-cppcoreguidelines-pro-type-reinterpret-cast,
-cppcoreguidelines-pro-bounds-constant-array-index,
-cppcoreguidelines-pro-bounds-avoid-unchecked-container-access,
-cppcoreguidelines-avoid-do-while,
google-*,
-google-readability-todo,
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ This project adheres to [Semantic Versioning], with the exception that minor rel

### Removed

- 🔥 Remove the density matrix support from the MQT Core DD package ([#1466]) ([**@burgholzer**])
- 🔥 Remove `datastructures` (`ds`) (sub)library from MQT Core ([#1458]) ([**@burgholzer**])
- 🔥 No longer actively type check Python code with `mypy` and solely rely on `ty` ([#1437]) ([**@burgholzer**])

Expand Down Expand Up @@ -314,6 +315,7 @@ _📚 Refer to the [GitHub Release Notes](https://github.com/munich-quantum-tool

<!-- PR links -->

[#1466]: https://github.com/munich-quantum-toolkit/core/pull/1466
[#1465]: https://github.com/munich-quantum-toolkit/core/pull/1465
[#1458]: https://github.com/munich-quantum-toolkit/core/pull/1458
[#1453]: https://github.com/munich-quantum-toolkit/core/pull/1453
Expand Down
7 changes: 7 additions & 0 deletions UPGRADING.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@ Known limitations:
- AppleClang 17+ is required to build MQT Core with MLIR enabled due to some C++20 features being used that are not yet properly supported by older versions.
- Our pre-built distributions are compiled in Release mode. On Windows, this leads to ABI incompatibilities with debug builds. Either build in Release mode or build LLVM from source in Debug mode to resolve this.

### Removal of the density matrix support from the DD package

The density matrix support within the DD package has been removed.
This change was made to reduce the maintenance burden of the package.
Any libraries that depend on the density matrix functionality, such as [MQT DDSIM], need to implement it on their own or use an alternative solution.
In a related fashion, this PR also removes the noise operations from the MQT Core IR as they no longer serve a purpose.

### Removal of the `datastructures` (sub)library

The `datastructures` (sub)library has been removed from the MQT Core repository.
Expand Down
10 changes: 6 additions & 4 deletions bindings/dd/register_matrix_dds.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,7 @@ void registerMatrixDDs(const nb::module_& m) {
mat.def("is_zero_terminal", &dd::mEdge::isZeroTerminal,
"Check if the DD is a zero terminal node.");

mat.def("is_identity", &dd::mEdge::isIdentity<>,
"up_to_global_phase"_a = true,
mat.def("is_identity", &dd::mEdge::isIdentity, "up_to_global_phase"_a = true,
R"pb(Check if the DD represents the identity matrix.

Args:
Expand All @@ -87,8 +86,11 @@ void registerMatrixDDs(const nb::module_& m) {
mat.def("size", nb::overload_cast<>(&dd::mEdge::size, nb::const_),
"Get the size of the DD by traversing it once.");

mat.def("get_entry", &dd::mEdge::getValueByIndex<>, "num_qubits"_a, "row"_a,
"col"_a, "Get the entry of the matrix by row and column index.");
mat.def("get_entry",
nb::overload_cast<size_t, size_t, size_t>(&dd::mEdge::getValueByIndex,
nb::const_),
"num_qubits"_a, "row"_a, "col"_a,
"Get the entry of the matrix by row and column index.");

mat.def("get_entry_by_path", &dd::mEdge::getValueByPath, "num_qubits"_a,
"decisions"_a, R"pb(Get the entry of the matrix by decisions.
Expand Down
3 changes: 3 additions & 0 deletions include/mqt-core/dd/Approximation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,12 @@

#pragma once

#include "dd/DDDefinitions.hpp"
#include "dd/Node.hpp"
#include "dd/Package.hpp"

#include <cstddef>

namespace dd {

/**
Expand Down
33 changes: 9 additions & 24 deletions include/mqt-core/dd/CachedEdge.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,12 @@
#include <complex>
#include <cstddef>
#include <functional>
#include <type_traits>

namespace dd {

struct vNode; // NOLINT(readability-identifier-naming)
struct mNode; // NOLINT(readability-identifier-naming)
struct dNode; // NOLINT(readability-identifier-naming)
class ComplexNumbers;
class MemoryManager;

template <typename T>
using isVector = std::enable_if_t<std::is_same_v<T, vNode>, bool>;
template <typename T>
using isMatrix = std::enable_if_t<std::is_same_v<T, mNode>, bool>;
template <typename T>
using isMatrixVariant =
std::enable_if_t<std::is_same_v<T, mNode> || std::is_same_v<T, dNode>,
bool>;

/**
* @brief A DD node with a cached edge weight
* @details Some DD operations create intermediate results that are not part of
Expand Down Expand Up @@ -116,40 +103,38 @@ template <typename Node> struct CachedEdge {

/**
* @brief Get a normalized vector DD from a fresh node and a list of edges.
* @tparam T template parameter to enable this method only for vNode
* @param p the fresh node
* @param e the list of edges that form the successor nodes
* @param mm a reference to the memory manager (for returning unused nodes)
* @param cn a reference to the complex number manager (for adding new
* complex numbers)
* @return the normalized vector DD
*/
template <typename T = Node, isVector<T> = true>
static auto normalize(Node* p, const std::array<CachedEdge, RADIX>& e,
MemoryManager& mm, ComplexNumbers& cn) -> CachedEdge;
MemoryManager& mm, ComplexNumbers& cn) -> CachedEdge
requires IsVector<Node>;

/**
* @brief Get a normalized (density) matrix) DD from a fresh node and a list
* @brief Get a normalized matrix DD from a fresh node and a list
* of edges.
* @tparam T template parameter to enable this method only for matrix nodes
* @param p the fresh node
* @param e the list of edges that form the successor nodes
* @param mm a reference to the memory manager (for returning unused nodes)
* @param cn a reference to the complex number manager (for adding new
* complex numbers)
* @return the normalized (density) matrix DD
* @return the normalized matrix DD
*/
template <typename T = Node, isMatrixVariant<T> = true>
static auto normalize(Node* p, const std::array<CachedEdge, NEDGE>& e,
MemoryManager& mm, ComplexNumbers& cn) -> CachedEdge;
MemoryManager& mm, ComplexNumbers& cn) -> CachedEdge
requires IsMatrix<Node>;

/**
* @brief Check whether the matrix represented by the DD is the identity.
* @tparam T template parameter to enable this function only for matrix nodes
* @return whether the matrix is the identity
*/
template <typename T = Node, isMatrixVariant<T> = true>
[[nodiscard]] bool isIdentity(const bool upToGlobalPhase = true) const {
[[nodiscard]] bool isIdentity(const bool upToGlobalPhase = true) const
requires IsMatrix<Node>
{
if (!isTerminal()) {
return false;
}
Expand Down
4 changes: 2 additions & 2 deletions include/mqt-core/dd/Complex.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ struct Complex {
* @return A complex number with real and imaginary part equal to zero.
*/
static constexpr Complex zero() noexcept {
return {&constants::zero, &constants::zero};
return {.r = &constants::zero, .i = &constants::zero};
}

/**
Expand All @@ -46,7 +46,7 @@ struct Complex {
* equal to zero.
*/
static constexpr Complex one() noexcept {
return {&constants::one, &constants::zero};
return {.r = &constants::one, .i = &constants::zero};
}

/**
Expand Down
32 changes: 3 additions & 29 deletions include/mqt-core/dd/ComputeTable.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

#pragma once

#include "dd/Node.hpp"
#include "dd/statistics/TableStatistics.hpp"
#include "ir/Definitions.hpp"

Expand Down Expand Up @@ -73,20 +72,8 @@ class ComputeTable {
*/
[[nodiscard]] std::size_t hash(const LeftOperandType& leftOperand,
const RightOperandType& rightOperand) const {
auto h1 = std::hash<LeftOperandType>{}(leftOperand);
if constexpr (std::is_same_v<LeftOperandType, dNode*>) {
if (!dNode::isTerminal(leftOperand)) {
h1 = qc::combineHash(
h1, dd::dNode::getDensityMatrixTempFlags(leftOperand->flags));
}
}
auto h2 = std::hash<RightOperandType>{}(rightOperand);
if constexpr (std::is_same_v<RightOperandType, dNode*>) {
if (!dNode::isTerminal(rightOperand)) {
h2 = qc::combineHash(
h2, dd::dNode::getDensityMatrixTempFlags(rightOperand->flags));
}
}
const auto h1 = std::hash<LeftOperandType>{}(leftOperand);
const auto h2 = std::hash<RightOperandType>{}(rightOperand);
const auto hash = qc::combineHash(h1, h2);
const auto mask = stats.numBuckets - 1;
return hash & mask;
Expand Down Expand Up @@ -121,12 +108,10 @@ class ComputeTable {
* @brief Look up a result in the compute table
* @param leftOperand The left operand
* @param rightOperand The right operand
* @param useDensityMatrix Whether a density matrix is expected
* @return A pointer to the result if it is found, otherwise nullptr.
*/
ResultType* lookup(const LeftOperandType& leftOperand,
const RightOperandType& rightOperand,
[[maybe_unused]] const bool useDensityMatrix = false) {
const RightOperandType& rightOperand) {
ResultType* result = nullptr;
++stats.lookups;
const auto key = hash(leftOperand, rightOperand);
Expand All @@ -142,17 +127,6 @@ class ComputeTable {
return result;
}

if constexpr (std::is_same_v<RightOperandType, dNode*> ||
std::is_same_v<RightOperandType, dCachedEdge>) {
// Since density matrices are reduced representations of matrices, a
// density matrix may not be returned when a matrix is required and vice
// versa
if (!dNode::isTerminal(entry.result.p) &&
dNode::isDensityMatrixNode(entry.result.p->flags) !=
useDensityMatrix) {
return result;
}
}
++stats.hits;
return &entry.result;
}
Expand Down
24 changes: 15 additions & 9 deletions include/mqt-core/dd/DDDefinitions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include <complex>
#include <cstddef>
#include <cstdint>
#include <numbers>
#include <string>
#include <type_traits>
#include <unordered_map>
Expand Down Expand Up @@ -55,14 +56,11 @@ enum class BasisStates : std::uint8_t {
left // NOLINT(readability-identifier-naming)
};

static constexpr fp SQRT2_2 = static_cast<fp>(
static constexpr auto SQRT2_2 = static_cast<fp>(
0.707106781186547524400844362104849039284835937688474036588L);
static constexpr fp PI = static_cast<fp>(
3.141592653589793238462643383279502884197169399375105820974L);
static constexpr fp PI_2 = static_cast<fp>(
1.570796326794896619231321691639751442098584699687552910487L);
static constexpr fp PI_4 = static_cast<fp>(
0.785398163397448309615660845819875721049292349843776455243L);
static constexpr fp PI = std::numbers::pi;
static constexpr auto PI_2 = PI / 2;
static constexpr fp PI_4 = PI / 4;

static constexpr std::uint64_t SERIALIZATION_VERSION = 1;

Expand Down Expand Up @@ -91,7 +89,7 @@ using TwoQubitGateMatrix =
* @param nbits The number of bits to use for the binary representation
* @return The binary representation of the decimal number
*/
[[nodiscard]] static inline std::string
[[nodiscard, maybe_unused]] static std::string
intToBinaryString(const std::size_t value, const std::size_t nbits) {
std::string binary(nbits, '0');
for (std::size_t j = 0; j < nbits; ++j) {
Expand All @@ -104,7 +102,7 @@ intToBinaryString(const std::size_t value, const std::size_t nbits) {

// calculates the Units in Last Place (ULP) distance of two floating point
// numbers
[[maybe_unused]] static std::size_t ulpDistance(fp a, fp b) {
[[nodiscard, maybe_unused]] static std::size_t ulpDistance(fp a, fp b) {
// NOLINTNEXTLINE(clang-diagnostic-float-equal)
if (a == b) {
return 0;
Expand Down Expand Up @@ -136,4 +134,12 @@ intToBinaryString(const std::size_t value, const std::size_t nbits) {
return k;
}

struct vNode;
struct mNode;

template <typename T>
concept IsVector = std::is_same_v<T, vNode>;
template <typename T>
concept IsMatrix = std::is_same_v<T, mNode>;

} // namespace dd
52 changes: 0 additions & 52 deletions include/mqt-core/dd/DDpackageConfig.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@

#pragma once

#include "ir/operations/OpType.hpp"

#include <cstddef>

namespace dd {
Expand All @@ -30,58 +28,10 @@ struct DDPackageConfig {
std::size_t ctMatMatMultNumBucket = 16384U;
std::size_t ctVecKronNumBucket = 4096U;
std::size_t ctMatKronNumBucket = 4096U;
std::size_t ctDmTraceNumBucket = 1U;
std::size_t ctMatTraceNumBucket = 4096U;
std::size_t ctVecInnerProdNumBucket = 4096U;
std::size_t ctDmNoiseNumBucket = 1U;
std::size_t utDmNumBucket = 1U;
std::size_t utDmInitialAllocationSize = 1U;
std::size_t ctDmDmMultNumBucket = 1U;
std::size_t ctDmAddNumBucket = 1U;

// The number of different quantum operations. i.e., the number of operations
// defined in OpType.hpp. This parameter is required to initialize the
// StochasticNoiseOperationTable.hpp
std::size_t stochasticCacheOps = 1;
};

constexpr auto STOCHASTIC_NOISE_SIMULATOR_DD_PACKAGE_CONFIG = []() {
DDPackageConfig config{};
config.stochasticCacheOps = qc::OpType::OpTypeEnd;
config.ctVecAddMagNumBucket = 1U;
config.ctMatAddMagNumBucket = 1U;
config.ctVecConjNumBucket = 1U;
return config;
}();

constexpr auto DENSITY_MATRIX_SIMULATOR_DD_PACKAGE_CONFIG = []() {
DDPackageConfig config{};
config.utDmNumBucket = 65536U;
config.utDmInitialAllocationSize = 4096U;
config.ctDmDmMultNumBucket = 16384U;
config.ctDmAddNumBucket = 16384U;
config.ctDmNoiseNumBucket = 4096U;
config.utMatNumBucket = 16384U;
config.ctMatAddNumBucket = 4096U;
config.ctVecAddNumBucket = 4096U;
config.ctMatConjTransNumBucket = 4096U;
config.ctMatMatMultNumBucket = 1U;
config.ctMatVecMultNumBucket = 1U;
config.utVecNumBucket = 1U;
config.utVecInitialAllocationSize = 1U;
config.utMatInitialAllocationSize = 1U;
config.ctVecKronNumBucket = 1U;
config.ctMatKronNumBucket = 1U;
config.ctDmTraceNumBucket = 4096U;
config.ctMatTraceNumBucket = 1U;
config.ctVecInnerProdNumBucket = 1U;
config.stochasticCacheOps = 1U;
config.ctVecAddMagNumBucket = 1U;
config.ctMatAddMagNumBucket = 1U;
config.ctVecConjNumBucket = 1U;
return config;
}();

constexpr auto UNITARY_SIMULATOR_DD_PACKAGE_CONFIG = []() {
DDPackageConfig config{};
config.utMatNumBucket = 65'536U;
Expand All @@ -90,8 +40,6 @@ constexpr auto UNITARY_SIMULATOR_DD_PACKAGE_CONFIG = []() {
config.utVecNumBucket = 1U;
config.utVecInitialAllocationSize = 1U;
config.ctVecAddNumBucket = 1U;
config.ctVecAddMagNumBucket = 1U;
config.ctMatAddMagNumBucket = 1U;
config.ctVecConjNumBucket = 1U;
config.ctMatConjTransNumBucket = 1U;
config.ctMatVecMultNumBucket = 1U;
Expand Down
Loading
Loading