-
-
Notifications
You must be signed in to change notification settings - Fork 53
Expand file tree
/
Copy pathDevice.hpp
More file actions
170 lines (148 loc) · 5.29 KB
/
Device.hpp
File metadata and controls
170 lines (148 loc) · 5.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
/*
* 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
*/
#pragma once
#include "fomac/FoMaC.hpp"
#include "qdmi/devices/na/Generator.hpp"
// NOLINTNEXTLINE(misc-include-cleaner)
#include <nlohmann/json.hpp>
#include <optional>
#include <vector>
namespace na {
/**
* @brief Class representing the Session library with neutral atom extensions.
* @see fomac::Session
*/
class Session : public fomac::Session {
public:
/**
* @brief Class representing a quantum device with neutral atom extensions.
* @see fomac::Session::Device
* @note Since it inherits from @ref na::Device, Device objects can be
* converted to `nlohmann::json` objects.
*/
class Device : public fomac::Session::Device, na::Device {
/**
* @brief Initializes the name from the underlying QDMI device.
*/
auto initNameFromDevice() -> void;
/**
* @brief Initializes the minimum atom distance from the underlying QDMI
* device.
*/
auto initMinAtomDistanceFromDevice() -> bool;
/**
* @brief Initializes the number of qubits from the underlying QDMI device.
*/
auto initQubitsNumFromDevice() -> void;
/**
* @brief Initializes the length unit from the underlying QDMI device.
*/
auto initLengthUnitFromDevice() -> bool;
/**
* @brief Initializes the duration unit from the underlying QDMI device.
*/
auto initDurationUnitFromDevice() -> bool;
/**
* @brief Initializes the decoherence times from the underlying QDMI device.
*/
auto initDecoherenceTimesFromDevice() -> bool;
/**
* @brief Initializes the trap lattices from the underlying QDMI device.
* @details It reconstructs the entire lattice structure from the
* information retrieved from the QDMI device, including lattice vectors,
* sublattice offsets, and extent.
* @see na::Device::Lattice
*/
auto initTrapsfromDevice() -> bool;
/**
* @brief Initializes the all operations from the underlying QDMI device.
*/
auto initOperationsFromDevice() -> bool;
/**
* @brief Constructs a Device object from a fomac::Session::Device object.
* @param device The fomac::Session::Device object to wrap.
* @note The constructor does not initialize the additional fields of this
* class. For their initialization, the corresponding `init*FromDevice`
* methods must be called, see @ref tryCreateFromDevice.
*/
explicit Device(const fomac::Session::Device& device);
public:
/// @returns the length unit of the device.
[[nodiscard]] auto getLengthUnit() const -> const Unit& {
return lengthUnit;
}
/// @returns the duration unit of the device.
[[nodiscard]] auto getDurationUnit() const -> const Unit& {
return durationUnit;
}
/// @returns the decoherence times of the device.
[[nodiscard]] auto getDecoherenceTimes() const -> const DecoherenceTimes& {
return decoherenceTimes;
}
/// @returns the list of trap lattices of the device.
[[nodiscard]] auto getTraps() const -> const std::vector<Lattice>& {
return traps;
}
/**
* @brief Try to create a Device object from a fomac::Session::Device
* object.
* @details This method attempts to create a Device object by initializing
* all necessary fields from the provided fomac::Session::Device object. If
* any required information is missing or invalid, the method returns
* `std::nullopt`.
* @param device is the fomac::Session::Device object to wrap.
* @return An optional containing the instantiated device if compatible,
* std::nullopt otherwise.
*/
[[nodiscard]] static auto
tryCreateFromDevice(const fomac::Session::Device& device)
-> std::optional<Device> {
Device d(device);
// The sequence of the following method calls does not matter.
// They are independent of each other.
if (!d.initMinAtomDistanceFromDevice()) {
return std::nullopt;
}
if (!d.initLengthUnitFromDevice()) {
return std::nullopt;
}
if (!d.initDurationUnitFromDevice()) {
return std::nullopt;
}
if (!d.initDecoherenceTimesFromDevice()) {
return std::nullopt;
}
if (!d.initTrapsfromDevice()) {
return std::nullopt;
}
if (!d.initOperationsFromDevice()) {
return std::nullopt;
}
d.initNameFromDevice();
d.initQubitsNumFromDevice();
return d;
}
// The following is the result of
// NLOHMANN_DEFINE_DERIVED_TYPE_INTRUSIVE_ONLY_SERIALIZE(Device, na::Device)
// without any new attributes, which is the reason the macro cannot be used.
template <typename BasicJsonType>
friend void to_json(BasicJsonType& nlohmannJsonJ,
const Device& nlohmannJsonT) {
// NOLINTNEXTLINE(misc-include-cleaner)
nlohmann::to_json(nlohmannJsonJ,
static_cast<const na::Device&>(nlohmannJsonT));
}
};
/// @brief Deleted default constructor to prevent instantiation.
Session() = delete;
/// @see QDMI_SESSION_PROPERTY_DEVICES
[[nodiscard]] static auto getDevices() -> std::vector<Device>;
};
} // namespace na