Maestro 0.1.0
Unified interface for quantum circuit simulation
Loading...
Searching...
No Matches
SimpleHost.h
Go to the documentation of this file.
1
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
43template <typename Time = Types::time_type>
44class SimpleHost : public IHost<Time> {
45 public:
60 SimpleHost(size_t hostId, size_t startQubitId, size_t numQubits,
61 size_t startClassicalBitId, size_t numClassicalBits)
62 : id(hostId),
63 startQubitId(startQubitId),
64 numQubits(numQubits),
65 startClassicalBitId(startClassicalBitId),
66 numClassicalBits(numClassicalBits) {}
67
74 size_t GetId() const override { return id; }
75
83 size_t GetNumQubits() const override { return numQubits; }
84
93 size_t GetNumNetworkEntangledQubits() const override {
94 if (std::numeric_limits<size_t>::max() == entangledQubitId) return 0;
95
96 return 1;
97 }
98
107 size_t GetNumClassicalBits() const override { return numClassicalBits; }
108
116 bool IsQubitOnHost(size_t qubitId) const override {
117 return qubitId >= startQubitId && qubitId < startQubitId + numQubits;
118 }
119
127 bool AreQubitsOnSameHost(size_t qubitId1, size_t qubitId2) const override {
128 return IsQubitOnHost(qubitId1) && IsQubitOnHost(qubitId2);
129 }
130
137 bool IsClassicalBitOnHost(size_t cbitId) const override {
138 return (cbitId >= startClassicalBitId &&
139 cbitId < startClassicalBitId + numClassicalBits) ||
140 cbitId == entangledQubitMeasurementBit;
141 }
142
151 bool IsEntangledQubitOnHost(size_t qubitId) const override {
152 if (GetNumNetworkEntangledQubits() == 0) return false;
153
154 return qubitId == entangledQubitId;
155 }
156
163 bool AreCbitsOnSameHost(size_t cbitId1, size_t cbitId2) const override {
164 return IsClassicalBitOnHost(cbitId1) && IsClassicalBitOnHost(cbitId2);
165 }
166
174 std::vector<size_t> GetQubitsIds() const override {
175 std::vector<size_t> res(numQubits);
176
177 std::iota(res.begin(), res.end(), startQubitId);
178
179 return res;
180 }
181
191 std::vector<size_t> GetNetworkEntangledQubitsIds() const override {
192 if (GetNumNetworkEntangledQubits() == 0) return {};
193
194 return {entangledQubitId};
195 }
196
203 std::vector<size_t> GetClassicalBitsIds() const override {
204 std::vector<size_t> res(numClassicalBits);
205
206 std::iota(res.begin(), res.end(), startClassicalBitId);
207
208 return res;
209 }
210
220 std::vector<size_t> GetEntangledQubitMeasurementBitIds() const override {
221 if (std::numeric_limits<size_t>::max() == entangledQubitMeasurementBit)
222 return {};
223
224 return {entangledQubitMeasurementBit};
225 }
226
239 bool SendPacketToHost(size_t hostId,
240 const std::vector<uint8_t> &packet) override {
241 return false;
242 }
243
255 bool RecvPacketFromHost(size_t hostId,
256 const std::vector<uint8_t> &packet) override {
257 return false;
258 }
259
268 size_t GetStartQubitId() const override { return startQubitId; }
269
278 size_t GetStartClassicalBitId() const override { return startClassicalBitId; }
279
289 void SetEntangledQubitId(size_t id) { entangledQubitId = id; }
290
303 entangledQubitMeasurementBit = id;
304 }
305
306 private:
307 size_t id;
309 size_t startQubitId =
310 0;
311 size_t numQubits = 0;
313 size_t startClassicalBitId =
314 0;
315 size_t numClassicalBits =
316 0;
318 size_t entangledQubitId =
319 std::numeric_limits<size_t>::max();
321 size_t entangledQubitMeasurementBit =
322 std::numeric_limits<size_t>::max();
325};
326
327} // namespace Network
328
329#endif // ! _SIMPLE_HOST_H_
The host interface.
Definition Host.h:51
The simple host implementation.
Definition SimpleHost.h:44
size_t GetNumClassicalBits() const override
Get the number of classical bits.
Definition SimpleHost.h:107
bool AreQubitsOnSameHost(size_t qubitId1, size_t qubitId2) const override
Check if two qubits are in the same host.
Definition SimpleHost.h:127
size_t GetId() const override
Get the host id.
Definition SimpleHost.h:74
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:302
size_t GetNumNetworkEntangledQubits() const override
Get the number of network entangled qubits.
Definition SimpleHost.h:93
bool SendPacketToHost(size_t hostId, const std::vector< uint8_t > &packet) override
Send a packet to a host.
Definition SimpleHost.h:239
bool IsEntangledQubitOnHost(size_t qubitId) const override
Check if a qubit used for entanglement between hosts is in the host.
Definition SimpleHost.h:151
bool RecvPacketFromHost(size_t hostId, const std::vector< uint8_t > &packet) override
Receive a packet from a host.
Definition SimpleHost.h:255
size_t GetStartClassicalBitId() const override
Get the id of the first classical bit assigned to the host.
Definition SimpleHost.h:278
bool AreCbitsOnSameHost(size_t cbitId1, size_t cbitId2) const override
Check if two classical bits are in the same host.
Definition SimpleHost.h:163
SimpleHost(size_t hostId, size_t startQubitId, size_t numQubits, size_t startClassicalBitId, size_t numClassicalBits)
The constructor.
Definition SimpleHost.h:60
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:220
std::vector< size_t > GetNetworkEntangledQubitsIds() const override
Get the ids of the qubits used for entanglement between hosts in the host.
Definition SimpleHost.h:191
size_t GetStartQubitId() const override
Get the id of the first qubit assigned to the host.
Definition SimpleHost.h:268
bool IsQubitOnHost(size_t qubitId) const override
Check if a qubit is in the host.
Definition SimpleHost.h:116
bool IsClassicalBitOnHost(size_t cbitId) const override
Check if a classical bit is in the host.
Definition SimpleHost.h:137
std::vector< size_t > GetQubitsIds() const override
Get the ids of the qubits in the host.
Definition SimpleHost.h:174
void SetEntangledQubitId(size_t id)
Set the id of the qubit used for entanglement between hosts.
Definition SimpleHost.h:289
size_t GetNumQubits() const override
Get the number of qubits.
Definition SimpleHost.h:83
std::vector< size_t > GetClassicalBitsIds() const override
Get the ids of the classical bits in the host.
Definition SimpleHost.h:203