Maestro 0.3.11
Unified interface for quantum circuit simulation
Loading...
Searching...
No Matches
SimpleHost.h
Go to the documentation of this file.
1
19
20#pragma once
21
22#ifndef _SIMPLE_HOST_H_
23#define _SIMPLE_HOST_H_
24
25#include <numeric>
26
27#include "Host.h"
28#include "Network.h"
29
30namespace Network
31{
32
44template <typename Time = Types::time_type> class SimpleHost : public IHost<Time>
45{
46 public:
61 SimpleHost(size_t hostId, size_t startQubitId, size_t numQubits, size_t startClassicalBitId, size_t numClassicalBits)
62 : id(hostId), startQubitId(startQubitId), numQubits(numQubits), startClassicalBitId(startClassicalBitId), numClassicalBits(numClassicalBits)
63 {
64 }
65
72 size_t GetId() const override
73 {
74 return id;
75 }
76
84 size_t GetNumQubits() const override
85 {
86 return numQubits;
87 }
88
97 size_t GetNumNetworkEntangledQubits() const override
98 {
99 if (std::numeric_limits<size_t>::max() == entangledQubitId)
100 return 0;
101
102 return 1;
103 }
104
113 size_t GetNumClassicalBits() const override
114 {
115 return numClassicalBits;
116 }
117
125 bool IsQubitOnHost(size_t qubitId) const override
126 {
127 return qubitId >= startQubitId && qubitId < startQubitId + numQubits;
128 }
129
137 bool AreQubitsOnSameHost(size_t qubitId1, size_t qubitId2) const override
138 {
139 return IsQubitOnHost(qubitId1) && IsQubitOnHost(qubitId2);
140 }
141
148 bool IsClassicalBitOnHost(size_t cbitId) const override
149 {
150 return (cbitId >= startClassicalBitId && cbitId < startClassicalBitId + numClassicalBits) || cbitId == entangledQubitMeasurementBit;
151 }
152
161 bool IsEntangledQubitOnHost(size_t qubitId) const override
162 {
164 return false;
165
166 return qubitId == entangledQubitId;
167 }
168
175 bool AreCbitsOnSameHost(size_t cbitId1, size_t cbitId2) const override
176 {
177 return IsClassicalBitOnHost(cbitId1) && IsClassicalBitOnHost(cbitId2);
178 }
179
187 std::vector<size_t> GetQubitsIds() const override
188 {
189 std::vector<size_t> res(numQubits);
190
191 std::iota(res.begin(), res.end(), startQubitId);
192
193 return res;
194 }
195
205 std::vector<size_t> GetNetworkEntangledQubitsIds() const override
206 {
208 return {};
209
210 return {entangledQubitId};
211 }
212
219 std::vector<size_t> GetClassicalBitsIds() const override
220 {
221 std::vector<size_t> res(numClassicalBits);
222
223 std::iota(res.begin(), res.end(), startClassicalBitId);
224
225 return res;
226 }
227
237 std::vector<size_t> GetEntangledQubitMeasurementBitIds() const override
238 {
239 if (std::numeric_limits<size_t>::max() == entangledQubitMeasurementBit)
240 return {};
241
242 return {entangledQubitMeasurementBit};
243 }
244
257 bool SendPacketToHost(size_t hostId, const std::vector<uint8_t> &packet) override
258 {
259 return false;
260 }
261
273 bool RecvPacketFromHost(size_t hostId, const std::vector<uint8_t> &packet) override
274 {
275 return false;
276 }
277
286 size_t GetStartQubitId() const override
287 {
288 return startQubitId;
289 }
290
299 size_t GetStartClassicalBitId() const override
300 {
301 return startClassicalBitId;
302 }
303
313 void SetEntangledQubitId(size_t id)
314 {
315 entangledQubitId = id;
316 }
317
330 {
331 entangledQubitMeasurementBit = id;
332 }
333
334 private:
335 size_t id;
336
337 size_t startQubitId = 0;
338 size_t numQubits = 0;
339
340 size_t startClassicalBitId = 0;
341 size_t numClassicalBits = 0;
342
343 size_t entangledQubitId = std::numeric_limits<size_t>::max();
345 size_t entangledQubitMeasurementBit = std::numeric_limits<size_t>::max();
348};
349
350} // namespace Network
351
352#endif // ! _SIMPLE_HOST_H_
The host interface.
Definition Host.h:53
size_t GetNumClassicalBits() const override
Get the number of classical bits.
Definition SimpleHost.h:113
bool AreQubitsOnSameHost(size_t qubitId1, size_t qubitId2) const override
Check if two qubits are in the same host.
Definition SimpleHost.h:137
size_t GetId() const override
Get the host id.
Definition SimpleHost.h:72
void SetEntangledQubitMeasurementBit(size_t id)
Set the id of the classical bit used for measurement of the qubit used for entanglement between hosts...
Definition SimpleHost.h:329
size_t GetNumNetworkEntangledQubits() const override
Get the number of network entangled qubits.
Definition SimpleHost.h:97
bool SendPacketToHost(size_t hostId, const std::vector< uint8_t > &packet) override
Send a packet to a host.
Definition SimpleHost.h:257
bool IsEntangledQubitOnHost(size_t qubitId) const override
Check if a qubit used for entanglement between hosts is in the host.
Definition SimpleHost.h:161
bool RecvPacketFromHost(size_t hostId, const std::vector< uint8_t > &packet) override
Receive a packet from a host.
Definition SimpleHost.h:273
size_t GetStartClassicalBitId() const override
Get the id of the first classical bit assigned to the host.
Definition SimpleHost.h:299
bool AreCbitsOnSameHost(size_t cbitId1, size_t cbitId2) const override
Check if two classical bits are in the same host.
Definition SimpleHost.h:175
SimpleHost(size_t hostId, size_t startQubitId, size_t numQubits, size_t startClassicalBitId, size_t numClassicalBits)
The constructor.
Definition SimpleHost.h:61
std::vector< size_t > GetEntangledQubitMeasurementBitIds() const override
Get the ids of the classical bits used for measurement of the qubits used for entanglement between ho...
Definition SimpleHost.h:237
std::vector< size_t > GetNetworkEntangledQubitsIds() const override
Get the ids of the qubits used for entanglement between hosts in the host.
Definition SimpleHost.h:205
size_t GetStartQubitId() const override
Get the id of the first qubit assigned to the host.
Definition SimpleHost.h:286
bool IsQubitOnHost(size_t qubitId) const override
Check if a qubit is in the host.
Definition SimpleHost.h:125
bool IsClassicalBitOnHost(size_t cbitId) const override
Check if a classical bit is in the host.
Definition SimpleHost.h:148
std::vector< size_t > GetQubitsIds() const override
Get the ids of the qubits in the host.
Definition SimpleHost.h:187
void SetEntangledQubitId(size_t id)
Set the id of the qubit used for entanglement between hosts.
Definition SimpleHost.h:313
size_t GetNumQubits() const override
Get the number of qubits.
Definition SimpleHost.h:84
std::vector< size_t > GetClassicalBitsIds() const override
Get the ids of the classical bits in the host.
Definition SimpleHost.h:219