Maestro 0.3.11
Unified interface for quantum circuit simulation
Loading...
Searching...
No Matches
MaestroLib.hpp
Go to the documentation of this file.
1#pragma once
2
3#include "../Utils/Library.h"
5#include <array>
6#include <complex>
7#include <limits>
8#include <memory>
9#include <string>
10#include <vector>
11
13{
14 public:
15 MaestroLibrary(const MaestroLibrary &) = delete;
17
20
21 MaestroLibrary() noexcept
22 {
23 }
24
26 {
27 }
28
29 bool Init(const char *libName) noexcept override
30 {
31 if (Utils::Library::Init(libName))
32 {
33 fGetMaestroObject = (void *(*)())GetFunction("GetMaestroObjectWithMute");
34 CheckFunction((void *)fGetMaestroObject, __LINE__);
35 if (fGetMaestroObject)
36 {
37 maestro = fGetMaestroObject();
38 if (maestro)
39 {
40 fCreateSimpleSimulator = (unsigned long int (*)(int))GetFunction("CreateSimpleSimulator");
41 CheckFunction((void *)fCreateSimpleSimulator, __LINE__);
42 fDestroySimpleSimulator = (void (*)(unsigned long int))GetFunction("DestroySimpleSimulator");
43 CheckFunction((void *)fDestroySimpleSimulator, __LINE__);
44
45 fRemoveAllOptimizationSimulatorsAndAdd =
46 (int (*)(unsigned long int simHandle, int simType, int simExecType))GetFunction("RemoveAllOptimizationSimulatorsAndAdd");
47 CheckFunction((void *)fRemoveAllOptimizationSimulatorsAndAdd, __LINE__);
48 fAddOptimizationSimulator = (int (*)(unsigned long int simHandle, int simType, int simExecType))GetFunction("AddOptimizationSimulator");
49 CheckFunction((void *)fAddOptimizationSimulator, __LINE__);
50
51 fSimpleExecute = (char *(*)(unsigned long int, const char *, const char *))GetFunction("SimpleExecute");
52 CheckFunction((void *)fSimpleExecute, __LINE__);
53
54 fSimpleEstimate = (char *(*)(unsigned long int, const char *, const char *, const char *))GetFunction("SimpleEstimate");
55 CheckFunction((void *)fSimpleEstimate, __LINE__);
56
57 fFreeResult = (void (*)(char *))GetFunction("FreeResult");
58 CheckFunction((void *)fFreeResult, __LINE__);
59
60 fCreateSimulator = (unsigned long int (*)(int, int))GetFunction("CreateSimulator");
61 CheckFunction((void *)fCreateSimulator, __LINE__);
62 fGetSimulator = (void *(*)(unsigned long int))GetFunction("GetSimulator");
63 CheckFunction((void *)fGetSimulator, __LINE__);
64 // Optional exports keep loading older libraries compatible.
65 fExpectationValues = reinterpret_cast<decltype(fExpectationValues)>(GetFunction("MaestroExpectationValues"));
66 fExpectationValuesComplex = reinterpret_cast<decltype(fExpectationValuesComplex)>(GetFunction("MaestroExpectationValuesComplex"));
67 fGetStateVector = reinterpret_cast<decltype(fGetStateVector)>(GetFunction("MaestroGetStateVector"));
68 fExpectationValueOperators = reinterpret_cast<decltype(fExpectationValueOperators)>(GetFunction("MaestroExpectationValueOperators"));
69 fMoveAtBeginningOfChain = reinterpret_cast<decltype(fMoveAtBeginningOfChain)>(GetFunction("MaestroMoveAtBeginningOfChain"));
70 fRunRequestJson = reinterpret_cast<decltype(fRunRequestJson)>(GetFunction("MaestroRunRequestJson"));
71 fValidateRequestJson = reinterpret_cast<decltype(fValidateRequestJson)>(GetFunction("MaestroValidateRequestJson"));
72 fDestroySimulator = (void (*)(unsigned long int))GetFunction("DestroySimulator");
73 CheckFunction((void *)fDestroySimulator, __LINE__);
74
75 fInitializeSimulator = (int (*)(void *))GetFunction("InitializeSimulator");
76 CheckFunction((void *)fInitializeSimulator, __LINE__);
77 fResetSimulator = (int (*)(void *))GetFunction("ResetSimulator");
78 CheckFunction((void *)fResetSimulator, __LINE__);
79 fConfigureSimulator = (int (*)(void *, const char *, const char *))GetFunction("ConfigureSimulator");
80 CheckFunction((void *)fConfigureSimulator, __LINE__);
81 fGetConfiguration = (char *(*)(void *, const char *))GetFunction("GetConfiguration");
82 CheckFunction((void *)fGetConfiguration, __LINE__);
83 fAllocateQubits = (unsigned long int (*)(void *, unsigned long int))GetFunction("AllocateQubits");
84 CheckFunction((void *)fAllocateQubits, __LINE__);
85 fGetNumberOfQubits = (unsigned long int (*)(void *))GetFunction("GetNumberOfQubits");
86 CheckFunction((void *)fGetNumberOfQubits, __LINE__);
87 fClearSimulator = (int (*)(void *))GetFunction("ClearSimulator");
88 CheckFunction((void *)fClearSimulator, __LINE__);
89 fMeasure = (unsigned long long int (*)(void *, const unsigned long int *, unsigned long int))GetFunction("Measure");
90 CheckFunction((void *)fMeasure, __LINE__);
91 fApplyReset = (int (*)(void *, const unsigned long int *, unsigned long int))GetFunction("ApplyReset");
92 CheckFunction((void *)fApplyReset, __LINE__);
93 fProbability = (double (*)(void *, unsigned long long int))GetFunction("Probability");
94 CheckFunction((void *)fProbability, __LINE__);
95 fFreeDoubleVector = (void (*)(double *))GetFunction("FreeDoubleVector");
96 CheckFunction((void *)fFreeDoubleVector, __LINE__);
97 fFreeULLIVector = (void (*)(unsigned long long int *))GetFunction("FreeULLIVector");
98 CheckFunction((void *)fFreeULLIVector, __LINE__);
99 fAmplitude = (double *(*)(void *, unsigned long long int))GetFunction("Amplitude");
100 CheckFunction((void *)fAmplitude, __LINE__);
101 fAllProbabilities = (double *(*)(void *))GetFunction("AllProbabilities");
102 CheckFunction((void *)fAllProbabilities, __LINE__);
103 fProbabilities = (double *(*)(void *, const unsigned long long int *, unsigned long int))GetFunction("Probabilities");
104 CheckFunction((void *)fProbabilities, __LINE__);
105 fSampleCounts =
106 (unsigned long long int *(*)(void *, const unsigned long long int *, unsigned long int, unsigned long int))GetFunction("SampleCounts");
107 CheckFunction((void *)fSampleCounts, __LINE__);
108 fGetSimulatorType = (int (*)(void *))GetFunction("GetSimulatorType");
109 CheckFunction((void *)fGetSimulatorType, __LINE__);
110 fGetSimulationType = (int (*)(void *))GetFunction("GetSimulationType");
111 CheckFunction((void *)fGetSimulationType, __LINE__);
112 // Optional exports preserve loading compatibility with older
113 // libraries.
114 fGetGateFusionMaxQubits = reinterpret_cast<decltype(fGetGateFusionMaxQubits)>(GetFunction("GetGateFusionMaxQubits"));
115 fIsGateFusionEnabled = reinterpret_cast<decltype(fIsGateFusionEnabled)>(GetFunction("IsGateFusionEnabled"));
116 fGetGateFusionStatistics = reinterpret_cast<decltype(fGetGateFusionStatistics)>(GetFunction("GetGateFusionStatistics"));
117 fApplyGenericOneQubitGate = reinterpret_cast<decltype(fApplyGenericOneQubitGate)>(GetFunction("ApplyGenericOneQubitGate"));
118 fApplyGenericTwoQubitGate = reinterpret_cast<decltype(fApplyGenericTwoQubitGate)>(GetFunction("ApplyGenericTwoQubitGate"));
119 fApplyGenericThreeQubitGate = reinterpret_cast<decltype(fApplyGenericThreeQubitGate)>(GetFunction("ApplyGenericThreeQubitGate"));
120 fFlushSimulator = (int (*)(void *))GetFunction("FlushSimulator");
121 CheckFunction((void *)fFlushSimulator, __LINE__);
122 fSaveStateToInternalDestructive = (int (*)(void *))GetFunction("SaveStateToInternalDestructive");
123 CheckFunction((void *)fSaveStateToInternalDestructive, __LINE__);
124 fRestoreInternalDestructiveSavedState = (int (*)(void *))GetFunction("RestoreInternalDestructiveSavedState");
125 CheckFunction((void *)fRestoreInternalDestructiveSavedState, __LINE__);
126 fSaveState = (int (*)(void *))GetFunction("SaveState");
127 CheckFunction((void *)fSaveState, __LINE__);
128 fRestoreState = (int (*)(void *))GetFunction("RestoreState");
129 CheckFunction((void *)fRestoreState, __LINE__);
130 fSetMultithreading = (int (*)(void *, int))GetFunction("SetMultithreading");
131 CheckFunction((void *)fSetMultithreading, __LINE__);
132 fGetMultithreading = (int (*)(void *))GetFunction("GetMultithreading");
133 CheckFunction((void *)fGetMultithreading, __LINE__);
134 fIsQcsim = (int (*)(void *))GetFunction("IsQcsim");
135 CheckFunction((void *)fIsQcsim, __LINE__);
136 fMeasureNoCollapse = (unsigned long long int (*)(void *))GetFunction("MeasureNoCollapse");
137 CheckFunction((void *)fMeasureNoCollapse, __LINE__);
138
139 fApplyX = (int (*)(void *, int))GetFunction("ApplyX");
140 CheckFunction((void *)fApplyX, __LINE__);
141 fApplyY = (int (*)(void *, int))GetFunction("ApplyY");
142 CheckFunction((void *)fApplyY, __LINE__);
143 fApplyZ = (int (*)(void *, int))GetFunction("ApplyZ");
144 CheckFunction((void *)fApplyZ, __LINE__);
145 fApplyH = (int (*)(void *, int))GetFunction("ApplyH");
146 CheckFunction((void *)fApplyH, __LINE__);
147 fApplyS = (int (*)(void *, int))GetFunction("ApplyS");
148 CheckFunction((void *)fApplyS, __LINE__);
149 fApplySDG = (int (*)(void *, int))GetFunction("ApplySDG");
150 CheckFunction((void *)fApplySDG, __LINE__);
151 fApplyT = (int (*)(void *, int))GetFunction("ApplyT");
152 CheckFunction((void *)fApplyT, __LINE__);
153 fApplyTDG = (int (*)(void *, int))GetFunction("ApplyTDG");
154 CheckFunction((void *)fApplyTDG, __LINE__);
155 fApplySX = (int (*)(void *, int))GetFunction("ApplySX");
156 CheckFunction((void *)fApplySX, __LINE__);
157 fApplySXDG = (int (*)(void *, int))GetFunction("ApplySXDG");
158 CheckFunction((void *)fApplySXDG, __LINE__);
159 fApplyK = (int (*)(void *, int))GetFunction("ApplyK");
160 CheckFunction((void *)fApplyK, __LINE__);
161 fApplyP = (int (*)(void *, int, double))GetFunction("ApplyP");
162 CheckFunction((void *)fApplyP, __LINE__);
163 fApplyRx = (int (*)(void *, int, double))GetFunction("ApplyRx");
164 CheckFunction((void *)fApplyRx, __LINE__);
165 fApplyRy = (int (*)(void *, int, double))GetFunction("ApplyRy");
166 CheckFunction((void *)fApplyRy, __LINE__);
167 fApplyRz = (int (*)(void *, int, double))GetFunction("ApplyRz");
168 CheckFunction((void *)fApplyRz, __LINE__);
169 fApplyU = (int (*)(void *, int, double, double, double, double))GetFunction("ApplyU");
170 CheckFunction((void *)fApplyU, __LINE__);
171 fApplyCX = (int (*)(void *, int, int))GetFunction("ApplyCX");
172 CheckFunction((void *)fApplyCX, __LINE__);
173 fApplyCY = (int (*)(void *, int, int))GetFunction("ApplyCY");
174 CheckFunction((void *)fApplyCY, __LINE__);
175 fApplyCZ = (int (*)(void *, int, int))GetFunction("ApplyCZ");
176 CheckFunction((void *)fApplyCZ, __LINE__);
177 fApplyCH = (int (*)(void *, int, int))GetFunction("ApplyCH");
178 CheckFunction((void *)fApplyCH, __LINE__);
179 fApplyCSX = (int (*)(void *, int, int))GetFunction("ApplyCSX");
180 CheckFunction((void *)fApplyCSX, __LINE__);
181 fApplyCSXDG = (int (*)(void *, int, int))GetFunction("ApplyCSXDG");
182 CheckFunction((void *)fApplyCSXDG, __LINE__);
183 fApplyCP = (int (*)(void *, int, int, double))GetFunction("ApplyCP");
184 CheckFunction((void *)fApplyCP, __LINE__);
185 fApplyCRx = (int (*)(void *, int, int, double))GetFunction("ApplyCRx");
186 CheckFunction((void *)fApplyCRx, __LINE__);
187 fApplyCRy = (int (*)(void *, int, int, double))GetFunction("ApplyCRy");
188 CheckFunction((void *)fApplyCRy, __LINE__);
189 fApplyCRz = (int (*)(void *, int, int, double))GetFunction("ApplyCRz");
190 CheckFunction((void *)fApplyCRz, __LINE__);
191 fApplyCCX = (int (*)(void *, int, int, int))GetFunction("ApplyCCX");
192 CheckFunction((void *)fApplyCCX, __LINE__);
193 fApplySwap = (int (*)(void *, int, int))GetFunction("ApplySwap");
194 CheckFunction((void *)fApplySwap, __LINE__);
195 fApplyCSwap = (int (*)(void *, int, int, int))GetFunction("ApplyCSwap");
196 CheckFunction((void *)fApplyCSwap, __LINE__);
197 fApplyCU = (int (*)(void *, int, int, double, double, double, double))GetFunction("ApplyCU");
198 CheckFunction((void *)fApplyCU, __LINE__);
199
200 return true;
201 }
202 }
203 else
204 std::cerr << "MaestroLibrary: Unable to get initialization function "
205 "for library"
206 << std::endl;
207 }
208 else
209 std::cerr << "MaestroLibrary: Unable to load the library" << std::endl;
210
211 return false;
212 }
213
214 static void CheckFunction(void *func, int line) noexcept
215 {
216 if (!func)
217 {
218 std::cerr << "MaestroLibrary: Unable to load function, line #: " << line;
219
220#ifdef __linux__
221 const char *dlsym_error = dlerror();
222 if (dlsym_error)
223 std::cerr << ", error: " << dlsym_error;
224#elif defined(_WIN32)
225 const DWORD error = GetLastError();
226 std::cerr << ", error code: " << error;
227#endif
228
229 std::cerr << std::endl;
230 }
231 }
232
233 bool IsValid() const
234 {
235 return maestro != nullptr;
236 }
237
238 virtual unsigned long int CreateSimpleSimulator(int nrQubits)
239 {
240 if (maestro && fCreateSimpleSimulator)
241 return fCreateSimpleSimulator(nrQubits);
242 else
243 throw std::runtime_error("MaestroLibrary: Unable to create the simple simulator.");
244
245 return 0;
246 }
247
248 void DestroySimpleSimulator(unsigned long int simHandle)
249 {
250 if (maestro && fDestroySimpleSimulator)
251 fDestroySimpleSimulator(simHandle);
252 else
253 throw std::runtime_error("MaestroLibrary: Unable to destroy the simple simulator.");
254 }
255
256 int RemoveAllOptimizationSimulatorsAndAdd(unsigned long int simHandle, int simType, int simExecType)
257 {
258 if (maestro && fRemoveAllOptimizationSimulatorsAndAdd)
259 return fRemoveAllOptimizationSimulatorsAndAdd(simHandle, simType, simExecType);
260 else
261 throw std::runtime_error("MaestroLibrary: Unable to remove all optimization simulators and "
262 "add a new one.");
263
264 return 0;
265 }
266
267 int AddOptimizationSimulator(unsigned long int simHandle, int simType, int simExecType)
268 {
269 if (maestro && fAddOptimizationSimulator)
270 return fAddOptimizationSimulator(simHandle, simType, simExecType);
271 else
272 throw std::runtime_error("MaestroLibrary: Unable to add an optimization simulator.");
273
274 return 0;
275 }
276
277 char *SimpleExecute(unsigned long int simpleSim, const char *jsonCircuit, const char *jsonConfig)
278 {
279 if (maestro && fSimpleExecute)
280 return fSimpleExecute(simpleSim, jsonCircuit, jsonConfig);
281 else
282 throw std::runtime_error("MaestroLibrary: Unable to execute the simple simulator.");
283
284 return nullptr;
285 }
286
287 char *SimpleEstimate(unsigned long int simpleSim, const char *jsonCircuit, const char *observableStr, const char *jsonConfig)
288 {
289 if (maestro && fSimpleEstimate)
290 return fSimpleEstimate(simpleSim, jsonCircuit, observableStr, jsonConfig);
291 else
292 throw std::runtime_error("MaestroLibrary: Unable to execute the simple simulator for "
293 "expectation values.");
294
295 return nullptr;
296 }
297
298 virtual void FreeResult(char *result)
299 {
300 if (maestro && fFreeResult)
301 fFreeResult(result);
302 else
303 throw std::runtime_error("MaestroLibrary: Unable to free the result.");
304 }
305
306 virtual unsigned long int CreateSimulator(int simType, int simExecType)
307 {
308 if (maestro && fCreateSimulator)
309 return fCreateSimulator(simType, simExecType);
310 else
311 throw std::runtime_error("MaestroLibrary: Unable to create the simulator.");
312
313 return 0;
314 }
315
316 void *GetSimulator(unsigned long int simHandle)
317 {
318 if (maestro && fGetSimulator)
319 return fGetSimulator(simHandle);
320 else
321 throw std::runtime_error("MaestroLibrary: Unable to get the simulator.");
322 }
323
324 void DestroySimulator(unsigned long int simHandle)
325 {
326 if (maestro && fDestroySimulator)
327 fDestroySimulator(simHandle);
328 else
329 throw std::runtime_error("MaestroLibrary: Unable to destroy the simulator.");
330 }
331
332 int InitializeSimulator(void *sim)
333 {
334 if (maestro && sim && fInitializeSimulator)
335 return fInitializeSimulator(sim);
336 else
337 throw std::runtime_error("MaestroLibrary: Unable to initialize the simulator.");
338
339 return 0;
340 }
341
342 int ResetSimulator(void *sim)
343 {
344 if (maestro && sim && fResetSimulator)
345 return fResetSimulator(sim);
346 else
347 throw std::runtime_error("MaestroLibrary: Unable to reset the simulator.");
348
349 return 0;
350 }
351
352 int ConfigureSimulator(void *sim, const char *key, const char *value)
353 {
354 if (maestro && sim && fConfigureSimulator)
355 return fConfigureSimulator(sim, key, value);
356 else
357 throw std::runtime_error("MaestroLibrary: Unable to configure the simulator.");
358
359 return 0;
360 }
361
362 char *GetConfiguration(void *sim, const char *key)
363 {
364 if (maestro && sim && fGetConfiguration)
365 return fGetConfiguration(sim, key);
366 else
367 throw std::runtime_error("MaestroLibrary: Unable to get the configuration of the simulator.");
368 return nullptr;
369 }
370
371 unsigned long int AllocateQubits(void *sim, unsigned long int nrQubits)
372 {
373 if (maestro && sim && fAllocateQubits)
374 return fAllocateQubits(sim, nrQubits);
375 else
376 throw std::runtime_error("MaestroLibrary: Unable to allocate qubits in the simulator.");
377 return 0;
378 }
379
380 unsigned long int GetNumberOfQubits(void *sim)
381 {
382 if (maestro && sim && fGetNumberOfQubits)
383 return fGetNumberOfQubits(sim);
384 else
385 throw std::runtime_error("MaestroLibrary: Unable to get the number of qubits in the "
386 "simulator.");
387 return 0;
388 }
389
390 int ClearSimulator(void *sim)
391 {
392 if (maestro && sim && fClearSimulator)
393 return fClearSimulator(sim);
394 else
395 throw std::runtime_error("MaestroLibrary: Unable to clear the simulator.");
396 return 0;
397 }
398
399 unsigned long long int Measure(void *sim, const unsigned long int *qubits, unsigned long int nrQubits)
400 {
401 if (maestro && sim && fMeasure)
402 return fMeasure(sim, qubits, nrQubits);
403 else
404 throw std::runtime_error("MaestroLibrary: Unable to measure the simulator.");
405 return 0;
406 }
407
408 int ApplyReset(void *sim, const unsigned long int *qubits, unsigned long int nrQubits)
409 {
410 if (maestro && sim && fApplyReset)
411 return fApplyReset(sim, qubits, nrQubits);
412 else
413 throw std::runtime_error("MaestroLibrary: Unable to apply reset to the simulator.");
414 return 0;
415 }
416
417 double Probability(void *sim, unsigned long long int outcome)
418 {
419 if (maestro && sim && fProbability)
420 return fProbability(sim, outcome);
421 else
422 throw std::runtime_error("MaestroLibrary: Unable to get the probability of an outcome.");
423 return 0.0;
424 }
425
426 virtual void FreeDoubleVector(double *vec)
427 {
428 if (maestro && fFreeDoubleVector)
429 fFreeDoubleVector(vec);
430 else
431 throw std::runtime_error("MaestroLibrary: Unable to free the double vector.");
432 }
433
434 virtual void FreeULLIVector(unsigned long long int *vec)
435 {
436 if (maestro && fFreeULLIVector)
437 fFreeULLIVector(vec);
438 else
439 throw std::runtime_error("MaestroLibrary: Unable to free the unsigned long long int vector.");
440 }
441
442 double *Amplitude(void *sim, unsigned long long int outcome)
443 {
444 if (maestro && sim && fAmplitude)
445 return fAmplitude(sim, outcome);
446 else
447 throw std::runtime_error("MaestroLibrary: Unable to get the amplitude of an outcome.");
448 return nullptr;
449 }
450
451 double *AllProbabilities(void *sim)
452 {
453 if (maestro && sim && fAllProbabilities)
454 return fAllProbabilities(sim);
455 else
456 throw std::runtime_error("MaestroLibrary: Unable to get all probabilities.");
457 return nullptr;
458 }
459
460 double *Probabilities(void *sim, const unsigned long long int *qubits, unsigned long int nrQubits)
461 {
462 if (maestro && sim && fProbabilities)
463 return fProbabilities(sim, qubits, nrQubits);
464 else
465 throw std::runtime_error("MaestroLibrary: Unable to get probabilities for specified qubits.");
466 return nullptr;
467 }
468
469 unsigned long long int *SampleCounts(void *sim, const unsigned long long int *qubits, unsigned long int nrQubits, unsigned long int shots)
470 {
471 if (maestro && sim && fSampleCounts)
472 return fSampleCounts(sim, qubits, nrQubits, shots);
473 else
474 throw std::runtime_error("MaestroLibrary: Unable to get sample counts for specified qubits.");
475 return nullptr;
476 }
477
478 int GetSimulatorType(void *sim)
479 {
480 if (maestro && sim && fGetSimulatorType)
481 return fGetSimulatorType(sim);
482 else
483 throw std::runtime_error("MaestroLibrary: Unable to get the simulator type.");
484 return -1;
485 }
486
487 int GetSimulationType(void *sim)
488 {
489 if (maestro && sim && fGetSimulationType)
490 return fGetSimulationType(sim);
491 else
492 throw std::runtime_error("MaestroLibrary: Unable to get the simulation type.");
493 return -1;
494 }
495
496 unsigned GetGateFusionMaxQubits(void *sim)
497 {
498 return maestro && sim && fGetGateFusionMaxQubits ? fGetGateFusionMaxQubits(sim) : 0;
499 }
500
501 int IsGateFusionEnabled(void *sim)
502 {
503 return maestro && sim && fIsGateFusionEnabled ? fIsGateFusionEnabled(sim) : 0;
504 }
505
507 {
508 return maestro && sim && fGetGateFusionStatistics ? fGetGateFusionStatistics(sim, statistics) : 0;
509 }
510
511 int ApplyGenericOneQubitGate(void *sim, unsigned long q0, const double *matrix)
512 {
513 return maestro && sim && fApplyGenericOneQubitGate ? fApplyGenericOneQubitGate(sim, q0, matrix) : 0;
514 }
515
516 int ApplyGenericTwoQubitGate(void *sim, unsigned long q0, unsigned long q1, const double *matrix)
517 {
518 return maestro && sim && fApplyGenericTwoQubitGate ? fApplyGenericTwoQubitGate(sim, q0, q1, matrix) : 0;
519 }
520
521 int ApplyGenericThreeQubitGate(void *sim, unsigned long q0, unsigned long q1, unsigned long q2, const double *matrix)
522 {
523 return maestro && sim && fApplyGenericThreeQubitGate ? fApplyGenericThreeQubitGate(sim, q0, q1, q2, matrix) : 0;
524 }
525
526 int FlushSimulator(void *sim)
527 {
528 if (maestro && sim && fFlushSimulator)
529 return fFlushSimulator(sim);
530 else
531 throw std::runtime_error("MaestroLibrary: Unable to flush the simulator.");
532 return 0;
533 }
534
536 {
537 if (maestro && sim && fSaveStateToInternalDestructive)
538 return fSaveStateToInternalDestructive(sim);
539 else
540 throw std::runtime_error("MaestroLibrary: Unable to save the state to internal destructive "
541 "storage.");
542 return 0;
543 }
544
546 {
547 if (maestro && sim && fRestoreInternalDestructiveSavedState)
548 return fRestoreInternalDestructiveSavedState(sim);
549 else
550 throw std::runtime_error("MaestroLibrary: Unable to restore the state from internal "
551 "destructive storage.");
552 return 0;
553 }
554
555 int SaveState(void *sim)
556 {
557 if (maestro && sim && fSaveState)
558 return fSaveState(sim);
559 else
560 throw std::runtime_error("MaestroLibrary: Unable to save the state.");
561 return 0;
562 }
563
564 int RestoreState(void *sim)
565 {
566 if (maestro && sim && fRestoreState)
567 return fRestoreState(sim);
568 else
569 throw std::runtime_error("MaestroLibrary: Unable to restore the state.");
570 return 0;
571 }
572
573 int SetMultithreading(void *sim, int multithreading)
574 {
575 if (maestro && sim && fSetMultithreading)
576 return fSetMultithreading(sim, multithreading);
577 else
578 throw std::runtime_error("MaestroLibrary: Unable to set multithreading.");
579 return 0;
580 }
581
582 int GetMultithreading(void *sim)
583 {
584 if (maestro && sim && fGetMultithreading)
585 return fGetMultithreading(sim);
586 else
587 throw std::runtime_error("MaestroLibrary: Unable to get multithreading status.");
588 return 0;
589 }
590
591 int IsQcsim(void *sim)
592 {
593 if (maestro && sim && fIsQcsim)
594 return fIsQcsim(sim);
595 else
596 throw std::runtime_error("MaestroLibrary: Unable to check if the simulator is a QCSIM.");
597 return 0;
598 }
599
600 unsigned long long int MeasureNoCollapse(void *sim)
601 {
602 if (maestro && sim && fMeasureNoCollapse)
603 return fMeasureNoCollapse(sim);
604 else
605 throw std::runtime_error("MaestroLibrary: Unable to measure without collapse.");
606 return 0;
607 }
608
609 int ApplyX(void *sim, int qubit)
610 {
611 if (maestro && sim && fApplyX)
612 return fApplyX(sim, qubit);
613 else
614 throw std::runtime_error("MaestroLibrary: Unable to apply X gate.");
615 return 0;
616 }
617
618 int ApplyY(void *sim, int qubit)
619 {
620 if (maestro && sim && fApplyY)
621 return fApplyY(sim, qubit);
622 else
623 throw std::runtime_error("MaestroLibrary: Unable to apply Y gate.");
624 return 0;
625 }
626
627 int ApplyZ(void *sim, int qubit)
628 {
629 if (maestro && sim && fApplyZ)
630 return fApplyZ(sim, qubit);
631 else
632 throw std::runtime_error("MaestroLibrary: Unable to apply Z gate.");
633 return 0;
634 }
635
636 int ApplyH(void *sim, int qubit)
637 {
638 if (maestro && sim && fApplyH)
639 return fApplyH(sim, qubit);
640 else
641 throw std::runtime_error("MaestroLibrary: Unable to apply H gate.");
642 return 0;
643 }
644
645 int ApplyS(void *sim, int qubit)
646 {
647 if (maestro && sim && fApplyS)
648 return fApplyS(sim, qubit);
649 else
650 throw std::runtime_error("MaestroLibrary: Unable to apply S gate.");
651 return 0;
652 }
653
654 int ApplySDG(void *sim, int qubit)
655 {
656 if (maestro && sim && fApplySDG)
657 return fApplySDG(sim, qubit);
658 else
659 throw std::runtime_error("MaestroLibrary: Unable to apply SDG gate.");
660 return 0;
661 }
662
663 int ApplyT(void *sim, int qubit)
664 {
665 if (maestro && sim && fApplyT)
666 return fApplyT(sim, qubit);
667 else
668 throw std::runtime_error("MaestroLibrary: Unable to apply T gate.");
669 return 0;
670 }
671
672 int ApplyTDG(void *sim, int qubit)
673 {
674 if (maestro && sim && fApplyTDG)
675 return fApplyTDG(sim, qubit);
676 else
677 throw std::runtime_error("MaestroLibrary: Unable to apply TDG gate.");
678 return 0;
679 }
680
681 int ApplySX(void *sim, int qubit)
682 {
683 if (maestro && sim && fApplySX)
684 return fApplySX(sim, qubit);
685 else
686 throw std::runtime_error("MaestroLibrary: Unable to apply SX gate.");
687 return 0;
688 }
689
690 int ApplySXDG(void *sim, int qubit)
691 {
692 if (maestro && sim && fApplySXDG)
693 return fApplySXDG(sim, qubit);
694 else
695 throw std::runtime_error("MaestroLibrary: Unable to apply SXDG gate.");
696 return 0;
697 }
698
699 int ApplyK(void *sim, int qubit)
700 {
701 if (maestro && sim && fApplyK)
702 return fApplyK(sim, qubit);
703 else
704 throw std::runtime_error("MaestroLibrary: Unable to apply K gate.");
705 return 0;
706 }
707
708 int ApplyP(void *sim, int qubit, double theta)
709 {
710 if (maestro && sim && fApplyP)
711 return fApplyP(sim, qubit, theta);
712 else
713 throw std::runtime_error("MaestroLibrary: Unable to apply P gate.");
714 return 0;
715 }
716
717 int ApplyRx(void *sim, int qubit, double theta)
718 {
719 if (maestro && sim && fApplyRx)
720 return fApplyRx(sim, qubit, theta);
721 else
722 throw std::runtime_error("MaestroLibrary: Unable to apply Rx gate.");
723 return 0;
724 }
725
726 int ApplyRy(void *sim, int qubit, double theta)
727 {
728 if (maestro && sim && fApplyRy)
729 return fApplyRy(sim, qubit, theta);
730 else
731 throw std::runtime_error("MaestroLibrary: Unable to apply Ry gate.");
732 return 0;
733 }
734
735 int ApplyRz(void *sim, int qubit, double theta)
736 {
737 if (maestro && sim && fApplyRz)
738 return fApplyRz(sim, qubit, theta);
739 else
740 throw std::runtime_error("MaestroLibrary: Unable to apply Rz gate.");
741 return 0;
742 }
743
744 int ApplyU(void *sim, int qubit, double theta, double phi, double lambda, double gamma)
745 {
746 if (maestro && sim && fApplyU)
747 return fApplyU(sim, qubit, theta, phi, lambda, gamma);
748 else
749 throw std::runtime_error("MaestroLibrary: Unable to apply U gate.");
750 return 0;
751 }
752
753 int ApplyCX(void *sim, int controlQubit, int targetQubit)
754 {
755 if (maestro && sim && fApplyCX)
756 return fApplyCX(sim, controlQubit, targetQubit);
757 else
758 throw std::runtime_error("MaestroLibrary: Unable to apply CX gate.");
759 return 0;
760 }
761
762 int ApplyCY(void *sim, int controlQubit, int targetQubit)
763 {
764 if (maestro && sim && fApplyCY)
765 return fApplyCY(sim, controlQubit, targetQubit);
766 else
767 throw std::runtime_error("MaestroLibrary: Unable to apply CY gate.");
768 return 0;
769 }
770
771 int ApplyCZ(void *sim, int controlQubit, int targetQubit)
772 {
773 if (maestro && sim && fApplyCZ)
774 return fApplyCZ(sim, controlQubit, targetQubit);
775 else
776 throw std::runtime_error("MaestroLibrary: Unable to apply CZ gate.");
777 return 0;
778 }
779
780 int ApplyCH(void *sim, int controlQubit, int targetQubit)
781 {
782 if (maestro && sim && fApplyCH)
783 return fApplyCH(sim, controlQubit, targetQubit);
784 else
785 throw std::runtime_error("MaestroLibrary: Unable to apply CH gate.");
786 return 0;
787 }
788
789 int ApplyCSX(void *sim, int controlQubit, int targetQubit)
790 {
791 if (maestro && sim && fApplyCSX)
792 return fApplyCSX(sim, controlQubit, targetQubit);
793 else
794 throw std::runtime_error("MaestroLibrary: Unable to apply CSX gate.");
795 return 0;
796 }
797
798 int ApplyCSXDG(void *sim, int controlQubit, int targetQubit)
799 {
800 if (maestro && sim && fApplyCSXDG)
801 return fApplyCSXDG(sim, controlQubit, targetQubit);
802 else
803 throw std::runtime_error("MaestroLibrary: Unable to apply CSXDG gate.");
804 return 0;
805 }
806
807 int ApplyCP(void *sim, int controlQubit, int targetQubit, double theta)
808 {
809 if (maestro && sim && fApplyCP)
810 return fApplyCP(sim, controlQubit, targetQubit, theta);
811 else
812 throw std::runtime_error("MaestroLibrary: Unable to apply CP gate.");
813 return 0;
814 }
815
816 int ApplyCRx(void *sim, int controlQubit, int targetQubit, double theta)
817 {
818 if (maestro && sim && fApplyCRx)
819 return fApplyCRx(sim, controlQubit, targetQubit, theta);
820 else
821 throw std::runtime_error("MaestroLibrary: Unable to apply CRx gate.");
822 return 0;
823 }
824
825 int ApplyCRy(void *sim, int controlQubit, int targetQubit, double theta)
826 {
827 if (maestro && sim && fApplyCRy)
828 return fApplyCRy(sim, controlQubit, targetQubit, theta);
829 else
830 throw std::runtime_error("MaestroLibrary: Unable to apply CRy gate.");
831 return 0;
832 }
833
834 int ApplyCRz(void *sim, int controlQubit, int targetQubit, double theta)
835 {
836 if (maestro && sim && fApplyCRz)
837 return fApplyCRz(sim, controlQubit, targetQubit, theta);
838 else
839 throw std::runtime_error("MaestroLibrary: Unable to apply CRz gate.");
840 return 0;
841 }
842
843 int ApplyCCX(void *sim, int controlQubit1, int controlQubit2, int targetQubit)
844 {
845 if (maestro && sim && fApplyCCX)
846 return fApplyCCX(sim, controlQubit1, controlQubit2, targetQubit);
847 else
848 throw std::runtime_error("MaestroLibrary: Unable to apply CCX gate.");
849 return 0;
850 }
851
852 int ApplySwap(void *sim, int qubit1, int qubit2)
853 {
854 if (maestro && sim && fApplySwap)
855 return fApplySwap(sim, qubit1, qubit2);
856 else
857 throw std::runtime_error("MaestroLibrary: Unable to apply Swap gate.");
858 return 0;
859 }
860
861 int ApplyCSwap(void *sim, int controlQubit, int qubit1, int qubit2)
862 {
863 if (maestro && sim && fApplyCSwap)
864 return fApplyCSwap(sim, controlQubit, qubit1, qubit2);
865 else
866 throw std::runtime_error("MaestroLibrary: Unable to apply CSwap gate.");
867 return 0;
868 }
869
870 int ApplyCU(void *sim, int controlQubit, int targetQubit, double theta, double phi, double lambda, double gamma)
871 {
872 if (maestro && sim && fApplyCU)
873 return fApplyCU(sim, controlQubit, targetQubit, theta, phi, lambda, gamma);
874 else
875 throw std::runtime_error("MaestroLibrary: Unable to apply CU gate.");
876 return 0;
877 }
878
879 std::vector<double> ExpectationValues(void *sim, const std::vector<std::string> &paulis)
880 {
881 if (!maestro || !sim || !fExpectationValues)
882 throw std::runtime_error("MaestroLibrary: Batch expectations unavailable.");
883 std::vector<const char *> strings;
884 strings.reserve(paulis.size());
885 for (const auto &pauli : paulis)
886 strings.push_back(pauli.c_str());
887 std::vector<double> values(paulis.size());
888 if (!fExpectationValues(sim, strings.data(), strings.size(), values.data(), values.size()))
889 throw std::runtime_error("MaestroLibrary: Batch expectations failed.");
890 return values;
891 }
892
893 std::vector<std::complex<double>> ExpectationValuesComplex(void *sim, const std::vector<std::string> &paulis, bool normalized = true)
894 {
895 if (!maestro || !sim || !fExpectationValuesComplex)
896 throw std::runtime_error("MaestroLibrary: Complex batch expectations unavailable.");
897 std::vector<const char *> strings;
898 strings.reserve(paulis.size());
899 for (const auto &pauli : paulis)
900 strings.push_back(pauli.c_str());
901 std::vector<double> real(paulis.size()), imag(paulis.size());
902 if (!fExpectationValuesComplex(sim, strings.data(), strings.size(), normalized ? 1 : 0, real.data(), imag.data(), real.size()))
903 throw std::runtime_error("MaestroLibrary: Complex batch expectations failed.");
904 std::vector<std::complex<double>> values;
905 values.reserve(paulis.size());
906 for (size_t i = 0; i < paulis.size(); ++i)
907 values.emplace_back(real[i], imag[i]);
908 return values;
909 }
910
911 // Versioned JSON requests return their complete response envelope.
912 std::string RunRequestJson(const std::string &request)
913 {
914 return RequestJson(request, fRunRequestJson);
915 }
916
917 std::string ValidateRequestJson(const std::string &request)
918 {
919 return RequestJson(request, fValidateRequestJson);
920 }
921
922 std::vector<std::complex<double>> GetStateVector(void *sim)
923 {
924 if (!maestro || !sim || !fGetStateVector)
925 throw std::runtime_error("MaestroLibrary: Statevector query unavailable.");
926 const auto n = GetNumberOfQubits(sim);
927 if (n >= std::numeric_limits<size_t>::digits)
928 throw std::length_error("Statevector exceeds the basis-index range");
929 const size_t count = n ? size_t{1} << n : 0;
930 if (count > std::vector<double>().max_size() / 2)
931 throw std::length_error("Statevector output is too large");
932 std::vector<std::complex<double>> result(count);
933 if (!fGetStateVector(sim, reinterpret_cast<double *>(result.data()), count))
934 throw std::runtime_error("MaestroLibrary: Statevector query failed.");
935 return result;
936 }
937
938 // Four entries per operator, in row-major order; repeated targets are
939 // allowed.
940 std::complex<double> ExpectationValueOperators(void *sim, const std::vector<unsigned long> &qubits,
941 const std::vector<std::array<std::complex<double>, 4>> &matrices)
942 {
943 if (!maestro || !sim || !fExpectationValueOperators)
944 throw std::runtime_error("MaestroLibrary: Operator expectation unavailable.");
945 if (qubits.size() != matrices.size())
946 throw std::invalid_argument("Each operator must have one target qubit");
947 if (matrices.size() > std::vector<double>().max_size() / 8)
948 throw std::length_error("Too many operators");
949 std::vector<double> raw;
950 raw.reserve(8 * matrices.size());
951 for (const auto &matrix : matrices)
952 for (const auto &entry : matrix)
953 {
954 raw.push_back(entry.real());
955 raw.push_back(entry.imag());
956 }
957 double re = 0., im = 0.;
958 if (!fExpectationValueOperators(sim, qubits.data(), qubits.size(), raw.data(), &re, &im))
959 throw std::runtime_error("MaestroLibrary: Operator expectation failed.");
960 return {re, im};
961 }
962
963 void MoveAtBeginningOfChain(void *sim, const std::vector<unsigned long> &qubits)
964 {
965 if (!maestro || !sim || !fMoveAtBeginningOfChain)
966 throw std::runtime_error("MaestroLibrary: Chain movement unavailable.");
967 if (!fMoveAtBeginningOfChain(sim, qubits.data(), qubits.size()))
968 throw std::runtime_error("MaestroLibrary: Chain movement failed.");
969 }
970
971 private:
972 std::string RequestJson(const std::string &request, char *(*call)(const char *))
973 {
974 if (!maestro || !call || !fFreeResult)
975 throw std::runtime_error("MaestroLibrary: JSON request API unavailable.");
976 auto release = [this](char *p) { FreeResult(p); };
977 std::unique_ptr<char, decltype(release)> result(call(request.c_str()), release);
978 if (!result)
979 throw std::runtime_error("MaestroLibrary: JSON request returned no response.");
980 return result.get();
981 }
982
983 char *(*fRunRequestJson)(const char *) = nullptr;
984 char *(*fValidateRequestJson)(const char *) = nullptr;
985 int (*fGetStateVector)(void *, double *, size_t) = nullptr;
986 int (*fExpectationValueOperators)(void *, const unsigned long *, size_t, const double *, double *, double *) = nullptr;
987 int (*fMoveAtBeginningOfChain)(void *, const unsigned long *, size_t) = nullptr;
988 int (*fExpectationValues)(void *, const char *const *, size_t, double *, size_t) = nullptr;
989 int (*fExpectationValuesComplex)(void *, const char *const *, size_t, int, double *, double *, size_t) = nullptr;
990 void *maestro = nullptr;
991
992 void *(*fGetMaestroObject)();
993
994 unsigned long int (*fCreateSimpleSimulator)(int);
995 void (*fDestroySimpleSimulator)(unsigned long int);
996
997 int (*fRemoveAllOptimizationSimulatorsAndAdd)(unsigned long int, int, int);
998 int (*fAddOptimizationSimulator)(unsigned long int, int, int);
999
1000 char *(*fSimpleExecute)(unsigned long int, const char *, const char *);
1001 char *(*fSimpleEstimate)(unsigned long int, const char *, const char *, const char *);
1002 void (*fFreeResult)(char *);
1003
1004 unsigned long int (*fCreateSimulator)(int, int);
1005 void *(*fGetSimulator)(unsigned long int);
1006 void (*fDestroySimulator)(unsigned long int);
1007
1008 int (*fInitializeSimulator)(void *);
1009 int (*fResetSimulator)(void *);
1010 int (*fConfigureSimulator)(void *, const char *, const char *);
1011 char *(*fGetConfiguration)(void *, const char *);
1012 unsigned long int (*fAllocateQubits)(void *, unsigned long int);
1013 unsigned long int (*fGetNumberOfQubits)(void *);
1014 int (*fClearSimulator)(void *);
1015 unsigned long long int (*fMeasure)(void *, const unsigned long int *, unsigned long int);
1016 int (*fApplyReset)(void *, const unsigned long int *, unsigned long int);
1017 double (*fProbability)(void *, unsigned long long int);
1018 void (*fFreeDoubleVector)(double *);
1019 void (*fFreeULLIVector)(unsigned long long int *);
1020 double *(*fAmplitude)(void *, unsigned long long int);
1021 double *(*fAllProbabilities)(void *);
1022 double *(*fProbabilities)(void *, const unsigned long long int *, unsigned long int);
1023 unsigned long long int *(*fSampleCounts)(void *, const unsigned long long int *, unsigned long int, unsigned long int);
1024 int (*fGetSimulatorType)(void *);
1025 int (*fGetSimulationType)(void *);
1026 unsigned (*fGetGateFusionMaxQubits)(void *) = nullptr;
1027 int (*fIsGateFusionEnabled)(void *) = nullptr;
1028 int (*fGetGateFusionStatistics)(void *, MaestroGateFusionStatistics *) = nullptr;
1029 int (*fApplyGenericOneQubitGate)(void *, unsigned long, const double *) = nullptr;
1030 int (*fApplyGenericTwoQubitGate)(void *, unsigned long, unsigned long, const double *) = nullptr;
1031 int (*fApplyGenericThreeQubitGate)(void *, unsigned long, unsigned long, unsigned long, const double *) = nullptr;
1032 int (*fFlushSimulator)(void *);
1033 int (*fSaveStateToInternalDestructive)(void *);
1034 int (*fRestoreInternalDestructiveSavedState)(void *);
1035 int (*fSaveState)(void *);
1036 int (*fRestoreState)(void *);
1037 int (*fSetMultithreading)(void *, int);
1038 int (*fGetMultithreading)(void *);
1039 int (*fIsQcsim)(void *);
1040 unsigned long long int (*fMeasureNoCollapse)(void *);
1041
1042 int (*fApplyX)(void *, int);
1043 int (*fApplyY)(void *, int);
1044 int (*fApplyZ)(void *, int);
1045 int (*fApplyH)(void *, int);
1046 int (*fApplyS)(void *, int);
1047 int (*fApplySDG)(void *, int);
1048 int (*fApplyT)(void *, int);
1049 int (*fApplyTDG)(void *, int);
1050 int (*fApplySX)(void *, int);
1051 int (*fApplySXDG)(void *, int);
1052 int (*fApplyK)(void *, int);
1053 int (*fApplyP)(void *, int, double);
1054 int (*fApplyRx)(void *, int, double);
1055 int (*fApplyRy)(void *, int, double);
1056 int (*fApplyRz)(void *, int, double);
1057 int (*fApplyU)(void *, int, double, double, double, double);
1058 int (*fApplyCX)(void *, int, int);
1059 int (*fApplyCY)(void *, int, int);
1060 int (*fApplyCZ)(void *, int, int);
1061 int (*fApplyCH)(void *, int, int);
1062 int (*fApplyCSX)(void *, int, int);
1063 int (*fApplyCSXDG)(void *, int, int);
1064 int (*fApplyCP)(void *, int, int, double);
1065 int (*fApplyCRx)(void *, int, int, double);
1066 int (*fApplyCRy)(void *, int, int, double);
1067 int (*fApplyCRz)(void *, int, int, double);
1068 int (*fApplyCCX)(void *, int, int, int);
1069 int (*fApplySwap)(void *, int, int);
1070 int (*fApplyCSwap)(void *, int, int, int);
1071 int (*fApplyCU)(void *, int, int, double, double, double, double);
1072};
struct MaestroGateFusionStatistics MaestroGateFusionStatistics
int ApplyCCX(void *sim, int controlQubit1, int controlQubit2, int targetQubit)
int ResetSimulator(void *sim)
void * GetSimulator(unsigned long int simHandle)
int ApplyGenericThreeQubitGate(void *sim, unsigned long q0, unsigned long q1, unsigned long q2, const double *matrix)
int IsGateFusionEnabled(void *sim)
int ApplyCZ(void *sim, int controlQubit, int targetQubit)
MaestroLibrary() noexcept
unsigned long int AllocateQubits(void *sim, unsigned long int nrQubits)
int ConfigureSimulator(void *sim, const char *key, const char *value)
MaestroLibrary & operator=(const MaestroLibrary &)=delete
int ApplyGenericTwoQubitGate(void *sim, unsigned long q0, unsigned long q1, const double *matrix)
unsigned long long int * SampleCounts(void *sim, const unsigned long long int *qubits, unsigned long int nrQubits, unsigned long int shots)
int ApplySXDG(void *sim, int qubit)
int ApplyS(void *sim, int qubit)
int GetSimulationType(void *sim)
std::string ValidateRequestJson(const std::string &request)
int GetSimulatorType(void *sim)
int ApplyH(void *sim, int qubit)
double * AllProbabilities(void *sim)
unsigned long long int Measure(void *sim, const unsigned long int *qubits, unsigned long int nrQubits)
int ApplySDG(void *sim, int qubit)
int RemoveAllOptimizationSimulatorsAndAdd(unsigned long int simHandle, int simType, int simExecType)
int ApplyT(void *sim, int qubit)
int ApplyY(void *sim, int qubit)
virtual ~MaestroLibrary()
static void CheckFunction(void *func, int line) noexcept
int ApplySX(void *sim, int qubit)
int SaveState(void *sim)
int ApplyX(void *sim, int qubit)
int ApplyCY(void *sim, int controlQubit, int targetQubit)
int ApplyCX(void *sim, int controlQubit, int targetQubit)
void DestroySimpleSimulator(unsigned long int simHandle)
int ApplyCRx(void *sim, int controlQubit, int targetQubit, double theta)
int ApplyGenericOneQubitGate(void *sim, unsigned long q0, const double *matrix)
int ClearSimulator(void *sim)
int ApplyCSX(void *sim, int controlQubit, int targetQubit)
bool IsValid() const
int ApplyK(void *sim, int qubit)
char * SimpleExecute(unsigned long int simpleSim, const char *jsonCircuit, const char *jsonConfig)
int RestoreState(void *sim)
std::complex< double > ExpectationValueOperators(void *sim, const std::vector< unsigned long > &qubits, const std::vector< std::array< std::complex< double >, 4 > > &matrices)
int ApplyCRz(void *sim, int controlQubit, int targetQubit, double theta)
unsigned GetGateFusionMaxQubits(void *sim)
double * Amplitude(void *sim, unsigned long long int outcome)
std::vector< std::complex< double > > ExpectationValuesComplex(void *sim, const std::vector< std::string > &paulis, bool normalized=true)
int AddOptimizationSimulator(unsigned long int simHandle, int simType, int simExecType)
virtual unsigned long int CreateSimpleSimulator(int nrQubits)
char * SimpleEstimate(unsigned long int simpleSim, const char *jsonCircuit, const char *observableStr, const char *jsonConfig)
double Probability(void *sim, unsigned long long int outcome)
int ApplyCH(void *sim, int controlQubit, int targetQubit)
int GetGateFusionStatistics(void *sim, MaestroGateFusionStatistics *statistics)
int ApplyCSwap(void *sim, int controlQubit, int qubit1, int qubit2)
virtual void FreeULLIVector(unsigned long long int *vec)
int IsQcsim(void *sim)
virtual unsigned long int CreateSimulator(int simType, int simExecType)
int ApplyCSXDG(void *sim, int controlQubit, int targetQubit)
int SaveStateToInternalDestructive(void *sim)
virtual void FreeDoubleVector(double *vec)
MaestroLibrary & operator=(MaestroLibrary &&)=default
int ApplyCRy(void *sim, int controlQubit, int targetQubit, double theta)
double * Probabilities(void *sim, const unsigned long long int *qubits, unsigned long int nrQubits)
int ApplyRz(void *sim, int qubit, double theta)
MaestroLibrary(const MaestroLibrary &)=delete
int ApplySwap(void *sim, int qubit1, int qubit2)
void DestroySimulator(unsigned long int simHandle)
int ApplyU(void *sim, int qubit, double theta, double phi, double lambda, double gamma)
int ApplyZ(void *sim, int qubit)
std::string RunRequestJson(const std::string &request)
int RestoreInternalDestructiveSavedState(void *sim)
int ApplyCU(void *sim, int controlQubit, int targetQubit, double theta, double phi, double lambda, double gamma)
int ApplyReset(void *sim, const unsigned long int *qubits, unsigned long int nrQubits)
int InitializeSimulator(void *sim)
int ApplyP(void *sim, int qubit, double theta)
int ApplyRy(void *sim, int qubit, double theta)
bool Init(const char *libName) noexcept override
int ApplyCP(void *sim, int controlQubit, int targetQubit, double theta)
int FlushSimulator(void *sim)
MaestroLibrary(MaestroLibrary &&)=default
int GetMultithreading(void *sim)
void MoveAtBeginningOfChain(void *sim, const std::vector< unsigned long > &qubits)
virtual void FreeResult(char *result)
std::vector< std::complex< double > > GetStateVector(void *sim)
int ApplyRx(void *sim, int qubit, double theta)
unsigned long int GetNumberOfQubits(void *sim)
char * GetConfiguration(void *sim, const char *key)
int ApplyTDG(void *sim, int qubit)
std::vector< double > ExpectationValues(void *sim, const std::vector< std::string > &paulis)
unsigned long long int MeasureNoCollapse(void *sim)
int SetMultithreading(void *sim, int multithreading)
void * GetFunction(const char *funcName) noexcept
Definition Library.h:112
virtual bool Init(const char *libName) noexcept
Definition Library.h:83