Maestro 0.1.0
Unified interface for quantum circuit simulation
Loading...
Searching...
No Matches
Scheduler.h
Go to the documentation of this file.
1
12#pragma once
13
14#ifndef _SCHEDULER_INTERFACE_H_
15#define _SCHEDULER_INTERFACE_H_
16
17#include "../Network/Network.h"
18#include "../Utils/ThreadsPool.h"
19
20namespace Schedulers {
21
33template <typename Time = Types::time_type>
36
37 CircuitInfo() = default;
38
40 size_t shots, size_t id, size_t gatesDepth, Time timeDepth,
41 size_t qubits)
43 id(id),
46 qubits(qubits) {}
47
48 bool operator==(const CircuitInfo<Time> &other) const {
49 if (ExecuteCircuit<Time>::operator==(other)) {
50 return id == other.id && gatesDepth == other.gatesDepth &&
51 timeDepth == other.timeDepth && qubits == other.qubits &&
52 hostId == other.hostId;
53 }
54
55 return false;
56 }
57
58 size_t id = 0;
59 size_t gatesDepth = 0;
60 Time timeDepth = 0;
61 size_t qubits = 0;
63
64 // those are redundant, but I set them anyway for convenience and easier usage
65 // in python
66 size_t hostId = 0;
67 size_t startQubits = 0;
68};
69
83template <typename Time = Types::time_type>
84struct ExecuteJob {
86 using ExecuteResults = typename NetworkClass::ExecuteResults;
87
88 std::shared_ptr<NetworkClass> hostNetwork;
89 size_t h = 0;
90 std::shared_ptr<Circuits::Circuit<Time>> circ;
91 size_t nrShots = 0;
93
94 void DoWork() {
95 if (!hostNetwork || !circ || nrShots == 0) return;
96
97 results = hostNetwork->RepeatedExecuteOnHost(circ, h, nrShots);
98 }
99
100 size_t GetJobCount() const { return 1; }
101};
102
113template <typename Time = Types::time_type>
114class IScheduler : public std::enable_shared_from_this<IScheduler<Time>> {
115 public:
117 using ExecuteResults = typename NetworkClass::ExecuteResults;
118
119 virtual ~IScheduler() = default;
120
121 virtual void SetNetwork(const std::shared_ptr<NetworkClass> &n) {
122 network = n;
123 }
124
125 std::shared_ptr<NetworkClass> GetNetwork() const { return network; }
126
144 virtual std::vector<ExecuteResults> ExecuteScheduled(
145 const std::vector<ExecuteCircuit<Time>> &circuits) = 0;
146
147 virtual std::shared_ptr<Circuits::Circuit<Time>> GetScheduledCircuit()
148 const = 0;
149
150 virtual std::vector<ExecuteResults> ExecuteScheduledSteps() = 0;
151
152 virtual const std::vector<std::vector<CircuitInfo<Time>>> &GetScheduledSteps()
153 const = 0;
154
155 virtual void SetScheduledSteps(
156 const std::vector<std::vector<CircuitInfo<Time>>> &steps) = 0;
157
158 virtual bool SetCurrentStep(size_t step) = 0;
159
160 virtual std::shared_ptr<Circuits::Circuit<Time>> GetScheduledCircuitForHost(
161 size_t hostId) const = 0;
162
163 virtual size_t GetCurrentShots() const = 0;
164
165 virtual void ExecuteCurrentStep() = 0;
166
167 virtual void SetDepthEstimationMethod(bool useSteps = true) = 0;
168
169 virtual bool GetDepthEstimationMethod() const = 0;
170
171 virtual void SetUseCost(bool useCost = true) = 0;
172
173 virtual bool GetUseCost() const = 0;
174
175 virtual void SetAddResetsAtEnd(bool addResets = true) = 0;
176
177 virtual bool GetAddResetsAtEnd() const = 0;
178
179 virtual void SetAddResetsAtStart(bool addResets = true) = 0;
180
181 virtual bool GetAddResetsAtStart() const = 0;
182
183 virtual std::vector<ExecuteResults> GetResults() const = 0;
184
185 virtual void CollectResults(const ExecuteResults &res, size_t nrShots) = 0;
186
187 virtual void CollectResultsForHost(const ExecuteResults &res, size_t hostId,
188 size_t nrShots) = 0;
189
190 virtual Network::SchedulerType GetType() const = 0;
191
192 private:
193 std::shared_ptr<NetworkClass>
194 network;
195};
196} // namespace Schedulers
197
198#endif
Circuit class for holding the sequence of operations.
Definition Circuit.h:45
std::unordered_map< Types::qubit_t, Types::qubit_t > BitMapping
The (qu)bit mapping for remapping.
Definition Circuit.h:54
The network interface.
Definition Network.h:56
The scheduler interface.
Definition Scheduler.h:114
virtual const std::vector< std::vector< CircuitInfo< Time > > > & GetScheduledSteps() const =0
virtual void ExecuteCurrentStep()=0
virtual bool GetDepthEstimationMethod() const =0
virtual bool SetCurrentStep(size_t step)=0
virtual void SetUseCost(bool useCost=true)=0
virtual std::vector< ExecuteResults > ExecuteScheduled(const std::vector< ExecuteCircuit< Time > > &circuits)=0
Schedule and execute circuits on the network.
virtual bool GetAddResetsAtEnd() const =0
virtual void CollectResults(const ExecuteResults &res, size_t nrShots)=0
virtual void SetAddResetsAtStart(bool addResets=true)=0
virtual std::vector< ExecuteResults > ExecuteScheduledSteps()=0
virtual std::vector< ExecuteResults > GetResults() const =0
virtual void SetDepthEstimationMethod(bool useSteps=true)=0
virtual void CollectResultsForHost(const ExecuteResults &res, size_t hostId, size_t nrShots)=0
typename Network::INetwork< Time > NetworkClass
Definition Scheduler.h:116
virtual size_t GetCurrentShots() const =0
virtual Network::SchedulerType GetType() const =0
virtual void SetNetwork(const std::shared_ptr< NetworkClass > &n)
Definition Scheduler.h:121
typename NetworkClass::ExecuteResults ExecuteResults
Definition Scheduler.h:117
std::shared_ptr< NetworkClass > GetNetwork() const
Definition Scheduler.h:125
virtual std::shared_ptr< Circuits::Circuit< Time > > GetScheduledCircuit() const =0
virtual bool GetUseCost() const =0
virtual std::shared_ptr< Circuits::Circuit< Time > > GetScheduledCircuitForHost(size_t hostId) const =0
virtual void SetScheduledSteps(const std::vector< std::vector< CircuitInfo< Time > > > &steps)=0
virtual ~IScheduler()=default
virtual bool GetAddResetsAtStart() const =0
virtual void SetAddResetsAtEnd(bool addResets=true)=0
SchedulerType
The type of the network scheduler for scheduling execution of multiple circuits.
Definition Controller.h:85
CircuitInfo(const std::shared_ptr< Circuits::Circuit< Time > > &circuit, size_t shots, size_t id, size_t gatesDepth, Time timeDepth, size_t qubits)
Definition Scheduler.h:39
typename Circuits::Circuit< Time >::BitMapping BitMapping
Definition Scheduler.h:35
bool operator==(const CircuitInfo< Time > &other) const
Definition Scheduler.h:48
A way to pack together a circuit and the number of shots for its execution.
Definition Controller.h:60
std::shared_ptr< Circuits::Circuit< Time > > circuit
Definition Controller.h:73
A struct representing a job to be executed on a host.
Definition Scheduler.h:84
ExecuteResults results
Definition Scheduler.h:92
typename NetworkClass::ExecuteResults ExecuteResults
Definition Scheduler.h:86
typename Network::INetwork< Time > NetworkClass
Definition Scheduler.h:85
std::shared_ptr< NetworkClass > hostNetwork
Definition Scheduler.h:88
std::shared_ptr< Circuits::Circuit< Time > > circ
Definition Scheduler.h:90
size_t GetJobCount() const
Definition Scheduler.h:100