Maestro 0.1.0
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
43template <typename Time = Types::time_type>
44class SimpleHost : public IHost<Time> {
45public:
60 SimpleHost(size_t hostId, size_t startQubitId, size_t numQubits,
61 size_t startClassicalBitId, size_t numClassicalBits)
62 : id(hostId), startQubitId(startQubitId), numQubits(numQubits),
63 startClassicalBitId(startClassicalBitId),
64 numClassicalBits(numClassicalBits) {}
65
72 size_t GetId() const override { return id; }
73
81 size_t GetNumQubits() const override { return numQubits; }
82
91 size_t GetNumNetworkEntangledQubits() const override {
92 if (std::numeric_limits<size_t>::max() == entangledQubitId)
93 return 0;
94
95 return 1;
96 }
97
106 size_t GetNumClassicalBits() const override { return numClassicalBits; }
107
115 bool IsQubitOnHost(size_t qubitId) const override {
116 return qubitId >= startQubitId && qubitId < startQubitId + numQubits;
117 }
118
126 bool AreQubitsOnSameHost(size_t qubitId1, size_t qubitId2) const override {
127 return IsQubitOnHost(qubitId1) && IsQubitOnHost(qubitId2);
128 }
129
136 bool IsClassicalBitOnHost(size_t cbitId) const override {
137 return (cbitId >= startClassicalBitId &&
138 cbitId < startClassicalBitId + numClassicalBits) ||
139 cbitId == entangledQubitMeasurementBit;
140 }
141
150 bool IsEntangledQubitOnHost(size_t qubitId) const override {
152 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 {
193 return {};
194
195 return {entangledQubitId};
196 }
197
204 std::vector<size_t> GetClassicalBitsIds() const override {
205 std::vector<size_t> res(numClassicalBits);
206
207 std::iota(res.begin(), res.end(), startClassicalBitId);
208
209 return res;
210 }
211
221 std::vector<size_t> GetEntangledQubitMeasurementBitIds() const override {
222 if (std::numeric_limits<size_t>::max() == entangledQubitMeasurementBit)
223 return {};
224
225 return {entangledQubitMeasurementBit};
226 }
227
240 bool SendPacketToHost(size_t hostId,
241 const std::vector<uint8_t> &packet) override {
242 return false;
243 }
244
256 bool RecvPacketFromHost(size_t hostId,
257 const std::vector<uint8_t> &packet) override {
258 return false;
259 }
260
269 size_t GetStartQubitId() const override { return startQubitId; }
270
279 size_t GetStartClassicalBitId() const override { return startClassicalBitId; }
280
290 void SetEntangledQubitId(size_t id) { entangledQubitId = id; }
291
304 entangledQubitMeasurementBit = id;
305 }
306
307private:
308 size_t id;
309
310 size_t startQubitId =
311 0;
312 size_t numQubits = 0;
313
314 size_t startClassicalBitId =
315 0;
316 size_t numClassicalBits =
317 0;
318
319 size_t entangledQubitId =
320 std::numeric_limits<size_t>::max();
322 size_t entangledQubitMeasurementBit =
323 std::numeric_limits<size_t>::max();
326};
327
328} // namespace Network
329
330#endif // ! _SIMPLE_HOST_H_
The host interface.
Definition Host.h:51
size_t GetNumClassicalBits() const override
Get the number of classical bits.
Definition SimpleHost.h:106
bool AreQubitsOnSameHost(size_t qubitId1, size_t qubitId2) const override
Check if two qubits are in the same host.
Definition SimpleHost.h:126
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:303
size_t GetNumNetworkEntangledQubits() const override
Get the number of network entangled qubits.
Definition SimpleHost.h:91
bool SendPacketToHost(size_t hostId, const std::vector< uint8_t > &packet) override
Send a packet to a host.
Definition SimpleHost.h:240
bool IsEntangledQubitOnHost(size_t qubitId) const override
Check if a qubit used for entanglement between hosts is in the host.
Definition SimpleHost.h:150
bool RecvPacketFromHost(size_t hostId, const std::vector< uint8_t > &packet) override
Receive a packet from a host.
Definition SimpleHost.h:256
size_t GetStartClassicalBitId() const override
Get the id of the first classical bit assigned to the host.
Definition SimpleHost.h:279
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:221
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:269
bool IsQubitOnHost(size_t qubitId) const override
Check if a qubit is in the host.
Definition SimpleHost.h:115
bool IsClassicalBitOnHost(size_t cbitId) const override
Check if a classical bit is in the host.
Definition SimpleHost.h:136
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:290
size_t GetNumQubits() const override
Get the number of qubits.
Definition SimpleHost.h:81
std::vector< size_t > GetClassicalBitsIds() const override
Get the ids of the classical bits in the host.
Definition SimpleHost.h:204