Maestro 0.2.11
Unified interface for quantum circuit simulation
Loading...
Searching...
No Matches
GpuLibrary.h
Go to the documentation of this file.
1
38
39#pragma once
40
41#ifndef _GPU_LIBRARY_H
42#define _GPU_LIBRARY_H
43
44#ifdef __linux__
45
46#include "../Utils/Library.h"
47
48#include <cstdlib>
49#include <stdint.h>
50#include <unordered_map>
51#include <vector>
52#include <complex>
53
54namespace Simulators {
55
56// use it as a singleton
57class GpuLibrary : public Utils::Library {
58 public:
59 GpuLibrary(const GpuLibrary &) = delete;
60 GpuLibrary &operator=(const GpuLibrary &) = delete;
61
62 GpuLibrary(GpuLibrary &&) = default;
63 GpuLibrary &operator=(GpuLibrary &&) = default;
64
65 GpuLibrary() noexcept {}
66
67 virtual ~GpuLibrary() {
68 if (LibraryHandle) FreeLib();
69 }
70
71 bool Init(const char *libName) noexcept override {
72 if (Utils::Library::Init(libName)) {
73 // Validate license before initializing the library.
74 // The license key is read from the MAESTRO_LICENSE_KEY env var.
75 // If not set, nullptr is passed to attempt cached/offline validation.
76 fValidateLicense = (int (*)(const char *))GetFunction("ValidateLicense");
77 if (!fValidateLicense) {
78 if (!IsMuted())
79 std::cerr << "GpuLibrary: License validation symbol not found. "
80 "The GPU library must export ValidateLicense."
81 << std::endl;
82 return false;
83 }
84 const char *licenseKey = std::getenv("MAESTRO_LICENSE_KEY");
85 int licenseStatus = fValidateLicense(licenseKey);
86 if (licenseStatus != 1) {
87 if (!IsMuted()) {
88 std::cerr << "GpuLibrary: License validation failed. ";
89 if (!licenseKey)
90 std::cerr << "Set MAESTRO_LICENSE_KEY environment variable "
91 "or activate the license first."
92 << std::endl;
93 else
94 std::cerr << "Check that your license key is correct." << std::endl;
95 }
96 return false;
97 }
98
99 InitLib = (void *(*)())GetFunction("InitLib");
100 CheckFunction((void *)InitLib, __LINE__);
101 if (InitLib) {
102 LibraryHandle = InitLib();
103 if (LibraryHandle) {
104 FreeLib = (void (*)())GetFunction("FreeLib");
105 CheckFunction((void *)FreeLib, __LINE__);
106
107 // state vector api functions
108
109 fCreateStateVector =
110 (void *(*)(void *))GetFunction("CreateStateVector");
111 CheckFunction((void *)fCreateStateVector, __LINE__);
112 fDestroyStateVector =
113 (void (*)(void *))GetFunction("DestroyStateVector");
114 CheckFunction((void *)fDestroyStateVector, __LINE__);
115
116 fCreate = (int (*)(void *, unsigned int))GetFunction("Create");
117 CheckFunction((void *)fCreate, __LINE__);
118 fCreateWithState =
119 (int (*)(void *, unsigned int, const double *))GetFunction(
120 "CreateWithState");
121 CheckFunction((void *)fCreateWithState, __LINE__);
122 fReset = (int (*)(void *))GetFunction("Reset");
123 CheckFunction((void *)fReset, __LINE__);
124
125 fSetDataType = (int (*)(void *, int))GetFunction("SetDataType");
126 CheckFunction((void *)fSetDataType, __LINE__);
127 fIsDoublePrecision =
128 (int (*)(void *))GetFunction("IsDoublePrecision");
129 CheckFunction((void *)fIsDoublePrecision, __LINE__);
130 fGetNrQubits = (int (*)(void *))GetFunction("GetNrQubits");
131 CheckFunction((void *)fGetNrQubits, __LINE__);
132
133 fMeasureQubitCollapse =
134 (int (*)(void *, int))GetFunction("MeasureQubitCollapse");
135 CheckFunction((void *)fMeasureQubitCollapse, __LINE__);
136 fMeasureQubitNoCollapse =
137 (int (*)(void *, int))GetFunction("MeasureQubitNoCollapse");
138 CheckFunction((void *)fMeasureQubitNoCollapse, __LINE__);
139 fMeasureQubitsCollapse = (int (*)(
140 void *, int *, int *, int))GetFunction("MeasureQubitsCollapse");
141 CheckFunction((void *)fMeasureQubitsCollapse, __LINE__);
142 fMeasureQubitsNoCollapse = (int (*)(
143 void *, int *, int *, int))GetFunction("MeasureQubitsNoCollapse");
144 CheckFunction((void *)fMeasureQubitsNoCollapse, __LINE__);
145 fMeasureAllQubitsCollapse = (unsigned long long (*)(
146 void *))GetFunction("MeasureAllQubitsCollapse");
147 CheckFunction((void *)fMeasureAllQubitsCollapse, __LINE__);
148 fMeasureAllQubitsNoCollapse = (unsigned long long (*)(
149 void *))GetFunction("MeasureAllQubitsNoCollapse");
150 CheckFunction((void *)fMeasureAllQubitsNoCollapse, __LINE__);
151
152 fSaveState = (int (*)(void *))GetFunction("SaveState");
153 CheckFunction((void *)fSaveState, __LINE__);
154 fSaveStateToHost = (int (*)(void *))GetFunction("SaveStateToHost");
155 CheckFunction((void *)fSaveStateToHost, __LINE__);
156 fSaveStateDestructive =
157 (int (*)(void *))GetFunction("SaveStateDestructive");
158 CheckFunction((void *)fSaveStateDestructive, __LINE__);
159 fRestoreStateFreeSaved =
160 (int (*)(void *))GetFunction("RestoreStateFreeSaved");
161 CheckFunction((void *)fRestoreStateFreeSaved, __LINE__);
162 fRestoreStateNoFreeSaved =
163 (int (*)(void *))GetFunction("RestoreStateNoFreeSaved");
164 CheckFunction((void *)fRestoreStateNoFreeSaved, __LINE__);
165 fFreeSavedState = (void (*)(void *))GetFunction("FreeSavedState");
166 CheckFunction((void *)fFreeSavedState, __LINE__);
167 fClone = (void *(*)(void *))GetFunction("Clone");
168 CheckFunction((void *)fClone, __LINE__);
169
170 fSample = (int (*)(void *, unsigned int, long int *, unsigned int,
171 int *))GetFunction("Sample");
172 CheckFunction((void *)fSample, __LINE__);
173 fSampleAll = (int (*)(void *, unsigned int, long int *))GetFunction(
174 "SampleAll");
175 CheckFunction((void *)fSampleAll, __LINE__);
176 fAmplitude = (int (*)(void *, long long int, double *,
177 double *))GetFunction("Amplitude");
178 CheckFunction((void *)fAmplitude, __LINE__);
179 fProbability =
180 (double (*)(void *, int *, int *, int))GetFunction("Probability");
181 CheckFunction((void *)fProbability, __LINE__);
182 fBasisStateProbability = (double (*)(
183 void *, long long int))GetFunction("BasisStateProbability");
184 CheckFunction((void *)fBasisStateProbability, __LINE__);
185 fAllProbabilities = (int (*)(
186 void *obj, double *probabilities))GetFunction("AllProbabilities");
187 CheckFunction((void *)fAllProbabilities, __LINE__);
188 fExpectationValue = (double (*)(void *, const char *,
189 int))GetFunction("ExpectationValue");
190 CheckFunction((void *)fExpectationValue, __LINE__);
191
192 fApplyX = (int (*)(void *, int))GetFunction("ApplyX");
193 CheckFunction((void *)fApplyX, __LINE__);
194 fApplyY = (int (*)(void *, int))GetFunction("ApplyY");
195 CheckFunction((void *)fApplyY, __LINE__);
196 fApplyZ = (int (*)(void *, int))GetFunction("ApplyZ");
197 CheckFunction((void *)fApplyZ, __LINE__);
198 fApplyH = (int (*)(void *, int))GetFunction("ApplyH");
199 CheckFunction((void *)fApplyH, __LINE__);
200 fApplyS = (int (*)(void *, int))GetFunction("ApplyS");
201 CheckFunction((void *)fApplyS, __LINE__);
202 fApplySDG = (int (*)(void *, int))GetFunction("ApplySDG");
203 CheckFunction((void *)fApplySDG, __LINE__);
204 fApplyT = (int (*)(void *, int))GetFunction("ApplyT");
205 CheckFunction((void *)fApplyT, __LINE__);
206 fApplyTDG = (int (*)(void *, int))GetFunction("ApplyTDG");
207 CheckFunction((void *)fApplyTDG, __LINE__);
208 fApplySX = (int (*)(void *, int))GetFunction("ApplySX");
209 CheckFunction((void *)fApplySX, __LINE__);
210 fApplySXDG = (int (*)(void *, int))GetFunction("ApplySXDG");
211 CheckFunction((void *)fApplySXDG, __LINE__);
212 fApplyK = (int (*)(void *, int))GetFunction("ApplyK");
213 CheckFunction((void *)fApplyK, __LINE__);
214 fApplyP = (int (*)(void *, int, double))GetFunction("ApplyP");
215 CheckFunction((void *)fApplyP, __LINE__);
216 fApplyRx = (int (*)(void *, int, double))GetFunction("ApplyRx");
217 CheckFunction((void *)fApplyRx, __LINE__);
218 fApplyRy = (int (*)(void *, int, double))GetFunction("ApplyRy");
219 CheckFunction((void *)fApplyRy, __LINE__);
220 fApplyRz = (int (*)(void *, int, double))GetFunction("ApplyRz");
221 CheckFunction((void *)fApplyRz, __LINE__);
222 fApplyU = (int (*)(void *, int, double, double, double,
223 double))GetFunction("ApplyU");
224 CheckFunction((void *)fApplyU, __LINE__);
225 fApplyCX = (int (*)(void *, int, int))GetFunction("ApplyCX");
226 CheckFunction((void *)fApplyCX, __LINE__);
227 fApplyCY = (int (*)(void *, int, int))GetFunction("ApplyCY");
228 CheckFunction((void *)fApplyCY, __LINE__);
229 fApplyCZ = (int (*)(void *, int, int))GetFunction("ApplyCZ");
230 CheckFunction((void *)fApplyCZ, __LINE__);
231 fApplyCH = (int (*)(void *, int, int))GetFunction("ApplyCH");
232 CheckFunction((void *)fApplyCH, __LINE__);
233 fApplyCSX = (int (*)(void *, int, int))GetFunction("ApplyCSX");
234 CheckFunction((void *)fApplyCSX, __LINE__);
235 fApplyCSXDG = (int (*)(void *, int, int))GetFunction("ApplyCSXDG");
236 CheckFunction((void *)fApplyCSXDG, __LINE__);
237 fApplyCP = (int (*)(void *, int, int, double))GetFunction("ApplyCP");
238 CheckFunction((void *)fApplyCP, __LINE__);
239 fApplyCRx =
240 (int (*)(void *, int, int, double))GetFunction("ApplyCRx");
241 CheckFunction((void *)fApplyCRx, __LINE__);
242 fApplyCRy =
243 (int (*)(void *, int, int, double))GetFunction("ApplyCRy");
244 CheckFunction((void *)fApplyCRy, __LINE__);
245 fApplyCRz =
246 (int (*)(void *, int, int, double))GetFunction("ApplyCRz");
247 CheckFunction((void *)fApplyCRz, __LINE__);
248 fApplyCCX = (int (*)(void *, int, int, int))GetFunction("ApplyCCX");
249 CheckFunction((void *)fApplyCCX, __LINE__);
250 fApplySwap = (int (*)(void *, int, int))GetFunction("ApplySwap");
251 CheckFunction((void *)fApplySwap, __LINE__);
252 fApplyCSwap =
253 (int (*)(void *, int, int, int))GetFunction("ApplyCSwap");
254 CheckFunction((void *)fApplyCSwap, __LINE__);
255 fApplyCU = (int (*)(void *, int, int, double, double, double,
256 double))GetFunction("ApplyCU");
257 CheckFunction((void *)fApplyCU, __LINE__);
258
259 // mps api functions
260
261 fCreateMPS = (void *(*)(void *))GetFunction("CreateMPS");
262 CheckFunction((void *)fCreateMPS, __LINE__);
263 fDestroyMPS = (void (*)(void *))GetFunction("DestroyMPS");
264 CheckFunction((void *)fDestroyMPS, __LINE__);
265
266 fMPSCreate = (int (*)(void *, unsigned int))GetFunction("MPSCreate");
267 CheckFunction((void *)fMPSCreate, __LINE__);
268 fMPSReset = (int (*)(void *))GetFunction("MPSReset");
269 CheckFunction((void *)fMPSReset, __LINE__);
270 fMPSSetInitialQubitsMap =
271 (int (*)(void *, const long long int *, unsigned int))GetFunction(
272 "MPSSetInitialQubitsMap");
273 CheckFunction((void *)fMPSSetInitialQubitsMap, __LINE__);
274 fMPSSetUseOptimalMeetingPosition = (int (*)(void *, int))GetFunction(
275 "MPSSetUseOptimalMeetingPosition");
276 CheckFunction((void *)fMPSSetUseOptimalMeetingPosition, __LINE__);
277
278 fMPSIsValid = (int (*)(void *))GetFunction("MPSIsValid");
279 CheckFunction((void *)fMPSIsValid, __LINE__);
280 fMPSIsCreated = (int (*)(void *))GetFunction("MPSIsCreated");
281 CheckFunction((void *)fMPSIsCreated, __LINE__);
282
283 fMPSSetDataType = (int (*)(void *, int))GetFunction("MPSSetDataType");
284 CheckFunction((void *)fMPSSetDataType, __LINE__);
285 fMPSIsDoublePrecision =
286 (int (*)(void *))GetFunction("MPSIsDoublePrecision");
287 CheckFunction((void *)fMPSIsDoublePrecision, __LINE__);
288 fMPSSetCutoff = (int (*)(void *, double))GetFunction("MPSSetCutoff");
289 CheckFunction((void *)fMPSSetCutoff, __LINE__);
290 fMPSGetCutoff = (double (*)(void *))GetFunction("MPSGetCutoff");
291 CheckFunction((void *)fMPSGetCutoff, __LINE__);
292 fMPSSetGesvdJ = (int (*)(void *, int))GetFunction("MPSSetGesvdJ");
293 CheckFunction((void *)fMPSSetGesvdJ, __LINE__);
294 fMPSGetGesvdJ = (int (*)(void *))GetFunction("MPSGetGesvdJ");
295 CheckFunction((void *)fMPSGetGesvdJ, __LINE__);
296 fMPSSetMaxExtent =
297 (int (*)(void *, long int))GetFunction("MPSSetMaxExtent");
298 CheckFunction((void *)fMPSSetMaxExtent, __LINE__);
299 fMPSGetMaxExtent =
300 (long int (*)(void *))GetFunction("MPSGetMaxExtent");
301 CheckFunction((void *)fMPSGetMaxExtent, __LINE__);
302 fMPSGetNrQubits = (int (*)(void *))GetFunction("MPSGetNrQubits");
303 CheckFunction((void *)fMPSGetNrQubits, __LINE__);
304 fMPSSetCallbackContext =
305 (int (*)(void *, void *))GetFunction("MPSSetCallbackContext");
306 CheckFunction((void *)fMPSSetCallbackContext, __LINE__);
307
308 fMPSSetMeetingPositionCallback =
309 (int (*)(void *, int64_t (*)(void *, const int64_t *)))
310 GetFunction("MPSSetMeetingPositionCallback");
311 CheckFunction((void *)fMPSSetMeetingPositionCallback, __LINE__);
312
313 fMPSAmplitude = (int (*)(void *, long int, long int *, double *,
314 double *))GetFunction("MPSAmplitude");
315 CheckFunction((void *)fMPSAmplitude, __LINE__);
316 fMPSProbability0 =
317 (double (*)(void *, unsigned int))GetFunction("MPSProbability0");
318 CheckFunction((void *)fMPSProbability0, __LINE__);
319 fMPSMeasure =
320 (int (*)(void *, unsigned int))GetFunction("MPSMeasure");
321 CheckFunction((void *)fMPSMeasure, __LINE__);
322 fMPSMeasureQubits = (int (*)(void *, long int, unsigned int *,
323 int *))GetFunction("MPSMeasureQubits");
324 CheckFunction((void *)fMPSMeasureQubits, __LINE__);
325
326 fMPSGetMapForSample = (void *(*)())GetFunction("MPSGetMapForSample");
327 CheckFunction((void *)fMPSGetMapForSample, __LINE__);
328 fMPSFreeMapForSample =
329 (int (*)(void *))GetFunction("MPSFreeMapForSample");
330 CheckFunction((void *)fMPSFreeMapForSample, __LINE__);
331 fMPSSample = (int (*)(void *, long int, long int, unsigned int *,
332 void *))GetFunction("MPSSample");
333 CheckFunction((void *)fMPSSample, __LINE__);
334
335 fMPSSaveState = (int (*)(void *))GetFunction("MPSSaveState");
336 CheckFunction((void *)fMPSSaveState, __LINE__);
337 fMPSRestoreState = (int (*)(void *))GetFunction("MPSRestoreState");
338 CheckFunction((void *)fMPSRestoreState, __LINE__);
339 fMPSCleanSavedState =
340 (int (*)(void *))GetFunction("MPSCleanSavedState");
341 CheckFunction((void *)fMPSCleanSavedState, __LINE__);
342 fMPSClone = (void *(*)(void *))GetFunction("MPSClone");
343 CheckFunction((void *)fMPSClone, __LINE__);
344
345 fMPSExpectationValue = (double (*)(
346 void *, const char *, int))GetFunction("MPSExpectationValue");
347 CheckFunction((void *)fMPSExpectationValue, __LINE__);
348 fMPSProjectOnZero =
349 (int (*)(void *, double *, double *))GetFunction("MPSProjectOnZero");
350 CheckFunction((void *)fMPSProjectOnZero, __LINE__);
351
352 fMPSApplyX = (int (*)(void *, unsigned int))GetFunction("MPSApplyX");
353 CheckFunction((void *)fMPSApplyX, __LINE__);
354 fMPSApplyY = (int (*)(void *, unsigned int))GetFunction("MPSApplyY");
355 CheckFunction((void *)fMPSApplyY, __LINE__);
356 fMPSApplyZ = (int (*)(void *, unsigned int))GetFunction("MPSApplyZ");
357 CheckFunction((void *)fMPSApplyZ, __LINE__);
358 fMPSApplyH = (int (*)(void *, unsigned int))GetFunction("MPSApplyH");
359 CheckFunction((void *)fMPSApplyH, __LINE__);
360 fMPSApplyS = (int (*)(void *, unsigned int))GetFunction("MPSApplyS");
361 CheckFunction((void *)fMPSApplyS, __LINE__);
362 fMPSApplySDG =
363 (int (*)(void *, unsigned int))GetFunction("MPSApplySDG");
364 CheckFunction((void *)fMPSApplySDG, __LINE__);
365 fMPSApplyT = (int (*)(void *, unsigned int))GetFunction("MPSApplyT");
366 CheckFunction((void *)fMPSApplyT, __LINE__);
367 fMPSApplyTDG =
368 (int (*)(void *, unsigned int))GetFunction("MPSApplyTDG");
369 CheckFunction((void *)fMPSApplyTDG, __LINE__);
370 fMPSApplySX =
371 (int (*)(void *, unsigned int))GetFunction("MPSApplySX");
372 CheckFunction((void *)fMPSApplySX, __LINE__);
373 fMPSApplySXDG =
374 (int (*)(void *, unsigned int))GetFunction("MPSApplySXDG");
375 CheckFunction((void *)fMPSApplySXDG, __LINE__);
376 fMPSApplyK = (int (*)(void *, unsigned int))GetFunction("MPSApplyK");
377 CheckFunction((void *)fMPSApplyK, __LINE__);
378 fMPSApplyP =
379 (int (*)(void *, unsigned int, double))GetFunction("MPSApplyP");
380 CheckFunction((void *)fMPSApplyP, __LINE__);
381 fMPSApplyRx =
382 (int (*)(void *, unsigned int, double))GetFunction("MPSApplyRx");
383 CheckFunction((void *)fMPSApplyRx, __LINE__);
384 fMPSApplyRy =
385 (int (*)(void *, unsigned int, double))GetFunction("MPSApplyRy");
386 CheckFunction((void *)fMPSApplyRy, __LINE__);
387 fMPSApplyRz =
388 (int (*)(void *, unsigned int, double))GetFunction("MPSApplyRz");
389 CheckFunction((void *)fMPSApplyRz, __LINE__);
390 fMPSApplyU = (int (*)(void *, unsigned int, double, double, double,
391 double))GetFunction("MPSApplyU");
392 CheckFunction((void *)fMPSApplyU, __LINE__);
393 fMPSApplySwap = (int (*)(void *, unsigned int,
394 unsigned int))GetFunction("MPSApplySwap");
395 CheckFunction((void *)fMPSApplySwap, __LINE__);
396 fMPSApplyCX = (int (*)(void *, unsigned int,
397 unsigned int))GetFunction("MPSApplyCX");
398 CheckFunction((void *)fMPSApplyCX, __LINE__);
399 fMPSApplyCY = (int (*)(void *, unsigned int,
400 unsigned int))GetFunction("MPSApplyCY");
401 CheckFunction((void *)fMPSApplyCY, __LINE__);
402 fMPSApplyCZ = (int (*)(void *, unsigned int,
403 unsigned int))GetFunction("MPSApplyCZ");
404 CheckFunction((void *)fMPSApplyCZ, __LINE__);
405 fMPSApplyCH = (int (*)(void *, unsigned int,
406 unsigned int))GetFunction("MPSApplyCH");
407 CheckFunction((void *)fMPSApplyCH, __LINE__);
408 fMPSApplyCSX = (int (*)(void *, unsigned int,
409 unsigned int))GetFunction("MPSApplyCSX");
410 CheckFunction((void *)fMPSApplyCSX, __LINE__);
411 fMPSApplyCSXDG = (int (*)(void *, unsigned int,
412 unsigned int))GetFunction("MPSApplyCSXDG");
413 CheckFunction((void *)fMPSApplyCSXDG, __LINE__);
414 fMPSApplyCP = (int (*)(void *, unsigned int, unsigned int,
415 double))GetFunction("MPSApplyCP");
416 CheckFunction((void *)fMPSApplyCP, __LINE__);
417 fMPSApplyCRx = (int (*)(void *, unsigned int, unsigned int,
418 double))GetFunction("MPSApplyCRx");
419 CheckFunction((void *)fMPSApplyCRx, __LINE__);
420 fMPSApplyCRy = (int (*)(void *, unsigned int, unsigned int,
421 double))GetFunction("MPSApplyCRy");
422 CheckFunction((void *)fMPSApplyCRy, __LINE__);
423 fMPSApplyCRz = (int (*)(void *, unsigned int, unsigned int,
424 double))GetFunction("MPSApplyCRz");
425 CheckFunction((void *)fMPSApplyCRz, __LINE__);
426 fMPSApplyCU =
427 (int (*)(void *, unsigned int, unsigned int, double, double,
428 double, double))GetFunction("MPSApplyCU");
429 CheckFunction((void *)fMPSApplyCU, __LINE__);
430
431 // tensor network api functions
432
433 fCreateTensorNet = (void *(*)(void *))GetFunction("CreateTensorNet");
434 CheckFunction((void *)fCreateTensorNet, __LINE__);
435 fDestroyTensorNet = (void (*)(void *))GetFunction("DestroyTensorNet");
436 CheckFunction((void *)fDestroyTensorNet, __LINE__);
437
438 fTNCreate = (int (*)(void *, unsigned int))GetFunction("TNCreate");
439 CheckFunction((void *)fTNCreate, __LINE__);
440 fTNReset = (int (*)(void *))GetFunction("TNReset");
441 CheckFunction((void *)fTNReset, __LINE__);
442
443 fTNIsValid = (int (*)(void *))GetFunction("TNIsValid");
444 CheckFunction((void *)fTNIsValid, __LINE__);
445 fTNIsCreated = (int (*)(void *))GetFunction("TNIsCreated");
446 CheckFunction((void *)fTNIsCreated, __LINE__);
447
448 fTNSetDataType = (int (*)(void *, int))GetFunction("TNSetDataType");
449 CheckFunction((void *)fTNSetDataType, __LINE__);
450 fTNIsDoublePrecision =
451 (int (*)(void *))GetFunction("TNIsDoublePrecision");
452 CheckFunction((void *)fTNIsDoublePrecision, __LINE__);
453 fTNSetCutoff = (int (*)(void *, double))GetFunction("TNSetCutoff");
454 CheckFunction((void *)fTNSetCutoff, __LINE__);
455 fTNGetCutoff = (double (*)(void *))GetFunction("TNGetCutoff");
456 CheckFunction((void *)fTNGetCutoff, __LINE__);
457 fTNSetGesvdJ = (int (*)(void *, int))GetFunction("TNSetGesvdJ");
458 CheckFunction((void *)fTNSetGesvdJ, __LINE__);
459 fTNGetGesvdJ = (int (*)(void *))GetFunction("TNGetGesvdJ");
460 CheckFunction((void *)fTNGetGesvdJ, __LINE__);
461 fTNSetMaxExtent =
462 (int (*)(void *, long int))GetFunction("TNSetMaxExtent");
463 CheckFunction((void *)fTNSetMaxExtent, __LINE__);
464 fTNGetMaxExtent = (long int (*)(void *))GetFunction("TNGetMaxExtent");
465 CheckFunction((void *)fTNGetMaxExtent, __LINE__);
466 fTNGetNrQubits = (int (*)(void *))GetFunction("TNGetNrQubits");
467 CheckFunction((void *)fTNGetNrQubits, __LINE__);
468 fTNAmplitude = (int (*)(void *, long int, long int *, double *,
469 double *))GetFunction("TNAmplitude");
470 CheckFunction((void *)fTNAmplitude, __LINE__);
471 fTNProbability0 =
472 (double (*)(void *, unsigned int))GetFunction("TNProbability0");
473 CheckFunction((void *)fTNProbability0, __LINE__);
474 fTNMeasure = (int (*)(void *, unsigned int))GetFunction("TNMeasure");
475 CheckFunction((void *)fTNMeasure, __LINE__);
476 fTNMeasureQubits = (int (*)(void *, long int, unsigned int *,
477 int *))GetFunction("TNMeasureQubits");
478 CheckFunction((void *)fTNMeasureQubits, __LINE__);
479
480 fTNGetMapForSample = (void *(*)())GetFunction("TNGetMapForSample");
481 CheckFunction((void *)fTNGetMapForSample, __LINE__);
482 fTNFreeMapForSample =
483 (int (*)(void *))GetFunction("TNFreeMapForSample");
484 CheckFunction((void *)fTNFreeMapForSample, __LINE__);
485 fTNSample = (int (*)(void *, long int, long int, unsigned int *,
486 void *))GetFunction("TNSample");
487 CheckFunction((void *)fTNSample, __LINE__);
488
489 fTNSaveState = (int (*)(void *))GetFunction("TNSaveState");
490 CheckFunction((void *)fTNSaveState, __LINE__);
491 fTNRestoreState = (int (*)(void *))GetFunction("TNRestoreState");
492 CheckFunction((void *)fTNRestoreState, __LINE__);
493 fTNCleanSavedState =
494 (int (*)(void *))GetFunction("TNCleanSavedState");
495 CheckFunction((void *)fTNCleanSavedState, __LINE__);
496 fTNClone = (void *(*)(void *))GetFunction("TNClone");
497 CheckFunction((void *)fTNClone, __LINE__);
498
499 fTNExpectationValue = (double (*)(
500 void *, const char *, int))GetFunction("TNExpectationValue");
501 CheckFunction((void *)fTNExpectationValue, __LINE__);
502
503 fTNApplyX = (int (*)(void *, unsigned int))GetFunction("TNApplyX");
504 CheckFunction((void *)fTNApplyX, __LINE__);
505 fTNApplyY = (int (*)(void *, unsigned int))GetFunction("TNApplyY");
506 CheckFunction((void *)fTNApplyY, __LINE__);
507 fTNApplyZ = (int (*)(void *, unsigned int))GetFunction("TNApplyZ");
508 CheckFunction((void *)fTNApplyZ, __LINE__);
509 fTNApplyH = (int (*)(void *, unsigned int))GetFunction("TNApplyH");
510 CheckFunction((void *)fTNApplyH, __LINE__);
511 fTNApplyS = (int (*)(void *, unsigned int))GetFunction("TNApplyS");
512 CheckFunction((void *)fTNApplyS, __LINE__);
513 fTNApplySDG =
514 (int (*)(void *, unsigned int))GetFunction("TNApplySDG");
515 CheckFunction((void *)fTNApplySDG, __LINE__);
516 fTNApplyT = (int (*)(void *, unsigned int))GetFunction("TNApplyT");
517 CheckFunction((void *)fTNApplyT, __LINE__);
518 fTNApplyTDG =
519 (int (*)(void *, unsigned int))GetFunction("TNApplyTDG");
520 CheckFunction((void *)fTNApplyTDG, __LINE__);
521 fTNApplySX = (int (*)(void *, unsigned int))GetFunction("TNApplySX");
522 CheckFunction((void *)fTNApplySX, __LINE__);
523 fTNApplySXDG =
524 (int (*)(void *, unsigned int))GetFunction("TNApplySXDG");
525 CheckFunction((void *)fTNApplySXDG, __LINE__);
526 fTNApplyK = (int (*)(void *, unsigned int))GetFunction("TNApplyK");
527 CheckFunction((void *)fTNApplyK, __LINE__);
528 fTNApplyP =
529 (int (*)(void *, unsigned int, double))GetFunction("TNApplyP");
530 CheckFunction((void *)fTNApplyP, __LINE__);
531 fTNApplyRx =
532 (int (*)(void *, unsigned int, double))GetFunction("TNApplyRx");
533 CheckFunction((void *)fTNApplyRx, __LINE__);
534 fTNApplyRy =
535 (int (*)(void *, unsigned int, double))GetFunction("TNApplyRy");
536 CheckFunction((void *)fTNApplyRy, __LINE__);
537 fTNApplyRz =
538 (int (*)(void *, unsigned int, double))GetFunction("TNApplyRz");
539 CheckFunction((void *)fTNApplyRz, __LINE__);
540 fTNApplyU = (int (*)(void *, unsigned int, double, double, double,
541 double))GetFunction("TNApplyU");
542 CheckFunction((void *)fTNApplyU, __LINE__);
543 fTNApplySwap = (int (*)(void *, unsigned int,
544 unsigned int))GetFunction("TNApplySwap");
545 CheckFunction((void *)fTNApplySwap, __LINE__);
546 fTNApplyCX = (int (*)(void *, unsigned int, unsigned int))GetFunction(
547 "TNApplyCX");
548 CheckFunction((void *)fTNApplyCX, __LINE__);
549 fTNApplyCY = (int (*)(void *, unsigned int, unsigned int))GetFunction(
550 "TNApplyCY");
551 CheckFunction((void *)fTNApplyCY, __LINE__);
552 fTNApplyCZ = (int (*)(void *, unsigned int, unsigned int))GetFunction(
553 "TNApplyCZ");
554 CheckFunction((void *)fTNApplyCZ, __LINE__);
555 fTNApplyCH = (int (*)(void *, unsigned int, unsigned int))GetFunction(
556 "TNApplyCH");
557 CheckFunction((void *)fTNApplyCH, __LINE__);
558 fTNApplyCSX = (int (*)(void *, unsigned int,
559 unsigned int))GetFunction("TNApplyCSX");
560 CheckFunction((void *)fTNApplyCSX, __LINE__);
561 fTNApplyCSXDG = (int (*)(void *, unsigned int,
562 unsigned int))GetFunction("TNApplyCSXDG");
563 CheckFunction((void *)fTNApplyCSXDG, __LINE__);
564 fTNApplyCP = (int (*)(void *, unsigned int, unsigned int,
565 double))GetFunction("TNApplyCP");
566 CheckFunction((void *)fTNApplyCP, __LINE__);
567 fTNApplyCRx = (int (*)(void *, unsigned int, unsigned int,
568 double))GetFunction("TNApplyCRx");
569 CheckFunction((void *)fTNApplyCRx, __LINE__);
570 fTNApplyCRy = (int (*)(void *, unsigned int, unsigned int,
571 double))GetFunction("TNApplyCRy");
572 CheckFunction((void *)fTNApplyCRy, __LINE__);
573 fTNApplyCRz = (int (*)(void *, unsigned int, unsigned int,
574 double))GetFunction("TNApplyCRz");
575 CheckFunction((void *)fTNApplyCRz, __LINE__);
576 fTNApplyCU =
577 (int (*)(void *, unsigned int, unsigned int, double, double,
578 double, double))GetFunction("TNApplyCU");
579 CheckFunction((void *)fTNApplyCU, __LINE__);
580
581 fTNApplyCCX = (int (*)(void *, unsigned int, unsigned int,
582 unsigned int))GetFunction("TNApplyCCX");
583 CheckFunction((void *)fTNApplyCCX, __LINE__);
584 fTNApplyCSwap = (int (*)(void *, unsigned int, unsigned int,
585 unsigned int))GetFunction("TNApplyCSwap");
586 CheckFunction((void *)fTNApplyCSwap, __LINE__);
587
588 // stabilizer simulator functions
589 fCreateStabilizerSimulator = (void *(*)(long long int, long long int,
590 long long int, long long int))
591 GetFunction("CreateStabilizerSimulator");
592 CheckFunction((void *)fCreateStabilizerSimulator, __LINE__);
593 fDestroyStabilizerSimulator =
594 (void (*)(void *))GetFunction("DestroyStabilizerSimulator");
595 CheckFunction((void *)fDestroyStabilizerSimulator, __LINE__);
596 fExecuteStabilizerCircuit = (int (*)(
597 void *, const char *, int,
598 unsigned long long int))GetFunction("ExecuteStabilizerCircuit");
599 CheckFunction((void *)fExecuteStabilizerCircuit, __LINE__);
600 fGetStabilizerXZTableSize =
601 (long long (*)(void *))GetFunction("GetStabilizerXZTableSize");
602 CheckFunction((void *)fGetStabilizerXZTableSize, __LINE__);
603 fGetStabilizerMTableSize =
604 (long long (*)(void *))GetFunction("GetStabilizerMTableSize");
605 CheckFunction((void *)fGetStabilizerMTableSize, __LINE__);
606
607 fGetStabilizerTableStrideMajor = (long long (*)(void *))GetFunction(
608 "GetStabilizerTableStrideMajor");
609 CheckFunction((void *)fGetStabilizerTableStrideMajor, __LINE__);
610
611 fGetStabilizerNumQubits =
612 (long long (*)(void *))GetFunction("GetStabilizerNumQubits");
613 CheckFunction((void *)fGetStabilizerNumQubits, __LINE__);
614 fGetStabilizerNumShots =
615 (long long (*)(void *))GetFunction("GetStabilizerNumShots");
616 CheckFunction((void *)fGetStabilizerNumShots, __LINE__);
617 fGetStabilizerNumMeasurements = (long long (*)(void *))GetFunction(
618 "GetStabilizerNumMeasurements");
619 CheckFunction((void *)fGetStabilizerNumMeasurements, __LINE__);
620 fGetStabilizerNumDetectors =
621 (long long (*)(void *))GetFunction("GetStabilizerNumDetectors");
622 CheckFunction((void *)fGetStabilizerNumDetectors, __LINE__);
623 fCopyStabilizerXTable = (int (*)(void *, unsigned int *))GetFunction(
624 "CopyStabilizerXTable");
625 CheckFunction((void *)fCopyStabilizerXTable, __LINE__);
626 fCopyStabilizerZTable = (int (*)(void *, unsigned int *))GetFunction(
627 "CopyStabilizerZTable");
628 CheckFunction((void *)fCopyStabilizerZTable, __LINE__);
629 fCopyStabilizerMTable = (int (*)(void *, unsigned int *))GetFunction(
630 "CopyStabilizerMTable");
631 CheckFunction((void *)fCopyStabilizerMTable, __LINE__);
632
633 fInitStabilizerXTable =
634 (int (*)(void *, const unsigned int *))GetFunction("InitXTable");
635 CheckFunction((void *)fInitStabilizerXTable, __LINE__);
636 fInitStabilizerZTable =
637 (int (*)(void *, const unsigned int *))GetFunction("InitZTable");
638 CheckFunction((void *)fInitStabilizerZTable, __LINE__);
639
640 // pauli propagation functions
641 fCreatePauliPropSimulator =
642 (void *(*)(int))GetFunction("CreatePauliPropSimulator");
643 CheckFunction((void *)fCreatePauliPropSimulator, __LINE__);
644 fDestroyPauliPropSimulator =
645 (void (*)(void *))GetFunction("DestroyPauliPropSimulator");
646 CheckFunction((void *)fDestroyPauliPropSimulator, __LINE__);
647
648 fPauliPropGetNrQubits =
649 (int (*)(void *))GetFunction("PauliPropGetNrQubits");
650 CheckFunction((void *)fPauliPropGetNrQubits, __LINE__);
651 fPauliPropSetWillUseSampling =
652 (int (*)(void *, int))GetFunction("PauliPropSetWillUseSampling");
653 CheckFunction((void *)fPauliPropSetWillUseSampling, __LINE__);
654 fPauliPropGetWillUseSampling =
655 (int (*)(void *))GetFunction("PauliPropGetWillUseSampling");
656 CheckFunction((void *)fPauliPropGetWillUseSampling, __LINE__);
657
658 fPauliPropGetCoefficientTruncationCutoff = (double (*)(
659 void *))GetFunction("PauliPropGetCoefficientTruncationCutoff");
660 CheckFunction((void *)fPauliPropGetCoefficientTruncationCutoff,
661 __LINE__);
662 fPauliPropSetCoefficientTruncationCutoff =
663 (void (*)(void *, double))GetFunction(
664 "PauliPropSetCoefficientTruncationCutoff");
665 CheckFunction((void *)fPauliPropSetCoefficientTruncationCutoff,
666 __LINE__);
667 fPauliPropGetWeightTruncationCutoff = (double (*)(void *))GetFunction(
668 "PauliPropGetWeightTruncationCutoff");
669 CheckFunction((void *)fPauliPropGetWeightTruncationCutoff, __LINE__);
670 fPauliPropSetWeightTruncationCutoff = (void (*)(
671 void *, double))GetFunction("PauliPropSetWeightTruncationCutoff");
672 CheckFunction((void *)fPauliPropSetWeightTruncationCutoff, __LINE__);
673 fPauliPropGetNumGatesBetweenTruncations = (int (*)(
674 void *))GetFunction("PauliPropGetNumGatesBetweenTruncations");
675 CheckFunction((void *)fPauliPropGetNumGatesBetweenTruncations,
676 __LINE__);
677 fPauliPropSetNumGatesBetweenTruncations =
678 (void (*)(void *, int))GetFunction(
679 "PauliPropSetNumGatesBetweenTruncations");
680 CheckFunction((void *)fPauliPropSetNumGatesBetweenTruncations,
681 __LINE__);
682 fPauliPropGetNumGatesBetweenDeduplications = (int (*)(
683 void *))GetFunction("PauliPropGetNumGatesBetweenDeduplications");
684 CheckFunction((void *)fPauliPropGetNumGatesBetweenDeduplications,
685 __LINE__);
686 fPauliPropSetNumGatesBetweenDeduplications =
687 (void (*)(void *, int))GetFunction(
688 "PauliPropSetNumGatesBetweenDeduplications");
689 CheckFunction((void *)fPauliPropSetNumGatesBetweenDeduplications,
690 __LINE__);
691
692 fPauliPropClearOperators =
693 (int (*)(void *))GetFunction("PauliPropClearOperators");
694 CheckFunction((void *)fPauliPropClearOperators, __LINE__);
695 fPauliPropAllocateMemory =
696 (int (*)(void *, double))GetFunction("PauliPropAllocateMemory");
697 CheckFunction((void *)fPauliPropAllocateMemory, __LINE__);
698
699 fPauliPropGetExpectationValue =
700 (double (*)(void *))GetFunction("PauliPropGetExpectationValue");
701 CheckFunction((void *)fPauliPropGetExpectationValue, __LINE__);
702 fPauliPropExecute = (int (*)(void *))GetFunction("PauliPropExecute");
703 CheckFunction((void *)fPauliPropExecute, __LINE__);
704 fPauliPropSetInPauliExpansionUnique =
705 (int (*)(void *, const char *))GetFunction(
706 "PauliPropSetInPauliExpansionUnique");
707 CheckFunction((void *)fPauliPropSetInPauliExpansionUnique, __LINE__);
708 fPauliPropSetInPauliExpansionMultiple =
709 (int (*)(void *, const char **, const double *, int))GetFunction(
710 "PauliPropSetInPauliExpansionMultiple");
711 CheckFunction((void *)fPauliPropSetInPauliExpansionMultiple,
712 __LINE__);
713
714 fPauliPropApplyX =
715 (int (*)(void *, int))GetFunction("PauliPropApplyX");
716 CheckFunction((void *)fPauliPropApplyX, __LINE__);
717 fPauliPropApplyY =
718 (int (*)(void *, int))GetFunction("PauliPropApplyY");
719 CheckFunction((void *)fPauliPropApplyY, __LINE__);
720 fPauliPropApplyZ =
721 (int (*)(void *, int))GetFunction("PauliPropApplyZ");
722 CheckFunction((void *)fPauliPropApplyZ, __LINE__);
723 fPauliPropApplyH =
724 (int (*)(void *, int))GetFunction("PauliPropApplyH");
725 CheckFunction((void *)fPauliPropApplyH, __LINE__);
726 fPauliPropApplyS =
727 (int (*)(void *, int))GetFunction("PauliPropApplyS");
728 CheckFunction((void *)fPauliPropApplyS, __LINE__);
729
730 fPauliPropApplySQRTX =
731 (int (*)(void *, int))GetFunction("PauliPropApplySQRTX");
732 CheckFunction((void *)fPauliPropApplySQRTX, __LINE__);
733 fPauliPropApplySQRTY =
734 (int (*)(void *, int))GetFunction("PauliPropApplySQRTY");
735 CheckFunction((void *)fPauliPropApplySQRTY, __LINE__);
736 fPauliPropApplySQRTZ =
737 (int (*)(void *, int))GetFunction("PauliPropApplySQRTZ");
738 CheckFunction((void *)fPauliPropApplySQRTZ, __LINE__);
739 fPauliPropApplyCX =
740 (int (*)(void *, int, int))GetFunction("PauliPropApplyCX");
741 CheckFunction((void *)fPauliPropApplyCX, __LINE__);
742 fPauliPropApplyCY =
743 (int (*)(void *, int, int))GetFunction("PauliPropApplyCY");
744 CheckFunction((void *)fPauliPropApplyCY, __LINE__);
745 fPauliPropApplyCZ =
746 (int (*)(void *, int, int))GetFunction("PauliPropApplyCZ");
747 CheckFunction((void *)fPauliPropApplyCZ, __LINE__);
748 fPauliPropApplySWAP =
749 (int (*)(void *, int, int))GetFunction("PauliPropApplySWAP");
750 CheckFunction((void *)fPauliPropApplySWAP, __LINE__);
751 fPauliPropApplyISWAP =
752 (int (*)(void *, int, int))GetFunction("PauliPropApplyISWAP");
753 CheckFunction((void *)fPauliPropApplyISWAP, __LINE__);
754 fPauliPropApplyRX =
755 (int (*)(void *, int, double))GetFunction("PauliPropApplyRX");
756 CheckFunction((void *)fPauliPropApplyRX, __LINE__);
757 fPauliPropApplyRY =
758 (int (*)(void *, int, double))GetFunction("PauliPropApplyRY");
759 CheckFunction((void *)fPauliPropApplyRY, __LINE__);
760 fPauliPropApplyRZ =
761 (int (*)(void *, int, double))GetFunction("PauliPropApplyRZ");
762 CheckFunction((void *)fPauliPropApplyRZ, __LINE__);
763
764 fPauliPropAddNoiseX =
765 (int (*)(void *, int, double))GetFunction("PauliPropAddNoiseX");
766 CheckFunction((void *)fPauliPropAddNoiseX, __LINE__);
767 fPauliPropAddNoiseY =
768 (int (*)(void *, int, double))GetFunction("PauliPropAddNoiseY");
769 CheckFunction((void *)fPauliPropAddNoiseY, __LINE__);
770 fPauliPropAddNoiseZ =
771 (int (*)(void *, int, double))GetFunction("PauliPropAddNoiseZ");
772 CheckFunction((void *)fPauliPropAddNoiseZ, __LINE__);
773 fPauliPropAddNoiseXYZ =
774 (int (*)(void *, int, double, double, double))GetFunction(
775 "PauliPropAddNoiseXYZ");
776 CheckFunction((void *)fPauliPropAddNoiseXYZ, __LINE__);
777 fPauliPropAddAmplitudeDamping =
778 (int (*)(void *, int, double, double))GetFunction(
779 "PauliPropAddAmplitudeDamping");
780 CheckFunction((void *)fPauliPropAddAmplitudeDamping, __LINE__);
781 fPauliPropQubitProbability0 = (double (*)(void *, int))GetFunction(
782 "PauliPropQubitProbability0");
783 CheckFunction((void *)fPauliPropQubitProbability0, __LINE__);
784 fPauliPropProbability =
785 (double (*)(void *, unsigned long long int))GetFunction(
786 "PauliPropProbability");
787 CheckFunction((void *)fPauliPropProbability, __LINE__);
788
789 fPauliPropMeasureQubit =
790 (int (*)(void *, int))GetFunction("PauliPropMeasureQubit");
791 CheckFunction((void *)fPauliPropMeasureQubit, __LINE__);
792
793 fPauliPropSampleQubits =
794 (unsigned char *(*)(void *, const int *, int))GetFunction(
795 "PauliPropSampleQubits");
796 CheckFunction((void *)fPauliPropSampleQubits, __LINE__);
797 fPauliPropFreeSampledQubits = (void (*)(unsigned char *))GetFunction(
798 "PauliPropFreeSampledQubits");
799 CheckFunction((void *)fPauliPropFreeSampledQubits, __LINE__);
800 fPauliPropSaveState =
801 (void (*)(void *))GetFunction("PauliPropSaveState");
802 CheckFunction((void *)fPauliPropSaveState, __LINE__);
803 fPauliPropRestoreState =
804 (void (*)(void *))GetFunction("PauliPropRestoreState");
805 CheckFunction((void *)fPauliPropRestoreState, __LINE__);
806
807 return true;
808 } else
809 std::cerr << "GpuLibrary: Unable to initialize gpu library"
810 << std::endl;
811 } else
812 std::cerr << "GpuLibrary: Unable to get initialization function for "
813 "gpu library"
814 << std::endl;
815 } else if (!Utils::Library::IsMuted())
816 std::cerr << "GpuLibrary: Unable to load gpu library" << std::endl;
817
818 return false;
819 }
820
821 static void CheckFunction(void *func, int line) {
822 if (!func) {
823 std::cerr << "GpuLibrary: Unable to load function, line #: " << line;
824 const char *dlsym_error = dlerror();
825 if (dlsym_error) std::cerr << ", error: " << dlsym_error;
826
827 std::cerr << std::endl;
828 }
829 }
830
831 bool IsValid() const { return LibraryHandle != nullptr; }
832
833 // statevector functions
834
835 void *CreateStateVector() {
836 if (LibraryHandle)
837 return fCreateStateVector(LibraryHandle);
838 else
839 throw std::runtime_error("GpuLibrary: Unable to create state vector");
840 }
841
842 void DestroyStateVector(void *obj) {
843 if (LibraryHandle)
844 fDestroyStateVector(obj);
845 else
846 throw std::runtime_error("GpuLibrary: Unable to destroy state vector");
847 }
848
849 bool Create(void *obj, unsigned int nrQubits) {
850 if (LibraryHandle)
851 return fCreate(obj, nrQubits) == 1;
852 else
853 throw std::runtime_error(
854 "GpuLibrary: Unable to create state vector state");
855
856 return false;
857 }
858
859 bool CreateWithState(void *obj, unsigned int nrQubits, const double *state) {
860 if (LibraryHandle)
861 return fCreateWithState(obj, nrQubits, state) == 1;
862 else
863 throw std::runtime_error(
864 "GpuLibrary: Unable to create state vector state with a state");
865
866 return false;
867 }
868
869 bool Reset(void *obj) {
870 if (LibraryHandle)
871 return fReset(obj) == 1;
872 else
873 throw std::runtime_error("GpuLibrary: Unable to reset state vector");
874
875 return false;
876 }
877
878 bool SetDataType(void *obj, int dataType) {
879 if (LibraryHandle)
880 return fSetDataType(obj, dataType) == 1;
881 else
882 throw std::runtime_error("GpuLibrary: Unable to set data type");
883
884 return false;
885 }
886
887 bool IsDoublePrecision(void *obj) const {
888 if (LibraryHandle)
889 return fIsDoublePrecision(obj) == 1;
890 else
891 throw std::runtime_error(
892 "GpuLibrary: Unable to check if double precision");
893
894 return false;
895 }
896
897 int GetNrQubits(void *obj) const {
898 if (LibraryHandle)
899 return fGetNrQubits(obj);
900 else
901 throw std::runtime_error("GpuLibrary: Unable to get number of qubits");
902 return 0;
903 }
904
905 bool MeasureQubitCollapse(void *obj, int qubitIndex) {
906 if (LibraryHandle)
907 return fMeasureQubitCollapse(obj, qubitIndex) == 1;
908 else
909 throw std::runtime_error(
910 "GpuLibrary: Unable to measure qubit with collapse");
911
912 return false;
913 }
914
915 bool MeasureQubitNoCollapse(void *obj, int qubitIndex) {
916 if (LibraryHandle)
917 return fMeasureQubitNoCollapse(obj, qubitIndex) == 1;
918 else
919 throw std::runtime_error(
920 "GpuLibrary: Unable to measure qubit no collapse");
921
922 return false;
923 }
924
925 bool MeasureQubitsCollapse(void *obj, int *qubits, int *bitstring,
926 int bitstringLen) {
927 if (LibraryHandle)
928 return fMeasureQubitsCollapse(obj, qubits, bitstring, bitstringLen) == 1;
929 else
930 throw std::runtime_error(
931 "GpuLibrary: Unable to measure qubits with collapse");
932
933 return false;
934 }
935
936 bool MeasureQubitsNoCollapse(void *obj, int *qubits, int *bitstring,
937 int bitstringLen) {
938 if (LibraryHandle)
939 return fMeasureQubitsNoCollapse(obj, qubits, bitstring, bitstringLen) ==
940 1;
941 else
942 throw std::runtime_error(
943 "GpuLibrary: Unable to measure qubits with no collapse");
944
945 return false;
946 }
947
948 unsigned long long MeasureAllQubitsCollapse(void *obj) {
949 if (LibraryHandle)
950 return fMeasureAllQubitsCollapse(obj);
951 else
952 throw std::runtime_error(
953 "GpuLibrary: Unable to measure all qubits with collapse");
954
955 return 0;
956 }
957
958 unsigned long long MeasureAllQubitsNoCollapse(void *obj) {
959 if (LibraryHandle)
960 return fMeasureAllQubitsNoCollapse(obj);
961 else
962 throw std::runtime_error(
963 "GpuLibrary: Unable to measure all qubits with no collapse");
964
965 return 0;
966 }
967
968 bool SaveState(void *obj) {
969 if (LibraryHandle)
970 return fSaveState(obj) == 1;
971 else
972 throw std::runtime_error("GpuLibrary: Unable to save state");
973
974 return false;
975 }
976
977 bool SaveStateToHost(void *obj) {
978 if (LibraryHandle)
979 return fSaveStateToHost(obj) == 1;
980 else
981 throw std::runtime_error("GpuLibrary: Unable to save state to host");
982
983 return false;
984 }
985
986 bool SaveStateDestructive(void *obj) {
987 if (LibraryHandle)
988 return fSaveStateDestructive(obj) == 1;
989 else
990 throw std::runtime_error(
991 "GpuLibrary: Unable to save state destructively");
992
993 return false;
994 }
995
996 bool RestoreStateFreeSaved(void *obj) {
997 if (LibraryHandle)
998 return fRestoreStateFreeSaved(obj) == 1;
999 else
1000 throw std::runtime_error(
1001 "GpuLibrary: Unable to restore state free saved");
1002
1003 return false;
1004 }
1005
1006 bool RestoreStateNoFreeSaved(void *obj) {
1007 if (LibraryHandle)
1008 return fRestoreStateNoFreeSaved(obj) == 1;
1009 else
1010 throw std::runtime_error(
1011 "GpuLibrary: Unable to restore state no free saved");
1012
1013 return false;
1014 }
1015
1016 void FreeSavedState(void *obj) {
1017 if (LibraryHandle)
1018 fFreeSavedState(obj);
1019 else
1020 throw std::runtime_error("GpuLibrary: Unable to free saved state");
1021 }
1022
1023 void *Clone(void *obj) const {
1024 if (LibraryHandle)
1025 return fClone(obj);
1026 else
1027 throw std::runtime_error("GpuLibrary: Unable to clone state vector");
1028
1029 return nullptr;
1030 }
1031
1032 bool Sample(void *obj, unsigned int nSamples, long int *samples,
1033 unsigned int nBits, int *bits) {
1034 if (LibraryHandle)
1035 return fSample(obj, nSamples, samples, nBits, bits) == 1;
1036 else
1037 throw std::runtime_error("GpuLibrary: Unable to sample state vector");
1038
1039 return false;
1040 }
1041
1042 bool SampleAll(void *obj, unsigned int nSamples, long int *samples) {
1043 if (LibraryHandle)
1044 return fSampleAll(obj, nSamples, samples) == 1;
1045 else
1046 throw std::runtime_error("GpuLibrary: Unable to sample state vector");
1047
1048 return false;
1049 }
1050
1051 bool Amplitude(void *obj, long long int state, double *real,
1052 double *imaginary) const {
1053 if (LibraryHandle)
1054 return fAmplitude(obj, state, real, imaginary) == 1;
1055 else
1056 throw std::runtime_error("GpuLibrary: Unable to get amplitude");
1057
1058 return false;
1059 }
1060
1061 double Probability(void *obj, int *qubits, int *mask, int len) const {
1062 if (LibraryHandle)
1063 return fProbability(obj, qubits, mask, len);
1064 else
1065 throw std::runtime_error("GpuLibrary: Unable to get probability");
1066
1067 return 0;
1068 }
1069
1070 double BasisStateProbability(void *obj, long long int state) const {
1071 if (LibraryHandle)
1072 return fBasisStateProbability(obj, state);
1073 else
1074 throw std::runtime_error(
1075 "GpuLibrary: Unable to get basis state probability");
1076
1077 return 0;
1078 }
1079
1080 bool AllProbabilities(void *obj, double *probabilities) const {
1081 if (LibraryHandle)
1082 return fAllProbabilities(obj, probabilities) == 1;
1083 else
1084 throw std::runtime_error("GpuLibrary: Unable to get all probabilities");
1085
1086 return false;
1087 }
1088
1089 double ExpectationValue(void *obj, const char *pauliString, int len) const {
1090 if (LibraryHandle)
1091 return fExpectationValue(obj, pauliString, len);
1092 else
1093 throw std::runtime_error("GpuLibrary: Unable to get expectation value");
1094
1095 return 0;
1096 }
1097
1098 bool ApplyX(void *obj, int qubit) {
1099 if (LibraryHandle)
1100 return fApplyX(obj, qubit) == 1;
1101 else
1102 throw std::runtime_error("GpuLibrary: Unable to apply X gate");
1103
1104 return false;
1105 }
1106
1107 bool ApplyY(void *obj, int qubit) {
1108 if (LibraryHandle)
1109 return fApplyY(obj, qubit) == 1;
1110 else
1111 throw std::runtime_error("GpuLibrary: Unable to apply Y gate");
1112
1113 return false;
1114 }
1115
1116 bool ApplyZ(void *obj, int qubit) {
1117 if (LibraryHandle)
1118 return fApplyZ(obj, qubit) == 1;
1119 else
1120 throw std::runtime_error("GpuLibrary: Unable to apply Z gate");
1121
1122 return false;
1123 }
1124
1125 bool ApplyH(void *obj, int qubit) {
1126 if (LibraryHandle)
1127 return fApplyH(obj, qubit) == 1;
1128 else
1129 throw std::runtime_error("GpuLibrary: Unable to apply H gate");
1130
1131 return false;
1132 }
1133
1134 bool ApplyS(void *obj, int qubit) {
1135 if (LibraryHandle)
1136 return fApplyS(obj, qubit) == 1;
1137 else
1138 throw std::runtime_error("GpuLibrary: Unable to apply S gate");
1139
1140 return false;
1141 }
1142
1143 bool ApplySDG(void *obj, int qubit) {
1144 if (LibraryHandle)
1145 return fApplySDG(obj, qubit) == 1;
1146 else
1147 throw std::runtime_error("GpuLibrary: Unable to apply SDG gate");
1148
1149 return false;
1150 }
1151
1152 bool ApplyT(void *obj, int qubit) {
1153 if (LibraryHandle)
1154 return fApplyT(obj, qubit) == 1;
1155 else
1156 throw std::runtime_error("GpuLibrary: Unable to apply T gate");
1157
1158 return false;
1159 }
1160
1161 bool ApplyTDG(void *obj, int qubit) {
1162 if (LibraryHandle)
1163 return fApplyTDG(obj, qubit) == 1;
1164 else
1165 throw std::runtime_error("GpuLibrary: Unable to apply TDG gate");
1166
1167 return false;
1168 }
1169
1170 bool ApplySX(void *obj, int qubit) {
1171 if (LibraryHandle)
1172 return fApplySX(obj, qubit) == 1;
1173 else
1174 throw std::runtime_error("GpuLibrary: Unable to apply SX gate");
1175
1176 return false;
1177 }
1178
1179 bool ApplySXDG(void *obj, int qubit) {
1180 if (LibraryHandle)
1181 return fApplySXDG(obj, qubit) == 1;
1182 else
1183 throw std::runtime_error("GpuLibrary: Unable to apply SXDG gate");
1184
1185 return false;
1186 }
1187
1188 bool ApplyK(void *obj, int qubit) {
1189 if (LibraryHandle)
1190 return fApplyK(obj, qubit) == 1;
1191 else
1192 throw std::runtime_error("GpuLibrary: Unable to apply K gate");
1193
1194 return false;
1195 }
1196
1197 bool ApplyP(void *obj, int qubit, double theta) {
1198 if (LibraryHandle)
1199 return fApplyP(obj, qubit, theta) == 1;
1200 else
1201 throw std::runtime_error("GpuLibrary: Unable to apply P gate");
1202
1203 return false;
1204 }
1205
1206 bool ApplyRx(void *obj, int qubit, double theta) {
1207 if (LibraryHandle)
1208 return fApplyRx(obj, qubit, theta) == 1;
1209 else
1210 throw std::runtime_error("GpuLibrary: Unable to apply Rx gate");
1211
1212 return false;
1213 }
1214
1215 bool ApplyRy(void *obj, int qubit, double theta) {
1216 if (LibraryHandle)
1217 return fApplyRy(obj, qubit, theta) == 1;
1218 else
1219 throw std::runtime_error("GpuLibrary: Unable to apply Ry gate");
1220
1221 return false;
1222 }
1223
1224 bool ApplyRz(void *obj, int qubit, double theta) {
1225 if (LibraryHandle)
1226 return fApplyRz(obj, qubit, theta) == 1;
1227 else
1228 throw std::runtime_error("GpuLibrary: Unable to apply Rz gate");
1229
1230 return false;
1231 }
1232
1233 bool ApplyU(void *obj, int qubit, double theta, double phi, double lambda,
1234 double gamma) {
1235 if (LibraryHandle)
1236 return fApplyU(obj, qubit, theta, phi, lambda, gamma) == 1;
1237 else
1238 throw std::runtime_error("GpuLibrary: Unable to apply U gate");
1239
1240 return false;
1241 }
1242
1243 bool ApplyCX(void *obj, int controlQubit, int targetQubit) {
1244 if (LibraryHandle)
1245 return fApplyCX(obj, controlQubit, targetQubit) == 1;
1246 else
1247 throw std::runtime_error("GpuLibrary: Unable to apply CX gate");
1248
1249 return false;
1250 }
1251
1252 bool ApplyCY(void *obj, int controlQubit, int targetQubit) {
1253 if (LibraryHandle)
1254 return fApplyCY(obj, controlQubit, targetQubit) == 1;
1255 else
1256 throw std::runtime_error("GpuLibrary: Unable to apply CY gate");
1257
1258 return false;
1259 }
1260
1261 bool ApplyCZ(void *obj, int controlQubit, int targetQubit) {
1262 if (LibraryHandle)
1263 return fApplyCZ(obj, controlQubit, targetQubit) == 1;
1264 else
1265 throw std::runtime_error("GpuLibrary: Unable to apply CZ gate");
1266
1267 return false;
1268 }
1269
1270 bool ApplyCH(void *obj, int controlQubit, int targetQubit) {
1271 if (LibraryHandle)
1272 return fApplyCH(obj, controlQubit, targetQubit) == 1;
1273 else
1274 throw std::runtime_error("GpuLibrary: Unable to apply CH gate");
1275
1276 return false;
1277 }
1278
1279 bool ApplyCSX(void *obj, int controlQubit, int targetQubit) {
1280 if (LibraryHandle)
1281 return fApplyCSX(obj, controlQubit, targetQubit) == 1;
1282 else
1283 throw std::runtime_error("GpuLibrary: Unable to apply CSX gate");
1284
1285 return false;
1286 }
1287
1288 bool ApplyCSXDG(void *obj, int controlQubit, int targetQubit) {
1289 if (LibraryHandle)
1290 return fApplyCSXDG(obj, controlQubit, targetQubit) == 1;
1291 else
1292 throw std::runtime_error("GpuLibrary: Unable to apply CSXDG gate");
1293
1294 return false;
1295 }
1296
1297 bool ApplyCP(void *obj, int controlQubit, int targetQubit, double theta) {
1298 if (LibraryHandle)
1299 return fApplyCP(obj, controlQubit, targetQubit, theta) == 1;
1300 else
1301 throw std::runtime_error("GpuLibrary: Unable to apply CP gate");
1302
1303 return false;
1304 }
1305
1306 bool ApplyCRx(void *obj, int controlQubit, int targetQubit, double theta) {
1307 if (LibraryHandle)
1308 return fApplyCRx(obj, controlQubit, targetQubit, theta) == 1;
1309 else
1310 throw std::runtime_error("GpuLibrary: Unable to apply CRx gate");
1311
1312 return false;
1313 }
1314
1315 bool ApplyCRy(void *obj, int controlQubit, int targetQubit, double theta) {
1316 if (LibraryHandle)
1317 return fApplyCRy(obj, controlQubit, targetQubit, theta) == 1;
1318 else
1319 throw std::runtime_error("GpuLibrary: Unable to apply CRy gate");
1320
1321 return false;
1322 }
1323
1324 bool ApplyCRz(void *obj, int controlQubit, int targetQubit, double theta) {
1325 if (LibraryHandle)
1326 return fApplyCRz(obj, controlQubit, targetQubit, theta) == 1;
1327 else
1328 throw std::runtime_error("GpuLibrary: Unable to apply CRz gate");
1329
1330 return false;
1331 }
1332
1333 bool ApplyCCX(void *obj, int controlQubit1, int controlQubit2,
1334 int targetQubit) {
1335 if (LibraryHandle)
1336 return fApplyCCX(obj, controlQubit1, controlQubit2, targetQubit) == 1;
1337 else
1338 throw std::runtime_error("GpuLibrary: Unable to apply CCX gate");
1339
1340 return false;
1341 }
1342
1343 bool ApplySwap(void *obj, int qubit1, int qubit2) {
1344 if (LibraryHandle)
1345 return fApplySwap(obj, qubit1, qubit2) == 1;
1346 else
1347 throw std::runtime_error("GpuLibrary: Unable to apply Swap gate");
1348
1349 return false;
1350 }
1351
1352 bool ApplyCSwap(void *obj, int controlQubit, int qubit1, int qubit2) {
1353 if (LibraryHandle)
1354 return fApplyCSwap(obj, controlQubit, qubit1, qubit2) == 1;
1355 else
1356 throw std::runtime_error("GpuLibrary: Unable to apply CSwap gate");
1357
1358 return false;
1359 }
1360
1361 bool ApplyCU(void *obj, int controlQubit, int targetQubit, double theta,
1362 double phi, double lambda, double gamma) {
1363 if (LibraryHandle)
1364 return fApplyCU(obj, controlQubit, targetQubit, theta, phi, lambda,
1365 gamma) == 1;
1366 else
1367 throw std::runtime_error("GpuLibrary: Unable to apply CU gate");
1368
1369 return false;
1370 }
1371
1372 // mps functions
1373
1374 void *CreateMPS() {
1375 if (LibraryHandle)
1376 return fCreateMPS(LibraryHandle);
1377 else
1378 throw std::runtime_error("GpuLibrary: Unable to create mps");
1379 }
1380
1381 void DestroyMPS(void *obj) {
1382 if (LibraryHandle)
1383 fDestroyMPS(obj);
1384 else
1385 throw std::runtime_error("GpuLibrary: Unable to destroy mps");
1386 }
1387
1388 bool MPSCreate(void *obj, unsigned int nrQubits) {
1389 if (LibraryHandle)
1390 return fMPSCreate(obj, nrQubits) == 1;
1391 else
1392 throw std::runtime_error(
1393 "GpuLibrary: Unable to create mps with the "
1394 "specified number of qubits");
1395
1396 return false;
1397 }
1398
1399 bool MPSReset(void *obj) {
1400 if (LibraryHandle)
1401 return fMPSReset(obj) == 1;
1402 else
1403 throw std::runtime_error("GpuLibrary: Unable to reset mps");
1404
1405 return false;
1406 }
1407
1408 bool MPSSetInitialQubitsMap(void *obj,
1409 const std::vector<long long int> &initialMap) {
1410 if (LibraryHandle)
1411 return fMPSSetInitialQubitsMap(obj, initialMap.data(),
1412 initialMap.size()) == 1;
1413 else
1414 throw std::runtime_error(
1415 "GpuLibrary: Unable to set initial qubits map for mps");
1416
1417 return false;
1418 }
1419
1420 bool MPSSetUseOptimalMeetingPosition(void *obj, int val) {
1421 if (LibraryHandle)
1422 return fMPSSetUseOptimalMeetingPosition(obj, val) == 1;
1423 else
1424 throw std::runtime_error(
1425 "GpuLibrary: Unable to set use optimal meeting position for mps");
1426 return false;
1427 }
1428
1429 bool MPSIsValid(void *obj) const {
1430 if (LibraryHandle)
1431 return fMPSIsValid(obj) == 1;
1432 else
1433 throw std::runtime_error("GpuLibrary: Unable to check if mps is valid");
1434
1435 return false;
1436 }
1437
1438 bool MPSIsCreated(void *obj) const {
1439 if (LibraryHandle)
1440 return fMPSIsCreated(obj) == 1;
1441 else
1442 throw std::runtime_error("GpuLibrary: Unable to check if mps is created");
1443
1444 return false;
1445 }
1446
1447 bool MPSSetDataType(void *obj, int useDoublePrecision) {
1448 if (LibraryHandle)
1449 return fMPSSetDataType(obj, useDoublePrecision) == 1;
1450 else
1451 throw std::runtime_error("GpuLibrary: Unable to set precision for mps");
1452
1453 return false;
1454 }
1455
1456 bool MPSIsDoublePrecision(void *obj) const {
1457 if (LibraryHandle)
1458 return fMPSIsDoublePrecision(obj) == 1;
1459 else
1460 throw std::runtime_error("GpuLibrary: Unable to get precision for mps");
1461
1462 return false;
1463 }
1464
1465 bool MPSSetCutoff(void *obj, double val) {
1466 if (LibraryHandle)
1467 return fMPSSetCutoff(obj, val) == 1;
1468 else
1469 throw std::runtime_error("GpuLibrary: Unable to set cutoff for mps");
1470
1471 return false;
1472 }
1473
1474 double MPSGetCutoff(void *obj) const {
1475 if (LibraryHandle)
1476 return fMPSGetCutoff(obj);
1477 else
1478 throw std::runtime_error("GpuLibrary: Unable to get cutoff for mps");
1479 }
1480
1481 bool MPSSetGesvdJ(void *obj, int val) {
1482 if (LibraryHandle)
1483 return fMPSSetGesvdJ(obj, val) == 1;
1484 else
1485 throw std::runtime_error("GpuLibrary: Unable to set GesvdJ for mps");
1486
1487 return false;
1488 }
1489
1490 bool MPSGetGesvdJ(void *obj) const {
1491 if (LibraryHandle)
1492 return fMPSGetGesvdJ(obj) == 1;
1493 else
1494 throw std::runtime_error("GpuLibrary: Unable to get GesvdJ for mps");
1495
1496 return false;
1497 }
1498
1499 bool MPSSetMaxExtent(void *obj, long int val) {
1500 if (LibraryHandle)
1501 return fMPSSetMaxExtent(obj, val) == 1;
1502 else
1503 throw std::runtime_error("GpuLibrary: Unable to set max extent for mps");
1504
1505 return false;
1506 }
1507
1508 long int MPSGetMaxExtent(void *obj) {
1509 if (LibraryHandle)
1510 return fMPSGetMaxExtent(obj);
1511 else
1512 throw std::runtime_error("GpuLibrary: Unable to get max extent for mps");
1513
1514 return 0;
1515 }
1516
1517 int MPSGetNrQubits(void *obj) {
1518 if (LibraryHandle)
1519 return fMPSGetNrQubits(obj);
1520 else
1521 throw std::runtime_error("GpuLibrary: Unable to get nr qubits for mps");
1522
1523 return 0;
1524 }
1525
1526 bool MPSSetCallbackContext(void *obj, void *context) {
1527 if (LibraryHandle)
1528 return fMPSSetCallbackContext(obj, context) == 1;
1529 else
1530 throw std::runtime_error(
1531 "GpuLibrary: Unable to set callback context for mps");
1532 return false;
1533 }
1534
1535 bool MPSSetMeetingPositionCallback(void *obj, int64_t(*callback)(void*, const int64_t*)) {
1536 if (LibraryHandle)
1537 return fMPSSetMeetingPositionCallback(obj, callback) == 1;
1538 else
1539 throw std::runtime_error(
1540 "GpuLibrary: Unable to set meeting position callback for mps");
1541 return false;
1542 }
1543
1544 bool MPSAmplitude(void *obj, long int numFixedValues, long int *fixedValues,
1545 double *real, double *imaginary) {
1546 if (LibraryHandle)
1547 return fMPSAmplitude(obj, numFixedValues, fixedValues, real, imaginary) ==
1548 1;
1549 else
1550 throw std::runtime_error("GpuLibrary: Unable to get mps amplitude");
1551
1552 return false;
1553 }
1554
1555 double MPSProbability0(void *obj, unsigned int qubit) {
1556 if (LibraryHandle)
1557 return fMPSProbability0(obj, qubit);
1558 else
1559 throw std::runtime_error(
1560 "GpuLibrary: Unable to get probability for 0 for mps");
1561
1562 return 0.0;
1563 }
1564
1565 bool MPSMeasure(void *obj, unsigned int qubit) {
1566 if (LibraryHandle)
1567 return fMPSMeasure(obj, qubit) == 1;
1568 else
1569 throw std::runtime_error("GpuLibrary: Unable to measure qubit on mps");
1570
1571 return false;
1572 }
1573
1574 bool MPSMeasureQubits(void *obj, long int numQubits, unsigned int *qubits,
1575 int *result) {
1576 if (LibraryHandle)
1577 return fMPSMeasureQubits(obj, numQubits, qubits, result) == 1;
1578 else
1579 throw std::runtime_error("GpuLibrary: Unable to measure qubits on mps");
1580
1581 return false;
1582 }
1583
1584 std::unordered_map<std::vector<bool>, int64_t> *MPSGetMapForSample() {
1585 if (LibraryHandle)
1586 return (std::unordered_map<std::vector<bool>, int64_t> *)
1587 fMPSGetMapForSample();
1588 else
1589 throw std::runtime_error(
1590 "GpuLibrary: Unable to get map for sample for mps");
1591
1592 return nullptr;
1593 }
1594
1595 bool MPSFreeMapForSample(
1596 std::unordered_map<std::vector<bool>, int64_t> *map) {
1597 if (LibraryHandle)
1598 return fMPSFreeMapForSample((void *)map) == 1;
1599 else
1600 throw std::runtime_error(
1601 "GpuLibrary: Unable to free map for sample for mps");
1602
1603 return false;
1604 }
1605
1606 bool MPSSample(void *obj, long int numShots, long int numQubits,
1607 unsigned int *qubits, void *resultMap) {
1608 if (LibraryHandle)
1609 return fMPSSample(obj, numShots, numQubits, qubits, resultMap) == 1;
1610 else
1611 throw std::runtime_error("GpuLibrary: Unable to sample mps");
1612
1613 return false;
1614 }
1615
1616 bool MPSSaveState(void *obj) {
1617 if (LibraryHandle)
1618 return fMPSSaveState(obj) == 1;
1619 else
1620 throw std::runtime_error("GpuLibrary: Unable to save mps state");
1621
1622 return false;
1623 }
1624
1625 bool MPSRestoreState(void *obj) {
1626 if (LibraryHandle)
1627 return fMPSRestoreState(obj) == 1;
1628 else
1629 throw std::runtime_error("GpuLibrary: Unable to restore mps state");
1630
1631 return false;
1632 }
1633
1634 bool MPSCleanSavedState(void *obj) {
1635 if (LibraryHandle)
1636 return fMPSCleanSavedState(obj) == 1;
1637 else
1638 throw std::runtime_error("GpuLibrary: Unable to clean mps saved state");
1639
1640 return false;
1641 }
1642
1643 void *MPSClone(void *obj) {
1644 if (LibraryHandle)
1645 return fMPSClone(obj);
1646 else
1647 throw std::runtime_error("GpuLibrary: Unable to clone mps");
1648
1649 return nullptr;
1650 }
1651
1652 double MPSExpectationValue(void *obj, const char *pauliString,
1653 int len) const {
1654 if (LibraryHandle)
1655 return fMPSExpectationValue(obj, pauliString, len);
1656 else
1657 throw std::runtime_error(
1658 "GpuLibrary: Unable to get mps expectation value");
1659
1660 return 0;
1661 }
1662
1663 std::complex<double> MPSProjectOnZero(void* obj)
1664 {
1665 if (LibraryHandle) {
1666 double real, imag;
1667 if (fMPSProjectOnZero(obj, &real, &imag) == 1)
1668 return std::complex<double>(real, imag);
1669 else
1670 throw std::runtime_error(
1671 "GpuLibrary: Unable to project on zero for mps");
1672 } else
1673 throw std::runtime_error(
1674 "GpuLibrary: Unable to project on zero for mps, library handle is null");
1675
1676 return std::complex<double>(0, 0);
1677 }
1678
1679 bool MPSApplyX(void *obj, unsigned int siteA) {
1680 if (LibraryHandle)
1681 return fMPSApplyX(obj, siteA) == 1;
1682 else
1683 throw std::runtime_error("GpuLibrary: Unable to apply X gate on mps");
1684
1685 return false;
1686 }
1687
1688 bool MPSApplyY(void *obj, unsigned int siteA) {
1689 if (LibraryHandle)
1690 return fMPSApplyY(obj, siteA) == 1;
1691 else
1692 throw std::runtime_error("GpuLibrary: Unable to apply Y gate on mps");
1693
1694 return false;
1695 }
1696
1697 bool MPSApplyZ(void *obj, unsigned int siteA) {
1698 if (LibraryHandle)
1699 return fMPSApplyZ(obj, siteA) == 1;
1700 else
1701 throw std::runtime_error("GpuLibrary: Unable to apply Z gate on mps");
1702
1703 return false;
1704 }
1705
1706 bool MPSApplyH(void *obj, unsigned int siteA) {
1707 if (LibraryHandle)
1708 return fMPSApplyH(obj, siteA) == 1;
1709 else
1710 throw std::runtime_error("GpuLibrary: Unable to apply H gate on mps");
1711
1712 return false;
1713 }
1714
1715 bool MPSApplyS(void *obj, unsigned int siteA) {
1716 if (LibraryHandle)
1717 return fMPSApplyS(obj, siteA) == 1;
1718 else
1719 throw std::runtime_error("GpuLibrary: Unable to apply S gate on mps");
1720
1721 return false;
1722 }
1723
1724 bool MPSApplySDG(void *obj, unsigned int siteA) {
1725 if (LibraryHandle)
1726 return fMPSApplySDG(obj, siteA) == 1;
1727 else
1728 throw std::runtime_error("GpuLibrary: Unable to apply sdg gate on mps");
1729
1730 return false;
1731 }
1732
1733 bool MPSApplyT(void *obj, unsigned int siteA) {
1734 if (LibraryHandle)
1735 return fMPSApplyT(obj, siteA) == 1;
1736 else
1737 throw std::runtime_error("GpuLibrary: Unable to apply t gate on mps");
1738
1739 return false;
1740 }
1741
1742 bool MPSApplyTDG(void *obj, unsigned int siteA) {
1743 if (LibraryHandle)
1744 return fMPSApplyTDG(obj, siteA) == 1;
1745 else
1746 throw std::runtime_error("GpuLibrary: Unable to appl tdg gate on mps");
1747
1748 return false;
1749 }
1750
1751 bool MPSApplySX(void *obj, unsigned int siteA) {
1752 if (LibraryHandle)
1753 return fMPSApplySX(obj, siteA) == 1;
1754 else
1755 throw std::runtime_error("GpuLibrary: Unable to apply sx gate on mps");
1756
1757 return false;
1758 }
1759
1760 bool MPSApplySXDG(void *obj, unsigned int siteA) {
1761 if (LibraryHandle)
1762 return fMPSApplySXDG(obj, siteA) == 1;
1763 else
1764 throw std::runtime_error("GpuLibrary: Unable to apply sxdg gate on mps");
1765
1766 return false;
1767 }
1768
1769 bool MPSApplyK(void *obj, unsigned int siteA) {
1770 if (LibraryHandle)
1771 return fMPSApplyK(obj, siteA) == 1;
1772 else
1773 throw std::runtime_error("GpuLibrary: Unable to apply k gate on mps");
1774
1775 return false;
1776 }
1777
1778 bool MPSApplyP(void *obj, unsigned int siteA, double theta) {
1779 if (LibraryHandle)
1780 return fMPSApplyP(obj, siteA, theta) == 1;
1781 else
1782 throw std::runtime_error("GpuLibrary: Unable to apply p gate on mps");
1783 return false;
1784 }
1785
1786 bool MPSApplyRx(void *obj, unsigned int siteA, double theta) {
1787 if (LibraryHandle)
1788 return fMPSApplyRx(obj, siteA, theta) == 1;
1789 else
1790 throw std::runtime_error("GpuLibrary: Unable to apply rx gate on mps");
1791
1792 return false;
1793 }
1794
1795 bool MPSApplyRy(void *obj, unsigned int siteA, double theta) {
1796 if (LibraryHandle)
1797 return fMPSApplyRy(obj, siteA, theta) == 1;
1798 else
1799 throw std::runtime_error("GpuLibrary: Unable to apply ry gate on mps");
1800
1801 return false;
1802 }
1803
1804 bool MPSApplyRz(void *obj, unsigned int siteA, double theta) {
1805 if (LibraryHandle)
1806 return fMPSApplyRz(obj, siteA, theta) == 1;
1807 else
1808 throw std::runtime_error("GpuLibrary: Unable to apply rz gate on mps");
1809
1810 return false;
1811 }
1812
1813 bool MPSApplyU(void *obj, unsigned int siteA, double theta, double phi,
1814 double lambda, double gamma) {
1815 if (LibraryHandle)
1816 return fMPSApplyU(obj, siteA, theta, phi, lambda, gamma) == 1;
1817 else
1818 throw std::runtime_error("GpuLibrary: Unable to apply u gate on mps");
1819
1820 return false;
1821 }
1822
1823 bool MPSApplySwap(void *obj, unsigned int controlQubit,
1824 unsigned int targetQubit) {
1825 if (LibraryHandle)
1826 return fMPSApplySwap(obj, controlQubit, targetQubit) == 1;
1827 else
1828 throw std::runtime_error("GpuLibrary: Unable to apply swap gate on mps");
1829
1830 return false;
1831 }
1832
1833 bool MPSApplyCX(void *obj, unsigned int controlQubit,
1834 unsigned int targetQubit) {
1835 if (LibraryHandle)
1836 return fMPSApplyCX(obj, controlQubit, targetQubit) == 1;
1837 else
1838 throw std::runtime_error("GpuLibrary: Unable to apply cx gate on mps");
1839
1840 return false;
1841 }
1842
1843 bool MPSApplyCY(void *obj, unsigned int controlQubit,
1844 unsigned int targetQubit) {
1845 if (LibraryHandle)
1846 return fMPSApplyCY(obj, controlQubit, targetQubit) == 1;
1847 else
1848 throw std::runtime_error("GpuLibrary: Unable to apply cy gate on mps");
1849
1850 return false;
1851 }
1852
1853 bool MPSApplyCZ(void *obj, unsigned int controlQubit,
1854 unsigned int targetQubit) {
1855 if (LibraryHandle)
1856 return fMPSApplyCZ(obj, controlQubit, targetQubit) == 1;
1857 else
1858 throw std::runtime_error("GpuLibrary: Unable to apply cz gate on mps");
1859
1860 return false;
1861 }
1862
1863 bool MPSApplyCH(void *obj, unsigned int controlQubit,
1864 unsigned int targetQubit) {
1865 if (LibraryHandle)
1866 return fMPSApplyCH(obj, controlQubit, targetQubit) == 1;
1867 else
1868 throw std::runtime_error("GpuLibrary: Unable to apply ch gate on mps");
1869
1870 return false;
1871 }
1872
1873 bool MPSApplyCSX(void *obj, unsigned int controlQubit,
1874 unsigned int targetQubit) {
1875 if (LibraryHandle)
1876 return fMPSApplyCSX(obj, controlQubit, targetQubit) == 1;
1877 else
1878 throw std::runtime_error("GpuLibrary: Unable to apply csx gate on mps");
1879 }
1880
1881 bool MPSApplyCSXDG(void *obj, unsigned int controlQubit,
1882 unsigned int targetQubit) {
1883 if (LibraryHandle)
1884 return fMPSApplyCSXDG(obj, controlQubit, targetQubit) == 1;
1885 else
1886 throw std::runtime_error("GpuLibrary: Unable to apply csxdg gate on mps");
1887
1888 return false;
1889 }
1890
1891 bool MPSApplyCP(void *obj, unsigned int controlQubit,
1892 unsigned int targetQubit, double theta) {
1893 if (LibraryHandle)
1894 return fMPSApplyCP(obj, controlQubit, targetQubit, theta) == 1;
1895 else
1896 throw std::runtime_error("GpuLibrary: Unable to apply cp gate on mps");
1897
1898 return false;
1899 }
1900
1901 bool MPSApplyCRx(void *obj, unsigned int controlQubit,
1902 unsigned int targetQubit, double theta) {
1903 if (LibraryHandle)
1904 return fMPSApplyCRx(obj, controlQubit, targetQubit, theta) == 1;
1905 else
1906 throw std::runtime_error("GpuLibrary: Unable to apply crx gate on mps");
1907
1908 return false;
1909 }
1910
1911 bool MPSApplyCRy(void *obj, unsigned int controlQubit,
1912 unsigned int targetQubit, double theta) {
1913 if (LibraryHandle)
1914 return fMPSApplyCRy(obj, controlQubit, targetQubit, theta) == 1;
1915 else
1916 throw std::runtime_error("GpuLibrary: Unable to apply cry gate on mps");
1917
1918 return false;
1919 }
1920
1921 bool MPSApplyCRz(void *obj, unsigned int controlQubit,
1922 unsigned int targetQubit, double theta) {
1923 if (LibraryHandle)
1924 return fMPSApplyCRz(obj, controlQubit, targetQubit, theta) == 1;
1925 else
1926 throw std::runtime_error("GpuLibrary: Unable to apply crz gate on mps");
1927
1928 return false;
1929 }
1930
1931 bool MPSApplyCU(void *obj, unsigned int controlQubit,
1932 unsigned int targetQubit, double theta, double phi,
1933 double lambda, double gamma) {
1934 if (LibraryHandle)
1935 return fMPSApplyCU(obj, controlQubit, targetQubit, theta, phi, lambda,
1936 gamma) == 1;
1937 else
1938 throw std::runtime_error("GpuLibrary: Unable to apply cu gate on mps");
1939
1940 return false;
1941 }
1942
1943 // tensor network functions
1944
1945 void *CreateTensorNet() {
1946 if (LibraryHandle)
1947 return fCreateTensorNet(LibraryHandle);
1948 else
1949 throw std::runtime_error("GpuLibrary: Unable to create tensor network");
1950 }
1951
1952 void DestroyTensorNet(void *obj) {
1953 if (LibraryHandle)
1954 fDestroyTensorNet(obj);
1955 else
1956 throw std::runtime_error("GpuLibrary: Unable to destroy tensor network");
1957 }
1958
1959 bool TNCreate(void *obj, unsigned int nrQubits) {
1960 if (LibraryHandle)
1961 return fTNCreate(obj, nrQubits) == 1;
1962 else
1963 throw std::runtime_error(
1964 "GpuLibrary: Unable to create tensor network with the "
1965 "specified number of qubits");
1966
1967 return false;
1968 }
1969
1970 bool TNReset(void *obj) {
1971 if (LibraryHandle)
1972 return fTNReset(obj) == 1;
1973 else
1974 throw std::runtime_error("GpuLibrary: Unable to reset tensor network");
1975
1976 return false;
1977 }
1978
1979 bool TNIsValid(void *obj) const {
1980 if (LibraryHandle)
1981 return fTNIsValid(obj) == 1;
1982 else
1983 throw std::runtime_error(
1984 "GpuLibrary: Unable to check if tensor network is valid");
1985
1986 return false;
1987 }
1988
1989 bool TNIsCreated(void *obj) const {
1990 if (LibraryHandle)
1991 return fTNIsCreated(obj) == 1;
1992 else
1993 throw std::runtime_error(
1994 "GpuLibrary: Unable to check if tensor network is created");
1995
1996 return false;
1997 }
1998
1999 bool TNSetDataType(void *obj, int useDoublePrecision) {
2000 if (LibraryHandle)
2001 return fTNSetDataType(obj, useDoublePrecision) == 1;
2002 else
2003 throw std::runtime_error(
2004 "GpuLibrary: Unable to set precision for tensor network");
2005
2006 return false;
2007 }
2008
2009 bool TNIsDoublePrecision(void *obj) const {
2010 if (LibraryHandle)
2011 return fTNIsDoublePrecision(obj) == 1;
2012 else
2013 throw std::runtime_error(
2014 "GpuLibrary: Unable to get precision for tensor network");
2015
2016 return false;
2017 }
2018
2019 bool TNSetCutoff(void *obj, double val) {
2020 if (LibraryHandle)
2021 return fTNSetCutoff(obj, val) == 1;
2022 else
2023 throw std::runtime_error(
2024 "GpuLibrary: Unable to set cutoff for tensor network");
2025
2026 return false;
2027 }
2028
2029 double TNGetCutoff(void *obj) const {
2030 if (LibraryHandle)
2031 return fTNGetCutoff(obj);
2032 else
2033 throw std::runtime_error(
2034 "GpuLibrary: Unable to get cutoff for tensor network");
2035 }
2036
2037 bool TNSetGesvdJ(void *obj, int val) {
2038 if (LibraryHandle)
2039 return fTNSetGesvdJ(obj, val) == 1;
2040 else
2041 throw std::runtime_error(
2042 "GpuLibrary: Unable to set GesvdJ for tensor network");
2043
2044 return false;
2045 }
2046
2047 bool TNGetGesvdJ(void *obj) const {
2048 if (LibraryHandle)
2049 return fTNGetGesvdJ(obj) == 1;
2050 else
2051 throw std::runtime_error(
2052 "GpuLibrary: Unable to get GesvdJ for tensor network");
2053
2054 return false;
2055 }
2056
2057 bool TNSetMaxExtent(void *obj, long int val) {
2058 if (LibraryHandle)
2059 return fTNSetMaxExtent(obj, val) == 1;
2060 else
2061 throw std::runtime_error(
2062 "GpuLibrary: Unable to set max extent for tensor network");
2063
2064 return false;
2065 }
2066
2067 long int TNGetMaxExtent(void *obj) {
2068 if (LibraryHandle)
2069 return fTNGetMaxExtent(obj);
2070 else
2071 throw std::runtime_error(
2072 "GpuLibrary: Unable to get max extent for tensor network");
2073
2074 return 0;
2075 }
2076
2077 int TNGetNrQubits(void *obj) {
2078 if (LibraryHandle)
2079 return fTNGetNrQubits(obj);
2080 else
2081 throw std::runtime_error(
2082 "GpuLibrary: Unable to get nr qubits for tensor network");
2083
2084 return 0;
2085 }
2086
2087 bool TNAmplitude(void *obj, long int numFixedValues, long int *fixedValues,
2088 double *real, double *imaginary) {
2089 if (LibraryHandle)
2090 return fTNAmplitude(obj, numFixedValues, fixedValues, real, imaginary) ==
2091 1;
2092 else
2093 throw std::runtime_error(
2094 "GpuLibrary: Unable to get tensor network amplitude");
2095
2096 return false;
2097 }
2098
2099 double TNProbability0(void *obj, unsigned int qubit) {
2100 if (LibraryHandle)
2101 return fTNProbability0(obj, qubit);
2102 else
2103 throw std::runtime_error(
2104 "GpuLibrary: Unable to get probability for 0 for tensor network");
2105
2106 return 0.0;
2107 }
2108
2109 bool TNMeasure(void *obj, unsigned int qubit) {
2110 if (LibraryHandle)
2111 return fTNMeasure(obj, qubit) == 1;
2112 else
2113 throw std::runtime_error(
2114 "GpuLibrary: Unable to measure qubit on tensor network");
2115
2116 return false;
2117 }
2118
2119 bool TNMeasureQubits(void *obj, long int numQubits, unsigned int *qubits,
2120 int *result) {
2121 if (LibraryHandle)
2122 return fTNMeasureQubits(obj, numQubits, qubits, result) == 1;
2123 else
2124 throw std::runtime_error(
2125 "GpuLibrary: Unable to measure qubits on tensor network");
2126
2127 return false;
2128 }
2129
2130 std::unordered_map<std::vector<bool>, int64_t> *TNGetMapForSample() {
2131 if (LibraryHandle)
2132 return (
2133 std::unordered_map<std::vector<bool>, int64_t> *)fTNGetMapForSample();
2134 else
2135 throw std::runtime_error(
2136 "GpuLibrary: Unable to get map for sample for tensor network");
2137
2138 return nullptr;
2139 }
2140
2141 bool TNFreeMapForSample(std::unordered_map<std::vector<bool>, int64_t> *map) {
2142 if (LibraryHandle)
2143 return fTNFreeMapForSample((void *)map) == 1;
2144 else
2145 throw std::runtime_error(
2146 "GpuLibrary: Unable to free map for sample for tensor network");
2147
2148 return false;
2149 }
2150
2151 bool TNSample(void *obj, long int numShots, long int numQubits,
2152 unsigned int *qubits, void *resultMap) {
2153 if (LibraryHandle)
2154 return fTNSample(obj, numShots, numQubits, qubits, resultMap) == 1;
2155 else
2156 throw std::runtime_error("GpuLibrary: Unable to sample tensor network");
2157
2158 return false;
2159 }
2160
2161 bool TNSaveState(void *obj) {
2162 if (LibraryHandle)
2163 return fTNSaveState(obj) == 1;
2164 else
2165 throw std::runtime_error(
2166 "GpuLibrary: Unable to save tensor network state");
2167
2168 return false;
2169 }
2170
2171 bool TNRestoreState(void *obj) {
2172 if (LibraryHandle)
2173 return fTNRestoreState(obj) == 1;
2174 else
2175 throw std::runtime_error(
2176 "GpuLibrary: Unable to restore tensor network state");
2177
2178 return false;
2179 }
2180
2181 bool TNCleanSavedState(void *obj) {
2182 if (LibraryHandle)
2183 return fTNCleanSavedState(obj) == 1;
2184 else
2185 throw std::runtime_error(
2186 "GpuLibrary: Unable to clean tensor network saved state");
2187
2188 return false;
2189 }
2190
2191 void *TNClone(void *obj) {
2192 if (LibraryHandle)
2193 return fTNClone(obj);
2194 else
2195 throw std::runtime_error("GpuLibrary: Unable to clone tensor network");
2196
2197 return nullptr;
2198 }
2199
2200 double TNExpectationValue(void *obj, const char *pauliString, int len) const {
2201 if (LibraryHandle)
2202 return fTNExpectationValue(obj, pauliString, len);
2203 else
2204 throw std::runtime_error(
2205 "GpuLibrary: Unable to get tensor network expectation value");
2206
2207 return 0;
2208 }
2209
2210 bool TNApplyX(void *obj, unsigned int siteA) {
2211 if (LibraryHandle)
2212 return fTNApplyX(obj, siteA) == 1;
2213 else
2214 throw std::runtime_error(
2215 "GpuLibrary: Unable to apply X gate on tensor network");
2216
2217 return false;
2218 }
2219
2220 bool TNApplyY(void *obj, unsigned int siteA) {
2221 if (LibraryHandle)
2222 return fTNApplyY(obj, siteA) == 1;
2223 else
2224 throw std::runtime_error(
2225 "GpuLibrary: Unable to apply Y gate on tensor network");
2226
2227 return false;
2228 }
2229
2230 bool TNApplyZ(void *obj, unsigned int siteA) {
2231 if (LibraryHandle)
2232 return fTNApplyZ(obj, siteA) == 1;
2233 else
2234 throw std::runtime_error(
2235 "GpuLibrary: Unable to apply Z gate on tensor network");
2236
2237 return false;
2238 }
2239
2240 bool TNApplyH(void *obj, unsigned int siteA) {
2241 if (LibraryHandle)
2242 return fTNApplyH(obj, siteA) == 1;
2243 else
2244 throw std::runtime_error(
2245 "GpuLibrary: Unable to apply H gate on tensor network");
2246
2247 return false;
2248 }
2249
2250 bool TNApplyS(void *obj, unsigned int siteA) {
2251 if (LibraryHandle)
2252 return fTNApplyS(obj, siteA) == 1;
2253 else
2254 throw std::runtime_error(
2255 "GpuLibrary: Unable to apply S gate on tensor network");
2256
2257 return false;
2258 }
2259
2260 bool TNApplySDG(void *obj, unsigned int siteA) {
2261 if (LibraryHandle)
2262 return fTNApplySDG(obj, siteA) == 1;
2263 else
2264 throw std::runtime_error(
2265 "GpuLibrary: Unable to apply sdg gate on tensor network");
2266
2267 return false;
2268 }
2269
2270 bool TNApplyT(void *obj, unsigned int siteA) {
2271 if (LibraryHandle)
2272 return fTNApplyT(obj, siteA) == 1;
2273 else
2274 throw std::runtime_error(
2275 "GpuLibrary: Unable to apply t gate on tensor network");
2276
2277 return false;
2278 }
2279
2280 bool TNApplyTDG(void *obj, unsigned int siteA) {
2281 if (LibraryHandle)
2282 return fTNApplyTDG(obj, siteA) == 1;
2283 else
2284 throw std::runtime_error(
2285 "GpuLibrary: Unable to apply tdg gate on tensor network");
2286
2287 return false;
2288 }
2289
2290 bool TNApplySX(void *obj, unsigned int siteA) {
2291 if (LibraryHandle)
2292 return fTNApplySX(obj, siteA) == 1;
2293 else
2294 throw std::runtime_error(
2295 "GpuLibrary: Unable to apply sx gate on tensor network");
2296
2297 return false;
2298 }
2299
2300 bool TNApplySXDG(void *obj, unsigned int siteA) {
2301 if (LibraryHandle)
2302 return fTNApplySXDG(obj, siteA) == 1;
2303 else
2304 throw std::runtime_error(
2305 "GpuLibrary: Unable to apply sxdg gate on tensor network");
2306
2307 return false;
2308 }
2309
2310 bool TNApplyK(void *obj, unsigned int siteA) {
2311 if (LibraryHandle)
2312 return fTNApplyK(obj, siteA) == 1;
2313 else
2314 throw std::runtime_error(
2315 "GpuLibrary: Unable to apply k gate on tensor network");
2316
2317 return false;
2318 }
2319
2320 bool TNApplyP(void *obj, unsigned int siteA, double theta) {
2321 if (LibraryHandle)
2322 return fTNApplyP(obj, siteA, theta) == 1;
2323 else
2324 throw std::runtime_error(
2325 "GpuLibrary: Unable to apply p gate on tensor network");
2326 return false;
2327 }
2328
2329 bool TNApplyRx(void *obj, unsigned int siteA, double theta) {
2330 if (LibraryHandle)
2331 return fTNApplyRx(obj, siteA, theta) == 1;
2332 else
2333 throw std::runtime_error(
2334 "GpuLibrary: Unable to apply rx gate on tensor network");
2335
2336 return false;
2337 }
2338
2339 bool TNApplyRy(void *obj, unsigned int siteA, double theta) {
2340 if (LibraryHandle)
2341 return fTNApplyRy(obj, siteA, theta) == 1;
2342 else
2343 throw std::runtime_error(
2344 "GpuLibrary: Unable to apply ry gate on tensor network");
2345
2346 return false;
2347 }
2348
2349 bool TNApplyRz(void *obj, unsigned int siteA, double theta) {
2350 if (LibraryHandle)
2351 return fTNApplyRz(obj, siteA, theta) == 1;
2352 else
2353 throw std::runtime_error(
2354 "GpuLibrary: Unable to apply rz gate on tensor network");
2355
2356 return false;
2357 }
2358
2359 bool TNApplyU(void *obj, unsigned int siteA, double theta, double phi,
2360 double lambda, double gamma) {
2361 if (LibraryHandle)
2362 return fTNApplyU(obj, siteA, theta, phi, lambda, gamma) == 1;
2363 else
2364 throw std::runtime_error(
2365 "GpuLibrary: Unable to apply u gate on tensor network");
2366
2367 return false;
2368 }
2369
2370 bool TNApplySwap(void *obj, unsigned int controlQubit,
2371 unsigned int targetQubit) {
2372 if (LibraryHandle)
2373 return fTNApplySwap(obj, controlQubit, targetQubit) == 1;
2374 else
2375 throw std::runtime_error(
2376 "GpuLibrary: Unable to apply swap gate on tensor network");
2377
2378 return false;
2379 }
2380
2381 bool TNApplyCX(void *obj, unsigned int controlQubit,
2382 unsigned int targetQubit) {
2383 if (LibraryHandle)
2384 return fTNApplyCX(obj, controlQubit, targetQubit) == 1;
2385 else
2386 throw std::runtime_error(
2387 "GpuLibrary: Unable to apply cx gate on tensor network");
2388
2389 return false;
2390 }
2391
2392 bool TNApplyCY(void *obj, unsigned int controlQubit,
2393 unsigned int targetQubit) {
2394 if (LibraryHandle)
2395 return fTNApplyCY(obj, controlQubit, targetQubit) == 1;
2396 else
2397 throw std::runtime_error(
2398 "GpuLibrary: Unable to apply cy gate on tensor network");
2399
2400 return false;
2401 }
2402
2403 bool TNApplyCZ(void *obj, unsigned int controlQubit,
2404 unsigned int targetQubit) {
2405 if (LibraryHandle)
2406 return fTNApplyCZ(obj, controlQubit, targetQubit) == 1;
2407 else
2408 throw std::runtime_error(
2409 "GpuLibrary: Unable to apply cz gate on tensor network");
2410
2411 return false;
2412 }
2413
2414 bool TNApplyCH(void *obj, unsigned int controlQubit,
2415 unsigned int targetQubit) {
2416 if (LibraryHandle)
2417 return fTNApplyCH(obj, controlQubit, targetQubit) == 1;
2418 else
2419 throw std::runtime_error(
2420 "GpuLibrary: Unable to apply ch gate on tensor network");
2421
2422 return false;
2423 }
2424
2425 bool TNApplyCSX(void *obj, unsigned int controlQubit,
2426 unsigned int targetQubit) {
2427 if (LibraryHandle)
2428 return fTNApplyCSX(obj, controlQubit, targetQubit) == 1;
2429 else
2430 throw std::runtime_error(
2431 "GpuLibrary: Unable to apply csx gate on tensor network");
2432 }
2433
2434 bool TNApplyCSXDG(void *obj, unsigned int controlQubit,
2435 unsigned int targetQubit) {
2436 if (LibraryHandle)
2437 return fTNApplyCSXDG(obj, controlQubit, targetQubit) == 1;
2438 else
2439 throw std::runtime_error(
2440 "GpuLibrary: Unable to apply csxdg gate on tensor network");
2441
2442 return false;
2443 }
2444
2445 bool TNApplyCP(void *obj, unsigned int controlQubit, unsigned int targetQubit,
2446 double theta) {
2447 if (LibraryHandle)
2448 return fTNApplyCP(obj, controlQubit, targetQubit, theta) == 1;
2449 else
2450 throw std::runtime_error(
2451 "GpuLibrary: Unable to apply cp gate on tensor network");
2452
2453 return false;
2454 }
2455
2456 bool TNApplyCRx(void *obj, unsigned int controlQubit,
2457 unsigned int targetQubit, double theta) {
2458 if (LibraryHandle)
2459 return fTNApplyCRx(obj, controlQubit, targetQubit, theta) == 1;
2460 else
2461 throw std::runtime_error(
2462 "GpuLibrary: Unable to apply crx gate on tensor network");
2463
2464 return false;
2465 }
2466
2467 bool TNApplyCRy(void *obj, unsigned int controlQubit,
2468 unsigned int targetQubit, double theta) {
2469 if (LibraryHandle)
2470 return fTNApplyCRy(obj, controlQubit, targetQubit, theta) == 1;
2471 else
2472 throw std::runtime_error(
2473 "GpuLibrary: Unable to apply cry gate on tensor network");
2474
2475 return false;
2476 }
2477
2478 bool TNApplyCRz(void *obj, unsigned int controlQubit,
2479 unsigned int targetQubit, double theta) {
2480 if (LibraryHandle)
2481 return fTNApplyCRz(obj, controlQubit, targetQubit, theta) == 1;
2482 else
2483 throw std::runtime_error(
2484 "GpuLibrary: Unable to apply crz gate on tensor network");
2485
2486 return false;
2487 }
2488
2489 bool TNApplyCU(void *obj, unsigned int controlQubit, unsigned int targetQubit,
2490 double theta, double phi, double lambda, double gamma) {
2491 if (LibraryHandle)
2492 return fTNApplyCU(obj, controlQubit, targetQubit, theta, phi, lambda,
2493 gamma) == 1;
2494 else
2495 throw std::runtime_error(
2496 "GpuLibrary: Unable to apply cu gate on tensor network");
2497
2498 return false;
2499 }
2500
2501 bool TNApplyCCX(void *obj, unsigned int controlQubit1,
2502 unsigned int controlQubit2, unsigned int targetQubit) {
2503 if (LibraryHandle)
2504 return fTNApplyCCX(obj, controlQubit1, controlQubit2, targetQubit) == 1;
2505 else
2506 throw std::runtime_error(
2507 "GpuLibrary: Unable to apply ccx gate on tensor network");
2508 return false;
2509 }
2510
2511 bool TNApplyCSwap(void *obj, unsigned int controlQubit,
2512 unsigned int targetQubit1, unsigned int targetQubit2) {
2513 if (LibraryHandle)
2514 return fTNApplyCSwap(obj, controlQubit, targetQubit1, targetQubit2) == 1;
2515 else
2516 throw std::runtime_error(
2517 "GpuLibrary: Unable to apply cswap gate on tensor network");
2518 return false;
2519 }
2520
2521 // stabilizer functions
2522 void *CreateStabilizerSimulator(long long int numQubits,
2523 long long int numShots,
2524 long long int numMeasurements,
2525 long long int numDetectors) {
2526 if (LibraryHandle)
2527 return fCreateStabilizerSimulator(numQubits, numShots, numMeasurements,
2528 numDetectors);
2529 else
2530 throw std::runtime_error(
2531 "GpuLibrary: Unable to create stabilizer simulator");
2532
2533 return nullptr;
2534 }
2535
2536 void DestroyStabilizerSimulator(void *obj) {
2537 if (!obj) return;
2538 if (LibraryHandle)
2539 fDestroyStabilizerSimulator(obj);
2540 else
2541 throw std::runtime_error(
2542 "GpuLibrary: Unable to destroy stabilizer simulator");
2543 }
2544
2545 bool ExecuteStabilizerCircuit(void *obj, const char *circuitStr,
2546 int randomizeMeasurements,
2547 unsigned long long int seed) {
2548 if (!obj) return false;
2549 if (LibraryHandle)
2550 return fExecuteStabilizerCircuit(obj, circuitStr, randomizeMeasurements,
2551 seed) == 1;
2552 else
2553 throw std::runtime_error(
2554 "GpuLibrary: Unable to execute stabilizer circuit");
2555
2556 return false;
2557 }
2558
2559 long long GetStabilizerXZTableSize(void *obj) {
2560 if (!obj) return 0;
2561 if (LibraryHandle)
2562 return fGetStabilizerXZTableSize(obj);
2563 else
2564 throw std::runtime_error(
2565 "GpuLibrary: Unable to get stabilizer XZ table size");
2566
2567 return 0;
2568 }
2569
2570 long long GetStabilizerMTableSize(void *obj) {
2571 if (!obj) return 0;
2572 if (LibraryHandle)
2573 return fGetStabilizerMTableSize(obj);
2574 else
2575 throw std::runtime_error(
2576 "GpuLibrary: Unable to get stabilizer M table size");
2577
2578 return 0;
2579 }
2580
2581 long long GetStabilizerTableStrideMajor(void *obj) {
2582 if (!obj) return 0;
2583 if (LibraryHandle)
2584 return fGetStabilizerTableStrideMajor(obj);
2585 else
2586 throw std::runtime_error(
2587 "GpuLibrary: Unable to get stabilizer table stride major");
2588 return 0;
2589 }
2590
2591 long long GetStabilizerNumQubits(void *obj) {
2592 if (!obj) return 0;
2593 if (LibraryHandle)
2594 return fGetStabilizerNumQubits(obj);
2595 else
2596 throw std::runtime_error(
2597 "GpuLibrary: Unable to get stabilizer number of qubits");
2598
2599 return 0;
2600 }
2601
2602 long long GetStabilizerNumShots(void *obj) {
2603 if (!obj) return 0;
2604 if (LibraryHandle)
2605 return fGetStabilizerNumShots(obj);
2606 else
2607 throw std::runtime_error(
2608 "GpuLibrary: Unable to get stabilizer number of shots");
2609
2610 return 0;
2611 }
2612
2613 long long GetStabilizerNumMeasurements(void *obj) {
2614 if (!obj) return 0;
2615 if (LibraryHandle)
2616 return fGetStabilizerNumMeasurements(obj);
2617 else
2618 throw std::runtime_error(
2619 "GpuLibrary: Unable to get stabilizer number of measurements");
2620
2621 return 0;
2622 }
2623
2624 long long GetStabilizerNumDetectors(void *obj) {
2625 if (!obj) return 0;
2626 if (LibraryHandle)
2627 return fGetStabilizerNumDetectors(obj);
2628 else
2629 throw std::runtime_error(
2630 "GpuLibrary: Unable to get stabilizer number of detectors");
2631
2632 return 0;
2633 }
2634
2635 int CopyStabilizerXTable(void *obj, unsigned int *xtable) {
2636 if (!obj) return 0;
2637 if (LibraryHandle)
2638 return fCopyStabilizerXTable(obj, xtable);
2639 else
2640 throw std::runtime_error("GpuLibrary: Unable to copy stabilizer X table");
2641 return 0;
2642 }
2643
2644 int CopyStabilizerZTable(void *obj, unsigned int *ztable) {
2645 if (!obj) return 0;
2646 if (LibraryHandle)
2647 return fCopyStabilizerZTable(obj, ztable);
2648 else
2649 throw std::runtime_error("GpuLibrary: Unable to copy stabilizer Z table");
2650 return 0;
2651 }
2652
2653 int CopyStabilizerMTable(void *obj, unsigned int *mtable) {
2654 if (!obj) return 0;
2655 if (LibraryHandle)
2656 return fCopyStabilizerMTable(obj, mtable);
2657 else
2658 throw std::runtime_error("GpuLibrary: Unable to copy stabilizer M table");
2659 return 0;
2660 }
2661
2662 int InitStabilizerXTable(void *obj, const unsigned int *xtable) {
2663 if (!obj) return 0;
2664 if (LibraryHandle)
2665 return fInitStabilizerXTable(obj, xtable);
2666 else
2667 throw std::runtime_error(
2668 "GpuLibrary: Unable to initialize stabilizer X table");
2669 return 0;
2670 }
2671
2672 int InitStabilizerZTable(void *obj, const unsigned int *ztable) {
2673 if (!obj) return 0;
2674 if (LibraryHandle)
2675 return fInitStabilizerZTable(obj, ztable);
2676 else
2677 throw std::runtime_error(
2678 "GpuLibrary: Unable to initialize stabilizer Z table");
2679 return 0;
2680 }
2681
2682 // pauli propagation functions
2683 void *CreatePauliPropSimulator(int nrQubits) {
2684 if (LibraryHandle)
2685 return fCreatePauliPropSimulator(nrQubits);
2686 else
2687 throw std::runtime_error(
2688 "GpuLibrary: Unable to create pauli propagation simulator");
2689 return nullptr;
2690 }
2691
2692 void DestroyPauliPropSimulator(void *obj) {
2693 if (!obj) return;
2694 if (LibraryHandle)
2695 fDestroyPauliPropSimulator(obj);
2696 else
2697 throw std::runtime_error(
2698 "GpuLibrary: Unable to destroy pauli propagation simulator");
2699 }
2700
2701 int PauliPropGetNrQubits(void *obj) {
2702 if (!obj) return 0;
2703 if (LibraryHandle)
2704 return fPauliPropGetNrQubits(obj);
2705 else
2706 throw std::runtime_error(
2707 "GpuLibrary: Unable to get number of qubits in pauli propagation "
2708 "simulator");
2709 return 0;
2710 }
2711
2712 int PauliPropSetWillUseSampling(void *obj, int willUseSampling) {
2713 if (!obj) return 0;
2714 if (LibraryHandle)
2715 return fPauliPropSetWillUseSampling(obj, willUseSampling) == 1;
2716 else
2717 throw std::runtime_error(
2718 "GpuLibrary: Unable to set 'will use sampling' in pauli propagation "
2719 "simulator");
2720 return 0;
2721 }
2722
2723 int PauliPropGetWillUseSampling(void *obj) {
2724 if (!obj) return 0;
2725 if (LibraryHandle)
2726 return fPauliPropGetWillUseSampling(obj);
2727 else
2728 throw std::runtime_error(
2729 "GpuLibrary: Unable to get 'will use sampling' in pauli propagation "
2730 "simulator");
2731 return 0;
2732 }
2733
2734 double PauliPropGetCoefficientTruncationCutoff(void *obj) {
2735 if (!obj) return 0.0;
2736 if (LibraryHandle)
2737 return fPauliPropGetCoefficientTruncationCutoff(obj);
2738 else
2739 throw std::runtime_error(
2740 "GpuLibrary: Unable to get coefficient truncation cutoff in pauli "
2741 "propagation simulator");
2742 return 0.0;
2743 }
2744
2745 void PauliPropSetCoefficientTruncationCutoff(void *obj, double cutoff) {
2746 if (!obj) return;
2747 if (LibraryHandle)
2748 fPauliPropSetCoefficientTruncationCutoff(obj, cutoff);
2749 else
2750 throw std::runtime_error(
2751 "GpuLibrary: Unable to set coefficient truncation cutoff in pauli "
2752 "propagation simulator");
2753 }
2754
2755 double PauliPropGetWeightTruncationCutoff(void *obj) {
2756 if (!obj) return 0.0;
2757 if (LibraryHandle)
2758 return fPauliPropGetWeightTruncationCutoff(obj);
2759 else
2760 throw std::runtime_error(
2761 "GpuLibrary: Unable to get weight truncation cutoff in pauli "
2762 "propagation simulator");
2763 return 0.0;
2764 }
2765
2766 void PauliPropSetWeightTruncationCutoff(void *obj, double cutoff) {
2767 if (!obj) return;
2768 if (LibraryHandle)
2769 fPauliPropSetWeightTruncationCutoff(obj, cutoff);
2770 else
2771 throw std::runtime_error(
2772 "GpuLibrary: Unable to set weight truncation cutoff in pauli "
2773 "propagation simulator");
2774 }
2775
2776 int PauliPropGetNumGatesBetweenTruncations(void *obj) {
2777 if (!obj) return 0;
2778 if (LibraryHandle)
2779 return fPauliPropGetNumGatesBetweenTruncations(obj);
2780 else
2781 throw std::runtime_error(
2782 "GpuLibrary: Unable to get number of gates between truncations in "
2783 "pauli propagation simulator");
2784 return 0;
2785 }
2786
2787 void PauliPropSetNumGatesBetweenTruncations(void *obj, int numGates) {
2788 if (!obj) return;
2789 if (LibraryHandle)
2790 fPauliPropSetNumGatesBetweenTruncations(obj, numGates);
2791 else
2792 throw std::runtime_error(
2793 "GpuLibrary: Unable to set number of gates between truncations in "
2794 "pauli "
2795 "propagation simulator");
2796 }
2797
2798 int PauliPropGetNumGatesBetweenDeduplications(void *obj) {
2799 if (!obj) return 0;
2800 if (LibraryHandle)
2801 return fPauliPropGetNumGatesBetweenDeduplications(obj);
2802 else
2803 throw std::runtime_error(
2804 "GpuLibrary: Unable to get number of gates between deduplications in "
2805 "pauli propagation simulator");
2806 return 0;
2807 }
2808
2809 void PauliPropSetNumGatesBetweenDeduplications(void *obj, int numGates) {
2810 if (!obj) return;
2811 if (LibraryHandle)
2812 fPauliPropSetNumGatesBetweenDeduplications(obj, numGates);
2813 else
2814 throw std::runtime_error(
2815 "GpuLibrary: Unable to set number of gates between deduplications in "
2816 "pauli "
2817 "propagation simulator");
2818 }
2819
2820 bool PauliPropClearOperators(void *obj) {
2821 if (!obj) return false;
2822 if (LibraryHandle)
2823 return fPauliPropClearOperators(obj) == 1;
2824 else
2825 throw std::runtime_error(
2826 "GpuLibrary: Unable to clear operators in pauli propagation "
2827 "simulator");
2828 return false;
2829 }
2830
2831 bool PauliPropAllocateMemory(void *obj, double percentage) {
2832 if (!obj) return false;
2833 if (LibraryHandle)
2834 return fPauliPropAllocateMemory(obj, percentage) == 1;
2835 else
2836 throw std::runtime_error(
2837 "GpuLibrary: Unable to allocate memory in pauli propagation "
2838 "simulator");
2839 return false;
2840 }
2841
2842 double PauliPropGetExpectationValue(void *obj) {
2843 if (!obj) return 0.0;
2844 if (LibraryHandle)
2845 return fPauliPropGetExpectationValue(obj);
2846 else
2847 throw std::runtime_error(
2848 "GpuLibrary: Unable to get expectation value in pauli propagation "
2849 "simulator");
2850 return 0.0;
2851 }
2852
2853 bool PauliPropExecute(void *obj) {
2854 if (!obj) return false;
2855 if (LibraryHandle)
2856 return fPauliPropExecute(obj) == 1;
2857 else
2858 throw std::runtime_error(
2859 "GpuLibrary: Unable to execute pauli propagation simulator");
2860 return false;
2861 }
2862
2863 bool PauliPropSetInPauliExpansionUnique(void *obj, const char *pauliString) {
2864 if (!obj) return false;
2865 if (LibraryHandle)
2866 return fPauliPropSetInPauliExpansionUnique(obj, pauliString) == 1;
2867 else
2868 throw std::runtime_error(
2869 "GpuLibrary: Unable to set unique pauli in pauli propagation "
2870 "simulator");
2871 return false;
2872 }
2873
2874 bool PauliPropSetInPauliExpansionMultiple(void *obj,
2875 const char **pauliStrings,
2876 const double *coefficients,
2877 int nrPaulis) {
2878 if (!obj) return false;
2879 if (LibraryHandle)
2880 return fPauliPropSetInPauliExpansionMultiple(obj, pauliStrings,
2881 coefficients, nrPaulis) == 1;
2882 else
2883 throw std::runtime_error(
2884 "GpuLibrary: Unable to set multiple pauli in pauli propagation "
2885 "simulator");
2886 return false;
2887 }
2888
2889 bool PauliPropApplyX(void *obj, int qubit) {
2890 if (!obj) return false;
2891 if (LibraryHandle)
2892 return fPauliPropApplyX(obj, qubit) == 1;
2893 else
2894 throw std::runtime_error("GpuLibrary: Unable to apply X gate on mps");
2895 return false;
2896 }
2897
2898 bool PauliPropApplyY(void *obj, int qubit) {
2899 if (!obj) return false;
2900 if (LibraryHandle)
2901 return fPauliPropApplyY(obj, qubit) == 1;
2902 else
2903 throw std::runtime_error("GpuLibrary: Unable to apply Y gate on mps");
2904 return false;
2905 }
2906
2907 bool PauliPropApplyZ(void *obj, int qubit) {
2908 if (!obj) return false;
2909 if (LibraryHandle)
2910 return fPauliPropApplyZ(obj, qubit) == 1;
2911 else
2912 throw std::runtime_error("GpuLibrary: Unable to apply Z gate on mps");
2913 return false;
2914 }
2915
2916 bool PauliPropApplyH(void *obj, int qubit) {
2917 if (!obj) return false;
2918 if (LibraryHandle)
2919 return fPauliPropApplyH(obj, qubit) == 1;
2920 else
2921 throw std::runtime_error("GpuLibrary: Unable to apply H gate on mps");
2922 return false;
2923 }
2924
2925 bool PauliPropApplyS(void *obj, int qubit) {
2926 if (!obj) return false;
2927 if (LibraryHandle)
2928 return fPauliPropApplyS(obj, qubit) == 1;
2929 else
2930 throw std::runtime_error("GpuLibrary: Unable to apply S gate on mps");
2931 return false;
2932 }
2933
2934 bool PauliPropApplySQRTX(void *obj, int qubit) {
2935 if (!obj) return false;
2936 if (LibraryHandle)
2937 return fPauliPropApplySQRTX(obj, qubit) == 1;
2938 else
2939 throw std::runtime_error("GpuLibrary: Unable to apply SQRTX gate on mps");
2940 return false;
2941 }
2942
2943 bool PauliPropApplySQRTY(void *obj, int qubit) {
2944 if (!obj) return false;
2945 if (LibraryHandle)
2946 return fPauliPropApplySQRTY(obj, qubit) == 1;
2947 else
2948 throw std::runtime_error("GpuLibrary: Unable to apply SQRTY gate on mps");
2949 return false;
2950 }
2951
2952 bool PauliPropApplySQRTZ(void *obj, int qubit) {
2953 if (!obj) return false;
2954 if (LibraryHandle)
2955 return fPauliPropApplySQRTZ(obj, qubit) == 1;
2956 else
2957 throw std::runtime_error("GpuLibrary: Unable to apply SQRTZ gate on mps");
2958 return false;
2959 }
2960
2961 bool PauliPropApplyCX(void *obj, int targetQubit, int controlQubit) {
2962 if (!obj) return false;
2963 if (LibraryHandle)
2964 return fPauliPropApplyCX(obj, targetQubit, controlQubit) == 1;
2965 else
2966 throw std::runtime_error("GpuLibrary: Unable to apply CX gate on mps");
2967 return false;
2968 }
2969
2970 bool PauliPropApplyCY(void *obj, int targetQubit, int controlQubit) {
2971 if (!obj) return false;
2972 if (LibraryHandle)
2973 return fPauliPropApplyCY(obj, targetQubit, controlQubit) == 1;
2974 else
2975 throw std::runtime_error("GpuLibrary: Unable to apply CY gate on mps");
2976 return false;
2977 }
2978
2979 bool PauliPropApplyCZ(void *obj, int targetQubit, int controlQubit) {
2980 if (!obj) return false;
2981 if (LibraryHandle)
2982 return fPauliPropApplyCZ(obj, targetQubit, controlQubit) == 1;
2983 else
2984 throw std::runtime_error("GpuLibrary: Unable to apply CZ gate on mps");
2985 return false;
2986 }
2987
2988 bool PauliPropApplySWAP(void *obj, int qubit1, int qubit2) {
2989 if (!obj) return false;
2990 if (LibraryHandle)
2991 return fPauliPropApplySWAP(obj, qubit1, qubit2) == 1;
2992 else
2993 throw std::runtime_error("GpuLibrary: Unable to apply SWAP gate on mps");
2994 return false;
2995 }
2996
2997 bool PauliPropApplyISWAP(void *obj, int qubit1, int qubit2) {
2998 if (!obj) return false;
2999 if (LibraryHandle)
3000 return fPauliPropApplyISWAP(obj, qubit1, qubit2) == 1;
3001 else
3002 throw std::runtime_error("GpuLibrary: Unable to apply ISWAP gate on mps");
3003 return false;
3004 }
3005
3006 bool PauliPropApplyRX(void *obj, int qubit, double angle) {
3007 if (!obj) return false;
3008 if (LibraryHandle)
3009 return fPauliPropApplyRX(obj, qubit, angle) == 1;
3010 else
3011 throw std::runtime_error("GpuLibrary: Unable to apply RX gate on mps");
3012 return false;
3013 }
3014
3015 bool PauliPropApplyRY(void *obj, int qubit, double angle) {
3016 if (!obj) return false;
3017 if (LibraryHandle)
3018 return fPauliPropApplyRY(obj, qubit, angle) == 1;
3019 else
3020 throw std::runtime_error("GpuLibrary: Unable to apply RY gate on mps");
3021 return false;
3022 }
3023
3024 bool PauliPropApplyRZ(void *obj, int qubit, double angle) {
3025 if (!obj) return false;
3026 if (LibraryHandle)
3027 return fPauliPropApplyRZ(obj, qubit, angle) == 1;
3028 else
3029 throw std::runtime_error("GpuLibrary: Unable to apply RZ gate on mps");
3030 return false;
3031 }
3032
3033 bool PauliPropAddNoiseX(void *obj, int qubit, double probability) {
3034 if (!obj) return false;
3035 if (LibraryHandle)
3036 return fPauliPropAddNoiseX(obj, qubit, probability) == 1;
3037 else
3038 throw std::runtime_error("GpuLibrary: Unable to add X noise on mps");
3039 return false;
3040 }
3041
3042 bool PauliPropAddNoiseY(void *obj, int qubit, double probability) {
3043 if (!obj) return false;
3044 if (LibraryHandle)
3045 return fPauliPropAddNoiseY(obj, qubit, probability) == 1;
3046 else
3047 throw std::runtime_error("GpuLibrary: Unable to add Y noise on mps");
3048 return false;
3049 }
3050
3051 bool PauliPropAddNoiseZ(void *obj, int qubit, double probability) {
3052 if (!obj) return false;
3053 if (LibraryHandle)
3054 return fPauliPropAddNoiseZ(obj, qubit, probability) == 1;
3055 else
3056 throw std::runtime_error("GpuLibrary: Unable to add Z noise on mps");
3057 return false;
3058 }
3059
3060 bool PauliPropAddNoiseXYZ(void *obj, int qubit, double probabilityX,
3061 double probabilityY, double probabilityZ) {
3062 if (!obj) return false;
3063 if (LibraryHandle)
3064 return fPauliPropAddNoiseXYZ(obj, qubit, probabilityX, probabilityY,
3065 probabilityZ) == 1;
3066 else
3067 throw std::runtime_error("GpuLibrary: Unable to add XYZ noise on mps");
3068 return false;
3069 }
3070
3071 bool PauliPropAddAmplitudeDamping(void *obj, int qubit, double dampingProb,
3072 double exciteProb) {
3073 if (!obj) return false;
3074 if (LibraryHandle)
3075 return fPauliPropAddAmplitudeDamping(obj, qubit, dampingProb,
3076 exciteProb) == 1;
3077 else
3078 throw std::runtime_error(
3079 "GpuLibrary: Unable to add amplitude damping on mps");
3080 return false;
3081 }
3082
3083 double PauliPropQubitProbability0(void *obj, int qubit) {
3084 if (!obj) return 0.0;
3085 if (LibraryHandle)
3086 return fPauliPropQubitProbability0(obj, qubit);
3087 else
3088 throw std::runtime_error(
3089 "GpuLibrary: Unable to get qubit probability 0 in pauli propagation "
3090 "simulator");
3091 return 0.0;
3092 }
3093
3094 double PauliPropProbability(void *obj, unsigned long long int outcome) {
3095 if (!obj) return 0.0;
3096 if (LibraryHandle)
3097 return fPauliPropProbability(obj, outcome);
3098 else
3099 throw std::runtime_error(
3100 "GpuLibrary: Unable to get probability of outcome in pauli "
3101 "propagation simulator");
3102 return 0.0;
3103 }
3104
3105 bool PauliPropMeasureQubit(void *obj, int qubit) {
3106 if (!obj) return false;
3107 if (LibraryHandle)
3108 return fPauliPropMeasureQubit(obj, qubit) == 1;
3109 else
3110 throw std::runtime_error(
3111 "GpuLibrary: Unable to measure qubit in pauli propagation simulator");
3112 return false;
3113 }
3114
3115 unsigned char *PauliPropSampleQubits(void *obj, const int *qubits,
3116 int nrQubits) {
3117 if (!obj) return nullptr;
3118 if (LibraryHandle)
3119 return fPauliPropSampleQubits(obj, qubits, nrQubits);
3120 else
3121 throw std::runtime_error(
3122 "GpuLibrary: Unable to sample qubits in pauli propagation simulator");
3123 return nullptr;
3124 }
3125
3126 void PauliPropFreeSampledQubits(unsigned char *samples) {
3127 if (!samples) return;
3128 if (LibraryHandle)
3129 fPauliPropFreeSampledQubits(samples);
3130 else
3131 throw std::runtime_error(
3132 "GpuLibrary: Unable to free sampled qubits in pauli propagation "
3133 "simulator");
3134 }
3135
3136 void PauliPropSaveState(void *obj) {
3137 if (!obj) return;
3138 if (LibraryHandle)
3139 fPauliPropSaveState(obj);
3140 else
3141 throw std::runtime_error(
3142 "GpuLibrary: Unable to save state in pauli propagation simulator");
3143 }
3144
3145 void PauliPropRestoreState(void *obj) {
3146 if (!obj) return;
3147 if (LibraryHandle)
3148 fPauliPropRestoreState(obj);
3149 else
3150 throw std::runtime_error(
3151 "GpuLibrary: Unable to restore state in pauli propagation simulator");
3152 }
3153
3154 private:
3155 void *LibraryHandle = nullptr;
3156
3157 int (*fValidateLicense)(const char *) = nullptr;
3158 void *(*InitLib)() = nullptr;
3159 void (*FreeLib)() = nullptr;
3160
3161 void *(*fCreateStateVector)(void *) = nullptr;
3162 void (*fDestroyStateVector)(void *) = nullptr;
3163 // statevector functions
3164 int (*fSetDataType)(void *, int) = nullptr;
3165 int (*fIsDoublePrecision)(void *) = nullptr;
3166 int (*fGetNrQubits)(void *) = nullptr;
3167 int (*fCreate)(void *, unsigned int) = nullptr;
3168 int (*fReset)(void *) = nullptr;
3169 int (*fCreateWithState)(void *, unsigned int, const double *) = nullptr;
3170 int (*fMeasureQubitCollapse)(void *, int) = nullptr;
3171 int (*fMeasureQubitNoCollapse)(void *, int) = nullptr;
3172 int (*fMeasureQubitsCollapse)(void *, int *, int *, int) = nullptr;
3173 int (*fMeasureQubitsNoCollapse)(void *, int *, int *, int) = nullptr;
3174 unsigned long long (*fMeasureAllQubitsCollapse)(void *) = nullptr;
3175 unsigned long long (*fMeasureAllQubitsNoCollapse)(void *) = nullptr;
3176
3177 int (*fSaveState)(void *) = nullptr;
3178 int (*fSaveStateToHost)(void *) = nullptr;
3179 int (*fSaveStateDestructive)(void *) = nullptr;
3180 int (*fRestoreStateFreeSaved)(void *) = nullptr;
3181 int (*fRestoreStateNoFreeSaved)(void *) = nullptr;
3182 void (*fFreeSavedState)(void *obj) = nullptr;
3183 void *(*fClone)(void *) = nullptr;
3184 int (*fSample)(void *, unsigned int, long int *, unsigned int,
3185 int *) = nullptr;
3186 int (*fSampleAll)(void *, unsigned int, long int *) = nullptr;
3187 int (*fAmplitude)(void *, long long int, double *, double *) = nullptr;
3188 double (*fProbability)(void *, int *, int *, int) = nullptr;
3189 double (*fBasisStateProbability)(void *, long long int) = nullptr;
3190 int (*fAllProbabilities)(void *, double *) = nullptr;
3191 double (*fExpectationValue)(void *, const char *, int) = nullptr;
3192
3193 int (*fApplyX)(void *, int) = nullptr;
3194 int (*fApplyY)(void *, int) = nullptr;
3195 int (*fApplyZ)(void *, int) = nullptr;
3196 int (*fApplyH)(void *, int) = nullptr;
3197 int (*fApplyS)(void *, int) = nullptr;
3198 int (*fApplySDG)(void *, int) = nullptr;
3199 int (*fApplyT)(void *, int) = nullptr;
3200 int (*fApplyTDG)(void *, int) = nullptr;
3201 int (*fApplySX)(void *, int) = nullptr;
3202 int (*fApplySXDG)(void *, int) = nullptr;
3203 int (*fApplyK)(void *, int) = nullptr;
3204 int (*fApplyP)(void *, int, double) = nullptr;
3205 int (*fApplyRx)(void *, int, double) = nullptr;
3206 int (*fApplyRy)(void *, int, double) = nullptr;
3207 int (*fApplyRz)(void *, int, double) = nullptr;
3208 int (*fApplyU)(void *, int, double, double, double, double) = nullptr;
3209 int (*fApplyCX)(void *, int, int) = nullptr;
3210 int (*fApplyCY)(void *, int, int) = nullptr;
3211 int (*fApplyCZ)(void *, int, int) = nullptr;
3212 int (*fApplyCH)(void *, int, int) = nullptr;
3213 int (*fApplyCSX)(void *, int, int) = nullptr;
3214 int (*fApplyCSXDG)(void *, int, int) = nullptr;
3215 int (*fApplyCP)(void *, int, int, double) = nullptr;
3216 int (*fApplyCRx)(void *, int, int, double) = nullptr;
3217 int (*fApplyCRy)(void *, int, int, double) = nullptr;
3218 int (*fApplyCRz)(void *, int, int, double) = nullptr;
3219 int (*fApplyCCX)(void *, int, int, int) = nullptr;
3220 int (*fApplySwap)(void *, int, int) = nullptr;
3221 int (*fApplyCSwap)(void *, int, int, int) = nullptr;
3222 int (*fApplyCU)(void *, int, int, double, double, double, double) = nullptr;
3223 // mps functions
3224 void *(*fCreateMPS)(void *) = nullptr;
3225 void (*fDestroyMPS)(void *) = nullptr;
3226
3227 int (*fMPSCreate)(void *, unsigned int) = nullptr;
3228 int (*fMPSReset)(void *) = nullptr;
3229 int (*fMPSSetInitialQubitsMap)(void *, const long long int *,
3230 unsigned int) = nullptr;
3231 int (*fMPSSetUseOptimalMeetingPosition)(void *, int) = nullptr;
3232
3233 int (*fMPSIsValid)(void *) = nullptr;
3234 int (*fMPSIsCreated)(void *) = nullptr;
3235
3236 int (*fMPSSetDataType)(void *, int) = nullptr;
3237 int (*fMPSIsDoublePrecision)(void *) = nullptr;
3238 int (*fMPSSetCutoff)(void *, double) = nullptr;
3239 double (*fMPSGetCutoff)(void *) = nullptr;
3240 int (*fMPSSetGesvdJ)(void *, int) = nullptr;
3241 int (*fMPSGetGesvdJ)(void *) = nullptr;
3242 int (*fMPSSetMaxExtent)(void *, long int) = nullptr;
3243 long int (*fMPSGetMaxExtent)(void *) = nullptr;
3244 int (*fMPSGetNrQubits)(void *) = nullptr;
3245 int (*fMPSSetCallbackContext)(void *, void *) = nullptr;
3246 int (*fMPSSetMeetingPositionCallback)(void *, int64_t (*)(void *, const int64_t *)) = nullptr;
3247
3248 int (*fMPSAmplitude)(void *, long int, long int *, double *,
3249 double *) = nullptr;
3250 double (*fMPSProbability0)(void *, unsigned int) = nullptr;
3251 int (*fMPSMeasure)(void *, unsigned int) = nullptr;
3252 int (*fMPSMeasureQubits)(void *, long int, unsigned int *, int *) = nullptr;
3253 void *(*fMPSGetMapForSample)() = nullptr;
3254 int (*fMPSFreeMapForSample)(void *) = nullptr;
3255 int (*fMPSSample)(void *, long int, long int, unsigned int *,
3256 void *) = nullptr;
3257
3258 int (*fMPSSaveState)(void *) = nullptr;
3259 int (*fMPSRestoreState)(void *) = nullptr;
3260 int (*fMPSCleanSavedState)(void *) = nullptr;
3261 void *(*fMPSClone)(void *) = nullptr;
3262
3263 double (*fMPSExpectationValue)(void *, const char *, int) = nullptr;
3264 int (*fMPSProjectOnZero)(void *, double *, double *) = nullptr;
3265
3266 int (*fMPSApplyX)(void *, unsigned int) = nullptr;
3267 int (*fMPSApplyY)(void *, unsigned int) = nullptr;
3268 int (*fMPSApplyZ)(void *, unsigned int) = nullptr;
3269 int (*fMPSApplyH)(void *, unsigned int) = nullptr;
3270 int (*fMPSApplyS)(void *, unsigned int) = nullptr;
3271 int (*fMPSApplySDG)(void *, unsigned int) = nullptr;
3272 int (*fMPSApplyT)(void *, unsigned int) = nullptr;
3273 int (*fMPSApplyTDG)(void *, unsigned int) = nullptr;
3274 int (*fMPSApplySX)(void *, unsigned int) = nullptr;
3275 int (*fMPSApplySXDG)(void *, unsigned int) = nullptr;
3276 int (*fMPSApplyK)(void *, unsigned int) = nullptr;
3277 int (*fMPSApplyP)(void *, unsigned int, double) = nullptr;
3278 int (*fMPSApplyRx)(void *, unsigned int, double) = nullptr;
3279 int (*fMPSApplyRy)(void *, unsigned int, double) = nullptr;
3280 int (*fMPSApplyRz)(void *, unsigned int, double) = nullptr;
3281 int (*fMPSApplyU)(void *, unsigned int, double, double, double,
3282 double) = nullptr;
3283 int (*fMPSApplySwap)(void *, unsigned int, unsigned int) = nullptr;
3284 int (*fMPSApplyCX)(void *, unsigned int, unsigned int) = nullptr;
3285 int (*fMPSApplyCY)(void *, unsigned int, unsigned int) = nullptr;
3286 int (*fMPSApplyCZ)(void *, unsigned int, unsigned int) = nullptr;
3287 int (*fMPSApplyCH)(void *, unsigned int, unsigned int) = nullptr;
3288 int (*fMPSApplyCSX)(void *, unsigned int, unsigned int) = nullptr;
3289 int (*fMPSApplyCSXDG)(void *, unsigned int, unsigned int) = nullptr;
3290 int (*fMPSApplyCP)(void *, unsigned int, unsigned int, double) = nullptr;
3291 int (*fMPSApplyCRx)(void *, unsigned int, unsigned int, double) = nullptr;
3292 int (*fMPSApplyCRy)(void *, unsigned int, unsigned int, double) = nullptr;
3293 int (*fMPSApplyCRz)(void *, unsigned int, unsigned int, double) = nullptr;
3294 int (*fMPSApplyCU)(void *, unsigned int, unsigned int, double, double, double,
3295 double) = nullptr;
3296
3297 // tensor network functions
3298 void *(*fCreateTensorNet)(void *) = nullptr;
3299 void (*fDestroyTensorNet)(void *) = nullptr;
3300
3301 int (*fTNCreate)(void *, unsigned int) = nullptr;
3302 int (*fTNReset)(void *) = nullptr;
3303 int (*fTNIsValid)(void *) = nullptr;
3304 int (*fTNIsCreated)(void *) = nullptr;
3305
3306 int (*fTNSetDataType)(void *, int) = nullptr;
3307 int (*fTNIsDoublePrecision)(void *) = nullptr;
3308 int (*fTNSetCutoff)(void *, double) = nullptr;
3309 double (*fTNGetCutoff)(void *) = nullptr;
3310 int (*fTNSetGesvdJ)(void *, int) = nullptr;
3311 int (*fTNGetGesvdJ)(void *) = nullptr;
3312 int (*fTNSetMaxExtent)(void *, long int) = nullptr;
3313 long int (*fTNGetMaxExtent)(void *) = nullptr;
3314 int (*fTNGetNrQubits)(void *) = nullptr;
3315 int (*fTNAmplitude)(void *, long int, long int *, double *,
3316 double *) = nullptr;
3317 double (*fTNProbability0)(void *, unsigned int) = nullptr;
3318 int (*fTNMeasure)(void *, unsigned int) = nullptr;
3319 int (*fTNMeasureQubits)(void *, long int, unsigned int *, int *) = nullptr;
3320 void *(*fTNGetMapForSample)() = nullptr;
3321 int (*fTNFreeMapForSample)(void *) = nullptr;
3322 int (*fTNSample)(void *, long int, long int, unsigned int *,
3323 void *) = nullptr;
3324
3325 int (*fTNSaveState)(void *) = nullptr;
3326 int (*fTNRestoreState)(void *) = nullptr;
3327 int (*fTNCleanSavedState)(void *) = nullptr;
3328 void *(*fTNClone)(void *) = nullptr;
3329
3330 double (*fTNExpectationValue)(void *, const char *, int) = nullptr;
3331
3332 int (*fTNApplyX)(void *, unsigned int) = nullptr;
3333 int (*fTNApplyY)(void *, unsigned int) = nullptr;
3334 int (*fTNApplyZ)(void *, unsigned int) = nullptr;
3335 int (*fTNApplyH)(void *, unsigned int) = nullptr;
3336 int (*fTNApplyS)(void *, unsigned int) = nullptr;
3337 int (*fTNApplySDG)(void *, unsigned int) = nullptr;
3338 int (*fTNApplyT)(void *, unsigned int) = nullptr;
3339 int (*fTNApplyTDG)(void *, unsigned int) = nullptr;
3340 int (*fTNApplySX)(void *, unsigned int) = nullptr;
3341 int (*fTNApplySXDG)(void *, unsigned int) = nullptr;
3342 int (*fTNApplyK)(void *, unsigned int) = nullptr;
3343 int (*fTNApplyP)(void *, unsigned int, double) = nullptr;
3344 int (*fTNApplyRx)(void *, unsigned int, double) = nullptr;
3345 int (*fTNApplyRy)(void *, unsigned int, double) = nullptr;
3346 int (*fTNApplyRz)(void *, unsigned int, double) = nullptr;
3347 int (*fTNApplyU)(void *, unsigned int, double, double, double,
3348 double) = nullptr;
3349 int (*fTNApplySwap)(void *, unsigned int, unsigned int) = nullptr;
3350 int (*fTNApplyCX)(void *, unsigned int, unsigned int) = nullptr;
3351 int (*fTNApplyCY)(void *, unsigned int, unsigned int) = nullptr;
3352 int (*fTNApplyCZ)(void *, unsigned int, unsigned int) = nullptr;
3353 int (*fTNApplyCH)(void *, unsigned int, unsigned int) = nullptr;
3354 int (*fTNApplyCSX)(void *, unsigned int, unsigned int) = nullptr;
3355 int (*fTNApplyCSXDG)(void *, unsigned int, unsigned int) = nullptr;
3356 int (*fTNApplyCP)(void *, unsigned int, unsigned int, double) = nullptr;
3357 int (*fTNApplyCRx)(void *, unsigned int, unsigned int, double) = nullptr;
3358 int (*fTNApplyCRy)(void *, unsigned int, unsigned int, double) = nullptr;
3359 int (*fTNApplyCRz)(void *, unsigned int, unsigned int, double) = nullptr;
3360 int (*fTNApplyCU)(void *, unsigned int, unsigned int, double, double, double,
3361 double) = nullptr;
3362 int (*fTNApplyCCX)(void *, unsigned int, unsigned int,
3363 unsigned int) = nullptr;
3364 int (*fTNApplyCSwap)(void *, unsigned int, unsigned int,
3365 unsigned int) = nullptr;
3366 // stabilizer functions
3367 void *(*fCreateStabilizerSimulator)(long long int, long long int,
3368 long long int, long long int) = nullptr;
3369 void (*fDestroyStabilizerSimulator)(void *) = nullptr;
3370 int (*fExecuteStabilizerCircuit)(void *, const char *, int,
3371 unsigned long long int) = nullptr;
3372 long long (*fGetStabilizerXZTableSize)(void *) = nullptr;
3373 long long (*fGetStabilizerMTableSize)(void *) = nullptr;
3374 long long (*fGetStabilizerTableStrideMajor)(void *) = nullptr;
3375 long long (*fGetStabilizerNumQubits)(void *) = nullptr;
3376 long long (*fGetStabilizerNumShots)(void *) = nullptr;
3377 long long (*fGetStabilizerNumMeasurements)(void *) = nullptr;
3378 long long (*fGetStabilizerNumDetectors)(void *) = nullptr;
3379 int (*fCopyStabilizerXTable)(void *, unsigned int *) = nullptr;
3380 int (*fCopyStabilizerZTable)(void *, unsigned int *) = nullptr;
3381 int (*fCopyStabilizerMTable)(void *, unsigned int *) = nullptr;
3382 int (*fInitStabilizerXTable)(void *, const unsigned int *) = nullptr;
3383 int (*fInitStabilizerZTable)(void *, const unsigned int *) = nullptr;
3384 // Pauli propagation functions
3385 void *(*fCreatePauliPropSimulator)(int) = nullptr;
3386 void (*fDestroyPauliPropSimulator)(void *) = nullptr;
3387
3388 int (*fPauliPropGetNrQubits)(void *) = nullptr;
3389 int (*fPauliPropSetWillUseSampling)(void *, int) = nullptr;
3390 int (*fPauliPropGetWillUseSampling)(void *) = nullptr;
3391 double (*fPauliPropGetCoefficientTruncationCutoff)(void *) = nullptr;
3392 void (*fPauliPropSetCoefficientTruncationCutoff)(void *, double) = nullptr;
3393 double (*fPauliPropGetWeightTruncationCutoff)(void *) = nullptr;
3394 void (*fPauliPropSetWeightTruncationCutoff)(void *, double) = nullptr;
3395 int (*fPauliPropGetNumGatesBetweenTruncations)(void *) = nullptr;
3396 void (*fPauliPropSetNumGatesBetweenTruncations)(void *, int) = nullptr;
3397 int (*fPauliPropGetNumGatesBetweenDeduplications)(void *) = nullptr;
3398 void (*fPauliPropSetNumGatesBetweenDeduplications)(void *, int) = nullptr;
3399 int (*fPauliPropClearOperators)(void *) = nullptr;
3400 int (*fPauliPropAllocateMemory)(void *, double) = nullptr;
3401 double (*fPauliPropGetExpectationValue)(void *) = nullptr;
3402 int (*fPauliPropExecute)(void *) = nullptr;
3403 int (*fPauliPropSetInPauliExpansionUnique)(void *, const char *) = nullptr;
3404 int (*fPauliPropSetInPauliExpansionMultiple)(void *, const char **,
3405 const double *, int) = nullptr;
3406
3407 int (*fPauliPropApplyX)(void *, int) = nullptr;
3408 int (*fPauliPropApplyY)(void *, int) = nullptr;
3409 int (*fPauliPropApplyZ)(void *, int) = nullptr;
3410 int (*fPauliPropApplyH)(void *, int) = nullptr;
3411 int (*fPauliPropApplyS)(void *, int) = nullptr;
3412 int (*fPauliPropApplySQRTX)(void *, int) = nullptr;
3413 int (*fPauliPropApplySQRTY)(void *, int) = nullptr;
3414 int (*fPauliPropApplySQRTZ)(void *, int) = nullptr;
3415 int (*fPauliPropApplyCX)(void *, int, int) = nullptr;
3416 int (*fPauliPropApplyCY)(void *, int, int) = nullptr;
3417 int (*fPauliPropApplyCZ)(void *, int, int) = nullptr;
3418 int (*fPauliPropApplySWAP)(void *, int, int) = nullptr;
3419 int (*fPauliPropApplyISWAP)(void *, int, int) = nullptr;
3420 int (*fPauliPropApplyRX)(void *, int, double) = nullptr;
3421 int (*fPauliPropApplyRY)(void *, int, double) = nullptr;
3422 int (*fPauliPropApplyRZ)(void *, int, double) = nullptr;
3423 int (*fPauliPropAddNoiseX)(void *, int, double) = nullptr;
3424 int (*fPauliPropAddNoiseY)(void *, int, double) = nullptr;
3425 int (*fPauliPropAddNoiseZ)(void *, int, double) = nullptr;
3426 int (*fPauliPropAddNoiseXYZ)(void *, int, double, double, double) = nullptr;
3427 int (*fPauliPropAddAmplitudeDamping)(void *, int, double, double) = nullptr;
3428 double (*fPauliPropQubitProbability0)(void *, int) = nullptr;
3429 double (*fPauliPropProbability)(void *, unsigned long long int) = nullptr;
3430
3431 int (*fPauliPropMeasureQubit)(void *, int) = nullptr;
3432 unsigned char *(*fPauliPropSampleQubits)(void *, const int *, int) = nullptr;
3433 void (*fPauliPropFreeSampledQubits)(unsigned char *) = nullptr;
3434 void (*fPauliPropSaveState)(void *) = nullptr;
3435 void (*fPauliPropRestoreState)(void *) = nullptr;
3436};
3437} // namespace Simulators
3438
3439#endif
3440#endif
int ApplyK(void *sim, int qubit)
double Probability(void *sim, unsigned long long int outcome)
int ApplyRx(void *sim, int qubit, double theta)
int ApplyX(void *sim, int qubit)
int ApplyU(void *sim, int qubit, double theta, double phi, double lambda, double gamma)
int ApplyCRy(void *sim, int controlQubit, int targetQubit, double theta)
int ApplyTDG(void *sim, int qubit)
int ApplyCSXDG(void *sim, int controlQubit, int targetQubit)
int ApplyS(void *sim, int qubit)
int ApplyCX(void *sim, int controlQubit, int targetQubit)
int ApplyCRz(void *sim, int controlQubit, int targetQubit, double theta)
double * AllProbabilities(void *sim)
int ApplyCP(void *sim, int controlQubit, int targetQubit, double theta)
int ApplySXDG(void *sim, int qubit)
int ApplySDG(void *sim, int qubit)
int ApplyCSwap(void *sim, int controlQubit, int qubit1, int qubit2)
int ApplyCCX(void *sim, int controlQubit1, int controlQubit2, int targetQubit)
int ApplyY(void *sim, int qubit)
double * Amplitude(void *sim, unsigned long long int outcome)
int ApplyZ(void *sim, int qubit)
int ApplyH(void *sim, int qubit)
int ApplyCY(void *sim, int controlQubit, int targetQubit)
int ApplyCU(void *sim, int controlQubit, int targetQubit, double theta, double phi, double lambda, double gamma)
int ApplySwap(void *sim, int qubit1, int qubit2)
int ApplyRy(void *sim, int qubit, double theta)
int ApplyP(void *sim, int qubit, double theta)
int ApplyCH(void *sim, int controlQubit, int targetQubit)
int ApplySX(void *sim, int qubit)
int ApplyCZ(void *sim, int controlQubit, int targetQubit)
int ApplyRz(void *sim, int qubit, double theta)
int ApplyT(void *sim, int qubit)
int ApplyCRx(void *sim, int controlQubit, int targetQubit, double theta)
int ApplyCSX(void *sim, int controlQubit, int targetQubit)
int SaveState(void *sim)
virtual bool Init(const char *libName) noexcept
Definition Library.h:78
bool IsMuted() const noexcept
Definition Library.h:114