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