13 #ifndef XACC_XACC_HPP_ 14 #define XACC_XACC_HPP_ 16 #include "Compiler.hpp" 17 #include "RemoteAccelerator.hpp" 18 #include "IRProvider.hpp" 20 #include "Algorithm.hpp" 21 #include "Optimizer.hpp" 22 #include "IRTransformation.hpp" 24 #include "heterogeneous.hpp" 27 #include <sys/types.h> 34 static constexpr
double pi = 3.141592653589793238;
37 extern bool xaccFrameworkInitialized;
42 extern std::shared_ptr<CLIParser> xaccCLParser;
47 extern std::string rootPathString;
49 extern std::map<std::string, std::shared_ptr<CompositeInstruction>>
51 extern std::map<std::string, std::shared_ptr<AcceleratorBuffer>>
58 using AcceleratorBufferPtr = std::shared_ptr<xacc::AcceleratorBuffer>;
59 class qbit :
public AcceleratorBufferPtr {
61 qbit() : AcceleratorBufferPtr(std::make_shared<xacc::AcceleratorBuffer>()) {}
63 : AcceleratorBufferPtr(std::make_shared<xacc::AcceleratorBuffer>(n)) {}
64 qbit(
const AcceleratorBufferPtr &ab) : AcceleratorBufferPtr(ab) {}
66 int operator[](
const int &i) {
return 0; }
67 ExtraInfo operator[](
const std::string &key) {
68 return AcceleratorBufferPtr::get()->getInformation(key);
70 qbit &operator=(
qbit &q) {
return q; }
72 qbit qalloc(
const int n);
75 void Initialize(
int argc,
char **argv);
77 void Initialize(std::vector<std::string> argv);
80 void PyInitialize(
const std::string rootPath);
84 void set_verbose(
bool verbose);
86 const std::string getRootDirectory();
87 std::vector<std::string> getIncludePaths();
91 void addCommandLineOption(
const std::string &optionName,
92 const std::string &optionDescription =
"");
93 void addCommandLineOptions(
const std::string &category,
94 const std::map<std::string, std::string> &options);
95 void addCommandLineOptions(
const std::map<std::string, std::string> &options);
97 void setGlobalLoggerPredicate(MessagePredicate predicate);
98 void logToFile(
bool enable);
99 void setLoggingLevel(
int level);
100 int getLoggingLevel();
101 void subscribeLoggingLevel(LoggingLevelNotification callback);
103 void info(
const std::string &msg,
104 MessagePredicate predicate = std::function<
bool(
void)>([]() {
107 void warning(
const std::string &msg,
108 MessagePredicate predicate = std::function<
bool(
void)>([]() {
111 void debug(
const std::string &msg,
112 MessagePredicate predicate = std::function<
bool(
void)>([]() {
115 void error(
const std::string &msg,
116 MessagePredicate predicate = std::function<
bool(
void)>([]() {
121 bool optionExists(
const std::string &optionKey);
122 const std::string getOption(
const std::string &optionKey);
123 void setOption(
const std::string &optionKey,
const std::string &value);
124 void unsetOption(
const std::string &optionKey);
126 std::shared_ptr<IRProvider> getIRProvider(
const std::string &name);
128 void storeBuffer(std::shared_ptr<AcceleratorBuffer> buffer);
129 void storeBuffer(
const std::string name,
130 std::shared_ptr<AcceleratorBuffer> buffer);
131 std::shared_ptr<AcceleratorBuffer> getBuffer(
const std::string &name);
132 bool hasBuffer(
const std::string &name);
134 void setAccelerator(
const std::string &acceleratorName);
135 std::shared_ptr<Accelerator>
136 getAccelerator(
const std::string &name,
const HeterogeneousMap ¶ms = {});
137 std::shared_ptr<Accelerator>
138 getAccelerator(
const std::string &name, std::shared_ptr<Client> client,
140 std::shared_ptr<Accelerator> getAccelerator();
141 std::shared_ptr<Accelerator>
142 getAcceleratorDecorator(
const std::string &decorator,
143 std::shared_ptr<Accelerator> acc,
146 bool hasAccelerator(
const std::string &name);
148 void setCompiler(
const std::string &compilerName);
149 std::shared_ptr<Compiler> getCompiler(
const std::string &name);
150 std::shared_ptr<Compiler> getCompiler();
151 bool hasCompiler(
const std::string &name);
153 std::shared_ptr<Algorithm> getAlgorithm(
const std::string name,
155 std::shared_ptr<Algorithm> getAlgorithm(
const std::string name,
157 std::shared_ptr<Algorithm> getAlgorithm(
const std::string name);
159 std::shared_ptr<Optimizer> getOptimizer(
const std::string name);
160 std::shared_ptr<Optimizer> getOptimizer(
const std::string name,
162 std::shared_ptr<Optimizer> getOptimizer(
const std::string name,
165 bool hasCache(
const std::string fileName,
const std::string subdirectory =
"");
168 const std::string subdirectory =
"");
170 const std::string subdirectory =
"");
171 template <
typename T>
172 void appendCache(
const std::string fileName,
const std::string key, T &¶m,
173 const std::string subdirectory =
"") {
174 auto rootPathStr = xacc::getRootDirectory();
175 if (!subdirectory.empty()) {
176 rootPathStr +=
"/" + subdirectory;
177 if (!xacc::directoryExists(rootPathStr)) {
179 mkdir(rootPathStr.c_str(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
183 if (xacc::fileExists(rootPathStr +
"/" + fileName)) {
184 auto existingCache = getCache(fileName, subdirectory);
185 existingCache.insert(key, param);
187 appendCache(fileName, existingCache, subdirectory);
189 std::ofstream out(rootPathStr +
"/" + fileName);
195 std::map<std::string, ExtraInfo> einfo;
199 b.addExtraInfo(key, einfo[key]);
208 template <
typename T>
209 void appendCache(
const std::string fileName,
const std::string key, T ¶m,
210 const std::string subdirectory =
"") {
211 auto rootPathStr = xacc::getRootDirectory();
212 if (!subdirectory.empty()) {
213 rootPathStr +=
"/" + subdirectory;
214 if (!xacc::directoryExists(rootPathStr)) {
216 mkdir(rootPathStr.c_str(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
220 if (xacc::fileExists(rootPathStr +
"/" + fileName)) {
221 auto existingCache = getCache(fileName, subdirectory);
222 existingCache.insert(key, param);
224 appendCache(fileName, existingCache, subdirectory);
226 std::ofstream out(rootPathStr +
"/" + fileName);
232 std::map<std::string, ExtraInfo> einfo;
236 b.addExtraInfo(key, einfo[key]);
245 std::shared_ptr<IRTransformation> getIRTransformation(
const std::string &name);
249 const std::string toLanguage);
251 void appendCompiled(std::shared_ptr<CompositeInstruction> composite,
252 bool _override =
true);
253 std::shared_ptr<CompositeInstruction> getCompiled(
const std::string name);
254 bool hasCompiled(
const std::string name);
256 void qasm(
const std::string &qasmString);
260 virtual bool load() = 0;
261 virtual bool unload() = 0;
263 void load_external_language_plugins();
264 void unload_external_language_plugins();
268 std::shared_ptr<CompositeInstruction>
269 asComposite(std::shared_ptr<Instruction> inst);
270 std::shared_ptr<Instruction>
271 asInstruction(std::shared_ptr<CompositeInstruction> comp);
Definition: Accelerator.hpp:25
Definition: heterogeneous.hpp:45
Definition: Identifiable.hpp:25
Definition: heterogeneous.hpp:240
Definition: CompositeInstruction.hpp:72
Definition: AcceleratorBuffer.hpp:117
virtual void print()
Definition: AcceleratorBuffer.cpp:432