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