File DensityNode.hpp

Density-matrix DD node, edge and cached-edge types.

This is a self-contained copy of the density-matrix support that used to live in the MQT Core DD package (dd::dNode, dd::dEdge, dd::dCachedEdge) before it was removed in https://github.com/munich-quantum-toolkit/core/pull/1466. It lives in the separate namespace dd::ddsim so that it can coexist with a Core version that still provides the old types.

namespace dd
namespace ddsim

Typedefs

using DensityMatrixDD = dEdge

Functions

inline dEdge densityFromMatrixEdge(const dd::mEdge &e)

Reinterpret a Core matrix edge as a density-matrix edge.

struct dCachedEdge
#include <DensityNode.hpp>

A density-matrix DD node with a cached (non-canonical) edge weight.

Public Functions

dCachedEdge() = default
inline dCachedEdge(dNode *n, const dd::ComplexValue &v)
inline dCachedEdge(dNode *n, const dd::Complex &c)
inline bool operator==(const dCachedEdge &other) const
inline bool operator!=(const dCachedEdge &other) const
inline bool isTerminal() const
inline bool isIdentity(bool upToGlobalPhase = true) const

Public Members

dNode *p = {}
dd::ComplexValue w

Public Static Functions

static inline dCachedEdge terminal(const dd::ComplexValue &w)
static inline dCachedEdge terminal(const std::complex<dd::fp> &w)
static inline dCachedEdge terminal(const dd::Complex &w)
static inline dCachedEdge zero()
static inline dCachedEdge one()
static auto normalize(dNode *p, const std::array<dCachedEdge, dd::NEDGE> &e, dd::MemoryManager &mm, dd::ComplexNumbers &cn) -> dCachedEdge

Get a normalized density-matrix DD from a fresh node and its edges.

struct dEdge
#include <DensityNode.hpp>

A weighted edge pointing to a density-matrix DD node.

Public Functions

inline constexpr bool operator==(const dEdge &other) const
inline constexpr bool operator!=(const dEdge &other) const
inline bool isTerminal() const
inline bool isZeroTerminal() const
inline bool isOneTerminal() const
inline bool isIdentity(bool upToGlobalPhase = true) const
std::size_t size() const

Get the size of the DD (number of nodes including the terminal).

void mark() const noexcept

Mark the edge (and its sub-DD) as used.

void unmark() const noexcept

Unmark the edge (and its sub-DD).

dd::SparsePVecStrKeys getSparseProbabilityVectorStrKeys(std::size_t numQubits, dd::fp threshold = 0.) const

Get the sparse probability vector using strings as keys.

Public Members

dNode *p
dd::Complex w

Public Static Functions

static inline constexpr dEdge zero()
static inline constexpr dEdge one()
static constexpr dEdge terminal(const dd::Complex &w)

Inline definitions that require the complete dNode type

static inline bool trackingRequired(const dEdge &e)
static auto normalize(dNode *p, const std::array<dEdge, dd::NEDGE> &e, dd::MemoryManager &mm, dd::ComplexNumbers &cn) -> dEdge

Get a normalized density-matrix DD from a fresh node and its edges.

static inline void setDensityMatrixTrue(dEdge &e)
static inline void alignDensityEdge(dEdge &e)
static inline void revertDmChangesToEdges(dEdge &x, dEdge &y)
static inline void revertDmChangesToEdge(dEdge &x)
static inline void applyDmChangesToEdges(dEdge &x, dEdge &y)
static inline void applyDmChangesToEdge(dEdge &x)

Private Functions

std::size_t size(std::unordered_set<const dNode*> &visited) const
void traverseDiagonal(const dd::fp &prob, std::size_t i, const dd::ProbabilityFunc &f, std::size_t level, dd::fp threshold = 0.) const
struct dNode : public dd::NodeBase
#include <DensityNode.hpp>

A density-matrix DD node.

Data Layout (8)|(2|2|4)|(24|24|24|24) = 112B

Public Functions

inline dNode *next() const noexcept

Getter for the next object.

inline bool isMarked() const noexcept

Check whether the node is marked as used.

inline void mark() noexcept

Mark the node as used.

inline void unmark() noexcept

Unmark the node.

inline constexpr void unsetTempDensityMatrixFlags() noexcept
void setDensityMatrixNodeFlag(bool densityMatrix) noexcept

Public Members

std::array<dEdge, dd::NEDGE> e = {}

Public Static Functions

static inline constexpr dNode *getTerminal() noexcept

Getter for the terminal object.

static inline bool isTerminal(const dNode *p) noexcept

Check whether a pointer represents a terminal density node.

Density nodes encode temporary state in the three least significant pointer bits. These bits do not make a terminal pointer non-terminal.

static inline constexpr bool tempDensityMatrixFlagsEqual(const std::uint8_t a, const std::uint8_t b) noexcept
static inline constexpr bool isConjugateTempFlagSet(const std::uintptr_t p) noexcept
static inline constexpr bool isNonReduceTempFlagSet(const std::uintptr_t p) noexcept
static inline constexpr bool isDensityMatrixTempFlagSet(const std::uintptr_t p) noexcept
static inline bool isDensityMatrixNode(const std::uintptr_t p) noexcept
static inline bool isConjugateTempFlagSet(const dNode *p) noexcept
static inline bool isNonReduceTempFlagSet(const dNode *p) noexcept
static inline bool isDensityMatrixTempFlagSet(const dNode *p) noexcept
static inline bool isDensityMatrixNode(const dNode *p) noexcept
static inline void setConjugateTempFlagTrue(dNode *&p) noexcept
static inline void setNonReduceTempFlagTrue(dNode *&p) noexcept
static inline void setDensityMatTempFlagTrue(dNode *&p) noexcept
static inline void alignDensityNode(dNode *&p) noexcept
static inline std::uintptr_t getDensityMatrixTempFlags(dNode *&p) noexcept
static inline constexpr std::uintptr_t getDensityMatrixTempFlags(const std::uintptr_t a) noexcept
static std::uint8_t alignDensityNodeNode(dNode *&p) noexcept
static void getAlignedNodeRevertModificationsOnSubEdges(dNode *p) noexcept
static void applyDmChangesToNode(dNode *&p) noexcept
static void revertDmChangesToNode(dNode *&p) noexcept

Public Static Attributes

static constexpr std::uint16_t MARK_FLAG = 0b10000U

Mark flag used for mark-and-sweep garbage collection.