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