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