19#include "../Utils/Library.h"
22#include <unordered_map>
30 GpuLibrary(
const GpuLibrary &) =
delete;
31 GpuLibrary &operator=(
const GpuLibrary &) =
delete;
33 GpuLibrary(GpuLibrary &&) =
default;
34 GpuLibrary &operator=(GpuLibrary &&) =
default;
36 GpuLibrary()
noexcept {}
38 virtual ~GpuLibrary() {
39 if (LibraryHandle) FreeLib();
42 bool Init(
const char *libName)
noexcept override {
44 InitLib = (
void *(*)())GetFunction(
"InitLib");
45 CheckFunction((
void *)InitLib, __LINE__);
47 LibraryHandle = InitLib();
49 FreeLib = (void (*)())GetFunction(
"FreeLib");
50 CheckFunction((
void *)FreeLib, __LINE__);
55 (
void *(*)(
void *))GetFunction(
"CreateStateVector");
56 CheckFunction((
void *)fCreateStateVector, __LINE__);
58 (void (*)(
void *))GetFunction(
"DestroyStateVector");
59 CheckFunction((
void *)fDestroyStateVector, __LINE__);
61 fCreate = (int (*)(
void *,
unsigned int))GetFunction(
"Create");
62 CheckFunction((
void *)fCreate, __LINE__);
64 (int (*)(
void *,
unsigned int,
const double *))GetFunction(
66 CheckFunction((
void *)fCreateWithState, __LINE__);
67 fReset = (int (*)(
void *))GetFunction(
"Reset");
68 CheckFunction((
void *)fReset, __LINE__);
70 fSetDataType = (int (*)(
void *, int))GetFunction(
"SetDataType");
71 CheckFunction((
void *)fSetDataType, __LINE__);
73 (int (*)(
void *))GetFunction(
"IsDoublePrecision");
74 CheckFunction((
void *)fIsDoublePrecision, __LINE__);
75 fGetNrQubits = (int (*)(
void *))GetFunction(
"GetNrQubits");
76 CheckFunction((
void *)fGetNrQubits, __LINE__);
78 fMeasureQubitCollapse =
79 (int (*)(
void *, int))GetFunction(
"MeasureQubitCollapse");
80 CheckFunction((
void *)fMeasureQubitCollapse, __LINE__);
81 fMeasureQubitNoCollapse =
82 (int (*)(
void *, int))GetFunction(
"MeasureQubitNoCollapse");
83 CheckFunction((
void *)fMeasureQubitNoCollapse, __LINE__);
84 fMeasureQubitsCollapse = (int (*)(
85 void *,
int *,
int *, int))GetFunction(
"MeasureQubitsCollapse");
86 CheckFunction((
void *)fMeasureQubitsCollapse, __LINE__);
87 fMeasureQubitsNoCollapse = (int (*)(
88 void *,
int *,
int *, int))GetFunction(
"MeasureQubitsNoCollapse");
89 CheckFunction((
void *)fMeasureQubitsNoCollapse, __LINE__);
90 fMeasureAllQubitsCollapse = (
unsigned long long (*)(
91 void *))GetFunction(
"MeasureAllQubitsCollapse");
92 CheckFunction((
void *)fMeasureAllQubitsCollapse, __LINE__);
93 fMeasureAllQubitsNoCollapse = (
unsigned long long (*)(
94 void *))GetFunction(
"MeasureAllQubitsNoCollapse");
95 CheckFunction((
void *)fMeasureAllQubitsNoCollapse, __LINE__);
97 fSaveState = (int (*)(
void *))GetFunction(
"SaveState");
98 CheckFunction((
void *)fSaveState, __LINE__);
99 fSaveStateToHost = (int (*)(
void *))GetFunction(
"SaveStateToHost");
100 CheckFunction((
void *)fSaveStateToHost, __LINE__);
101 fSaveStateDestructive =
102 (int (*)(
void *))GetFunction(
"SaveStateDestructive");
103 CheckFunction((
void *)fSaveStateDestructive, __LINE__);
104 fRestoreStateFreeSaved =
105 (int (*)(
void *))GetFunction(
"RestoreStateFreeSaved");
106 CheckFunction((
void *)fRestoreStateFreeSaved, __LINE__);
107 fRestoreStateNoFreeSaved =
108 (int (*)(
void *))GetFunction(
"RestoreStateNoFreeSaved");
109 CheckFunction((
void *)fRestoreStateNoFreeSaved, __LINE__);
110 fFreeSavedState = (void (*)(
void *))GetFunction(
"FreeSavedState");
111 CheckFunction((
void *)fFreeSavedState, __LINE__);
112 fClone = (
void *(*)(
void *))GetFunction(
"Clone");
113 CheckFunction((
void *)fClone, __LINE__);
115 fSample = (int (*)(
void *,
unsigned int,
long int *,
unsigned int,
116 int *))GetFunction(
"Sample");
117 CheckFunction((
void *)fSample, __LINE__);
118 fSampleAll = (int (*)(
void *,
unsigned int,
long int *))GetFunction(
120 CheckFunction((
void *)fSampleAll, __LINE__);
121 fAmplitude = (int (*)(
void *,
long long int,
double *,
122 double *))GetFunction(
"Amplitude");
123 CheckFunction((
void *)fAmplitude, __LINE__);
125 (double (*)(
void *,
int *,
int *, int))GetFunction(
"Probability");
126 CheckFunction((
void *)fProbability, __LINE__);
127 fBasisStateProbability = (double (*)(
128 void *,
long long int))GetFunction(
"BasisStateProbability");
129 CheckFunction((
void *)fBasisStateProbability, __LINE__);
130 fAllProbabilities = (int (*)(
131 void *obj,
double *probabilities))GetFunction(
"AllProbabilities");
132 CheckFunction((
void *)fAllProbabilities, __LINE__);
133 fExpectationValue = (double (*)(
void *,
const char *,
134 int))GetFunction(
"ExpectationValue");
135 CheckFunction((
void *)fExpectationValue, __LINE__);
137 fApplyX = (int (*)(
void *, int))GetFunction(
"ApplyX");
138 CheckFunction((
void *)fApplyX, __LINE__);
139 fApplyY = (int (*)(
void *, int))GetFunction(
"ApplyY");
140 CheckFunction((
void *)fApplyY, __LINE__);
141 fApplyZ = (int (*)(
void *, int))GetFunction(
"ApplyZ");
142 CheckFunction((
void *)fApplyZ, __LINE__);
143 fApplyH = (int (*)(
void *, int))GetFunction(
"ApplyH");
144 CheckFunction((
void *)fApplyH, __LINE__);
145 fApplyS = (int (*)(
void *, int))GetFunction(
"ApplyS");
146 CheckFunction((
void *)fApplyS, __LINE__);
147 fApplySDG = (int (*)(
void *, int))GetFunction(
"ApplySDG");
148 CheckFunction((
void *)fApplySDG, __LINE__);
149 fApplyT = (int (*)(
void *, int))GetFunction(
"ApplyT");
150 CheckFunction((
void *)fApplyT, __LINE__);
151 fApplyTDG = (int (*)(
void *, int))GetFunction(
"ApplyTDG");
152 CheckFunction((
void *)fApplyTDG, __LINE__);
153 fApplySX = (int (*)(
void *, int))GetFunction(
"ApplySX");
154 CheckFunction((
void *)fApplySX, __LINE__);
155 fApplySXDG = (int (*)(
void *, int))GetFunction(
"ApplySXDG");
156 CheckFunction((
void *)fApplySXDG, __LINE__);
157 fApplyK = (int (*)(
void *, int))GetFunction(
"ApplyK");
158 CheckFunction((
void *)fApplyK, __LINE__);
159 fApplyP = (int (*)(
void *, int, double))GetFunction(
"ApplyP");
160 CheckFunction((
void *)fApplyP, __LINE__);
161 fApplyRx = (int (*)(
void *, int, double))GetFunction(
"ApplyRx");
162 CheckFunction((
void *)fApplyRx, __LINE__);
163 fApplyRy = (int (*)(
void *, int, double))GetFunction(
"ApplyRy");
164 CheckFunction((
void *)fApplyRy, __LINE__);
165 fApplyRz = (int (*)(
void *, int, double))GetFunction(
"ApplyRz");
166 CheckFunction((
void *)fApplyRz, __LINE__);
167 fApplyU = (int (*)(
void *, int, double, double, double,
168 double))GetFunction(
"ApplyU");
169 CheckFunction((
void *)fApplyU, __LINE__);
170 fApplyCX = (int (*)(
void *, int, int))GetFunction(
"ApplyCX");
171 CheckFunction((
void *)fApplyCX, __LINE__);
172 fApplyCY = (int (*)(
void *, int, int))GetFunction(
"ApplyCY");
173 CheckFunction((
void *)fApplyCY, __LINE__);
174 fApplyCZ = (int (*)(
void *, int, int))GetFunction(
"ApplyCZ");
175 CheckFunction((
void *)fApplyCZ, __LINE__);
176 fApplyCH = (int (*)(
void *, int, int))GetFunction(
"ApplyCH");
177 CheckFunction((
void *)fApplyCH, __LINE__);
178 fApplyCSX = (int (*)(
void *, int, int))GetFunction(
"ApplyCSX");
179 CheckFunction((
void *)fApplyCSX, __LINE__);
180 fApplyCSXDG = (int (*)(
void *, int, int))GetFunction(
"ApplyCSXDG");
181 CheckFunction((
void *)fApplyCSXDG, __LINE__);
182 fApplyCP = (int (*)(
void *, int, int, double))GetFunction(
"ApplyCP");
183 CheckFunction((
void *)fApplyCP, __LINE__);
185 (int (*)(
void *, int, int, double))GetFunction(
"ApplyCRx");
186 CheckFunction((
void *)fApplyCRx, __LINE__);
188 (int (*)(
void *, int, int, double))GetFunction(
"ApplyCRy");
189 CheckFunction((
void *)fApplyCRy, __LINE__);
191 (int (*)(
void *, int, int, double))GetFunction(
"ApplyCRz");
192 CheckFunction((
void *)fApplyCRz, __LINE__);
193 fApplyCCX = (int (*)(
void *, int, int, int))GetFunction(
"ApplyCCX");
194 CheckFunction((
void *)fApplyCCX, __LINE__);
195 fApplySwap = (int (*)(
void *, int, int))GetFunction(
"ApplySwap");
196 CheckFunction((
void *)fApplySwap, __LINE__);
198 (int (*)(
void *, int, int, int))GetFunction(
"ApplyCSwap");
199 CheckFunction((
void *)fApplyCSwap, __LINE__);
200 fApplyCU = (int (*)(
void *, int, int, double, double, double,
201 double))GetFunction(
"ApplyCU");
202 CheckFunction((
void *)fApplyCU, __LINE__);
206 fCreateMPS = (
void *(*)(
void *))GetFunction(
"CreateMPS");
207 CheckFunction((
void *)fCreateMPS, __LINE__);
208 fDestroyMPS = (void (*)(
void *))GetFunction(
"DestroyMPS");
209 CheckFunction((
void *)fDestroyMPS, __LINE__);
211 fMPSCreate = (int (*)(
void *,
unsigned int))GetFunction(
"MPSCreate");
212 CheckFunction((
void *)fMPSCreate, __LINE__);
213 fMPSReset = (int (*)(
void *))GetFunction(
"MPSReset");
214 CheckFunction((
void *)fMPSReset, __LINE__);
216 fMPSIsValid = (int (*)(
void *))GetFunction(
"MPSIsValid");
217 CheckFunction((
void *)fMPSIsValid, __LINE__);
218 fMPSIsCreated = (int (*)(
void *))GetFunction(
"MPSIsCreated");
219 CheckFunction((
void *)fMPSIsCreated, __LINE__);
221 fMPSSetDataType = (int (*)(
void *, int))GetFunction(
"MPSSetDataType");
222 CheckFunction((
void *)fMPSSetDataType, __LINE__);
223 fMPSIsDoublePrecision =
224 (int (*)(
void *))GetFunction(
"MPSIsDoublePrecision");
225 CheckFunction((
void *)fMPSIsDoublePrecision, __LINE__);
226 fMPSSetCutoff = (int (*)(
void *, double))GetFunction(
"MPSSetCutoff");
227 CheckFunction((
void *)fMPSSetCutoff, __LINE__);
228 fMPSGetCutoff = (double (*)(
void *))GetFunction(
"MPSGetCutoff");
229 CheckFunction((
void *)fMPSGetCutoff, __LINE__);
230 fMPSSetGesvdJ = (int (*)(
void *, int))GetFunction(
"MPSSetGesvdJ");
231 CheckFunction((
void *)fMPSSetGesvdJ, __LINE__);
232 fMPSGetGesvdJ = (int (*)(
void *))GetFunction(
"MPSGetGesvdJ");
233 CheckFunction((
void *)fMPSGetGesvdJ, __LINE__);
235 (int (*)(
void *,
long int))GetFunction(
"MPSSetMaxExtent");
236 CheckFunction((
void *)fMPSSetMaxExtent, __LINE__);
238 (
long int (*)(
void *))GetFunction(
"MPSGetMaxExtent");
239 CheckFunction((
void *)fMPSGetMaxExtent, __LINE__);
240 fMPSGetNrQubits = (int (*)(
void *))GetFunction(
"MPSGetNrQubits");
241 CheckFunction((
void *)fMPSGetNrQubits, __LINE__);
242 fMPSAmplitude = (int (*)(
void *,
long int,
long int *,
double *,
243 double *))GetFunction(
"MPSAmplitude");
244 CheckFunction((
void *)fMPSAmplitude, __LINE__);
246 (double (*)(
void *,
unsigned int))GetFunction(
"MPSProbability0");
247 CheckFunction((
void *)fMPSProbability0, __LINE__);
249 (int (*)(
void *,
unsigned int))GetFunction(
"MPSMeasure");
250 CheckFunction((
void *)fMPSMeasure, __LINE__);
251 fMPSMeasureQubits = (int (*)(
void *,
long int,
unsigned int *,
252 int *))GetFunction(
"MPSMeasureQubits");
253 CheckFunction((
void *)fMPSMeasureQubits, __LINE__);
255 fMPSGetMapForSample = (
void *(*)())GetFunction(
"MPSGetMapForSample");
256 CheckFunction((
void *)fMPSGetMapForSample, __LINE__);
257 fMPSFreeMapForSample =
258 (int (*)(
void *))GetFunction(
"MPSFreeMapForSample");
259 CheckFunction((
void *)fMPSFreeMapForSample, __LINE__);
260 fMPSSample = (int (*)(
void *,
long int,
long int,
unsigned int *,
261 void *))GetFunction(
"MPSSample");
262 CheckFunction((
void *)fMPSSample, __LINE__);
264 fMPSSaveState = (int (*)(
void *))GetFunction(
"MPSSaveState");
265 CheckFunction((
void *)fMPSSaveState, __LINE__);
266 fMPSRestoreState = (int (*)(
void *))GetFunction(
"MPSRestoreState");
267 CheckFunction((
void *)fMPSRestoreState, __LINE__);
268 fMPSCleanSavedState =
269 (int (*)(
void *))GetFunction(
"MPSCleanSavedState");
270 CheckFunction((
void *)fMPSCleanSavedState, __LINE__);
271 fMPSClone = (
void *(*)(
void *))GetFunction(
"MPSClone");
272 CheckFunction((
void *)fMPSClone, __LINE__);
274 fMPSExpectationValue = (double (*)(
275 void *,
const char *, int))GetFunction(
"MPSExpectationValue");
276 CheckFunction((
void *)fMPSExpectationValue, __LINE__);
278 fMPSApplyX = (int (*)(
void *,
unsigned int))GetFunction(
"MPSApplyX");
279 CheckFunction((
void *)fMPSApplyX, __LINE__);
280 fMPSApplyY = (int (*)(
void *,
unsigned int))GetFunction(
"MPSApplyY");
281 CheckFunction((
void *)fMPSApplyY, __LINE__);
282 fMPSApplyZ = (int (*)(
void *,
unsigned int))GetFunction(
"MPSApplyZ");
283 CheckFunction((
void *)fMPSApplyZ, __LINE__);
284 fMPSApplyH = (int (*)(
void *,
unsigned int))GetFunction(
"MPSApplyH");
285 CheckFunction((
void *)fMPSApplyH, __LINE__);
286 fMPSApplyS = (int (*)(
void *,
unsigned int))GetFunction(
"MPSApplyS");
287 CheckFunction((
void *)fMPSApplyS, __LINE__);
289 (int (*)(
void *,
unsigned int))GetFunction(
"MPSApplySDG");
290 CheckFunction((
void *)fMPSApplySDG, __LINE__);
291 fMPSApplyT = (int (*)(
void *,
unsigned int))GetFunction(
"MPSApplyT");
292 CheckFunction((
void *)fMPSApplyT, __LINE__);
294 (int (*)(
void *,
unsigned int))GetFunction(
"MPSApplyTDG");
295 CheckFunction((
void *)fMPSApplyTDG, __LINE__);
297 (int (*)(
void *,
unsigned int))GetFunction(
"MPSApplySX");
298 CheckFunction((
void *)fMPSApplySX, __LINE__);
300 (int (*)(
void *,
unsigned int))GetFunction(
"MPSApplySXDG");
301 CheckFunction((
void *)fMPSApplySXDG, __LINE__);
302 fMPSApplyK = (int (*)(
void *,
unsigned int))GetFunction(
"MPSApplyK");
303 CheckFunction((
void *)fMPSApplyK, __LINE__);
305 (int (*)(
void *,
unsigned int, double))GetFunction(
"MPSApplyP");
306 CheckFunction((
void *)fMPSApplyP, __LINE__);
308 (int (*)(
void *,
unsigned int, double))GetFunction(
"MPSApplyRx");
309 CheckFunction((
void *)fMPSApplyRx, __LINE__);
311 (int (*)(
void *,
unsigned int, double))GetFunction(
"MPSApplyRy");
312 CheckFunction((
void *)fMPSApplyRy, __LINE__);
314 (int (*)(
void *,
unsigned int, double))GetFunction(
"MPSApplyRz");
315 CheckFunction((
void *)fMPSApplyRz, __LINE__);
316 fMPSApplyU = (int (*)(
void *,
unsigned int, double, double, double,
317 double))GetFunction(
"MPSApplyU");
318 CheckFunction((
void *)fMPSApplyU, __LINE__);
319 fMPSApplySwap = (int (*)(
void *,
unsigned int,
320 unsigned int))GetFunction(
"MPSApplySwap");
321 CheckFunction((
void *)fMPSApplySwap, __LINE__);
322 fMPSApplyCX = (int (*)(
void *,
unsigned int,
323 unsigned int))GetFunction(
"MPSApplyCX");
324 CheckFunction((
void *)fMPSApplyCX, __LINE__);
325 fMPSApplyCY = (int (*)(
void *,
unsigned int,
326 unsigned int))GetFunction(
"MPSApplyCY");
327 CheckFunction((
void *)fMPSApplyCY, __LINE__);
328 fMPSApplyCZ = (int (*)(
void *,
unsigned int,
329 unsigned int))GetFunction(
"MPSApplyCZ");
330 CheckFunction((
void *)fMPSApplyCZ, __LINE__);
331 fMPSApplyCH = (int (*)(
void *,
unsigned int,
332 unsigned int))GetFunction(
"MPSApplyCH");
333 CheckFunction((
void *)fMPSApplyCH, __LINE__);
334 fMPSApplyCSX = (int (*)(
void *,
unsigned int,
335 unsigned int))GetFunction(
"MPSApplyCSX");
336 CheckFunction((
void *)fMPSApplyCSX, __LINE__);
337 fMPSApplyCSXDG = (int (*)(
void *,
unsigned int,
338 unsigned int))GetFunction(
"MPSApplyCSXDG");
339 CheckFunction((
void *)fMPSApplyCSXDG, __LINE__);
340 fMPSApplyCP = (int (*)(
void *,
unsigned int,
unsigned int,
341 double))GetFunction(
"MPSApplyCP");
342 CheckFunction((
void *)fMPSApplyCP, __LINE__);
343 fMPSApplyCRx = (int (*)(
void *,
unsigned int,
unsigned int,
344 double))GetFunction(
"MPSApplyCRx");
345 CheckFunction((
void *)fMPSApplyCRx, __LINE__);
346 fMPSApplyCRy = (int (*)(
void *,
unsigned int,
unsigned int,
347 double))GetFunction(
"MPSApplyCRy");
348 CheckFunction((
void *)fMPSApplyCRy, __LINE__);
349 fMPSApplyCRz = (int (*)(
void *,
unsigned int,
unsigned int,
350 double))GetFunction(
"MPSApplyCRz");
351 CheckFunction((
void *)fMPSApplyCRz, __LINE__);
353 (int (*)(
void *,
unsigned int,
unsigned int, double, double,
354 double, double))GetFunction(
"MPSApplyCU");
355 CheckFunction((
void *)fMPSApplyCU, __LINE__);
359 fCreateTensorNet = (
void *(*)(
void *))GetFunction(
"CreateTensorNet");
360 CheckFunction((
void *)fCreateTensorNet, __LINE__);
361 fDestroyTensorNet = (void (*)(
void *))GetFunction(
"DestroyTensorNet");
362 CheckFunction((
void *)fDestroyTensorNet, __LINE__);
364 fTNCreate = (int (*)(
void *,
unsigned int))GetFunction(
"TNCreate");
365 CheckFunction((
void *)fTNCreate, __LINE__);
366 fTNReset = (int (*)(
void *))GetFunction(
"TNReset");
367 CheckFunction((
void *)fTNReset, __LINE__);
369 fTNIsValid = (int (*)(
void *))GetFunction(
"TNIsValid");
370 CheckFunction((
void *)fTNIsValid, __LINE__);
371 fTNIsCreated = (int (*)(
void *))GetFunction(
"TNIsCreated");
372 CheckFunction((
void *)fTNIsCreated, __LINE__);
374 fTNSetDataType = (int (*)(
void *, int))GetFunction(
"TNSetDataType");
375 CheckFunction((
void *)fTNSetDataType, __LINE__);
376 fTNIsDoublePrecision =
377 (int (*)(
void *))GetFunction(
"TNIsDoublePrecision");
378 CheckFunction((
void *)fTNIsDoublePrecision, __LINE__);
379 fTNSetCutoff = (int (*)(
void *, double))GetFunction(
"TNSetCutoff");
380 CheckFunction((
void *)fTNSetCutoff, __LINE__);
381 fTNGetCutoff = (double (*)(
void *))GetFunction(
"TNGetCutoff");
382 CheckFunction((
void *)fTNGetCutoff, __LINE__);
383 fTNSetGesvdJ = (int (*)(
void *, int))GetFunction(
"TNSetGesvdJ");
384 CheckFunction((
void *)fTNSetGesvdJ, __LINE__);
385 fTNGetGesvdJ = (int (*)(
void *))GetFunction(
"TNGetGesvdJ");
386 CheckFunction((
void *)fTNGetGesvdJ, __LINE__);
388 (int (*)(
void *,
long int))GetFunction(
"TNSetMaxExtent");
389 CheckFunction((
void *)fTNSetMaxExtent, __LINE__);
390 fTNGetMaxExtent = (
long int (*)(
void *))GetFunction(
"TNGetMaxExtent");
391 CheckFunction((
void *)fTNGetMaxExtent, __LINE__);
392 fTNGetNrQubits = (int (*)(
void *))GetFunction(
"TNGetNrQubits");
393 CheckFunction((
void *)fTNGetNrQubits, __LINE__);
394 fTNAmplitude = (int (*)(
void *,
long int,
long int *,
double *,
395 double *))GetFunction(
"TNAmplitude");
396 CheckFunction((
void *)fTNAmplitude, __LINE__);
398 (double (*)(
void *,
unsigned int))GetFunction(
"TNProbability0");
399 CheckFunction((
void *)fTNProbability0, __LINE__);
400 fTNMeasure = (int (*)(
void *,
unsigned int))GetFunction(
"TNMeasure");
401 CheckFunction((
void *)fTNMeasure, __LINE__);
402 fTNMeasureQubits = (int (*)(
void *,
long int,
unsigned int *,
403 int *))GetFunction(
"TNMeasureQubits");
404 CheckFunction((
void *)fTNMeasureQubits, __LINE__);
406 fTNGetMapForSample = (
void *(*)())GetFunction(
"TNGetMapForSample");
407 CheckFunction((
void *)fTNGetMapForSample, __LINE__);
408 fTNFreeMapForSample =
409 (int (*)(
void *))GetFunction(
"TNFreeMapForSample");
410 CheckFunction((
void *)fTNFreeMapForSample, __LINE__);
411 fTNSample = (int (*)(
void *,
long int,
long int,
unsigned int *,
412 void *))GetFunction(
"TNSample");
413 CheckFunction((
void *)fTNSample, __LINE__);
415 fTNSaveState = (int (*)(
void *))GetFunction(
"TNSaveState");
416 CheckFunction((
void *)fTNSaveState, __LINE__);
417 fTNRestoreState = (int (*)(
void *))GetFunction(
"TNRestoreState");
418 CheckFunction((
void *)fTNRestoreState, __LINE__);
420 (int (*)(
void *))GetFunction(
"TNCleanSavedState");
421 CheckFunction((
void *)fTNCleanSavedState, __LINE__);
422 fTNClone = (
void *(*)(
void *))GetFunction(
"TNClone");
423 CheckFunction((
void *)fTNClone, __LINE__);
425 fTNExpectationValue = (double (*)(
426 void *,
const char *, int))GetFunction(
"TNExpectationValue");
427 CheckFunction((
void *)fTNExpectationValue, __LINE__);
429 fTNApplyX = (int (*)(
void *,
unsigned int))GetFunction(
"TNApplyX");
430 CheckFunction((
void *)fTNApplyX, __LINE__);
431 fTNApplyY = (int (*)(
void *,
unsigned int))GetFunction(
"TNApplyY");
432 CheckFunction((
void *)fTNApplyY, __LINE__);
433 fTNApplyZ = (int (*)(
void *,
unsigned int))GetFunction(
"TNApplyZ");
434 CheckFunction((
void *)fTNApplyZ, __LINE__);
435 fTNApplyH = (int (*)(
void *,
unsigned int))GetFunction(
"TNApplyH");
436 CheckFunction((
void *)fTNApplyH, __LINE__);
437 fTNApplyS = (int (*)(
void *,
unsigned int))GetFunction(
"TNApplyS");
438 CheckFunction((
void *)fTNApplyS, __LINE__);
440 (int (*)(
void *,
unsigned int))GetFunction(
"TNApplySDG");
441 CheckFunction((
void *)fTNApplySDG, __LINE__);
442 fTNApplyT = (int (*)(
void *,
unsigned int))GetFunction(
"TNApplyT");
443 CheckFunction((
void *)fTNApplyT, __LINE__);
445 (int (*)(
void *,
unsigned int))GetFunction(
"TNApplyTDG");
446 CheckFunction((
void *)fTNApplyTDG, __LINE__);
447 fTNApplySX = (int (*)(
void *,
unsigned int))GetFunction(
"TNApplySX");
448 CheckFunction((
void *)fTNApplySX, __LINE__);
450 (int (*)(
void *,
unsigned int))GetFunction(
"TNApplySXDG");
451 CheckFunction((
void *)fTNApplySXDG, __LINE__);
452 fTNApplyK = (int (*)(
void *,
unsigned int))GetFunction(
"TNApplyK");
453 CheckFunction((
void *)fTNApplyK, __LINE__);
455 (int (*)(
void *,
unsigned int, double))GetFunction(
"TNApplyP");
456 CheckFunction((
void *)fTNApplyP, __LINE__);
458 (int (*)(
void *,
unsigned int, double))GetFunction(
"TNApplyRx");
459 CheckFunction((
void *)fTNApplyRx, __LINE__);
461 (int (*)(
void *,
unsigned int, double))GetFunction(
"TNApplyRy");
462 CheckFunction((
void *)fTNApplyRy, __LINE__);
464 (int (*)(
void *,
unsigned int, double))GetFunction(
"TNApplyRz");
465 CheckFunction((
void *)fTNApplyRz, __LINE__);
466 fTNApplyU = (int (*)(
void *,
unsigned int, double, double, double,
467 double))GetFunction(
"TNApplyU");
468 CheckFunction((
void *)fTNApplyU, __LINE__);
469 fTNApplySwap = (int (*)(
void *,
unsigned int,
470 unsigned int))GetFunction(
"TNApplySwap");
471 CheckFunction((
void *)fTNApplySwap, __LINE__);
472 fTNApplyCX = (int (*)(
void *,
unsigned int,
unsigned int))GetFunction(
474 CheckFunction((
void *)fTNApplyCX, __LINE__);
475 fTNApplyCY = (int (*)(
void *,
unsigned int,
unsigned int))GetFunction(
477 CheckFunction((
void *)fTNApplyCY, __LINE__);
478 fTNApplyCZ = (int (*)(
void *,
unsigned int,
unsigned int))GetFunction(
480 CheckFunction((
void *)fTNApplyCZ, __LINE__);
481 fTNApplyCH = (int (*)(
void *,
unsigned int,
unsigned int))GetFunction(
483 CheckFunction((
void *)fTNApplyCH, __LINE__);
484 fTNApplyCSX = (int (*)(
void *,
unsigned int,
485 unsigned int))GetFunction(
"TNApplyCSX");
486 CheckFunction((
void *)fTNApplyCSX, __LINE__);
487 fTNApplyCSXDG = (int (*)(
void *,
unsigned int,
488 unsigned int))GetFunction(
"TNApplyCSXDG");
489 CheckFunction((
void *)fTNApplyCSXDG, __LINE__);
490 fTNApplyCP = (int (*)(
void *,
unsigned int,
unsigned int,
491 double))GetFunction(
"TNApplyCP");
492 CheckFunction((
void *)fTNApplyCP, __LINE__);
493 fTNApplyCRx = (int (*)(
void *,
unsigned int,
unsigned int,
494 double))GetFunction(
"TNApplyCRx");
495 CheckFunction((
void *)fTNApplyCRx, __LINE__);
496 fTNApplyCRy = (int (*)(
void *,
unsigned int,
unsigned int,
497 double))GetFunction(
"TNApplyCRy");
498 CheckFunction((
void *)fTNApplyCRy, __LINE__);
499 fTNApplyCRz = (int (*)(
void *,
unsigned int,
unsigned int,
500 double))GetFunction(
"TNApplyCRz");
501 CheckFunction((
void *)fTNApplyCRz, __LINE__);
503 (int (*)(
void *,
unsigned int,
unsigned int, double, double,
504 double, double))GetFunction(
"TNApplyCU");
505 CheckFunction((
void *)fTNApplyCU, __LINE__);
507 fTNApplyCCX = (int (*)(
void *,
unsigned int,
unsigned int,
508 unsigned int))GetFunction(
"TNApplyCCX");
509 CheckFunction((
void *)fTNApplyCCX, __LINE__);
510 fTNApplyCSwap = (int (*)(
void *,
unsigned int,
unsigned int,
511 unsigned int))GetFunction(
"TNApplyCSwap");
512 CheckFunction((
void *)fTNApplyCSwap, __LINE__);
515 fCreateStabilizerSimulator = (
void *(*)(
long long int,
long long int,
516 long long int,
long long int))
517 GetFunction(
"CreateStabilizerSimulator");
518 CheckFunction((
void *)fCreateStabilizerSimulator, __LINE__);
519 fDestroyStabilizerSimulator =
520 (void (*)(
void *))GetFunction(
"DestroyStabilizerSimulator");
521 CheckFunction((
void *)fDestroyStabilizerSimulator, __LINE__);
522 fExecuteStabilizerCircuit = (int (*)(
523 void *,
const char *, int,
524 unsigned long long int))GetFunction(
"ExecuteStabilizerCircuit");
525 CheckFunction((
void *)fExecuteStabilizerCircuit, __LINE__);
526 fGetStabilizerXZTableSize =
527 (
long long (*)(
void *))GetFunction(
"GetStabilizerXZTableSize");
528 CheckFunction((
void *)fGetStabilizerXZTableSize, __LINE__);
529 fGetStabilizerMTableSize =
530 (
long long (*)(
void *))GetFunction(
"GetStabilizerMTableSize");
531 CheckFunction((
void *)fGetStabilizerMTableSize, __LINE__);
533 fGetStabilizerTableStrideMajor = (
long long (*)(
void *))GetFunction(
534 "GetStabilizerTableStrideMajor");
535 CheckFunction((
void *)fGetStabilizerTableStrideMajor, __LINE__);
537 fGetStabilizerNumQubits =
538 (
long long (*)(
void *))GetFunction(
"GetStabilizerNumQubits");
539 CheckFunction((
void *)fGetStabilizerNumQubits, __LINE__);
540 fGetStabilizerNumShots =
541 (
long long (*)(
void *))GetFunction(
"GetStabilizerNumShots");
542 CheckFunction((
void *)fGetStabilizerNumShots, __LINE__);
543 fGetStabilizerNumMeasurements = (
long long (*)(
void *))GetFunction(
544 "GetStabilizerNumMeasurements");
545 CheckFunction((
void *)fGetStabilizerNumMeasurements, __LINE__);
546 fGetStabilizerNumDetectors =
547 (
long long (*)(
void *))GetFunction(
"GetStabilizerNumDetectors");
548 CheckFunction((
void *)fGetStabilizerNumDetectors, __LINE__);
549 fCopyStabilizerXTable = (int (*)(
void *,
unsigned int *))GetFunction(
550 "CopyStabilizerXTable");
551 CheckFunction((
void *)fCopyStabilizerXTable, __LINE__);
552 fCopyStabilizerZTable = (int (*)(
void *,
unsigned int *))GetFunction(
553 "CopyStabilizerZTable");
554 CheckFunction((
void *)fCopyStabilizerZTable, __LINE__);
555 fCopyStabilizerMTable = (int (*)(
void *,
unsigned int *))GetFunction(
556 "CopyStabilizerMTable");
557 CheckFunction((
void *)fCopyStabilizerMTable, __LINE__);
559 fInitStabilizerXTable = (int (*)(
560 void *,
const unsigned int *))GetFunction(
"InitXTable");
561 CheckFunction((
void *)fInitStabilizerXTable, __LINE__);
562 fInitStabilizerZTable = (int (*)(
563 void *,
const unsigned int *))GetFunction(
"InitZTable");
564 CheckFunction((
void *)fInitStabilizerZTable, __LINE__);
567 fCreatePauliPropSimulator = (
void *(*)(
int))GetFunction(
"CreatePauliPropSimulator");
568 CheckFunction((
void *)fCreatePauliPropSimulator, __LINE__);
569 fDestroyPauliPropSimulator = (void (*)(
void *))GetFunction(
"DestroyPauliPropSimulator");
570 CheckFunction((
void *)fDestroyPauliPropSimulator, __LINE__);
572 fPauliPropGetNrQubits = (int (*)(
void *))GetFunction(
"PauliPropGetNrQubits");
573 CheckFunction((
void *)fPauliPropGetNrQubits, __LINE__);
574 fPauliPropSetWillUseSampling = (int (*)(
void *, int))GetFunction(
"PauliPropSetWillUseSampling");
575 CheckFunction((
void *)fPauliPropSetWillUseSampling, __LINE__);
576 fPauliPropGetWillUseSampling = (int (*)(
void *))GetFunction(
"PauliPropGetWillUseSampling");
577 CheckFunction((
void *)fPauliPropGetWillUseSampling, __LINE__);
579 fPauliPropGetCoefficientTruncationCutoff = (double (*)(
void *))GetFunction(
"PauliPropGetCoefficientTruncationCutoff");
580 CheckFunction((
void *)fPauliPropGetCoefficientTruncationCutoff, __LINE__);
581 fPauliPropSetCoefficientTruncationCutoff = (void (*)(
void *, double))GetFunction(
"PauliPropSetCoefficientTruncationCutoff");
582 CheckFunction((
void *)fPauliPropSetCoefficientTruncationCutoff, __LINE__);
583 fPauliPropGetWeightTruncationCutoff = (double (*)(
void *))GetFunction(
"PauliPropGetWeightTruncationCutoff");
584 CheckFunction((
void *)fPauliPropGetWeightTruncationCutoff, __LINE__);
585 fPauliPropSetWeightTruncationCutoff = (void (*)(
void *, double))GetFunction(
"PauliPropSetWeightTruncationCutoff");
586 CheckFunction((
void *)fPauliPropSetWeightTruncationCutoff, __LINE__);
587 fPauliPropGetNumGatesBetweenTruncations = (int (*)(
void *))GetFunction(
"PauliPropGetNumGatesBetweenTruncations");
588 CheckFunction((
void *)fPauliPropGetNumGatesBetweenTruncations, __LINE__);
589 fPauliPropSetNumGatesBetweenTruncations = (void (*)(
void *, int))GetFunction(
"PauliPropSetNumGatesBetweenTruncations");
590 CheckFunction((
void *)fPauliPropSetNumGatesBetweenTruncations, __LINE__);
591 fPauliPropGetNumGatesBetweenDeduplications = (int (*)(
void *))GetFunction(
"PauliPropGetNumGatesBetweenDeduplications");
592 CheckFunction((
void *)fPauliPropGetNumGatesBetweenDeduplications, __LINE__);
593 fPauliPropSetNumGatesBetweenDeduplications = (void (*)(
void *, int))GetFunction(
"PauliPropSetNumGatesBetweenDeduplications");
594 CheckFunction((
void *)fPauliPropSetNumGatesBetweenDeduplications, __LINE__);
597 fPauliPropClearOperators = (int (*)(
void *))GetFunction(
"PauliPropClearOperators");
598 CheckFunction((
void *)fPauliPropClearOperators, __LINE__);
599 fPauliPropAllocateMemory = (int (*)(
void *, double))GetFunction(
"PauliPropAllocateMemory");
600 CheckFunction((
void *)fPauliPropAllocateMemory, __LINE__);
602 fPauliPropGetExpectationValue = (double (*)(
void *))GetFunction(
"PauliPropGetExpectationValue");
603 CheckFunction((
void *)fPauliPropGetExpectationValue, __LINE__);
604 fPauliPropExecute = (int (*)(
void *))GetFunction(
"PauliPropExecute");
605 CheckFunction((
void *)fPauliPropExecute, __LINE__);
606 fPauliPropSetInPauliExpansionUnique = (int (*)(
void *,
const char *))GetFunction(
"PauliPropSetInPauliExpansionUnique");
607 CheckFunction((
void *)fPauliPropSetInPauliExpansionUnique, __LINE__);
608 fPauliPropSetInPauliExpansionMultiple = (int (*)(
void *,
const char **,
609 const double *, int))GetFunction(
"PauliPropSetInPauliExpansionMultiple");
610 CheckFunction((
void *)fPauliPropSetInPauliExpansionMultiple, __LINE__);
612 fPauliPropApplyX = (int (*)(
void *, int))GetFunction(
"PauliPropApplyX");
613 CheckFunction((
void *)fPauliPropApplyX, __LINE__);
614 fPauliPropApplyY = (int (*)(
void *, int))GetFunction(
"PauliPropApplyY");
615 CheckFunction((
void *)fPauliPropApplyY, __LINE__);
616 fPauliPropApplyZ = (int (*)(
void *, int))GetFunction(
"PauliPropApplyZ");
617 CheckFunction((
void *)fPauliPropApplyZ, __LINE__);
618 fPauliPropApplyH = (int (*)(
void *, int))GetFunction(
"PauliPropApplyH");
619 CheckFunction((
void *)fPauliPropApplyH, __LINE__);
620 fPauliPropApplyS = (int (*)(
void *, int))GetFunction(
"PauliPropApplyS");
621 CheckFunction((
void *)fPauliPropApplyS, __LINE__);
623 fPauliPropApplySQRTX = (int (*)(
void *, int))GetFunction(
"PauliPropApplySQRTX");
624 CheckFunction((
void *)fPauliPropApplySQRTX, __LINE__);
625 fPauliPropApplySQRTY = (int (*)(
void *, int))GetFunction(
"PauliPropApplySQRTY");
626 CheckFunction((
void *)fPauliPropApplySQRTY, __LINE__);
627 fPauliPropApplySQRTZ = (int (*)(
void *, int))GetFunction(
"PauliPropApplySQRTZ");
628 CheckFunction((
void *)fPauliPropApplySQRTZ, __LINE__);
629 fPauliPropApplyCX = (int (*)(
void *, int, int))GetFunction(
"PauliPropApplyCX");
630 CheckFunction((
void *)fPauliPropApplyCX, __LINE__);
631 fPauliPropApplyCY = (int (*)(
void *, int, int))GetFunction(
"PauliPropApplyCY");
632 CheckFunction((
void *)fPauliPropApplyCY, __LINE__);
633 fPauliPropApplyCZ = (int (*)(
void *, int, int))GetFunction(
"PauliPropApplyCZ");
634 CheckFunction((
void *)fPauliPropApplyCZ, __LINE__);
635 fPauliPropApplySWAP = (int (*)(
void *, int, int))GetFunction(
"PauliPropApplySWAP");
636 CheckFunction((
void *)fPauliPropApplySWAP, __LINE__);
637 fPauliPropApplyISWAP = (int (*)(
void *, int, int))GetFunction(
"PauliPropApplyISWAP");
638 CheckFunction((
void *)fPauliPropApplyISWAP, __LINE__);
639 fPauliPropApplyRX = (int (*)(
void *, int, double))GetFunction(
"PauliPropApplyRX");
640 CheckFunction((
void *)fPauliPropApplyRX, __LINE__);
641 fPauliPropApplyRY = (int (*)(
void *, int, double))GetFunction(
"PauliPropApplyRY");
642 CheckFunction((
void *)fPauliPropApplyRY, __LINE__);
643 fPauliPropApplyRZ = (int (*)(
void *, int, double))GetFunction(
"PauliPropApplyRZ");
644 CheckFunction((
void *)fPauliPropApplyRZ, __LINE__);
646 fPauliPropAddNoiseX = (int (*)(
void *, int, double))GetFunction(
"PauliPropAddNoiseX");
647 CheckFunction((
void *)fPauliPropAddNoiseX, __LINE__);
648 fPauliPropAddNoiseY = (int (*)(
void *, int, double))GetFunction(
"PauliPropAddNoiseY");
649 CheckFunction((
void *)fPauliPropAddNoiseY, __LINE__);
650 fPauliPropAddNoiseZ = (int (*)(
void *, int, double))GetFunction(
"PauliPropAddNoiseZ");
651 CheckFunction((
void *)fPauliPropAddNoiseZ, __LINE__);
652 fPauliPropAddNoiseXYZ = (int (*)(
void *, int, double, double, double))GetFunction(
"PauliPropAddNoiseXYZ");
653 CheckFunction((
void *)fPauliPropAddNoiseXYZ, __LINE__);
654 fPauliPropAddAmplitudeDamping = (int (*)(
void *, int, double, double))GetFunction(
"PauliPropAddAmplitudeDamping");
655 CheckFunction((
void *)fPauliPropAddAmplitudeDamping, __LINE__);
656 fPauliPropQubitProbability0 = (double (*)(
void *, int))GetFunction(
"PauliPropQubitProbability0");
657 CheckFunction((
void *)fPauliPropQubitProbability0, __LINE__);
658 fPauliPropProbability = (double (*)(
void *,
unsigned long long int))GetFunction(
"PauliPropProbability");
659 CheckFunction((
void *)fPauliPropProbability, __LINE__);
661 fPauliPropMeasureQubit = (int (*)(
void *, int))GetFunction(
"PauliPropMeasureQubit");
662 CheckFunction((
void *)fPauliPropMeasureQubit, __LINE__);
664 fPauliPropSampleQubits = (
unsigned char *(*)(
void *,
const int *,
int))GetFunction(
"PauliPropSampleQubits");
665 CheckFunction((
void *)fPauliPropSampleQubits, __LINE__);
666 fPauliPropFreeSampledQubits = (void (*)(
unsigned char *))GetFunction(
"PauliPropFreeSampledQubits");
667 CheckFunction((
void *)fPauliPropFreeSampledQubits, __LINE__);
668 fPauliPropSaveState = (void (*)(
void *))GetFunction(
"PauliPropSaveState");
669 CheckFunction((
void *)fPauliPropSaveState, __LINE__);
670 fPauliPropRestoreState = (void (*)(
void *))GetFunction(
"PauliPropRestoreState");
671 CheckFunction((
void *)fPauliPropRestoreState, __LINE__);
675 std::cerr <<
"GpuLibrary: Unable to initialize gpu library"
678 std::cerr <<
"GpuLibrary: Unable to get initialization function for "
682 std::cerr <<
"GpuLibrary: Unable to load gpu library" << std::endl;
687 static void CheckFunction(
void *func,
int line) {
689 std::cerr <<
"GpuLibrary: Unable to load function, line #: " << line;
690 const char *dlsym_error = dlerror();
691 if (dlsym_error) std::cerr <<
", error: " << dlsym_error;
693 std::cerr << std::endl;
697 bool IsValid()
const {
return LibraryHandle !=
nullptr; }
701 void *CreateStateVector() {
703 return fCreateStateVector(LibraryHandle);
705 throw std::runtime_error(
"GpuLibrary: Unable to create state vector");
708 void DestroyStateVector(
void *obj) {
710 fDestroyStateVector(obj);
712 throw std::runtime_error(
"GpuLibrary: Unable to destroy state vector");
715 bool Create(
void *obj,
unsigned int nrQubits) {
717 return fCreate(obj, nrQubits) == 1;
719 throw std::runtime_error(
720 "GpuLibrary: Unable to create state vector state");
725 bool CreateWithState(
void *obj,
unsigned int nrQubits,
const double *state) {
727 return fCreateWithState(obj, nrQubits, state) == 1;
729 throw std::runtime_error(
730 "GpuLibrary: Unable to create state vector state with a state");
735 bool Reset(
void *obj) {
737 return fReset(obj) == 1;
739 throw std::runtime_error(
"GpuLibrary: Unable to reset state vector");
744 bool SetDataType(
void *obj,
int dataType) {
746 return fSetDataType(obj, dataType) == 1;
748 throw std::runtime_error(
"GpuLibrary: Unable to set data type");
753 bool IsDoublePrecision(
void *obj)
const {
755 return fIsDoublePrecision(obj) == 1;
757 throw std::runtime_error(
758 "GpuLibrary: Unable to check if double precision");
763 int GetNrQubits(
void *obj)
const {
765 return fGetNrQubits(obj);
767 throw std::runtime_error(
"GpuLibrary: Unable to get number of qubits");
771 bool MeasureQubitCollapse(
void *obj,
int qubitIndex) {
773 return fMeasureQubitCollapse(obj, qubitIndex) == 1;
775 throw std::runtime_error(
776 "GpuLibrary: Unable to measure qubit with collapse");
781 bool MeasureQubitNoCollapse(
void *obj,
int qubitIndex) {
783 return fMeasureQubitNoCollapse(obj, qubitIndex) == 1;
785 throw std::runtime_error(
786 "GpuLibrary: Unable to measure qubit no collapse");
791 bool MeasureQubitsCollapse(
void *obj,
int *qubits,
int *bitstring,
794 return fMeasureQubitsCollapse(obj, qubits, bitstring, bitstringLen) == 1;
796 throw std::runtime_error(
797 "GpuLibrary: Unable to measure qubits with collapse");
802 bool MeasureQubitsNoCollapse(
void *obj,
int *qubits,
int *bitstring,
805 return fMeasureQubitsNoCollapse(obj, qubits, bitstring, bitstringLen) ==
808 throw std::runtime_error(
809 "GpuLibrary: Unable to measure qubits with no collapse");
814 unsigned long long MeasureAllQubitsCollapse(
void *obj) {
816 return fMeasureAllQubitsCollapse(obj);
818 throw std::runtime_error(
819 "GpuLibrary: Unable to measure all qubits with collapse");
824 unsigned long long MeasureAllQubitsNoCollapse(
void *obj) {
826 return fMeasureAllQubitsNoCollapse(obj);
828 throw std::runtime_error(
829 "GpuLibrary: Unable to measure all qubits with no collapse");
836 return fSaveState(obj) == 1;
838 throw std::runtime_error(
"GpuLibrary: Unable to save state");
843 bool SaveStateToHost(
void *obj) {
845 return fSaveStateToHost(obj) == 1;
847 throw std::runtime_error(
"GpuLibrary: Unable to save state to host");
852 bool SaveStateDestructive(
void *obj) {
854 return fSaveStateDestructive(obj) == 1;
856 throw std::runtime_error(
857 "GpuLibrary: Unable to save state destructively");
862 bool RestoreStateFreeSaved(
void *obj) {
864 return fRestoreStateFreeSaved(obj) == 1;
866 throw std::runtime_error(
867 "GpuLibrary: Unable to restore state free saved");
872 bool RestoreStateNoFreeSaved(
void *obj) {
874 return fRestoreStateNoFreeSaved(obj) == 1;
876 throw std::runtime_error(
877 "GpuLibrary: Unable to restore state no free saved");
882 void FreeSavedState(
void *obj) {
884 fFreeSavedState(obj);
886 throw std::runtime_error(
"GpuLibrary: Unable to free saved state");
889 void *Clone(
void *obj)
const {
893 throw std::runtime_error(
"GpuLibrary: Unable to clone state vector");
898 bool Sample(
void *obj,
unsigned int nSamples,
long int *samples,
899 unsigned int nBits,
int *bits) {
901 return fSample(obj, nSamples, samples, nBits, bits) == 1;
903 throw std::runtime_error(
"GpuLibrary: Unable to sample state vector");
908 bool SampleAll(
void *obj,
unsigned int nSamples,
long int *samples) {
910 return fSampleAll(obj, nSamples, samples) == 1;
912 throw std::runtime_error(
"GpuLibrary: Unable to sample state vector");
917 bool Amplitude(
void *obj,
long long int state,
double *real,
918 double *imaginary)
const {
920 return fAmplitude(obj, state, real, imaginary) == 1;
922 throw std::runtime_error(
"GpuLibrary: Unable to get amplitude");
927 double Probability(
void *obj,
int *qubits,
int *mask,
int len)
const {
929 return fProbability(obj, qubits, mask, len);
931 throw std::runtime_error(
"GpuLibrary: Unable to get probability");
936 double BasisStateProbability(
void *obj,
long long int state)
const {
938 return fBasisStateProbability(obj, state);
940 throw std::runtime_error(
941 "GpuLibrary: Unable to get basis state probability");
948 return fAllProbabilities(obj, probabilities) == 1;
950 throw std::runtime_error(
"GpuLibrary: Unable to get all probabilities");
955 double ExpectationValue(
void *obj,
const char *pauliString,
int len)
const {
957 return fExpectationValue(obj, pauliString, len);
959 throw std::runtime_error(
"GpuLibrary: Unable to get expectation value");
964 bool ApplyX(
void *obj,
int qubit) {
966 return fApplyX(obj, qubit) == 1;
968 throw std::runtime_error(
"GpuLibrary: Unable to apply X gate");
973 bool ApplyY(
void *obj,
int qubit) {
975 return fApplyY(obj, qubit) == 1;
977 throw std::runtime_error(
"GpuLibrary: Unable to apply Y gate");
982 bool ApplyZ(
void *obj,
int qubit) {
984 return fApplyZ(obj, qubit) == 1;
986 throw std::runtime_error(
"GpuLibrary: Unable to apply Z gate");
991 bool ApplyH(
void *obj,
int qubit) {
993 return fApplyH(obj, qubit) == 1;
995 throw std::runtime_error(
"GpuLibrary: Unable to apply H gate");
1000 bool ApplyS(
void *obj,
int qubit) {
1002 return fApplyS(obj, qubit) == 1;
1004 throw std::runtime_error(
"GpuLibrary: Unable to apply S gate");
1009 bool ApplySDG(
void *obj,
int qubit) {
1011 return fApplySDG(obj, qubit) == 1;
1013 throw std::runtime_error(
"GpuLibrary: Unable to apply SDG gate");
1018 bool ApplyT(
void *obj,
int qubit) {
1020 return fApplyT(obj, qubit) == 1;
1022 throw std::runtime_error(
"GpuLibrary: Unable to apply T gate");
1027 bool ApplyTDG(
void *obj,
int qubit) {
1029 return fApplyTDG(obj, qubit) == 1;
1031 throw std::runtime_error(
"GpuLibrary: Unable to apply TDG gate");
1036 bool ApplySX(
void *obj,
int qubit) {
1038 return fApplySX(obj, qubit) == 1;
1040 throw std::runtime_error(
"GpuLibrary: Unable to apply SX gate");
1047 return fApplySXDG(obj, qubit) == 1;
1049 throw std::runtime_error(
"GpuLibrary: Unable to apply SXDG gate");
1054 bool ApplyK(
void *obj,
int qubit) {
1056 return fApplyK(obj, qubit) == 1;
1058 throw std::runtime_error(
"GpuLibrary: Unable to apply K gate");
1063 bool ApplyP(
void *obj,
int qubit,
double theta) {
1065 return fApplyP(obj, qubit, theta) == 1;
1067 throw std::runtime_error(
"GpuLibrary: Unable to apply P gate");
1072 bool ApplyRx(
void *obj,
int qubit,
double theta) {
1074 return fApplyRx(obj, qubit, theta) == 1;
1076 throw std::runtime_error(
"GpuLibrary: Unable to apply Rx gate");
1081 bool ApplyRy(
void *obj,
int qubit,
double theta) {
1083 return fApplyRy(obj, qubit, theta) == 1;
1085 throw std::runtime_error(
"GpuLibrary: Unable to apply Ry gate");
1090 bool ApplyRz(
void *obj,
int qubit,
double theta) {
1092 return fApplyRz(obj, qubit, theta) == 1;
1094 throw std::runtime_error(
"GpuLibrary: Unable to apply Rz gate");
1099 bool ApplyU(
void *obj,
int qubit,
double theta,
double phi,
double lambda,
1102 return fApplyU(obj, qubit, theta, phi, lambda, gamma) == 1;
1104 throw std::runtime_error(
"GpuLibrary: Unable to apply U gate");
1109 bool ApplyCX(
void *obj,
int controlQubit,
int targetQubit) {
1111 return fApplyCX(obj, controlQubit, targetQubit) == 1;
1113 throw std::runtime_error(
"GpuLibrary: Unable to apply CX gate");
1118 bool ApplyCY(
void *obj,
int controlQubit,
int targetQubit) {
1120 return fApplyCY(obj, controlQubit, targetQubit) == 1;
1122 throw std::runtime_error(
"GpuLibrary: Unable to apply CY gate");
1127 bool ApplyCZ(
void *obj,
int controlQubit,
int targetQubit) {
1129 return fApplyCZ(obj, controlQubit, targetQubit) == 1;
1131 throw std::runtime_error(
"GpuLibrary: Unable to apply CZ gate");
1136 bool ApplyCH(
void *obj,
int controlQubit,
int targetQubit) {
1138 return fApplyCH(obj, controlQubit, targetQubit) == 1;
1140 throw std::runtime_error(
"GpuLibrary: Unable to apply CH gate");
1145 bool ApplyCSX(
void *obj,
int controlQubit,
int targetQubit) {
1147 return fApplyCSX(obj, controlQubit, targetQubit) == 1;
1149 throw std::runtime_error(
"GpuLibrary: Unable to apply CSX gate");
1154 bool ApplyCSXDG(
void *obj,
int controlQubit,
int targetQubit) {
1156 return fApplyCSXDG(obj, controlQubit, targetQubit) == 1;
1158 throw std::runtime_error(
"GpuLibrary: Unable to apply CSXDG gate");
1163 bool ApplyCP(
void *obj,
int controlQubit,
int targetQubit,
double theta) {
1165 return fApplyCP(obj, controlQubit, targetQubit, theta) == 1;
1167 throw std::runtime_error(
"GpuLibrary: Unable to apply CP gate");
1172 bool ApplyCRx(
void *obj,
int controlQubit,
int targetQubit,
double theta) {
1174 return fApplyCRx(obj, controlQubit, targetQubit, theta) == 1;
1176 throw std::runtime_error(
"GpuLibrary: Unable to apply CRx gate");
1181 bool ApplyCRy(
void *obj,
int controlQubit,
int targetQubit,
double theta) {
1183 return fApplyCRy(obj, controlQubit, targetQubit, theta) == 1;
1185 throw std::runtime_error(
"GpuLibrary: Unable to apply CRy gate");
1190 bool ApplyCRz(
void *obj,
int controlQubit,
int targetQubit,
double theta) {
1192 return fApplyCRz(obj, controlQubit, targetQubit, theta) == 1;
1194 throw std::runtime_error(
"GpuLibrary: Unable to apply CRz gate");
1199 bool ApplyCCX(
void *obj,
int controlQubit1,
int controlQubit2,
1202 return fApplyCCX(obj, controlQubit1, controlQubit2, targetQubit) == 1;
1204 throw std::runtime_error(
"GpuLibrary: Unable to apply CCX gate");
1209 bool ApplySwap(
void *obj,
int qubit1,
int qubit2) {
1211 return fApplySwap(obj, qubit1, qubit2) == 1;
1213 throw std::runtime_error(
"GpuLibrary: Unable to apply Swap gate");
1218 bool ApplyCSwap(
void *obj,
int controlQubit,
int qubit1,
int qubit2) {
1220 return fApplyCSwap(obj, controlQubit, qubit1, qubit2) == 1;
1222 throw std::runtime_error(
"GpuLibrary: Unable to apply CSwap gate");
1227 bool ApplyCU(
void *obj,
int controlQubit,
int targetQubit,
double theta,
1228 double phi,
double lambda,
double gamma) {
1230 return fApplyCU(obj, controlQubit, targetQubit, theta, phi, lambda,
1233 throw std::runtime_error(
"GpuLibrary: Unable to apply CU gate");
1242 return fCreateMPS(LibraryHandle);
1244 throw std::runtime_error(
"GpuLibrary: Unable to create mps");
1247 void DestroyMPS(
void *obj) {
1251 throw std::runtime_error(
"GpuLibrary: Unable to destroy mps");
1254 bool MPSCreate(
void *obj,
unsigned int nrQubits) {
1256 return fMPSCreate(obj, nrQubits) == 1;
1258 throw std::runtime_error(
1259 "GpuLibrary: Unable to create mps with the "
1260 "specified number of qubits");
1265 bool MPSReset(
void *obj) {
1267 return fMPSReset(obj) == 1;
1269 throw std::runtime_error(
"GpuLibrary: Unable to reset mps");
1274 bool MPSIsValid(
void *obj)
const {
1276 return fMPSIsValid(obj) == 1;
1278 throw std::runtime_error(
"GpuLibrary: Unable to check if mps is valid");
1283 bool MPSIsCreated(
void *obj)
const {
1285 return fMPSIsCreated(obj) == 1;
1287 throw std::runtime_error(
"GpuLibrary: Unable to check if mps is created");
1292 bool MPSSetDataType(
void *obj,
int useDoublePrecision) {
1294 return fMPSSetDataType(obj, useDoublePrecision) == 1;
1296 throw std::runtime_error(
"GpuLibrary: Unable to set precision for mps");
1301 bool MPSIsDoublePrecision(
void *obj)
const {
1303 return fMPSIsDoublePrecision(obj) == 1;
1305 throw std::runtime_error(
"GpuLibrary: Unable to get precision for mps");
1310 bool MPSSetCutoff(
void *obj,
double val) {
1312 return fMPSSetCutoff(obj, val) == 1;
1314 throw std::runtime_error(
"GpuLibrary: Unable to set cutoff for mps");
1319 double MPSGetCutoff(
void *obj)
const {
1321 return fMPSGetCutoff(obj);
1323 throw std::runtime_error(
"GpuLibrary: Unable to get cutoff for mps");
1326 bool MPSSetGesvdJ(
void *obj,
int val) {
1328 return fMPSSetGesvdJ(obj, val) == 1;
1330 throw std::runtime_error(
"GpuLibrary: Unable to set GesvdJ for mps");
1335 bool MPSGetGesvdJ(
void *obj)
const {
1337 return fMPSGetGesvdJ(obj) == 1;
1339 throw std::runtime_error(
"GpuLibrary: Unable to get GesvdJ for mps");
1344 bool MPSSetMaxExtent(
void *obj,
long int val) {
1346 return fMPSSetMaxExtent(obj, val) == 1;
1348 throw std::runtime_error(
"GpuLibrary: Unable to set max extent for mps");
1353 long int MPSGetMaxExtent(
void *obj) {
1355 return fMPSGetMaxExtent(obj);
1357 throw std::runtime_error(
"GpuLibrary: Unable to get max extent for mps");
1362 int MPSGetNrQubits(
void *obj) {
1364 return fMPSGetNrQubits(obj);
1366 throw std::runtime_error(
"GpuLibrary: Unable to get nr qubits for mps");
1371 bool MPSAmplitude(
void *obj,
long int numFixedValues,
long int *fixedValues,
1372 double *real,
double *imaginary) {
1374 return fMPSAmplitude(obj, numFixedValues, fixedValues, real, imaginary) ==
1377 throw std::runtime_error(
"GpuLibrary: Unable to get mps amplitude");
1382 double MPSProbability0(
void *obj,
unsigned int qubit) {
1384 return fMPSProbability0(obj, qubit);
1386 throw std::runtime_error(
1387 "GpuLibrary: Unable to get probability for 0 for mps");
1392 bool MPSMeasure(
void *obj,
unsigned int qubit) {
1394 return fMPSMeasure(obj, qubit) == 1;
1396 throw std::runtime_error(
"GpuLibrary: Unable to measure qubit on mps");
1401 bool MPSMeasureQubits(
void *obj,
long int numQubits,
unsigned int *qubits,
1404 return fMPSMeasureQubits(obj, numQubits, qubits, result) == 1;
1406 throw std::runtime_error(
"GpuLibrary: Unable to measure qubits on mps");
1411 std::unordered_map<std::vector<bool>, int64_t> *MPSGetMapForSample() {
1413 return (std::unordered_map<std::vector<bool>, int64_t> *)
1414 fMPSGetMapForSample();
1416 throw std::runtime_error(
1417 "GpuLibrary: Unable to get map for sample for mps");
1422 bool MPSFreeMapForSample(
1423 std::unordered_map<std::vector<bool>, int64_t> *map) {
1425 return fMPSFreeMapForSample((
void *)map) == 1;
1427 throw std::runtime_error(
1428 "GpuLibrary: Unable to free map for sample for mps");
1433 bool MPSSample(
void *obj,
long int numShots,
long int numQubits,
1434 unsigned int *qubits,
void *resultMap) {
1436 return fMPSSample(obj, numShots, numQubits, qubits, resultMap) == 1;
1438 throw std::runtime_error(
"GpuLibrary: Unable to sample mps");
1443 bool MPSSaveState(
void *obj) {
1445 return fMPSSaveState(obj) == 1;
1447 throw std::runtime_error(
"GpuLibrary: Unable to save mps state");
1452 bool MPSRestoreState(
void *obj) {
1454 return fMPSRestoreState(obj) == 1;
1456 throw std::runtime_error(
"GpuLibrary: Unable to restore mps state");
1461 bool MPSCleanSavedState(
void *obj) {
1463 return fMPSCleanSavedState(obj) == 1;
1465 throw std::runtime_error(
"GpuLibrary: Unable to clean mps saved state");
1470 void *MPSClone(
void *obj) {
1472 return fMPSClone(obj);
1474 throw std::runtime_error(
"GpuLibrary: Unable to clone mps");
1479 double MPSExpectationValue(
void *obj,
const char *pauliString,
1482 return fMPSExpectationValue(obj, pauliString, len);
1484 throw std::runtime_error(
1485 "GpuLibrary: Unable to get mps expectation value");
1490 bool MPSApplyX(
void *obj,
unsigned int siteA) {
1492 return fMPSApplyX(obj, siteA) == 1;
1494 throw std::runtime_error(
"GpuLibrary: Unable to apply X gate on mps");
1499 bool MPSApplyY(
void *obj,
unsigned int siteA) {
1501 return fMPSApplyY(obj, siteA) == 1;
1503 throw std::runtime_error(
"GpuLibrary: Unable to apply Y gate on mps");
1508 bool MPSApplyZ(
void *obj,
unsigned int siteA) {
1510 return fMPSApplyZ(obj, siteA) == 1;
1512 throw std::runtime_error(
"GpuLibrary: Unable to apply Z gate on mps");
1517 bool MPSApplyH(
void *obj,
unsigned int siteA) {
1519 return fMPSApplyH(obj, siteA) == 1;
1521 throw std::runtime_error(
"GpuLibrary: Unable to apply H gate on mps");
1526 bool MPSApplyS(
void *obj,
unsigned int siteA) {
1528 return fMPSApplyS(obj, siteA) == 1;
1530 throw std::runtime_error(
"GpuLibrary: Unable to apply S gate on mps");
1535 bool MPSApplySDG(
void *obj,
unsigned int siteA) {
1537 return fMPSApplySDG(obj, siteA) == 1;
1539 throw std::runtime_error(
"GpuLibrary: Unable to apply sdg gate on mps");
1544 bool MPSApplyT(
void *obj,
unsigned int siteA) {
1546 return fMPSApplyT(obj, siteA) == 1;
1548 throw std::runtime_error(
"GpuLibrary: Unable to apply t gate on mps");
1553 bool MPSApplyTDG(
void *obj,
unsigned int siteA) {
1555 return fMPSApplyTDG(obj, siteA) == 1;
1557 throw std::runtime_error(
"GpuLibrary: Unable to appl tdg gate on mps");
1562 bool MPSApplySX(
void *obj,
unsigned int siteA) {
1564 return fMPSApplySX(obj, siteA) == 1;
1566 throw std::runtime_error(
"GpuLibrary: Unable to apply sx gate on mps");
1571 bool MPSApplySXDG(
void *obj,
unsigned int siteA) {
1573 return fMPSApplySXDG(obj, siteA) == 1;
1575 throw std::runtime_error(
"GpuLibrary: Unable to apply sxdg gate on mps");
1580 bool MPSApplyK(
void *obj,
unsigned int siteA) {
1582 return fMPSApplyK(obj, siteA) == 1;
1584 throw std::runtime_error(
"GpuLibrary: Unable to apply k gate on mps");
1589 bool MPSApplyP(
void *obj,
unsigned int siteA,
double theta) {
1591 return fMPSApplyP(obj, siteA, theta) == 1;
1593 throw std::runtime_error(
"GpuLibrary: Unable to apply p gate on mps");
1597 bool MPSApplyRx(
void *obj,
unsigned int siteA,
double theta) {
1599 return fMPSApplyRx(obj, siteA, theta) == 1;
1601 throw std::runtime_error(
"GpuLibrary: Unable to apply rx gate on mps");
1606 bool MPSApplyRy(
void *obj,
unsigned int siteA,
double theta) {
1608 return fMPSApplyRy(obj, siteA, theta) == 1;
1610 throw std::runtime_error(
"GpuLibrary: Unable to apply ry gate on mps");
1615 bool MPSApplyRz(
void *obj,
unsigned int siteA,
double theta) {
1617 return fMPSApplyRz(obj, siteA, theta) == 1;
1619 throw std::runtime_error(
"GpuLibrary: Unable to apply rz gate on mps");
1624 bool MPSApplyU(
void *obj,
unsigned int siteA,
double theta,
double phi,
1625 double lambda,
double gamma) {
1627 return fMPSApplyU(obj, siteA, theta, phi, lambda, gamma) == 1;
1629 throw std::runtime_error(
"GpuLibrary: Unable to apply u gate on mps");
1634 bool MPSApplySwap(
void *obj,
unsigned int controlQubit,
1635 unsigned int targetQubit) {
1637 return fMPSApplySwap(obj, controlQubit, targetQubit) == 1;
1639 throw std::runtime_error(
"GpuLibrary: Unable to apply swap gate on mps");
1644 bool MPSApplyCX(
void *obj,
unsigned int controlQubit,
1645 unsigned int targetQubit) {
1647 return fMPSApplyCX(obj, controlQubit, targetQubit) == 1;
1649 throw std::runtime_error(
"GpuLibrary: Unable to apply cx gate on mps");
1654 bool MPSApplyCY(
void *obj,
unsigned int controlQubit,
1655 unsigned int targetQubit) {
1657 return fMPSApplyCY(obj, controlQubit, targetQubit) == 1;
1659 throw std::runtime_error(
"GpuLibrary: Unable to apply cy gate on mps");
1664 bool MPSApplyCZ(
void *obj,
unsigned int controlQubit,
1665 unsigned int targetQubit) {
1667 return fMPSApplyCZ(obj, controlQubit, targetQubit) == 1;
1669 throw std::runtime_error(
"GpuLibrary: Unable to apply cz gate on mps");
1674 bool MPSApplyCH(
void *obj,
unsigned int controlQubit,
1675 unsigned int targetQubit) {
1677 return fMPSApplyCH(obj, controlQubit, targetQubit) == 1;
1679 throw std::runtime_error(
"GpuLibrary: Unable to apply ch gate on mps");
1684 bool MPSApplyCSX(
void *obj,
unsigned int controlQubit,
1685 unsigned int targetQubit) {
1687 return fMPSApplyCSX(obj, controlQubit, targetQubit) == 1;
1689 throw std::runtime_error(
"GpuLibrary: Unable to apply csx gate on mps");
1692 bool MPSApplyCSXDG(
void *obj,
unsigned int controlQubit,
1693 unsigned int targetQubit) {
1695 return fMPSApplyCSXDG(obj, controlQubit, targetQubit) == 1;
1697 throw std::runtime_error(
"GpuLibrary: Unable to apply csxdg gate on mps");
1702 bool MPSApplyCP(
void *obj,
unsigned int controlQubit,
1703 unsigned int targetQubit,
double theta) {
1705 return fMPSApplyCP(obj, controlQubit, targetQubit, theta) == 1;
1707 throw std::runtime_error(
"GpuLibrary: Unable to apply cp gate on mps");
1712 bool MPSApplyCRx(
void *obj,
unsigned int controlQubit,
1713 unsigned int targetQubit,
double theta) {
1715 return fMPSApplyCRx(obj, controlQubit, targetQubit, theta) == 1;
1717 throw std::runtime_error(
"GpuLibrary: Unable to apply crx gate on mps");
1722 bool MPSApplyCRy(
void *obj,
unsigned int controlQubit,
1723 unsigned int targetQubit,
double theta) {
1725 return fMPSApplyCRy(obj, controlQubit, targetQubit, theta) == 1;
1727 throw std::runtime_error(
"GpuLibrary: Unable to apply cry gate on mps");
1732 bool MPSApplyCRz(
void *obj,
unsigned int controlQubit,
1733 unsigned int targetQubit,
double theta) {
1735 return fMPSApplyCRz(obj, controlQubit, targetQubit, theta) == 1;
1737 throw std::runtime_error(
"GpuLibrary: Unable to apply crz gate on mps");
1742 bool MPSApplyCU(
void *obj,
unsigned int controlQubit,
1743 unsigned int targetQubit,
double theta,
double phi,
1744 double lambda,
double gamma) {
1746 return fMPSApplyCU(obj, controlQubit, targetQubit, theta, phi, lambda,
1749 throw std::runtime_error(
"GpuLibrary: Unable to apply cu gate on mps");
1756 void *CreateTensorNet() {
1758 return fCreateTensorNet(LibraryHandle);
1760 throw std::runtime_error(
"GpuLibrary: Unable to create tensor network");
1763 void DestroyTensorNet(
void *obj) {
1765 fDestroyTensorNet(obj);
1767 throw std::runtime_error(
"GpuLibrary: Unable to destroy tensor network");
1770 bool TNCreate(
void *obj,
unsigned int nrQubits) {
1772 return fTNCreate(obj, nrQubits) == 1;
1774 throw std::runtime_error(
1775 "GpuLibrary: Unable to create tensor network with the "
1776 "specified number of qubits");
1781 bool TNReset(
void *obj) {
1783 return fTNReset(obj) == 1;
1785 throw std::runtime_error(
"GpuLibrary: Unable to reset tensor network");
1790 bool TNIsValid(
void *obj)
const {
1792 return fTNIsValid(obj) == 1;
1794 throw std::runtime_error(
1795 "GpuLibrary: Unable to check if tensor network is valid");
1800 bool TNIsCreated(
void *obj)
const {
1802 return fTNIsCreated(obj) == 1;
1804 throw std::runtime_error(
1805 "GpuLibrary: Unable to check if tensor network is created");
1810 bool TNSetDataType(
void *obj,
int useDoublePrecision) {
1812 return fTNSetDataType(obj, useDoublePrecision) == 1;
1814 throw std::runtime_error(
1815 "GpuLibrary: Unable to set precision for tensor network");
1820 bool TNIsDoublePrecision(
void *obj)
const {
1822 return fTNIsDoublePrecision(obj) == 1;
1824 throw std::runtime_error(
1825 "GpuLibrary: Unable to get precision for tensor network");
1830 bool TNSetCutoff(
void *obj,
double val) {
1832 return fTNSetCutoff(obj, val) == 1;
1834 throw std::runtime_error(
1835 "GpuLibrary: Unable to set cutoff for tensor network");
1840 double TNGetCutoff(
void *obj)
const {
1842 return fTNGetCutoff(obj);
1844 throw std::runtime_error(
1845 "GpuLibrary: Unable to get cutoff for tensor network");
1848 bool TNSetGesvdJ(
void *obj,
int val) {
1850 return fTNSetGesvdJ(obj, val) == 1;
1852 throw std::runtime_error(
1853 "GpuLibrary: Unable to set GesvdJ for tensor network");
1858 bool TNGetGesvdJ(
void *obj)
const {
1860 return fTNGetGesvdJ(obj) == 1;
1862 throw std::runtime_error(
1863 "GpuLibrary: Unable to get GesvdJ for tensor network");
1868 bool TNSetMaxExtent(
void *obj,
long int val) {
1870 return fTNSetMaxExtent(obj, val) == 1;
1872 throw std::runtime_error(
1873 "GpuLibrary: Unable to set max extent for tensor network");
1878 long int TNGetMaxExtent(
void *obj) {
1880 return fTNGetMaxExtent(obj);
1882 throw std::runtime_error(
1883 "GpuLibrary: Unable to get max extent for tensor network");
1888 int TNGetNrQubits(
void *obj) {
1890 return fTNGetNrQubits(obj);
1892 throw std::runtime_error(
1893 "GpuLibrary: Unable to get nr qubits for tensor network");
1898 bool TNAmplitude(
void *obj,
long int numFixedValues,
long int *fixedValues,
1899 double *real,
double *imaginary) {
1901 return fTNAmplitude(obj, numFixedValues, fixedValues, real, imaginary) ==
1904 throw std::runtime_error(
1905 "GpuLibrary: Unable to get tensor network amplitude");
1910 double TNProbability0(
void *obj,
unsigned int qubit) {
1912 return fTNProbability0(obj, qubit);
1914 throw std::runtime_error(
1915 "GpuLibrary: Unable to get probability for 0 for tensor network");
1920 bool TNMeasure(
void *obj,
unsigned int qubit) {
1922 return fTNMeasure(obj, qubit) == 1;
1924 throw std::runtime_error(
1925 "GpuLibrary: Unable to measure qubit on tensor network");
1930 bool TNMeasureQubits(
void *obj,
long int numQubits,
unsigned int *qubits,
1933 return fTNMeasureQubits(obj, numQubits, qubits, result) == 1;
1935 throw std::runtime_error(
1936 "GpuLibrary: Unable to measure qubits on tensor network");
1941 std::unordered_map<std::vector<bool>, int64_t> *TNGetMapForSample() {
1944 std::unordered_map<std::vector<bool>, int64_t> *)fTNGetMapForSample();
1946 throw std::runtime_error(
1947 "GpuLibrary: Unable to get map for sample for tensor network");
1952 bool TNFreeMapForSample(std::unordered_map<std::vector<bool>, int64_t> *map) {
1954 return fTNFreeMapForSample((
void *)map) == 1;
1956 throw std::runtime_error(
1957 "GpuLibrary: Unable to free map for sample for tensor network");
1962 bool TNSample(
void *obj,
long int numShots,
long int numQubits,
1963 unsigned int *qubits,
void *resultMap) {
1965 return fTNSample(obj, numShots, numQubits, qubits, resultMap) == 1;
1967 throw std::runtime_error(
"GpuLibrary: Unable to sample tensor network");
1972 bool TNSaveState(
void *obj) {
1974 return fTNSaveState(obj) == 1;
1976 throw std::runtime_error(
1977 "GpuLibrary: Unable to save tensor network state");
1982 bool TNRestoreState(
void *obj) {
1984 return fTNRestoreState(obj) == 1;
1986 throw std::runtime_error(
1987 "GpuLibrary: Unable to restore tensor network state");
1992 bool TNCleanSavedState(
void *obj) {
1994 return fTNCleanSavedState(obj) == 1;
1996 throw std::runtime_error(
1997 "GpuLibrary: Unable to clean tensor network saved state");
2002 void *TNClone(
void *obj) {
2004 return fTNClone(obj);
2006 throw std::runtime_error(
"GpuLibrary: Unable to clone tensor network");
2011 double TNExpectationValue(
void *obj,
const char *pauliString,
int len)
const {
2013 return fTNExpectationValue(obj, pauliString, len);
2015 throw std::runtime_error(
2016 "GpuLibrary: Unable to get tensor network expectation value");
2021 bool TNApplyX(
void *obj,
unsigned int siteA) {
2023 return fTNApplyX(obj, siteA) == 1;
2025 throw std::runtime_error(
2026 "GpuLibrary: Unable to apply X gate on tensor network");
2031 bool TNApplyY(
void *obj,
unsigned int siteA) {
2033 return fTNApplyY(obj, siteA) == 1;
2035 throw std::runtime_error(
2036 "GpuLibrary: Unable to apply Y gate on tensor network");
2041 bool TNApplyZ(
void *obj,
unsigned int siteA) {
2043 return fTNApplyZ(obj, siteA) == 1;
2045 throw std::runtime_error(
2046 "GpuLibrary: Unable to apply Z gate on tensor network");
2051 bool TNApplyH(
void *obj,
unsigned int siteA) {
2053 return fTNApplyH(obj, siteA) == 1;
2055 throw std::runtime_error(
2056 "GpuLibrary: Unable to apply H gate on tensor network");
2061 bool TNApplyS(
void *obj,
unsigned int siteA) {
2063 return fTNApplyS(obj, siteA) == 1;
2065 throw std::runtime_error(
2066 "GpuLibrary: Unable to apply S gate on tensor network");
2071 bool TNApplySDG(
void *obj,
unsigned int siteA) {
2073 return fTNApplySDG(obj, siteA) == 1;
2075 throw std::runtime_error(
2076 "GpuLibrary: Unable to apply sdg gate on tensor network");
2081 bool TNApplyT(
void *obj,
unsigned int siteA) {
2083 return fTNApplyT(obj, siteA) == 1;
2085 throw std::runtime_error(
2086 "GpuLibrary: Unable to apply t gate on tensor network");
2091 bool TNApplyTDG(
void *obj,
unsigned int siteA) {
2093 return fTNApplyTDG(obj, siteA) == 1;
2095 throw std::runtime_error(
2096 "GpuLibrary: Unable to apply tdg gate on tensor network");
2101 bool TNApplySX(
void *obj,
unsigned int siteA) {
2103 return fTNApplySX(obj, siteA) == 1;
2105 throw std::runtime_error(
2106 "GpuLibrary: Unable to apply sx gate on tensor network");
2111 bool TNApplySXDG(
void *obj,
unsigned int siteA) {
2113 return fTNApplySXDG(obj, siteA) == 1;
2115 throw std::runtime_error(
2116 "GpuLibrary: Unable to apply sxdg gate on tensor network");
2121 bool TNApplyK(
void *obj,
unsigned int siteA) {
2123 return fTNApplyK(obj, siteA) == 1;
2125 throw std::runtime_error(
2126 "GpuLibrary: Unable to apply k gate on tensor network");
2131 bool TNApplyP(
void *obj,
unsigned int siteA,
double theta) {
2133 return fTNApplyP(obj, siteA, theta) == 1;
2135 throw std::runtime_error(
2136 "GpuLibrary: Unable to apply p gate on tensor network");
2140 bool TNApplyRx(
void *obj,
unsigned int siteA,
double theta) {
2142 return fTNApplyRx(obj, siteA, theta) == 1;
2144 throw std::runtime_error(
2145 "GpuLibrary: Unable to apply rx gate on tensor network");
2150 bool TNApplyRy(
void *obj,
unsigned int siteA,
double theta) {
2152 return fTNApplyRy(obj, siteA, theta) == 1;
2154 throw std::runtime_error(
2155 "GpuLibrary: Unable to apply ry gate on tensor network");
2160 bool TNApplyRz(
void *obj,
unsigned int siteA,
double theta) {
2162 return fTNApplyRz(obj, siteA, theta) == 1;
2164 throw std::runtime_error(
2165 "GpuLibrary: Unable to apply rz gate on tensor network");
2170 bool TNApplyU(
void *obj,
unsigned int siteA,
double theta,
double phi,
2171 double lambda,
double gamma) {
2173 return fTNApplyU(obj, siteA, theta, phi, lambda, gamma) == 1;
2175 throw std::runtime_error(
2176 "GpuLibrary: Unable to apply u gate on tensor network");
2181 bool TNApplySwap(
void *obj,
unsigned int controlQubit,
2182 unsigned int targetQubit) {
2184 return fTNApplySwap(obj, controlQubit, targetQubit) == 1;
2186 throw std::runtime_error(
2187 "GpuLibrary: Unable to apply swap gate on tensor network");
2192 bool TNApplyCX(
void *obj,
unsigned int controlQubit,
2193 unsigned int targetQubit) {
2195 return fTNApplyCX(obj, controlQubit, targetQubit) == 1;
2197 throw std::runtime_error(
2198 "GpuLibrary: Unable to apply cx gate on tensor network");
2203 bool TNApplyCY(
void *obj,
unsigned int controlQubit,
2204 unsigned int targetQubit) {
2206 return fTNApplyCY(obj, controlQubit, targetQubit) == 1;
2208 throw std::runtime_error(
2209 "GpuLibrary: Unable to apply cy gate on tensor network");
2214 bool TNApplyCZ(
void *obj,
unsigned int controlQubit,
2215 unsigned int targetQubit) {
2217 return fTNApplyCZ(obj, controlQubit, targetQubit) == 1;
2219 throw std::runtime_error(
2220 "GpuLibrary: Unable to apply cz gate on tensor network");
2225 bool TNApplyCH(
void *obj,
unsigned int controlQubit,
2226 unsigned int targetQubit) {
2228 return fTNApplyCH(obj, controlQubit, targetQubit) == 1;
2230 throw std::runtime_error(
2231 "GpuLibrary: Unable to apply ch gate on tensor network");
2236 bool TNApplyCSX(
void *obj,
unsigned int controlQubit,
2237 unsigned int targetQubit) {
2239 return fTNApplyCSX(obj, controlQubit, targetQubit) == 1;
2241 throw std::runtime_error(
2242 "GpuLibrary: Unable to apply csx gate on tensor network");
2245 bool TNApplyCSXDG(
void *obj,
unsigned int controlQubit,
2246 unsigned int targetQubit) {
2248 return fTNApplyCSXDG(obj, controlQubit, targetQubit) == 1;
2250 throw std::runtime_error(
2251 "GpuLibrary: Unable to apply csxdg gate on tensor network");
2256 bool TNApplyCP(
void *obj,
unsigned int controlQubit,
unsigned int targetQubit,
2259 return fTNApplyCP(obj, controlQubit, targetQubit, theta) == 1;
2261 throw std::runtime_error(
2262 "GpuLibrary: Unable to apply cp gate on tensor network");
2267 bool TNApplyCRx(
void *obj,
unsigned int controlQubit,
2268 unsigned int targetQubit,
double theta) {
2270 return fTNApplyCRx(obj, controlQubit, targetQubit, theta) == 1;
2272 throw std::runtime_error(
2273 "GpuLibrary: Unable to apply crx gate on tensor network");
2278 bool TNApplyCRy(
void *obj,
unsigned int controlQubit,
2279 unsigned int targetQubit,
double theta) {
2281 return fTNApplyCRy(obj, controlQubit, targetQubit, theta) == 1;
2283 throw std::runtime_error(
2284 "GpuLibrary: Unable to apply cry gate on tensor network");
2289 bool TNApplyCRz(
void *obj,
unsigned int controlQubit,
2290 unsigned int targetQubit,
double theta) {
2292 return fTNApplyCRz(obj, controlQubit, targetQubit, theta) == 1;
2294 throw std::runtime_error(
2295 "GpuLibrary: Unable to apply crz gate on tensor network");
2300 bool TNApplyCU(
void *obj,
unsigned int controlQubit,
unsigned int targetQubit,
2301 double theta,
double phi,
double lambda,
double gamma) {
2303 return fTNApplyCU(obj, controlQubit, targetQubit, theta, phi, lambda,
2306 throw std::runtime_error(
2307 "GpuLibrary: Unable to apply cu gate on tensor network");
2312 bool TNApplyCCX(
void *obj,
unsigned int controlQubit1,
2313 unsigned int controlQubit2,
unsigned int targetQubit) {
2315 return fTNApplyCCX(obj, controlQubit1, controlQubit2, targetQubit) == 1;
2317 throw std::runtime_error(
2318 "GpuLibrary: Unable to apply ccx gate on tensor network");
2322 bool TNApplyCSwap(
void *obj,
unsigned int controlQubit,
2323 unsigned int targetQubit1,
unsigned int targetQubit2) {
2325 return fTNApplyCSwap(obj, controlQubit, targetQubit1, targetQubit2) == 1;
2327 throw std::runtime_error(
2328 "GpuLibrary: Unable to apply cswap gate on tensor network");
2333 void *CreateStabilizerSimulator(
long long int numQubits,
2334 long long int numShots,
2335 long long int numMeasurements,
2336 long long int numDetectors) {
2338 return fCreateStabilizerSimulator(numQubits, numShots, numMeasurements,
2341 throw std::runtime_error(
2342 "GpuLibrary: Unable to create stabilizer simulator");
2347 void DestroyStabilizerSimulator(
void *obj) {
2350 fDestroyStabilizerSimulator(obj);
2352 throw std::runtime_error(
2353 "GpuLibrary: Unable to destroy stabilizer simulator");
2356 bool ExecuteStabilizerCircuit(
void *obj,
const char *circuitStr,
2357 int randomizeMeasurements,
2358 unsigned long long int seed) {
2359 if (!obj)
return false;
2361 return fExecuteStabilizerCircuit(obj, circuitStr, randomizeMeasurements,
2364 throw std::runtime_error(
2365 "GpuLibrary: Unable to execute stabilizer circuit");
2370 long long GetStabilizerXZTableSize(
void *obj) {
2373 return fGetStabilizerXZTableSize(obj);
2375 throw std::runtime_error(
2376 "GpuLibrary: Unable to get stabilizer XZ table size");
2381 long long GetStabilizerMTableSize(
void *obj) {
2384 return fGetStabilizerMTableSize(obj);
2386 throw std::runtime_error(
2387 "GpuLibrary: Unable to get stabilizer M table size");
2392 long long GetStabilizerTableStrideMajor(
void *obj) {
2395 return fGetStabilizerTableStrideMajor(obj);
2397 throw std::runtime_error(
2398 "GpuLibrary: Unable to get stabilizer table stride major");
2402 long long GetStabilizerNumQubits(
void *obj) {
2405 return fGetStabilizerNumQubits(obj);
2407 throw std::runtime_error(
2408 "GpuLibrary: Unable to get stabilizer number of qubits");
2413 long long GetStabilizerNumShots(
void *obj) {
2416 return fGetStabilizerNumShots(obj);
2418 throw std::runtime_error(
2419 "GpuLibrary: Unable to get stabilizer number of shots");
2424 long long GetStabilizerNumMeasurements(
void *obj) {
2427 return fGetStabilizerNumMeasurements(obj);
2429 throw std::runtime_error(
2430 "GpuLibrary: Unable to get stabilizer number of measurements");
2435 long long GetStabilizerNumDetectors(
void *obj) {
2438 return fGetStabilizerNumDetectors(obj);
2440 throw std::runtime_error(
2441 "GpuLibrary: Unable to get stabilizer number of detectors");
2446 int CopyStabilizerXTable(
void *obj,
unsigned int *xtable) {
2449 return fCopyStabilizerXTable(obj, xtable);
2451 throw std::runtime_error(
"GpuLibrary: Unable to copy stabilizer X table");
2455 int CopyStabilizerZTable(
void *obj,
unsigned int *ztable) {
2458 return fCopyStabilizerZTable(obj, ztable);
2460 throw std::runtime_error(
"GpuLibrary: Unable to copy stabilizer Z table");
2464 int CopyStabilizerMTable(
void *obj,
unsigned int *mtable) {
2467 return fCopyStabilizerMTable(obj, mtable);
2469 throw std::runtime_error(
"GpuLibrary: Unable to copy stabilizer M table");
2473 int InitStabilizerXTable(
void *obj,
const unsigned int *xtable) {
2476 return fInitStabilizerXTable(obj, xtable);
2478 throw std::runtime_error(
2479 "GpuLibrary: Unable to initialize stabilizer X table");
2483 int InitStabilizerZTable(
void *obj,
const unsigned int *ztable) {
2486 return fInitStabilizerZTable(obj, ztable);
2488 throw std::runtime_error(
2489 "GpuLibrary: Unable to initialize stabilizer Z table");
2494 void* CreatePauliPropSimulator(
int nrQubits)
2497 return fCreatePauliPropSimulator(nrQubits);
2499 throw std::runtime_error(
2500 "GpuLibrary: Unable to create pauli propagation simulator");
2504 void DestroyPauliPropSimulator(
void* obj)
2508 fDestroyPauliPropSimulator(obj);
2510 throw std::runtime_error(
2511 "GpuLibrary: Unable to destroy pauli propagation simulator");
2514 int PauliPropGetNrQubits(
void *obj)
2518 return fPauliPropGetNrQubits(obj);
2520 throw std::runtime_error(
2521 "GpuLibrary: Unable to get number of qubits in pauli propagation simulator");
2525 int PauliPropSetWillUseSampling(
void* obj,
int willUseSampling)
2529 return fPauliPropSetWillUseSampling(obj, willUseSampling) == 1;
2531 throw std::runtime_error(
2532 "GpuLibrary: Unable to set 'will use sampling' in pauli propagation simulator");
2536 int PauliPropGetWillUseSampling(
void* obj)
2540 return fPauliPropGetWillUseSampling(obj);
2542 throw std::runtime_error(
2543 "GpuLibrary: Unable to get 'will use sampling' in pauli propagation simulator");
2547 double PauliPropGetCoefficientTruncationCutoff(
void* obj)
2549 if (!obj)
return 0.0;
2551 return fPauliPropGetCoefficientTruncationCutoff(obj);
2553 throw std::runtime_error(
2554 "GpuLibrary: Unable to get coefficient truncation cutoff in pauli propagation simulator");
2558 void PauliPropSetCoefficientTruncationCutoff(
void* obj,
double cutoff)
2562 fPauliPropSetCoefficientTruncationCutoff(obj, cutoff);
2564 throw std::runtime_error(
2565 "GpuLibrary: Unable to set coefficient truncation cutoff in pauli "
2566 "propagation simulator");
2569 double PauliPropGetWeightTruncationCutoff(
void* obj)
2571 if (!obj)
return 0.0;
2573 return fPauliPropGetWeightTruncationCutoff(obj);
2575 throw std::runtime_error(
2576 "GpuLibrary: Unable to get weight truncation cutoff in pauli propagation simulator");
2580 void PauliPropSetWeightTruncationCutoff(
void* obj,
double cutoff)
2584 fPauliPropSetWeightTruncationCutoff(obj, cutoff);
2586 throw std::runtime_error(
2587 "GpuLibrary: Unable to set weight truncation cutoff in pauli "
2588 "propagation simulator");
2591 int PauliPropGetNumGatesBetweenTruncations(
void* obj)
2595 return fPauliPropGetNumGatesBetweenTruncations(obj);
2597 throw std::runtime_error(
2598 "GpuLibrary: Unable to get number of gates between truncations in pauli propagation simulator");
2602 void PauliPropSetNumGatesBetweenTruncations(
void* obj,
int numGates)
2606 fPauliPropSetNumGatesBetweenTruncations(obj, numGates);
2608 throw std::runtime_error(
2609 "GpuLibrary: Unable to set number of gates between truncations in pauli "
2610 "propagation simulator");
2613 int PauliPropGetNumGatesBetweenDeduplications(
void* obj)
2617 return fPauliPropGetNumGatesBetweenDeduplications(obj);
2619 throw std::runtime_error(
2620 "GpuLibrary: Unable to get number of gates between deduplications in pauli propagation simulator");
2624 void PauliPropSetNumGatesBetweenDeduplications(
void* obj,
int numGates)
2628 fPauliPropSetNumGatesBetweenDeduplications(obj, numGates);
2630 throw std::runtime_error(
2631 "GpuLibrary: Unable to set number of gates between deduplications in pauli "
2632 "propagation simulator");
2635 bool PauliPropClearOperators(
void* obj)
2637 if (!obj)
return false;
2639 return fPauliPropClearOperators(obj) == 1;
2641 throw std::runtime_error(
2642 "GpuLibrary: Unable to clear operators in pauli propagation simulator");
2646 bool PauliPropAllocateMemory(
void* obj,
double percentage)
2648 if (!obj)
return false;
2650 return fPauliPropAllocateMemory(obj, percentage) == 1;
2652 throw std::runtime_error(
2653 "GpuLibrary: Unable to allocate memory in pauli propagation simulator");
2657 double PauliPropGetExpectationValue(
void* obj)
2659 if (!obj)
return 0.0;
2661 return fPauliPropGetExpectationValue(obj);
2663 throw std::runtime_error(
2664 "GpuLibrary: Unable to get expectation value in pauli propagation simulator");
2668 bool PauliPropExecute(
void* obj)
2670 if (!obj)
return false;
2672 return fPauliPropExecute(obj) == 1;
2674 throw std::runtime_error(
2675 "GpuLibrary: Unable to execute pauli propagation simulator");
2679 bool PauliPropSetInPauliExpansionUnique(
void* obj,
const char* pauliString)
2681 if (!obj)
return false;
2683 return fPauliPropSetInPauliExpansionUnique(obj, pauliString) == 1;
2685 throw std::runtime_error(
2686 "GpuLibrary: Unable to set unique pauli in pauli propagation simulator");
2690 bool PauliPropSetInPauliExpansionMultiple(
void* obj,
const char** pauliStrings,
2691 const double* coefficients,
2694 if (!obj)
return false;
2696 return fPauliPropSetInPauliExpansionMultiple(obj, pauliStrings, coefficients, nrPaulis) == 1;
2698 throw std::runtime_error(
2699 "GpuLibrary: Unable to set multiple pauli in pauli propagation simulator");
2703 bool PauliPropApplyX(
void* obj,
int qubit)
2705 if (!obj)
return false;
2707 return fPauliPropApplyX(obj, qubit) == 1;
2709 throw std::runtime_error(
"GpuLibrary: Unable to apply X gate on mps");
2713 bool PauliPropApplyY(
void* obj,
int qubit) {
2714 if (!obj)
return false;
2716 return fPauliPropApplyY(obj, qubit) == 1;
2718 throw std::runtime_error(
"GpuLibrary: Unable to apply Y gate on mps");
2722 bool PauliPropApplyZ(
void *obj,
int qubit)
2724 if (!obj)
return false;
2726 return fPauliPropApplyZ(obj, qubit) == 1;
2728 throw std::runtime_error(
"GpuLibrary: Unable to apply Z gate on mps");
2732 bool PauliPropApplyH(
void *obj,
int qubit)
2734 if (!obj)
return false;
2736 return fPauliPropApplyH(obj, qubit) == 1;
2738 throw std::runtime_error(
"GpuLibrary: Unable to apply H gate on mps");
2742 bool PauliPropApplyS(
void *obj,
int qubit)
2744 if (!obj)
return false;
2746 return fPauliPropApplyS(obj, qubit) == 1;
2748 throw std::runtime_error(
"GpuLibrary: Unable to apply S gate on mps");
2752 bool PauliPropApplySQRTX(
void *obj,
int qubit)
2754 if (!obj)
return false;
2756 return fPauliPropApplySQRTX(obj, qubit) == 1;
2758 throw std::runtime_error(
"GpuLibrary: Unable to apply SQRTX gate on mps");
2762 bool PauliPropApplySQRTY(
void *obj,
int qubit)
2764 if (!obj)
return false;
2766 return fPauliPropApplySQRTY(obj, qubit) == 1;
2768 throw std::runtime_error(
"GpuLibrary: Unable to apply SQRTY gate on mps");
2772 bool PauliPropApplySQRTZ(
void *obj,
int qubit)
2774 if (!obj)
return false;
2776 return fPauliPropApplySQRTZ(obj, qubit) == 1;
2778 throw std::runtime_error(
"GpuLibrary: Unable to apply SQRTZ gate on mps");
2782 bool PauliPropApplyCX(
void *obj,
int targetQubit,
int controlQubit)
2784 if (!obj)
return false;
2786 return fPauliPropApplyCX(obj, targetQubit, controlQubit) == 1;
2788 throw std::runtime_error(
"GpuLibrary: Unable to apply CX gate on mps");
2792 bool PauliPropApplyCY(
void *obj,
int targetQubit,
int controlQubit)
2794 if (!obj)
return false;
2796 return fPauliPropApplyCY(obj, targetQubit, controlQubit) == 1;
2798 throw std::runtime_error(
"GpuLibrary: Unable to apply CY gate on mps");
2802 bool PauliPropApplyCZ(
void *obj,
int targetQubit,
int controlQubit)
2804 if (!obj)
return false;
2806 return fPauliPropApplyCZ(obj, targetQubit, controlQubit) == 1;
2808 throw std::runtime_error(
"GpuLibrary: Unable to apply CZ gate on mps");
2812 bool PauliPropApplySWAP(
void *obj,
int qubit1,
int qubit2)
2814 if (!obj)
return false;
2816 return fPauliPropApplySWAP(obj, qubit1, qubit2) == 1;
2818 throw std::runtime_error(
"GpuLibrary: Unable to apply SWAP gate on mps");
2822 bool PauliPropApplyISWAP(
void *obj,
int qubit1,
int qubit2)
2824 if (!obj)
return false;
2826 return fPauliPropApplyISWAP(obj, qubit1, qubit2) == 1;
2828 throw std::runtime_error(
"GpuLibrary: Unable to apply ISWAP gate on mps");
2832 bool PauliPropApplyRX(
void *obj,
int qubit,
double angle)
2834 if (!obj)
return false;
2836 return fPauliPropApplyRX(obj, qubit, angle) == 1;
2838 throw std::runtime_error(
"GpuLibrary: Unable to apply RX gate on mps");
2842 bool PauliPropApplyRY(
void *obj,
int qubit,
double angle)
2844 if (!obj)
return false;
2846 return fPauliPropApplyRY(obj, qubit, angle) == 1;
2848 throw std::runtime_error(
"GpuLibrary: Unable to apply RY gate on mps");
2852 bool PauliPropApplyRZ(
void *obj,
int qubit,
double angle)
2854 if (!obj)
return false;
2856 return fPauliPropApplyRZ(obj, qubit, angle) == 1;
2858 throw std::runtime_error(
"GpuLibrary: Unable to apply RZ gate on mps");
2862 bool PauliPropAddNoiseX(
void *obj,
int qubit,
double probability)
2864 if (!obj)
return false;
2866 return fPauliPropAddNoiseX(obj, qubit, probability) == 1;
2868 throw std::runtime_error(
"GpuLibrary: Unable to add X noise on mps");
2872 bool PauliPropAddNoiseY(
void *obj,
int qubit,
double probability)
2874 if (!obj)
return false;
2876 return fPauliPropAddNoiseY(obj, qubit, probability) == 1;
2878 throw std::runtime_error(
"GpuLibrary: Unable to add Y noise on mps");
2882 bool PauliPropAddNoiseZ(
void* obj,
int qubit,
double probability)
2884 if (!obj)
return false;
2886 return fPauliPropAddNoiseZ(obj, qubit, probability) == 1;
2888 throw std::runtime_error(
"GpuLibrary: Unable to add Z noise on mps");
2892 bool PauliPropAddNoiseXYZ(
void* obj,
int qubit,
double probabilityX,
2893 double probabilityY,
double probabilityZ)
2895 if (!obj)
return false;
2897 return fPauliPropAddNoiseXYZ(obj, qubit, probabilityX,
2898 probabilityY, probabilityZ) == 1;
2900 throw std::runtime_error(
"GpuLibrary: Unable to add XYZ noise on mps");
2904 bool PauliPropAddAmplitudeDamping(
void* obj,
int qubit,
double dampingProb,
double exciteProb)
2906 if (!obj)
return false;
2908 return fPauliPropAddAmplitudeDamping(obj, qubit, dampingProb, exciteProb) == 1;
2910 throw std::runtime_error(
2911 "GpuLibrary: Unable to add amplitude damping on mps");
2915 double PauliPropQubitProbability0(
void *obj,
int qubit)
2917 if (!obj)
return 0.0;
2919 return fPauliPropQubitProbability0(obj, qubit);
2921 throw std::runtime_error(
2922 "GpuLibrary: Unable to get qubit probability 0 in pauli propagation simulator");
2926 double PauliPropProbability(
void* obj,
unsigned long long int outcome)
2928 if (!obj)
return 0.0;
2930 return fPauliPropProbability(obj, outcome);
2932 throw std::runtime_error(
2933 "GpuLibrary: Unable to get probability of outcome in pauli propagation simulator");
2937 bool PauliPropMeasureQubit(
void* obj,
int qubit)
2939 if (!obj)
return false;
2941 return fPauliPropMeasureQubit(obj, qubit) == 1;
2943 throw std::runtime_error(
2944 "GpuLibrary: Unable to measure qubit in pauli propagation simulator");
2948 unsigned char* PauliPropSampleQubits(
void* obj,
const int* qubits,
2951 if (!obj)
return nullptr;
2953 return fPauliPropSampleQubits(obj, qubits, nrQubits);
2955 throw std::runtime_error(
2956 "GpuLibrary: Unable to sample qubits in pauli propagation simulator");
2960 void PauliPropFreeSampledQubits(
unsigned char* samples)
2962 if (!samples)
return;
2964 fPauliPropFreeSampledQubits(samples);
2966 throw std::runtime_error(
2967 "GpuLibrary: Unable to free sampled qubits in pauli propagation "
2971 void PauliPropSaveState(
void *obj)
2975 fPauliPropSaveState(obj);
2977 throw std::runtime_error(
2978 "GpuLibrary: Unable to save state in pauli propagation simulator");
2981 void PauliPropRestoreState(
void *obj)
2985 fPauliPropRestoreState(obj);
2987 throw std::runtime_error(
2988 "GpuLibrary: Unable to restore state in pauli propagation simulator");
2992 void *LibraryHandle =
nullptr;
2997 void *(*fCreateStateVector)(
void *);
2998 void (*fDestroyStateVector)(
void *);
3001 int (*fSetDataType)(
void *, int);
3002 int (*fIsDoublePrecision)(
void *);
3003 int (*fGetNrQubits)(
void *);
3004 int (*fCreate)(
void *,
unsigned int);
3005 int (*fReset)(
void *);
3006 int (*fCreateWithState)(
void *,
unsigned int,
const double *);
3007 int (*fMeasureQubitCollapse)(
void *, int);
3008 int (*fMeasureQubitNoCollapse)(
void *, int);
3009 int (*fMeasureQubitsCollapse)(
void *,
int *,
int *, int);
3010 int (*fMeasureQubitsNoCollapse)(
void *,
int *,
int *, int);
3011 unsigned long long (*fMeasureAllQubitsCollapse)(
void *);
3012 unsigned long long (*fMeasureAllQubitsNoCollapse)(
void *);
3014 int (*fSaveState)(
void *);
3015 int (*fSaveStateToHost)(
void *);
3016 int (*fSaveStateDestructive)(
void *);
3017 int (*fRestoreStateFreeSaved)(
void *);
3018 int (*fRestoreStateNoFreeSaved)(
void *);
3019 void (*fFreeSavedState)(
void *obj);
3020 void *(*fClone)(
void *);
3021 int (*fSample)(
void *,
unsigned int,
long int *,
unsigned int,
int *);
3022 int (*fSampleAll)(
void *,
unsigned int,
long int *);
3023 int (*fAmplitude)(
void *,
long long int,
double *,
double *);
3024 double (*fProbability)(
void *,
int *,
int *, int);
3025 double (*fBasisStateProbability)(
void *,
long long int);
3026 int (*fAllProbabilities)(
void *,
double *);
3027 double (*fExpectationValue)(
void *,
const char *, int);
3029 int (*fApplyX)(
void *, int);
3030 int (*fApplyY)(
void *, int);
3031 int (*fApplyZ)(
void *, int);
3032 int (*fApplyH)(
void *, int);
3033 int (*fApplyS)(
void *, int);
3034 int (*fApplySDG)(
void *, int);
3035 int (*fApplyT)(
void *, int);
3036 int (*fApplyTDG)(
void *, int);
3037 int (*fApplySX)(
void *, int);
3038 int (*fApplySXDG)(
void *, int);
3039 int (*fApplyK)(
void *, int);
3040 int (*fApplyP)(
void *, int, double);
3041 int (*fApplyRx)(
void *, int, double);
3042 int (*fApplyRy)(
void *, int, double);
3043 int (*fApplyRz)(
void *, int, double);
3044 int (*fApplyU)(
void *, int, double, double, double, double);
3045 int (*fApplyCX)(
void *, int, int);
3046 int (*fApplyCY)(
void *, int, int);
3047 int (*fApplyCZ)(
void *, int, int);
3048 int (*fApplyCH)(
void *, int, int);
3049 int (*fApplyCSX)(
void *, int, int);
3050 int (*fApplyCSXDG)(
void *, int, int);
3051 int (*fApplyCP)(
void *, int, int, double);
3052 int (*fApplyCRx)(
void *, int, int, double);
3053 int (*fApplyCRy)(
void *, int, int, double);
3054 int (*fApplyCRz)(
void *, int, int, double);
3055 int (*fApplyCCX)(
void *, int, int, int);
3056 int (*fApplySwap)(
void *, int, int);
3057 int (*fApplyCSwap)(
void *, int, int, int);
3058 int (*fApplyCU)(
void *, int, int, double, double, double, double);
3061 void *(*fCreateMPS)(
void *);
3062 void (*fDestroyMPS)(
void *);
3064 int (*fMPSCreate)(
void *,
unsigned int);
3065 int (*fMPSReset)(
void *);
3067 int (*fMPSIsValid)(
void *);
3068 int (*fMPSIsCreated)(
void *);
3070 int (*fMPSSetDataType)(
void *, int);
3071 int (*fMPSIsDoublePrecision)(
void *);
3072 int (*fMPSSetCutoff)(
void *, double);
3073 double (*fMPSGetCutoff)(
void *);
3074 int (*fMPSSetGesvdJ)(
void *, int);
3075 int (*fMPSGetGesvdJ)(
void *);
3076 int (*fMPSSetMaxExtent)(
void *,
long int);
3077 long int (*fMPSGetMaxExtent)(
void *);
3078 int (*fMPSGetNrQubits)(
void *);
3079 int (*fMPSAmplitude)(
void *,
long int,
long int *,
double *,
double *);
3080 double (*fMPSProbability0)(
void *,
unsigned int);
3081 int (*fMPSMeasure)(
void *,
unsigned int);
3082 int (*fMPSMeasureQubits)(
void *,
long int,
unsigned int *,
int *);
3084 void *(*fMPSGetMapForSample)();
3085 int (*fMPSFreeMapForSample)(
void *);
3086 int (*fMPSSample)(
void *,
long int,
long int,
unsigned int *,
void *);
3088 int (*fMPSSaveState)(
void *);
3089 int (*fMPSRestoreState)(
void *);
3090 int (*fMPSCleanSavedState)(
void *);
3091 void *(*fMPSClone)(
void *);
3093 double (*fMPSExpectationValue)(
void *,
const char *, int);
3095 int (*fMPSApplyX)(
void *,
unsigned int);
3096 int (*fMPSApplyY)(
void *,
unsigned int);
3097 int (*fMPSApplyZ)(
void *,
unsigned int);
3098 int (*fMPSApplyH)(
void *,
unsigned int);
3099 int (*fMPSApplyS)(
void *,
unsigned int);
3100 int (*fMPSApplySDG)(
void *,
unsigned int);
3101 int (*fMPSApplyT)(
void *,
unsigned int);
3102 int (*fMPSApplyTDG)(
void *,
unsigned int);
3103 int (*fMPSApplySX)(
void *,
unsigned int);
3104 int (*fMPSApplySXDG)(
void *,
unsigned int);
3105 int (*fMPSApplyK)(
void *,
unsigned int);
3106 int (*fMPSApplyP)(
void *,
unsigned int, double);
3107 int (*fMPSApplyRx)(
void *,
unsigned int, double);
3108 int (*fMPSApplyRy)(
void *,
unsigned int, double);
3109 int (*fMPSApplyRz)(
void *,
unsigned int, double);
3110 int (*fMPSApplyU)(
void *,
unsigned int, double, double, double, double);
3111 int (*fMPSApplySwap)(
void *,
unsigned int,
unsigned int);
3112 int (*fMPSApplyCX)(
void *,
unsigned int,
unsigned int);
3113 int (*fMPSApplyCY)(
void *,
unsigned int,
unsigned int);
3114 int (*fMPSApplyCZ)(
void *,
unsigned int,
unsigned int);
3115 int (*fMPSApplyCH)(
void *,
unsigned int,
unsigned int);
3116 int (*fMPSApplyCSX)(
void *,
unsigned int,
unsigned int);
3117 int (*fMPSApplyCSXDG)(
void *,
unsigned int,
unsigned int);
3118 int (*fMPSApplyCP)(
void *,
unsigned int,
unsigned int, double);
3119 int (*fMPSApplyCRx)(
void *,
unsigned int,
unsigned int, double);
3120 int (*fMPSApplyCRy)(
void *,
unsigned int,
unsigned int, double);
3121 int (*fMPSApplyCRz)(
void *,
unsigned int,
unsigned int, double);
3122 int (*fMPSApplyCU)(
void *,
unsigned int,
unsigned int, double, double, double,
3126 void *(*fCreateTensorNet)(
void *);
3127 void (*fDestroyTensorNet)(
void *);
3129 int (*fTNCreate)(
void *,
unsigned int);
3130 int (*fTNReset)(
void *);
3132 int (*fTNIsValid)(
void *);
3133 int (*fTNIsCreated)(
void *);
3135 int (*fTNSetDataType)(
void *, int);
3136 int (*fTNIsDoublePrecision)(
void *);
3137 int (*fTNSetCutoff)(
void *, double);
3138 double (*fTNGetCutoff)(
void *);
3139 int (*fTNSetGesvdJ)(
void *, int);
3140 int (*fTNGetGesvdJ)(
void *);
3141 int (*fTNSetMaxExtent)(
void *,
long int);
3142 long int (*fTNGetMaxExtent)(
void *);
3143 int (*fTNGetNrQubits)(
void *);
3144 int (*fTNAmplitude)(
void *,
long int,
long int *,
double *,
double *);
3145 double (*fTNProbability0)(
void *,
unsigned int);
3146 int (*fTNMeasure)(
void *,
unsigned int);
3147 int (*fTNMeasureQubits)(
void *,
long int,
unsigned int *,
int *);
3149 void *(*fTNGetMapForSample)();
3150 int (*fTNFreeMapForSample)(
void *);
3151 int (*fTNSample)(
void *,
long int,
long int,
unsigned int *,
void *);
3153 int (*fTNSaveState)(
void *);
3154 int (*fTNRestoreState)(
void *);
3155 int (*fTNCleanSavedState)(
void *);
3156 void *(*fTNClone)(
void *);
3158 double (*fTNExpectationValue)(
void *,
const char *, int);
3160 int (*fTNApplyX)(
void *,
unsigned int);
3161 int (*fTNApplyY)(
void *,
unsigned int);
3162 int (*fTNApplyZ)(
void *,
unsigned int);
3163 int (*fTNApplyH)(
void *,
unsigned int);
3164 int (*fTNApplyS)(
void *,
unsigned int);
3165 int (*fTNApplySDG)(
void *,
unsigned int);
3166 int (*fTNApplyT)(
void *,
unsigned int);
3167 int (*fTNApplyTDG)(
void *,
unsigned int);
3168 int (*fTNApplySX)(
void *,
unsigned int);
3169 int (*fTNApplySXDG)(
void *,
unsigned int);
3170 int (*fTNApplyK)(
void *,
unsigned int);
3171 int (*fTNApplyP)(
void *,
unsigned int, double);
3172 int (*fTNApplyRx)(
void *,
unsigned int, double);
3173 int (*fTNApplyRy)(
void *,
unsigned int, double);
3174 int (*fTNApplyRz)(
void *,
unsigned int, double);
3175 int (*fTNApplyU)(
void *,
unsigned int, double, double, double, double);
3176 int (*fTNApplySwap)(
void *,
unsigned int,
unsigned int);
3177 int (*fTNApplyCX)(
void *,
unsigned int,
unsigned int);
3178 int (*fTNApplyCY)(
void *,
unsigned int,
unsigned int);
3179 int (*fTNApplyCZ)(
void *,
unsigned int,
unsigned int);
3180 int (*fTNApplyCH)(
void *,
unsigned int,
unsigned int);
3181 int (*fTNApplyCSX)(
void *,
unsigned int,
unsigned int);
3182 int (*fTNApplyCSXDG)(
void *,
unsigned int,
unsigned int);
3183 int (*fTNApplyCP)(
void *,
unsigned int,
unsigned int, double);
3184 int (*fTNApplyCRx)(
void *,
unsigned int,
unsigned int, double);
3185 int (*fTNApplyCRy)(
void *,
unsigned int,
unsigned int, double);
3186 int (*fTNApplyCRz)(
void *,
unsigned int,
unsigned int, double);
3187 int (*fTNApplyCU)(
void *,
unsigned int,
unsigned int, double, double, double,
3189 int (*fTNApplyCCX)(
void *,
unsigned int,
unsigned int,
unsigned int);
3190 int (*fTNApplyCSwap)(
void *,
unsigned int,
unsigned int,
unsigned int);
3193 void *(*fCreateStabilizerSimulator)(
long long int,
long long int,
3194 long long int,
long long int);
3195 void (*fDestroyStabilizerSimulator)(
void *);
3196 int (*fExecuteStabilizerCircuit)(
void *,
const char *, int,
3197 unsigned long long int);
3198 long long (*fGetStabilizerXZTableSize)(
void *);
3199 long long (*fGetStabilizerMTableSize)(
void *);
3200 long long (*fGetStabilizerTableStrideMajor)(
void *);
3201 long long (*fGetStabilizerNumQubits)(
void *);
3202 long long (*fGetStabilizerNumShots)(
void *);
3203 long long (*fGetStabilizerNumMeasurements)(
void *);
3204 long long (*fGetStabilizerNumDetectors)(
void *);
3205 int (*fCopyStabilizerXTable)(
void *,
unsigned int *);
3206 int (*fCopyStabilizerZTable)(
void *,
unsigned int *);
3207 int (*fCopyStabilizerMTable)(
void *,
unsigned int *);
3208 int (*fInitStabilizerXTable)(
void *,
const unsigned int *);
3209 int (*fInitStabilizerZTable)(
void *,
const unsigned int *);
3212 void *(*fCreatePauliPropSimulator)(int);
3213 void (*fDestroyPauliPropSimulator)(
void *);
3215 int (*fPauliPropGetNrQubits)(
void *);
3216 int (*fPauliPropSetWillUseSampling)(
void *, int);
3217 int (*fPauliPropGetWillUseSampling)(
void *);
3218 double (*fPauliPropGetCoefficientTruncationCutoff)(
void *);
3219 void (*fPauliPropSetCoefficientTruncationCutoff)(
void *, double);
3220 double (*fPauliPropGetWeightTruncationCutoff)(
void *);
3221 void (*fPauliPropSetWeightTruncationCutoff)(
void *, double);
3222 int (*fPauliPropGetNumGatesBetweenTruncations)(
void *);
3223 void (*fPauliPropSetNumGatesBetweenTruncations)(
void *, int);
3224 int (*fPauliPropGetNumGatesBetweenDeduplications)(
void *);
3225 void (*fPauliPropSetNumGatesBetweenDeduplications)(
void *, int);
3226 int (*fPauliPropClearOperators)(
void *);
3227 int (*fPauliPropAllocateMemory)(
void *, double);
3228 double (*fPauliPropGetExpectationValue)(
void *);
3229 int (*fPauliPropExecute)(
void *);
3230 int (*fPauliPropSetInPauliExpansionUnique)(
void *,
const char *);
3231 int (*fPauliPropSetInPauliExpansionMultiple)(
void *,
const char **,
3232 const double *, int);
3234 int (*fPauliPropApplyX)(
void *, int);
3235 int (*fPauliPropApplyY)(
void *, int);
3236 int (*fPauliPropApplyZ)(
void *, int);
3237 int (*fPauliPropApplyH)(
void *, int);
3238 int (*fPauliPropApplyS)(
void *, int);
3239 int (*fPauliPropApplySQRTX)(
void *, int);
3240 int (*fPauliPropApplySQRTY)(
void *, int);
3241 int (*fPauliPropApplySQRTZ)(
void *, int);
3242 int (*fPauliPropApplyCX)(
void *, int, int);
3243 int (*fPauliPropApplyCY)(
void *, int, int);
3244 int (*fPauliPropApplyCZ)(
void *, int, int);
3245 int (*fPauliPropApplySWAP)(
void *, int, int);
3246 int (*fPauliPropApplyISWAP)(
void *, int, int);
3247 int (*fPauliPropApplyRX)(
void *, int, double);
3248 int (*fPauliPropApplyRY)(
void *, int, double);
3249 int (*fPauliPropApplyRZ)(
void *, int, double);
3251 int (*fPauliPropAddNoiseX)(
void *, int, double);
3252 int (*fPauliPropAddNoiseY)(
void *, int, double);
3253 int (*fPauliPropAddNoiseZ)(
void *, int, double);
3254 int (*fPauliPropAddNoiseXYZ)(
void *, int, double, double, double);
3255 int (*fPauliPropAddAmplitudeDamping)(
void *, int, double, double);
3256 double (*fPauliPropQubitProbability0)(
void *, int);
3257 double (*fPauliPropProbability)(
void *,
unsigned long long int);
3259 int (*fPauliPropMeasureQubit)(
void *, int);
3260 unsigned char *(*fPauliPropSampleQubits)(
void *,
const int *, int);
3261 void (*fPauliPropFreeSampledQubits)(
unsigned char *);
3262 void (*fPauliPropSaveState)(
void *);
3263 void (*fPauliPropRestoreState)(
void *);
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)
virtual bool Init(const char *libName) noexcept
bool IsMuted() const noexcept