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