Maestro 0.2.5
Unified interface for quantum circuit simulation
Loading...
Searching...
No Matches
QuestLibSim.h
Go to the documentation of this file.
1
12#pragma once
13
14#ifndef _QUEST_LIB_SIM_H_
15#define _QUEST_LIB_SIM_H_
16
17#include "../Utils/Library.h"
18#include <complex>
19#include <vector>
20
21namespace Simulators {
22
23// use it as a singleton
25 public:
26 QuestLibSim(const QuestLibSim &) = delete;
27 QuestLibSim &operator=(const QuestLibSim &) = delete;
28
29 QuestLibSim(QuestLibSim &&) = default;
31
32 QuestLibSim() noexcept {}
33
34 virtual ~QuestLibSim() {
35 if (initialized && fFinalize) {
36 fFinalize();
37 initialized = false;
38 }
39 }
40
41 bool Init(const char *libName) noexcept override {
42 if (Utils::Library::Init(libName)) {
43 fInitialize = (void (*)())GetFunction("Initialize");
44 CheckFunction((void *)fInitialize, __LINE__);
45 fFinalize = (void (*)())GetFunction("Finalize");
46 CheckFunction((void *)fFinalize, __LINE__);
47
48 fCreateSimulator =
49 (unsigned long int (*)(int))GetFunction("CreateSimulator");
50 CheckFunction((void *)fCreateSimulator, __LINE__);
51 fDestroySimulator =
52 (void (*)(unsigned long int))GetFunction("DestroySimulator");
53 CheckFunction((void *)fDestroySimulator, __LINE__);
54 fCloneSimulator =
55 (unsigned long int (*)(void *))GetFunction("CloneSimulator");
56 CheckFunction((void *)fCloneSimulator, __LINE__);
57 fGetSimulator = (void *(*)(unsigned long int))GetFunction("GetSimulator");
58 CheckFunction((void *)fGetSimulator, __LINE__);
59
60 fGetNumQubits = (int (*)(void *))GetFunction("GetNumQubits");
61 CheckFunction((void *)fGetNumQubits, __LINE__);
62 fGetQubitProbability0 =
63 (double (*)(void *, int))GetFunction("GetQubitProbability0");
64 CheckFunction((void *)fGetQubitProbability0, __LINE__);
65 fGetQubitProbability1 =
66 (double (*)(void *, int))GetFunction("GetQubitProbability1");
67 CheckFunction((void *)fGetQubitProbability1, __LINE__);
68 fGetOutcomeProbability = (double (*)(void *, long long int))GetFunction(
69 "GetOutcomeProbability");
70 CheckFunction((void *)fGetOutcomeProbability, __LINE__);
71 fGetExpectationValue =
72 (double (*)(void *, const char *))GetFunction("GetExpectationValue");
73 CheckFunction((void *)fGetExpectationValue, __LINE__);
74
75 fMeasure = (int (*)(void *, int))GetFunction("Measure");
76 CheckFunction((void *)fMeasure, __LINE__);
77 fMeasureQubits =
78 (long long int (*)(void *, int *, int))GetFunction("MeasureQubits");
79 CheckFunction((void *)fMeasureQubits, __LINE__);
80
81 fApplyP = (void (*)(void *, int, double))GetFunction("ApplyP");
82 CheckFunction((void *)fApplyP, __LINE__);
83 fApplyX = (void (*)(void *, int))GetFunction("ApplyX");
84 CheckFunction((void *)fApplyX, __LINE__);
85 fApplyY = (void (*)(void *, int))GetFunction("ApplyY");
86 CheckFunction((void *)fApplyY, __LINE__);
87 fApplyZ = (void (*)(void *, int))GetFunction("ApplyZ");
88 CheckFunction((void *)fApplyZ, __LINE__);
89 fApplyH = (void (*)(void *, int))GetFunction("ApplyH");
90 CheckFunction((void *)fApplyH, __LINE__);
91 fApplyS = (void (*)(void *, int))GetFunction("ApplyS");
92 CheckFunction((void *)fApplyS, __LINE__);
93 fApplyT = (void (*)(void *, int))GetFunction("ApplyT");
94 CheckFunction((void *)fApplyT, __LINE__);
95
96 fApplyRx = (void (*)(void *, int, double))GetFunction("ApplyRx");
97 CheckFunction((void *)fApplyRx, __LINE__);
98 fApplyRy = (void (*)(void *, int, double))GetFunction("ApplyRy");
99 CheckFunction((void *)fApplyRy, __LINE__);
100 fApplyRz = (void (*)(void *, int, double))GetFunction("ApplyRz");
101 CheckFunction((void *)fApplyRz, __LINE__);
102
103 fApplyCS = (void (*)(void *, int, int))GetFunction("ApplyCS");
104 CheckFunction((void *)fApplyCS, __LINE__);
105 fApplyCT = (void (*)(void *, int, int))GetFunction("ApplyCT");
106 CheckFunction((void *)fApplyCT, __LINE__);
107 fApplyCH = (void (*)(void *, int, int))GetFunction("ApplyCH");
108 CheckFunction((void *)fApplyCH, __LINE__);
109 fApplySwap = (void (*)(void *, int, int))GetFunction("ApplySwap");
110 CheckFunction((void *)fApplySwap, __LINE__);
111 fApplyCX = (void (*)(void *, int, int))GetFunction("ApplyCX");
112 CheckFunction((void *)fApplyCX, __LINE__);
113 fApplyCY = (void (*)(void *, int, int))GetFunction("ApplyCY");
114 CheckFunction((void *)fApplyCY, __LINE__);
115 fApplyCZ = (void (*)(void *, int, int))GetFunction("ApplyCZ");
116 CheckFunction((void *)fApplyCZ, __LINE__);
117
118 fApplyCRx = (void (*)(void *, int, int, double))GetFunction("ApplyCRx");
119 CheckFunction((void *)fApplyCRx, __LINE__);
120 fApplyCRy = (void (*)(void *, int, int, double))GetFunction("ApplyCRy");
121 CheckFunction((void *)fApplyCRy, __LINE__);
122 fApplyCRz = (void (*)(void *, int, int, double))GetFunction("ApplyCRz");
123 CheckFunction((void *)fApplyCRz, __LINE__);
124
125 fApplyCSwap = (void (*)(void *, int, int, int))GetFunction("ApplyCSwap");
126 CheckFunction((void *)fApplyCSwap, __LINE__);
127 fApplyCCX = (void (*)(void *, int, int, int))GetFunction("ApplyCCX");
128 CheckFunction((void *)fApplyCCX, __LINE__);
129
130 fApplySdg = (void (*)(void *, int))GetFunction("ApplySdg");
131 CheckFunction((void *)fApplySdg, __LINE__);
132 fApplyTdg = (void (*)(void *, int))GetFunction("ApplyTdg");
133 CheckFunction((void *)fApplyTdg, __LINE__);
134 fApplySx = (void (*)(void *, int))GetFunction("ApplySx");
135 CheckFunction((void *)fApplySx, __LINE__);
136 fApplySxDg = (void (*)(void *, int))GetFunction("ApplySxDg");
137 CheckFunction((void *)fApplySxDg, __LINE__);
138 fApplyK = (void (*)(void *, int))GetFunction("ApplyK");
139 CheckFunction((void *)fApplyK, __LINE__);
140
141 fApplyU = (void (*)(void *, int, double, double, double,
142 double))GetFunction("ApplyU");
143 CheckFunction((void *)fApplyU, __LINE__);
144 fApplyCU = (void (*)(void *, int, int, double, double, double,
145 double))GetFunction("ApplyCU");
146 CheckFunction((void *)fApplyCU, __LINE__);
147 fApplyCP = (void (*)(void *, int, int, double))GetFunction("ApplyCP");
148 CheckFunction((void *)fApplyCP, __LINE__);
149 fApplyCSx = (void (*)(void *, int, int))GetFunction("ApplyCSx");
150 CheckFunction((void *)fApplyCSx, __LINE__);
151 fApplyCSxDg = (void (*)(void *, int, int))GetFunction("ApplyCSxDg");
152 CheckFunction((void *)fApplyCSxDg, __LINE__);
153
154 fGetAmplitudes = (int (*)(
155 void *, void *, unsigned long long int))GetFunction("GetAmplitudes");
156 CheckFunction((void *)fGetAmplitudes, __LINE__);
157 fGetAmplitude =
158 (int (*)(void *, long long int, void *,
159 unsigned long long int))GetFunction("GetAmplitude");
160 CheckFunction((void *)fGetAmplitude, __LINE__);
161 fIsDoublePrecision = (int (*)())GetFunction("IsDoublePrecision");
162 CheckFunction((void *)fIsDoublePrecision, __LINE__);
163
164 if (fInitialize) {
165 fInitialize();
166 initialized = true;
167 return true;
168 }
169 }
170
171 return false;
172 }
173
174 static void CheckFunction(void *func, int line) noexcept {
175 if (!func) {
176 std::cerr << "QuestLibSim: Unable to load function, line #: " << line;
177
178#ifdef __linux__
179 const char *dlsym_error = dlerror();
180 if (dlsym_error) std::cerr << ", error: " << dlsym_error;
181#elif defined(_WIN32)
182 const DWORD error = GetLastError();
183 std::cerr << ", error code: " << error;
184#endif
185
186 std::cerr << std::endl;
187 }
188 }
189
190 bool IsValid() const { return initialized; }
191
192 // simulator management
193
194 unsigned long int CreateSimulator(int nrQubits) {
195 if (initialized)
196 return fCreateSimulator(nrQubits);
197 else
198 throw std::runtime_error("QuestLibSim: Unable to create simulator");
199
200 return 0;
201 }
202
203 void DestroySimulator(unsigned long int simHandle) {
204 if (initialized)
205 fDestroySimulator(simHandle);
206 else
207 throw std::runtime_error("QuestLibSim: Unable to destroy simulator");
208 }
209
210 unsigned long int CloneSimulator(void *sim) {
211 if (initialized)
212 return fCloneSimulator(sim);
213 else
214 throw std::runtime_error("QuestLibSim: Unable to clone simulator");
215
216 return 0;
217 }
218
219 void *GetSimulator(unsigned long int simHandle) {
220 if (initialized)
221 return fGetSimulator(simHandle);
222 else
223 throw std::runtime_error("QuestLibSim: Unable to get simulator");
224
225 return nullptr;
226 }
227
228 // state query functions
229
230 int GetNumQubits(void *sim) const {
231 if (initialized)
232 return fGetNumQubits(sim);
233 else
234 throw std::runtime_error("QuestLibSim: Unable to get number of qubits");
235
236 return 0;
237 }
238
239 double GetQubitProbability0(void *sim, int qubit) const {
240 if (initialized)
241 return fGetQubitProbability0(sim, qubit);
242 else
243 throw std::runtime_error(
244 "QuestLibSim: Unable to get qubit probability 0");
245
246 return 0;
247 }
248
249 double GetQubitProbability1(void *sim, int qubit) const {
250 if (initialized)
251 return fGetQubitProbability1(sim, qubit);
252 else
253 throw std::runtime_error(
254 "QuestLibSim: Unable to get qubit probability 1");
255
256 return 0;
257 }
258
259 double GetOutcomeProbability(void *sim, long long int outcome) const {
260 if (initialized)
261 return fGetOutcomeProbability(sim, outcome);
262 else
263 throw std::runtime_error(
264 "QuestLibSim: Unable to get outcome probability");
265
266 return 0;
267 }
268
269 double GetExpectationValue(void *sim, const char *pauliStr) const {
270 if (initialized)
271 return fGetExpectationValue(sim, pauliStr);
272 else
273 throw std::runtime_error("QuestLibSim: Unable to get expectation value");
274
275 return 0;
276 }
277
278 // measurement functions
279
280 int Measure(void *sim, int qubit) {
281 if (initialized)
282 return fMeasure(sim, qubit);
283 else
284 throw std::runtime_error("QuestLibSim: Unable to measure qubit");
285
286 return 0;
287 }
288
289 long long int MeasureQubits(void *sim, int *qubits, int numQubits) {
290 if (initialized)
291 return fMeasureQubits(sim, qubits, numQubits);
292 else
293 throw std::runtime_error("QuestLibSim: Unable to measure qubits");
294
295 return 0;
296 }
297
298 // single-qubit gate functions
299
300 void ApplyP(void *sim, int qubit, double angle) {
301 if (initialized)
302 fApplyP(sim, qubit, angle);
303 else
304 throw std::runtime_error("QuestLibSim: Unable to apply P gate");
305 }
306
307 void ApplyX(void *sim, int qubit) {
308 if (initialized)
309 fApplyX(sim, qubit);
310 else
311 throw std::runtime_error("QuestLibSim: Unable to apply X gate");
312 }
313
314 void ApplyY(void *sim, int qubit) {
315 if (initialized)
316 fApplyY(sim, qubit);
317 else
318 throw std::runtime_error("QuestLibSim: Unable to apply Y gate");
319 }
320
321 void ApplyZ(void *sim, int qubit) {
322 if (initialized)
323 fApplyZ(sim, qubit);
324 else
325 throw std::runtime_error("QuestLibSim: Unable to apply Z gate");
326 }
327
328 void ApplyH(void *sim, int qubit) {
329 if (initialized)
330 fApplyH(sim, qubit);
331 else
332 throw std::runtime_error("QuestLibSim: Unable to apply H gate");
333 }
334
335 void ApplyS(void *sim, int qubit) {
336 if (initialized)
337 fApplyS(sim, qubit);
338 else
339 throw std::runtime_error("QuestLibSim: Unable to apply S gate");
340 }
341
342 void ApplyT(void *sim, int qubit) {
343 if (initialized)
344 fApplyT(sim, qubit);
345 else
346 throw std::runtime_error("QuestLibSim: Unable to apply T gate");
347 }
348
349 void ApplySdg(void *sim, int qubit) {
350 if (initialized)
351 fApplySdg(sim, qubit);
352 else
353 throw std::runtime_error("QuestLibSim: Unable to apply Sdg gate");
354 }
355
356 void ApplyTdg(void *sim, int qubit) {
357 if (initialized)
358 fApplyTdg(sim, qubit);
359 else
360 throw std::runtime_error("QuestLibSim: Unable to apply Tdg gate");
361 }
362
363 void ApplySx(void *sim, int qubit) {
364 if (initialized)
365 fApplySx(sim, qubit);
366 else
367 throw std::runtime_error("QuestLibSim: Unable to apply Sx gate");
368 }
369
370 void ApplySxDg(void *sim, int qubit) {
371 if (initialized)
372 fApplySxDg(sim, qubit);
373 else
374 throw std::runtime_error("QuestLibSim: Unable to apply SxDg gate");
375 }
376
377 void ApplyK(void *sim, int qubit) {
378 if (initialized)
379 fApplyK(sim, qubit);
380 else
381 throw std::runtime_error("QuestLibSim: Unable to apply K gate");
382 }
383
384 // single-qubit rotation gate functions
385
386 void ApplyRx(void *sim, int qubit, double angle) {
387 if (initialized)
388 fApplyRx(sim, qubit, angle);
389 else
390 throw std::runtime_error("QuestLibSim: Unable to apply Rx gate");
391 }
392
393 void ApplyRy(void *sim, int qubit, double angle) {
394 if (initialized)
395 fApplyRy(sim, qubit, angle);
396 else
397 throw std::runtime_error("QuestLibSim: Unable to apply Ry gate");
398 }
399
400 void ApplyRz(void *sim, int qubit, double angle) {
401 if (initialized)
402 fApplyRz(sim, qubit, angle);
403 else
404 throw std::runtime_error("QuestLibSim: Unable to apply Rz gate");
405 }
406
407 void ApplyU(void *sim, int qubit, double theta, double phi, double lambda,
408 double gamma) {
409 if (initialized)
410 fApplyU(sim, qubit, theta, phi, lambda, gamma);
411 else
412 throw std::runtime_error("QuestLibSim: Unable to apply U gate");
413 }
414
415 // two-qubit gate functions
416
417 void ApplyCS(void *sim, int control, int target) {
418 if (initialized)
419 fApplyCS(sim, control, target);
420 else
421 throw std::runtime_error("QuestLibSim: Unable to apply CS gate");
422 }
423
424 void ApplyCT(void *sim, int control, int target) {
425 if (initialized)
426 fApplyCT(sim, control, target);
427 else
428 throw std::runtime_error("QuestLibSim: Unable to apply CT gate");
429 }
430
431 void ApplyCH(void *sim, int control, int target) {
432 if (initialized)
433 fApplyCH(sim, control, target);
434 else
435 throw std::runtime_error("QuestLibSim: Unable to apply CH gate");
436 }
437
438 void ApplySwap(void *sim, int qubit1, int qubit2) {
439 if (initialized)
440 fApplySwap(sim, qubit1, qubit2);
441 else
442 throw std::runtime_error("QuestLibSim: Unable to apply Swap gate");
443 }
444
445 void ApplyCX(void *sim, int control, int target) {
446 if (initialized)
447 fApplyCX(sim, control, target);
448 else
449 throw std::runtime_error("QuestLibSim: Unable to apply CX gate");
450 }
451
452 void ApplyCY(void *sim, int control, int target) {
453 if (initialized)
454 fApplyCY(sim, control, target);
455 else
456 throw std::runtime_error("QuestLibSim: Unable to apply CY gate");
457 }
458
459 void ApplyCZ(void *sim, int control, int target) {
460 if (initialized)
461 fApplyCZ(sim, control, target);
462 else
463 throw std::runtime_error("QuestLibSim: Unable to apply CZ gate");
464 }
465
466 void ApplyCRx(void *sim, int control, int target, double angle) {
467 if (initialized)
468 fApplyCRx(sim, control, target, angle);
469 else
470 throw std::runtime_error("QuestLibSim: Unable to apply CRx gate");
471 }
472
473 void ApplyCRy(void *sim, int control, int target, double angle) {
474 if (initialized)
475 fApplyCRy(sim, control, target, angle);
476 else
477 throw std::runtime_error("QuestLibSim: Unable to apply CRy gate");
478 }
479
480 void ApplyCRz(void *sim, int control, int target, double angle) {
481 if (initialized)
482 fApplyCRz(sim, control, target, angle);
483 else
484 throw std::runtime_error("QuestLibSim: Unable to apply CRz gate");
485 }
486
487 void ApplyCP(void *sim, int control, int target, double angle) {
488 if (initialized)
489 fApplyCP(sim, control, target, angle);
490 else
491 throw std::runtime_error("QuestLibSim: Unable to apply CP gate");
492 }
493
494 void ApplyCU(void *sim, int control, int target, double theta, double phi,
495 double lambda, double gamma) {
496 if (initialized)
497 fApplyCU(sim, control, target, theta, phi, lambda, gamma);
498 else
499 throw std::runtime_error("QuestLibSim: Unable to apply CU gate");
500 }
501
502 void ApplyCSx(void *sim, int control, int target) {
503 if (initialized)
504 fApplyCSx(sim, control, target);
505 else
506 throw std::runtime_error("QuestLibSim: Unable to apply CSx gate");
507 }
508
509 void ApplyCSxDg(void *sim, int control, int target) {
510 if (initialized)
511 fApplyCSxDg(sim, control, target);
512 else
513 throw std::runtime_error("QuestLibSim: Unable to apply CSxDg gate");
514 }
515
516 // three-qubit gate functions
517
518 void ApplyCSwap(void *sim, int control, int qubit1, int qubit2) {
519 if (initialized)
520 fApplyCSwap(sim, control, qubit1, qubit2);
521 else
522 throw std::runtime_error("QuestLibSim: Unable to apply CSwap gate");
523 }
524
525 void ApplyCCX(void *sim, int control1, int control2, int target) {
526 if (initialized)
527 fApplyCCX(sim, control1, control2, target);
528 else
529 throw std::runtime_error("QuestLibSim: Unable to apply CCX gate");
530 }
531
532 // amplitude functions
533
534 bool GetAmplitudes(void *sim,
535 std::vector<std::complex<double>> &amplitudes) const {
536 if (initialized) {
537 if (IsDoublePrecision())
538 return fGetAmplitudes(
539 sim, amplitudes.data(),
540 amplitudes.size() * sizeof(std::complex<double>)) == 1;
541 else {
542 std::vector<std::complex<float>> amplitudesSingle(amplitudes.size());
543 if (fGetAmplitudes(
544 sim, amplitudesSingle.data(),
545 amplitudesSingle.size() * sizeof(std::complex<float>)) == 1) {
546 for (size_t i = 0; i < amplitudes.size(); ++i)
547 amplitudes[i] = std::complex<double>(
548 static_cast<double>(amplitudesSingle[i].real()),
549 static_cast<double>(amplitudesSingle[i].imag()));
550
551 return true;
552 }
553 }
554 } else
555 throw std::runtime_error("QuestLibSim: Unable to get amplitudes");
556
557 return false;
558 }
559
560 bool GetAmplitude(void *sim, long long int index,
561 std::complex<double> &amplitude) const {
562 if (initialized) {
563 if (IsDoublePrecision())
564 return fGetAmplitude(sim, index, &amplitude,
565 sizeof(std::complex<double>)) == 1;
566 else {
567 std::complex<float> ampSingle;
568 if (fGetAmplitude(sim, index, &ampSingle,
569 sizeof(std::complex<float>)) == 1) {
570 amplitude =
571 std::complex<double>(static_cast<double>(ampSingle.real()),
572 static_cast<double>(ampSingle.imag()));
573 return true;
574 }
575 }
576 } else
577 throw std::runtime_error("QuestLibSim: Unable to get amplitude");
578 return false;
579 }
580
581 bool IsDoublePrecision() const {
582 if (initialized)
583 return fIsDoublePrecision() == 1;
584 else
585 throw std::runtime_error("QuestLibSim: Unable to check double precision");
586 return false;
587 }
588
589 private:
590 bool initialized = false;
591
592 void (*fInitialize)() = nullptr;
593 void (*fFinalize)() = nullptr;
594
595 unsigned long int (*fCreateSimulator)(int) = nullptr;
596 void (*fDestroySimulator)(unsigned long int) = nullptr;
597 unsigned long int (*fCloneSimulator)(void *) = nullptr;
598 void *(*fGetSimulator)(unsigned long int) = nullptr;
599
600 int (*fGetNumQubits)(void *) = nullptr;
601 double (*fGetQubitProbability0)(void *, int) = nullptr;
602 double (*fGetQubitProbability1)(void *, int) = nullptr;
603 double (*fGetOutcomeProbability)(void *, long long int) = nullptr;
604 double (*fGetExpectationValue)(void *, const char *) = nullptr;
605
606 int (*fMeasure)(void *, int) = nullptr;
607 long long int (*fMeasureQubits)(void *, int *, int) = nullptr;
608
609 void (*fApplyP)(void *, int, double) = nullptr;
610 void (*fApplyX)(void *, int) = nullptr;
611 void (*fApplyY)(void *, int) = nullptr;
612 void (*fApplyZ)(void *, int) = nullptr;
613 void (*fApplyH)(void *, int) = nullptr;
614 void (*fApplyS)(void *, int) = nullptr;
615 void (*fApplyT)(void *, int) = nullptr;
616 void (*fApplyRx)(void *, int, double) = nullptr;
617 void (*fApplyRy)(void *, int, double) = nullptr;
618 void (*fApplyRz)(void *, int, double) = nullptr;
619
620 void (*fApplyCS)(void *, int, int) = nullptr;
621 void (*fApplyCT)(void *, int, int) = nullptr;
622 void (*fApplyCH)(void *, int, int) = nullptr;
623 void (*fApplySwap)(void *, int, int) = nullptr;
624 void (*fApplyCX)(void *, int, int) = nullptr;
625 void (*fApplyCY)(void *, int, int) = nullptr;
626 void (*fApplyCZ)(void *, int, int) = nullptr;
627 void (*fApplyCRx)(void *, int, int, double) = nullptr;
628 void (*fApplyCRy)(void *, int, int, double) = nullptr;
629 void (*fApplyCRz)(void *, int, int, double) = nullptr;
630
631 void (*fApplyCSwap)(void *, int, int, int) = nullptr;
632 void (*fApplyCCX)(void *, int, int, int) = nullptr;
633
634 void (*fApplySdg)(void *, int) = nullptr;
635 void (*fApplyTdg)(void *, int) = nullptr;
636 void (*fApplySx)(void *, int) = nullptr;
637 void (*fApplySxDg)(void *, int) = nullptr;
638 void (*fApplyK)(void *, int) = nullptr;
639
640 void (*fApplyU)(void *, int, double, double, double, double) = nullptr;
641 void (*fApplyCU)(void *, int, int, double, double, double, double) = nullptr;
642 void (*fApplyCP)(void *, int, int, double) = nullptr;
643 void (*fApplyCSx)(void *, int, int) = nullptr;
644 void (*fApplyCSxDg)(void *, int, int) = nullptr;
645 int (*fGetAmplitudes)(void *, void *, unsigned long long int) = nullptr;
646 int (*fGetAmplitude)(void *, long long int, void *,
647 unsigned long long int) = nullptr;
648 int (*fIsDoublePrecision)() = nullptr;
649};
650
651} // namespace Simulators
652
653#endif // _QUEST_LIB_SIM_H_
unsigned long int CreateSimulator(int nrQubits)
void ApplyCRz(void *sim, int control, int target, double angle)
bool IsDoublePrecision() const
QuestLibSim(QuestLibSim &&)=default
void ApplyRy(void *sim, int qubit, double angle)
void ApplyU(void *sim, int qubit, double theta, double phi, double lambda, double gamma)
void ApplyCS(void *sim, int control, int target)
void ApplyCZ(void *sim, int control, int target)
void ApplyCH(void *sim, int control, int target)
bool GetAmplitude(void *sim, long long int index, std::complex< double > &amplitude) const
void ApplyCRx(void *sim, int control, int target, double angle)
void ApplyTdg(void *sim, int qubit)
int Measure(void *sim, int qubit)
void ApplyCP(void *sim, int control, int target, double angle)
void ApplyCX(void *sim, int control, int target)
void ApplyX(void *sim, int qubit)
void ApplyRz(void *sim, int qubit, double angle)
void DestroySimulator(unsigned long int simHandle)
void ApplyCSxDg(void *sim, int control, int target)
void ApplyK(void *sim, int qubit)
void ApplyH(void *sim, int qubit)
void ApplySx(void *sim, int qubit)
double GetQubitProbability1(void *sim, int qubit) const
long long int MeasureQubits(void *sim, int *qubits, int numQubits)
void ApplyCY(void *sim, int control, int target)
void ApplyCSwap(void *sim, int control, int qubit1, int qubit2)
void ApplyS(void *sim, int qubit)
void ApplyCU(void *sim, int control, int target, double theta, double phi, double lambda, double gamma)
void ApplyZ(void *sim, int qubit)
int GetNumQubits(void *sim) const
double GetQubitProbability0(void *sim, int qubit) const
void ApplySdg(void *sim, int qubit)
double GetExpectationValue(void *sim, const char *pauliStr) const
void ApplySxDg(void *sim, int qubit)
QuestLibSim(const QuestLibSim &)=delete
bool Init(const char *libName) noexcept override
Definition QuestLibSim.h:41
void ApplySwap(void *sim, int qubit1, int qubit2)
void ApplyCSx(void *sim, int control, int target)
unsigned long int CloneSimulator(void *sim)
void ApplyCCX(void *sim, int control1, int control2, int target)
QuestLibSim & operator=(QuestLibSim &&)=default
double GetOutcomeProbability(void *sim, long long int outcome) const
static void CheckFunction(void *func, int line) noexcept
void ApplyP(void *sim, int qubit, double angle)
bool GetAmplitudes(void *sim, std::vector< std::complex< double > > &amplitudes) const
void ApplyT(void *sim, int qubit)
QuestLibSim & operator=(const QuestLibSim &)=delete
void ApplyRx(void *sim, int qubit, double angle)
void * GetSimulator(unsigned long int simHandle)
void ApplyY(void *sim, int qubit)
void ApplyCT(void *sim, int control, int target)
void ApplyCRy(void *sim, int control, int target, double angle)
void * GetFunction(const char *funcName) noexcept
Definition Library.h:104
virtual bool Init(const char *libName) noexcept
Definition Library.h:78