Skip to content
2 changes: 1 addition & 1 deletion bindings/fomac/fomac.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

#include "fomac/FoMaC.hpp"

#include "qdmi/Driver.hpp"
#include "../../include/mqt-core/qdmi/driver/Driver.hpp"
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Outdated

#include <nanobind/nanobind.h>
#include <nanobind/operators.h>
Expand Down
2 changes: 1 addition & 1 deletion bindings/na/register_fomac.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

#include "fomac/FoMaC.hpp"
#include "na/fomac/Device.hpp"
#include "qdmi/na/Generator.hpp"
#include "qdmi/devices/na/Generator.hpp"

#include <nanobind/nanobind.h>
#include <nanobind/operators.h>
Expand Down
2 changes: 1 addition & 1 deletion include/mqt-core/fomac/FoMaC.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

#pragma once

#include "qdmi/Common.hpp"
#include "../qdmi/devices/common/Common.hpp"

#include <algorithm>
#include <complex>
Expand Down
2 changes: 1 addition & 1 deletion include/mqt-core/na/fomac/Device.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#pragma once

#include "fomac/FoMaC.hpp"
#include "qdmi/na/Generator.hpp"
#include "qdmi/devices/na/Generator.hpp"

// NOLINTNEXTLINE(misc-include-cleaner)
#include <nlohmann/json.hpp>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,35 @@
#include <string>

namespace qdmi {
template <class Concrete> class Singleton {
protected:
/// @brief Protected constructor to enforce the singleton pattern.
Singleton() = default;

public:
// Default move constructor and move assignment operator.
Singleton(Singleton&&) = default;
Singleton& operator=(Singleton&&) = default;
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Outdated
// Delete copy constructor and assignment operator to enforce singleton.
Singleton(const Singleton&) = delete;
Singleton& operator=(const Singleton&) = delete;

/// @brief Destructor for the Device class.
virtual ~Singleton() = default;

/// @returns the singleton instance of the Device class.
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Outdated
[[nodiscard]] static auto get() -> Concrete& {
// NOLINTNEXTLINE(cppcoreguidelines-owning-memory)
static auto* instance = new Concrete();
// The instance is intentionally leaked to avoid static deinitialization
// issues (cf. static (de)initialization order fiasco)
return *instance;
}
};

/**
* @brief Function used to mark unreachable code
* @details Uses compiler specific extensions if possible. Even if no extension
* @details Uses compiler-specific extensions if possible. Even if no extension
* is used, undefined behavior is still raised by an empty function body and the
* noreturn attribute.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,15 @@
#include <map>
#include <memory>
#include <mutex>
#include <qdmi/devices/common/Common.hpp>
#include <random>
#include <string>
#include <unordered_map>

namespace qdmi::dd {
class Device final {
class Device final : public Singleton<Device> {
friend Singleton;

Comment thread
coderabbitai[bot] marked this conversation as resolved.
/// Provides access to the device name.
std::string name_;

Expand Down Expand Up @@ -64,18 +67,8 @@ class Device final {
Device();

public:
// Default move constructor and move assignment operator.
Device(Device&&) = delete;
Device& operator=(Device&&) = delete;
// Delete copy constructor and assignment operator to enforce singleton.
Device(const Device&) = delete;
Device& operator=(const Device&) = delete;

/// @brief Destructor for the Device class.
~Device() = default;

/// @returns the singleton instance of the Device class.
[[nodiscard]] static auto get() -> Device&;
~Device() override = default;

/**
* @brief Allocates a new device session.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,17 @@
#include <cstdint>
#include <memory>
#include <optional>
#include <qdmi/devices/common/Common.hpp>
#include <string>
#include <unordered_map>
#include <utility>
#include <variant>
#include <vector>

namespace qdmi::na {
class Device final {
class Device final : public Singleton<Device> {
friend Singleton;
Comment thread
ystade marked this conversation as resolved.
Outdated

Comment thread
coderabbitai[bot] marked this conversation as resolved.
/// @brief Provides access to the device name.
std::string name_;

Expand Down Expand Up @@ -69,18 +72,8 @@ class Device final {
Device();

public:
// Default move constructor and move assignment operator.
Device(Device&&) = default;
Device& operator=(Device&&) = default;
// Delete copy constructor and assignment operator to enforce singleton.
Device(const Device&) = delete;
Device& operator=(const Device&) = delete;

/// @brief Destructor for the Device class.
~Device() = default;

/// @returns the singleton instance of the Device class.
[[nodiscard]] static auto get() -> Device&;
~Device() override = default;

/**
* @brief Allocates a new device session.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,17 @@
#include <cstddef>
#include <cstdint>
#include <memory>
#include <qdmi/devices/common/Common.hpp>
#include <string>
#include <unordered_map>
#include <utility>
#include <variant>
#include <vector>

namespace qdmi::sc {
class Device final {
class Device final : public Singleton<Device> {
friend Singleton;

Comment thread
coderabbitai[bot] marked this conversation as resolved.
/// @brief Provides access to the device name.
std::string name_;

Expand All @@ -51,18 +54,8 @@ class Device final {
Device();

public:
// Delete move constructor and move assignment operator.
Device(Device&&) = delete;
Device& operator=(Device&&) = delete;
// Delete copy constructor and assignment operator to enforce singleton.
Device(const Device&) = delete;
Device& operator=(const Device&) = delete;

/// @brief Destructor for the Device class.
~Device();

/// @returns the singleton instance of the Device class.
[[nodiscard]] static auto get() -> Device&;
~Device() override;

Comment thread
ystade marked this conversation as resolved.
Outdated
/**
* @brief Allocates a new device session.
Expand Down
2 changes: 1 addition & 1 deletion src/fomac/FoMaC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

#include "fomac/FoMaC.hpp"

#include "qdmi/Common.hpp"
#include "../../include/mqt-core/qdmi/devices/common/Common.hpp"
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Outdated

#include <algorithm>
#include <complex>
Expand Down
2 changes: 1 addition & 1 deletion src/na/fomac/Device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

#include "fomac/FoMaC.hpp"
#include "ir/Definitions.hpp"
#include "qdmi/na/Generator.hpp"
#include "qdmi/devices/na/Generator.hpp"

#include <algorithm>
#include <array>
Expand Down
52 changes: 2 additions & 50 deletions src/qdmi/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,56 +6,8 @@
#
# Licensed under the MIT License

set(TARGET_NAME ${MQT_CORE_TARGET_NAME}-qdmi-common)

if(NOT TARGET ${TARGET_NAME})
# Add common library
add_mqt_core_library(${TARGET_NAME} ALIAS_NAME QDMICommon)

# Add sources to target
target_sources(${TARGET_NAME} PRIVATE Common.cpp)

# Add headers using file sets
target_sources(${TARGET_NAME} PUBLIC FILE_SET HEADERS BASE_DIRS ${MQT_CORE_INCLUDE_BUILD_DIR}
FILES ${MQT_CORE_INCLUDE_BUILD_DIR}/qdmi/Common.hpp)

# Add link libraries
target_link_libraries(
${TARGET_NAME}
PUBLIC qdmi::qdmi
PRIVATE qdmi::qdmi_project_warnings)

# add to list of MQT core targets
list(APPEND MQT_CORE_TARGETS ${TARGET_NAME})
endif()

add_subdirectory(dd)
add_subdirectory(sc)
add_subdirectory(na)

set(TARGET_NAME ${MQT_CORE_TARGET_NAME}-qdmi-driver)

if(NOT TARGET ${TARGET_NAME})
# Add driver library
add_mqt_core_library(${TARGET_NAME} ALIAS_NAME QDMIDriver)

# Add sources to target
target_sources(${TARGET_NAME} PRIVATE Driver.cpp)

# Add headers using file sets
target_sources(${TARGET_NAME} PUBLIC FILE_SET HEADERS BASE_DIRS ${MQT_CORE_INCLUDE_BUILD_DIR}
FILES ${MQT_CORE_INCLUDE_BUILD_DIR}/qdmi/Driver.hpp)

# Add link libraries
target_link_libraries(
${TARGET_NAME}
PUBLIC qdmi::qdmi MQT::CoreQDMICommon
PRIVATE MQT::CoreQDMINaDevice MQT::CoreQDMIScDevice MQT::CoreQDMI_DDSIM_Device
qdmi::qdmi_project_warnings spdlog::spdlog ${CMAKE_DL_LIBS})

# add to list of MQT core targets
list(APPEND MQT_CORE_TARGETS ${TARGET_NAME})
endif()
add_subdirectory(devices)
add_subdirectory(driver)

set(MQT_CORE_TARGETS
${MQT_CORE_TARGETS}
Expand Down
16 changes: 16 additions & 0 deletions src/qdmi/devices/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Copyright (c) 2023 - 2026 Chair for Design Automation, TUM
# Copyright (c) 2025 - 2026 Munich Quantum Software Company GmbH
# All rights reserved.
#
# SPDX-License-Identifier: MIT
#
# Licensed under the MIT License

add_subdirectory(common)
add_subdirectory(dd)
add_subdirectory(sc)
add_subdirectory(na)

set(MQT_CORE_TARGETS
${MQT_CORE_TARGETS}
PARENT_SCOPE)
35 changes: 35 additions & 0 deletions src/qdmi/devices/common/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Copyright (c) 2023 - 2026 Chair for Design Automation, TUM
# Copyright (c) 2025 - 2026 Munich Quantum Software Company GmbH
# All rights reserved.
#
# SPDX-License-Identifier: MIT
#
# Licensed under the MIT License

set(TARGET_NAME ${MQT_CORE_TARGET_NAME}-qdmi-common)

if(NOT TARGET ${TARGET_NAME})
# Add common library
add_mqt_core_library(${TARGET_NAME} ALIAS_NAME QDMICommon)

# Add sources to target
target_sources(${TARGET_NAME} PRIVATE Common.cpp)

# Add headers using file sets
target_sources(
${TARGET_NAME} PUBLIC FILE_SET HEADERS BASE_DIRS ${MQT_CORE_INCLUDE_BUILD_DIR} FILES
${MQT_CORE_INCLUDE_BUILD_DIR}/qdmi/devices/common/Common.hpp)

# Add link libraries
target_link_libraries(
${TARGET_NAME}
PUBLIC qdmi::qdmi
PRIVATE qdmi::qdmi_project_warnings)

# add to list of MQT core targets
list(APPEND MQT_CORE_TARGETS ${TARGET_NAME})
endif()

set(MQT_CORE_TARGETS
${MQT_CORE_TARGETS}
PARENT_SCOPE)
2 changes: 1 addition & 1 deletion src/qdmi/Common.cpp → src/qdmi/devices/common/Common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
/// @brief Common definitions and utilities for working with QDMI in C++.
/// @note This file will be upstreamed to the QDMI core library in the future.

#include "qdmi/Common.hpp"
#include "qdmi/devices/common/Common.hpp"

#include <iostream>
#include <qdmi/constants.h>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ if(NOT TARGET ${TARGET_NAME})
${MQT_CORE_INCLUDE_BUILD_DIR}
${CMAKE_CURRENT_BINARY_DIR}/include
FILES
${MQT_CORE_INCLUDE_BUILD_DIR}/qdmi/dd/Device.hpp
${MQT_CORE_INCLUDE_BUILD_DIR}/qdmi/devices/dd/Device.hpp
${QDMI_HDRS})

# Add link libraries
Expand All @@ -48,9 +48,7 @@ if(NOT TARGET ${TARGET_NAME})
set_target_properties(${TARGET_NAME} PROPERTIES POSITION_INDEPENDENT_CODE ON)

# Add to list of MQT Core targets
set(MQT_CORE_TARGETS
${MQT_CORE_TARGETS} ${TARGET_NAME}
PARENT_SCOPE)
list(APPEND MQT_CORE_TARGETS ${TARGET_NAME})

# Make QDMI version available
target_compile_definitions(${TARGET_NAME} PRIVATE QDMI_VERSION="${QDMI_VERSION}")
Expand All @@ -59,3 +57,7 @@ if(NOT TARGET ${TARGET_NAME})
# in the tests
add_library(qdmi::mqt_ddsim_device ALIAS ${TARGET_NAME})
endif()

set(MQT_CORE_TARGETS
${MQT_CORE_TARGETS}
PARENT_SCOPE)
11 changes: 2 additions & 9 deletions src/qdmi/dd/Device.cpp → src/qdmi/devices/dd/Device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* @brief The MQT QDMI device implementation for its DD-based simulator.
*/

#include "qdmi/dd/Device.hpp"
#include "qdmi/devices/dd/Device.hpp"

#include "circuit_optimizer/CircuitOptimizer.hpp"
#include "dd/DDDefinitions.hpp"
Expand All @@ -22,7 +22,7 @@
#include "ir/QuantumComputation.hpp"
#include "mqt_ddsim_qdmi/device.h"
#include "qasm3/Importer.hpp"
#include "qdmi/Common.hpp"
#include "qdmi/devices/common/Common.hpp"

#include <algorithm>
#include <array>
Expand Down Expand Up @@ -149,13 +149,6 @@ namespace qdmi::dd {
Device::Device()
: name_("MQT Core DDSIM QDMI Device"),
qubitsNum_(std::numeric_limits<::dd::Qubit>::max()) {}
auto Device::get() -> Device& {
// NOLINTNEXTLINE(cppcoreguidelines-owning-memory)
static auto* instance = new Device();
// The instance is intentionally leaked to avoid static deinitialization
// issues (cf. static (de)initialization order fiasco)
return *instance;
}
auto Device::sessionAlloc(MQT_DDSIM_QDMI_Device_Session* session)
-> QDMI_STATUS {
if (session == nullptr) {
Expand Down
2 changes: 1 addition & 1 deletion src/qdmi/na/App.cpp → src/qdmi/devices/na/App.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* Licensed under the MIT License
*/

#include "qdmi/na/Generator.hpp"
#include "qdmi/devices/na/Generator.hpp"

#include <cstddef>
#include <cstdint>
Expand Down
Loading
Loading