Maestro 0.3.1
Unified interface for quantum circuit simulation
Loading...
Searching...
No Matches
GpuLibrary.h
Go to the documentation of this file.
1
38
39#pragma once
40
41#ifndef _GPU_LIBRARY_H
42#define _GPU_LIBRARY_H
43
44#ifdef __linux__
45
46#include "../Utils/Library.h"
47
48#include <cstdlib>
49#include <stdint.h>
50#include <unordered_map>
51#include <vector>
52#include <complex>
53#include <stdexcept>
54#include <memory>
55#include <mutex>
56
57namespace Simulators {
58
59// One plugin handle and API table for the process. The plugin owns device state.
60class GpuLibrary : public Utils::Library {
61 GpuLibrary() noexcept = default;
62
63 public:
64 static std::shared_ptr<GpuLibrary> GetInstance() {
65 static const auto instance = std::shared_ptr<GpuLibrary>(new GpuLibrary());
66 return instance;
67 }
68
69 GpuLibrary(const GpuLibrary &) = delete;
70 GpuLibrary &operator=(const GpuLibrary &) = delete;
71 GpuLibrary(GpuLibrary &&) = delete;
72 GpuLibrary &operator=(GpuLibrary &&) = delete;
73
74 ~GpuLibrary() override {
75 if (LibraryHandle && FreeLib) FreeLib();
76 }
77
78 // Keep selection and native simulator initialization together even if the
79 // plugin's selected device is process-global. Ordinary simulator operations
80 // do not take this lock or change the device: the plugin owns that behavior.
81 std::unique_lock<std::recursive_mutex> LockInitialization() {
82 return std::unique_lock<std::recursive_mutex>(initializationMutex);
83 }
84
85 bool Load(const char *libName) noexcept {
86 auto lock = LockInitialization();
87 if (GetHandle()) {
88 if (loadedPath == libName) return true;
89 if (!IsMuted())
90 std::cerr << "GpuLibrary: singleton already loaded from " << loadedPath
91 << "; cannot load " << libName << std::endl;
92 return false;
93 }
94 if (!Utils::Library::Init(libName)) return false;
95 loadedPath = libName;
96 fGetGpuDeviceCount = (int (*)())GetFunction("GetGpuDeviceCount");
97 fSetGpuDevice = (int (*)(int))GetFunction("SetGpuDevice");
98 fGetStateVectorGpuId = (int (*)(void*))GetFunction("GetStateVectorGpuId");
99 fMPSGetGpuId = (int (*)(void*))GetFunction("MPSGetGpuId");
100 fTNGetGpuId = (int (*)(void*))GetFunction("TNGetGpuId");
101 fDMGetGpuId = (int (*)(void*))GetFunction("DMGetGpuId");
102 fMPOGetGpuId = (int (*)(void*))GetFunction("MPOGetGpuId");
103 fGetStabilizerGpuId = (int (*)(void*))GetFunction("GetStabilizerGpuId");
104 fPauliPropGetGpuId = (int (*)(void*))GetFunction("PauliPropGetGpuId");
105
106 return true;
107 }
108
109 int DiscoverDevices(const char *path) {
110 auto lock = LockInitialization();
111 SetMute(true);
112 return Load(path) ? GetGpuDeviceCount() : 0;
113 }
114
115 bool InitializeForDevice(const char *path, int device, bool mute = false) {
116 auto lock = LockInitialization();
117 SetMute(mute);
118 if (device < 0) throw std::invalid_argument("gpu_device must be nonnegative");
119 if (!Load(path)) return false;
120 const int count = GetGpuDeviceCount();
121 if (device >= count) {
122 if (!mute)
123 std::cerr << "GpuLibrary: GPU device " << device << " is unavailable ("
124 << count << " visible devices)" << std::endl;
125 return false;
126 }
127 // Reapply selection on every acquisition, including after InitLib has
128 // already run. Native objects retain their own device inside the plugin.
129 if (!SetGpuDevice(device)) {
130 if (!mute)
131 std::cerr << "GpuLibrary: Unable to select GPU device " << device << std::endl;
132 return false;
133 }
134 return Init(path);
135 }
136
137 bool Init(const char *libName) noexcept override {
138 auto lock = LockInitialization();
139 if (!Load(libName)) return false;
140 if (IsValid()) return true;
141 {
142 // Validate license before initializing the library.
143 // The license key is read from the MAESTRO_LICENSE_KEY env var.
144 // If not set, nullptr is passed to attempt cached/offline validation.
145 fValidateLicense = (int (*)(const char *))GetFunction("ValidateLicense");
146 if (!fValidateLicense) {
147 if (!IsMuted())
148 std::cerr << "GpuLibrary: License validation symbol not found. "
149 "The GPU library must export ValidateLicense."
150 << std::endl;
151 return false;
152 }
153 const char *licenseKey = std::getenv("MAESTRO_LICENSE_KEY");
154 int licenseStatus = fValidateLicense(licenseKey);
155 if (licenseStatus != 1) {
156 if (!IsMuted()) {
157 std::cerr << "GpuLibrary: License validation failed. ";
158 if (!licenseKey)
159 std::cerr << "Set MAESTRO_LICENSE_KEY environment variable "
160 "or activate the license first."
161 << std::endl;
162 else
163 std::cerr << "Check that your license key is correct." << std::endl;
164 }
165 return false;
166 }
167
168 FreeLib = (void (*)())GetFunction("FreeLib");
169 if (!fSetGpuDevice || !FreeLib) {
170 if (!IsMuted())
171 std::cerr << "GpuLibrary: SetGpuDevice and FreeLib are required." << std::endl;
172 return false;
173 }
174
175 InitLib = (void *(*)())GetFunction("InitLib");
176 CheckFunction((void *)InitLib, __LINE__);
177 if (InitLib) {
178 LibraryHandle = InitLib();
179 if (LibraryHandle) {
180 FreeLib = (void (*)())GetFunction("FreeLib");
181 CheckFunction((void *)FreeLib, __LINE__);
182
183 // state vector api functions
184
185 fCreateStateVector =
186 (void *(*)(void *))GetFunction("CreateStateVector");
187 CheckFunction((void *)fCreateStateVector, __LINE__);
188 fDestroyStateVector =
189 (void (*)(void *))GetFunction("DestroyStateVector");
190 CheckFunction((void *)fDestroyStateVector, __LINE__);
191
192 fCreate = (int (*)(void *, unsigned int))GetFunction("Create");
193 CheckFunction((void *)fCreate, __LINE__);
194 fCreateWithState =
195 (int (*)(void *, unsigned int, const double *))GetFunction(
196 "CreateWithState");
197 CheckFunction((void *)fCreateWithState, __LINE__);
198 fReset = (int (*)(void *))GetFunction("Reset");
199 CheckFunction((void *)fReset, __LINE__);
200
201 fSetDataType = (int (*)(void *, int))GetFunction("SetDataType");
202 CheckFunction((void *)fSetDataType, __LINE__);
203 fIsDoublePrecision =
204 (int (*)(void *))GetFunction("IsDoublePrecision");
205 CheckFunction((void *)fIsDoublePrecision, __LINE__);
206 fGetNrQubits = (int (*)(void *))GetFunction("GetNrQubits");
207 CheckFunction((void *)fGetNrQubits, __LINE__);
208
209 fMeasureQubitCollapse =
210 (int (*)(void *, int))GetFunction("MeasureQubitCollapse");
211 CheckFunction((void *)fMeasureQubitCollapse, __LINE__);
212 fMeasureQubitNoCollapse =
213 (int (*)(void *, int))GetFunction("MeasureQubitNoCollapse");
214 CheckFunction((void *)fMeasureQubitNoCollapse, __LINE__);
215 fMeasureQubitsCollapse = (int (*)(
216 void *, int *, int *, int))GetFunction("MeasureQubitsCollapse");
217 CheckFunction((void *)fMeasureQubitsCollapse, __LINE__);
218 fMeasureQubitsNoCollapse = (int (*)(
219 void *, int *, int *, int))GetFunction("MeasureQubitsNoCollapse");
220 CheckFunction((void *)fMeasureQubitsNoCollapse, __LINE__);
221 fMeasureAllQubitsCollapse = (unsigned long long (*)(
222 void *))GetFunction("MeasureAllQubitsCollapse");
223 CheckFunction((void *)fMeasureAllQubitsCollapse, __LINE__);
224 fMeasureAllQubitsNoCollapse = (unsigned long long (*)(
225 void *))GetFunction("MeasureAllQubitsNoCollapse");
226 CheckFunction((void *)fMeasureAllQubitsNoCollapse, __LINE__);
227
228 fSaveState = (int (*)(void *))GetFunction("SaveState");
229 CheckFunction((void *)fSaveState, __LINE__);
230 fSaveStateToHost = (int (*)(void *))GetFunction("SaveStateToHost");
231 CheckFunction((void *)fSaveStateToHost, __LINE__);
232 fSaveStateDestructive =
233 (int (*)(void *))GetFunction("SaveStateDestructive");
234 CheckFunction((void *)fSaveStateDestructive, __LINE__);
235 fRestoreStateFreeSaved =
236 (int (*)(void *))GetFunction("RestoreStateFreeSaved");
237 CheckFunction((void *)fRestoreStateFreeSaved, __LINE__);
238 fRestoreStateNoFreeSaved =
239 (int (*)(void *))GetFunction("RestoreStateNoFreeSaved");
240 CheckFunction((void *)fRestoreStateNoFreeSaved, __LINE__);
241 fFreeSavedState = (void (*)(void *))GetFunction("FreeSavedState");
242 CheckFunction((void *)fFreeSavedState, __LINE__);
243 fClone = (void *(*)(void *))GetFunction("Clone");
244 CheckFunction((void *)fClone, __LINE__);
245 fSetSeed =
246 (int (*)(void *, unsigned long long))GetFunction("SetSeed");
247 CheckFunction((void *)fSetSeed, __LINE__);
248
249 fSample = (int (*)(void *, unsigned int, long int *, unsigned int,
250 int *))GetFunction("Sample");
251 CheckFunction((void *)fSample, __LINE__);
252 fSampleAll = (int (*)(void *, unsigned int, long int *))GetFunction(
253 "SampleAll");
254 CheckFunction((void *)fSampleAll, __LINE__);
255 fAmplitude = (int (*)(void *, long long int, double *,
256 double *))GetFunction("Amplitude");
257 CheckFunction((void *)fAmplitude, __LINE__);
258 fProbability =
259 (double (*)(void *, int *, int *, int))GetFunction("Probability");
260 CheckFunction((void *)fProbability, __LINE__);
261 fBasisStateProbability = (double (*)(
262 void *, long long int))GetFunction("BasisStateProbability");
263 CheckFunction((void *)fBasisStateProbability, __LINE__);
264 fAllProbabilities = (int (*)(
265 void *obj, double *probabilities))GetFunction("AllProbabilities");
266 CheckFunction((void *)fAllProbabilities, __LINE__);
267 fExpectationValue = (double (*)(void *, const char *,
268 int))GetFunction("ExpectationValue");
269 CheckFunction((void *)fExpectationValue, __LINE__);
270
271 fApplyX = (int (*)(void *, int))GetFunction("ApplyX");
272 CheckFunction((void *)fApplyX, __LINE__);
273 fApplyY = (int (*)(void *, int))GetFunction("ApplyY");
274 CheckFunction((void *)fApplyY, __LINE__);
275 fApplyZ = (int (*)(void *, int))GetFunction("ApplyZ");
276 CheckFunction((void *)fApplyZ, __LINE__);
277 fApplyH = (int (*)(void *, int))GetFunction("ApplyH");
278 CheckFunction((void *)fApplyH, __LINE__);
279 fApplyS = (int (*)(void *, int))GetFunction("ApplyS");
280 CheckFunction((void *)fApplyS, __LINE__);
281 fApplySDG = (int (*)(void *, int))GetFunction("ApplySDG");
282 CheckFunction((void *)fApplySDG, __LINE__);
283 fApplyT = (int (*)(void *, int))GetFunction("ApplyT");
284 CheckFunction((void *)fApplyT, __LINE__);
285 fApplyTDG = (int (*)(void *, int))GetFunction("ApplyTDG");
286 CheckFunction((void *)fApplyTDG, __LINE__);
287 fApplySX = (int (*)(void *, int))GetFunction("ApplySX");
288 CheckFunction((void *)fApplySX, __LINE__);
289 fApplySXDG = (int (*)(void *, int))GetFunction("ApplySXDG");
290 CheckFunction((void *)fApplySXDG, __LINE__);
291 fApplyK = (int (*)(void *, int))GetFunction("ApplyK");
292 CheckFunction((void *)fApplyK, __LINE__);
293 fApplyP = (int (*)(void *, int, double))GetFunction("ApplyP");
294 CheckFunction((void *)fApplyP, __LINE__);
295 fApplyRx = (int (*)(void *, int, double))GetFunction("ApplyRx");
296 CheckFunction((void *)fApplyRx, __LINE__);
297 fApplyRy = (int (*)(void *, int, double))GetFunction("ApplyRy");
298 CheckFunction((void *)fApplyRy, __LINE__);
299 fApplyRz = (int (*)(void *, int, double))GetFunction("ApplyRz");
300 CheckFunction((void *)fApplyRz, __LINE__);
301 fApplyU = (int (*)(void *, int, double, double, double,
302 double))GetFunction("ApplyU");
303 CheckFunction((void *)fApplyU, __LINE__);
304 fApplyCX = (int (*)(void *, int, int))GetFunction("ApplyCX");
305 CheckFunction((void *)fApplyCX, __LINE__);
306 fApplyCY = (int (*)(void *, int, int))GetFunction("ApplyCY");
307 CheckFunction((void *)fApplyCY, __LINE__);
308 fApplyCZ = (int (*)(void *, int, int))GetFunction("ApplyCZ");
309 CheckFunction((void *)fApplyCZ, __LINE__);
310 fApplyCH = (int (*)(void *, int, int))GetFunction("ApplyCH");
311 CheckFunction((void *)fApplyCH, __LINE__);
312 fApplyCSX = (int (*)(void *, int, int))GetFunction("ApplyCSX");
313 CheckFunction((void *)fApplyCSX, __LINE__);
314 fApplyCSXDG = (int (*)(void *, int, int))GetFunction("ApplyCSXDG");
315 CheckFunction((void *)fApplyCSXDG, __LINE__);
316 fApplyCP = (int (*)(void *, int, int, double))GetFunction("ApplyCP");
317 CheckFunction((void *)fApplyCP, __LINE__);
318 fApplyCRx =
319 (int (*)(void *, int, int, double))GetFunction("ApplyCRx");
320 CheckFunction((void *)fApplyCRx, __LINE__);
321 fApplyCRy =
322 (int (*)(void *, int, int, double))GetFunction("ApplyCRy");
323 CheckFunction((void *)fApplyCRy, __LINE__);
324 fApplyCRz =
325 (int (*)(void *, int, int, double))GetFunction("ApplyCRz");
326 CheckFunction((void *)fApplyCRz, __LINE__);
327 fApplyCCX = (int (*)(void *, int, int, int))GetFunction("ApplyCCX");
328 CheckFunction((void *)fApplyCCX, __LINE__);
329 fApplySwap = (int (*)(void *, int, int))GetFunction("ApplySwap");
330 CheckFunction((void *)fApplySwap, __LINE__);
331 fApplyCSwap =
332 (int (*)(void *, int, int, int))GetFunction("ApplyCSwap");
333 CheckFunction((void *)fApplyCSwap, __LINE__);
334 fApplyCU = (int (*)(void *, int, int, double, double, double,
335 double))GetFunction("ApplyCU");
336 CheckFunction((void *)fApplyCU, __LINE__);
337
338 // density matrix api functions
339#define LOAD_DM(name, type) \
340 f##name = reinterpret_cast<type>(GetFunction(#name)); \
341 CheckFunction(reinterpret_cast<void *>(f##name), __LINE__)
342 LOAD_DM(CreateDensityMatrix, void *(*)(void *));
343 LOAD_DM(DestroyDensityMatrix, void (*)(void *));
344 LOAD_DM(DMCreate, int (*)(void *, unsigned int));
345 LOAD_DM(DMCreateWithState,
346 int (*)(void *, unsigned int, const double *));
347 LOAD_DM(DMCreateWithBasisState,
348 int (*)(void *, unsigned int, unsigned long long));
349 LOAD_DM(DMCreateWithMixtureOfBasisStates,
350 int (*)(void *, unsigned int, const unsigned long long *,
351 const double *, int));
352 LOAD_DM(DMReset, int (*)(void *));
353 LOAD_DM(DMIsValid, int (*)(void *));
354 LOAD_DM(DMIsCreated, int (*)(void *));
355 LOAD_DM(DMSetDataType, int (*)(void *, int));
356 LOAD_DM(DMIsDoublePrecision, int (*)(void *));
357 LOAD_DM(DMGetNrQubits, int (*)(void *));
358 LOAD_DM(DMSaveState, int (*)(void *));
359 LOAD_DM(DMRestoreState, int (*)(void *));
360 LOAD_DM(DMCleanSavedState, int (*)(void *));
361 LOAD_DM(DMClone, void *(*)(void *));
362 LOAD_DM(DMSetSeed, int (*)(void *, unsigned long long));
363 LOAD_DM(DMMeasureQubitCollapse, int (*)(void *, int));
364 LOAD_DM(DMMeasureQubitNoCollapse, int (*)(void *, int));
365 LOAD_DM(DMMeasureQubitsCollapse, int (*)(void *, int *, int *, int));
366 LOAD_DM(DMMeasureQubitsNoCollapse, int (*)(void *, int *, int *, int));
367 LOAD_DM(DMMeasureAllQubitsCollapse, unsigned long long (*)(void *));
368 LOAD_DM(DMMeasureAllQubitsNoCollapse, unsigned long long (*)(void *));
369 LOAD_DM(DMSample, int (*)(void *, unsigned int, long int *, unsigned int, int *));
370 LOAD_DM(DMSampleAll,
371 int (*)(void *, unsigned int, long int *));
372 LOAD_DM(DMGetElement,
373 int (*)(void *, long long, long long, double *, double *));
374 LOAD_DM(DMBasisStateProbability, double (*)(void *, long long));
375 LOAD_DM(DMAllProbabilities, int (*)(void *, double *));
376 LOAD_DM(DMExpectationValue,
377 double (*)(void *, const char *, int));
378 LOAD_DM(DMQubitProbability0, double (*)(void *, unsigned int));
379 LOAD_DM(DMTrace, double (*)(void *));
380 LOAD_DM(DMPurity, double (*)(void *));
381 LOAD_DM(DMIsHermitian, int (*)(void *, double));
382 LOAD_DM(DMPartialTrace, int (*)(void *, const int *, int, double *));
383 LOAD_DM(DMHilbertSchmidtOverlap, int (*)(void *, void *, double *, double *));
384 LOAD_DM(DMFidelityWithStatevector, int (*)(void *, const double *, double *));
385 LOAD_DM(DMApplyKraus,
386 int (*)(void *, int, const int *, int, const double *));
387#define LOAD_DM_GATE1(name) LOAD_DM(name, int (*)(void *, int))
388#define LOAD_DM_GATE2(name) LOAD_DM(name, int (*)(void *, int, int))
389#define LOAD_DM_ROT1(name) LOAD_DM(name, int (*)(void *, int, double))
390#define LOAD_DM_ROT2(name) LOAD_DM(name, int (*)(void *, int, int, double))
391 LOAD_DM_GATE1(DMApplyReset);
392 LOAD_DM_ROT1(DMApplyBitFlipNoise); LOAD_DM_ROT1(DMApplyPhaseFlipNoise);
393 LOAD_DM_ROT1(DMApplyDepolarizingNoise); LOAD_DM_ROT1(DMApplyAmplitudeDamping);
394 LOAD_DM_ROT1(DMApplyPhaseDamping);
395 LOAD_DM_GATE1(DMApplyNonSelectiveMeasurement);
396 LOAD_DM_GATE1(DMApplyX); LOAD_DM_GATE1(DMApplyY);
397 LOAD_DM_GATE1(DMApplyZ); LOAD_DM_GATE1(DMApplyH);
398 LOAD_DM_GATE1(DMApplyS); LOAD_DM_GATE1(DMApplySDG);
399 LOAD_DM_GATE1(DMApplyT); LOAD_DM_GATE1(DMApplyTDG);
400 LOAD_DM_GATE1(DMApplySX); LOAD_DM_GATE1(DMApplySXDG);
401 LOAD_DM_GATE1(DMApplyK);
402 LOAD_DM_ROT1(DMApplyP); LOAD_DM_ROT1(DMApplyRx);
403 LOAD_DM_ROT1(DMApplyRy); LOAD_DM_ROT1(DMApplyRz);
404 LOAD_DM(DMApplyU,
405 int (*)(void *, int, double, double, double, double));
406 LOAD_DM_GATE2(DMApplyCX); LOAD_DM_GATE2(DMApplyCY);
407 LOAD_DM_GATE2(DMApplyCZ); LOAD_DM_GATE2(DMApplyCH);
408 LOAD_DM_GATE2(DMApplyCSX); LOAD_DM_GATE2(DMApplyCSXDG);
409 LOAD_DM_ROT2(DMApplyCP); LOAD_DM_ROT2(DMApplyCRx);
410 LOAD_DM_ROT2(DMApplyCRy); LOAD_DM_ROT2(DMApplyCRz);
411 LOAD_DM(DMApplyCCX, int (*)(void *, int, int, int));
412 LOAD_DM_GATE2(DMApplySwap);
413 LOAD_DM(DMApplyCSwap, int (*)(void *, int, int, int));
414 LOAD_DM(DMApplyCU,
415 int (*)(void *, int, int, double, double, double, double));
416#undef LOAD_DM_ROT2
417#undef LOAD_DM_ROT1
418#undef LOAD_DM_GATE2
419#undef LOAD_DM_GATE1
420#undef LOAD_DM
421
422 // matrix product operator (mpo) api functions
423#define LOAD_MPO(name, type) \
424 f##name = reinterpret_cast<type>(GetFunction(#name)); \
425 CheckFunction(reinterpret_cast<void *>(f##name), __LINE__)
426 LOAD_MPO(CreateMPO, void *(*)(void *));
427 LOAD_MPO(DestroyMPO, void (*)(void *));
428 LOAD_MPO(MPOCreate, int (*)(void *, unsigned int));
429 LOAD_MPO(MPOCreateWithState,
430 int (*)(void *, unsigned int, const double *));
431 LOAD_MPO(MPOCreateWithBasisState,
432 int (*)(void *, unsigned int, unsigned long long));
433 LOAD_MPO(MPOCreateWithBasisStateBits,
434 int (*)(void *, unsigned int, const unsigned char *));
435 LOAD_MPO(MPOCreateWithMixtureOfBasisStates,
436 int (*)(void *, unsigned int, const unsigned long long *,
437 const double *, int));
438 LOAD_MPO(MPOCreateWithMixtureOfBasisStatesBits,
439 int (*)(void *, unsigned int, const unsigned char *,
440 const double *, int));
441 LOAD_MPO(MPOReset, int (*)(void *));
442 LOAD_MPO(MPOSetInitialQubitsMap,
443 int (*)(void *, const long long int *, int));
444 LOAD_MPO(MPOSetUseOptimalMeetingPosition, int (*)(void *, int));
445 LOAD_MPO(MPOGetUseOptimalMeetingPosition, int (*)(void *));
446 LOAD_MPO(MPOIsValid, int (*)(void *));
447 LOAD_MPO(MPOIsCreated, int (*)(void *));
448 LOAD_MPO(MPOSetDataType, int (*)(void *, int));
449 LOAD_MPO(MPOIsDoublePrecision, int (*)(void *));
450 LOAD_MPO(MPOGetNrQubits, int (*)(void *));
451 LOAD_MPO(MPOSetCutoff, int (*)(void *, double));
452 LOAD_MPO(MPOGetCutoff, double (*)(void *));
453 LOAD_MPO(MPOSetTruncationMode, int (*)(void *, int));
454 LOAD_MPO(MPOGetTruncationMode, int (*)(void *));
455 LOAD_MPO(MPOSetGesvdJ, int (*)(void *, int));
456 LOAD_MPO(MPOGetGesvdJ, int (*)(void *));
457 // Optional in older plugins; checked when explicitly requested.
458 fMPOSetGesvdP = (int (*)(void *, int))GetFunction("MPOSetGesvdP");
459 fMPOGetGesvdP = (int (*)(void *))GetFunction("MPOGetGesvdP");
460 fMPOSetGesvdR = (int (*)(void *, int))GetFunction("MPOSetGesvdR");
461 fMPOGetGesvdR = (int (*)(void *))GetFunction("MPOGetGesvdR");
462 fMPOGetLastSvdAlgo = (int (*)(void *))GetFunction("MPOGetLastSvdAlgo");
463
464 LOAD_MPO(MPOSetMaxExtent, int (*)(void *, long int));
465 LOAD_MPO(MPOGetMaxExtent, long int (*)(void *));
466 LOAD_MPO(MPOGetBondDimensions,
467 int (*)(void *, long long int *));
468 LOAD_MPO(MPOSetCallbackContext, int (*)(void *, void *));
469 LOAD_MPO(MPOSetMeetingPositionCallback,
470 int (*)(void *, int64_t (*)(void *, const int64_t *)));
471 LOAD_MPO(MPOSetBondDimensionsCallback,
472 int (*)(void *, void (*)(void *, const int64_t *)));
473 LOAD_MPO(MPOReCanonicalize, int (*)(void *, int));
474 LOAD_MPO(MPOTrim, int (*)(void *, double, long int, int));
475 LOAD_MPO(MPOSaveState, int (*)(void *));
476 LOAD_MPO(MPORestoreState, int (*)(void *));
477 LOAD_MPO(MPOCleanSavedState, int (*)(void *));
478 LOAD_MPO(MPOClone, void *(*)(void *));
479 LOAD_MPO(MPOSetSeed, int (*)(void *, unsigned long long));
480 LOAD_MPO(MPOMeasureQubitCollapse, int (*)(void *, int));
481 LOAD_MPO(MPOMeasureQubitNoCollapse, int (*)(void *, int));
482 LOAD_MPO(MPOMeasureQubitsCollapse, int (*)(void *, int *, int *, int));
483 LOAD_MPO(MPOMeasureQubitsNoCollapse, int (*)(void *, int *, int *, int));
484 LOAD_MPO(MPOMeasureAllQubitsCollapse, unsigned long long (*)(void *));
485 LOAD_MPO(MPOMeasureAllQubitsNoCollapse, unsigned long long (*)(void *));
486 LOAD_MPO(MPOSample,
487 int (*)(void *, unsigned int, long int *, unsigned int,
488 int *));
489 LOAD_MPO(MPOSampleAll,
490 int (*)(void *, unsigned int, long int *));
491 LOAD_MPO(MPOGetElement,
492 int (*)(void *, long long, long long, double *, double *));
493 LOAD_MPO(MPOBasisStateProbability, double (*)(void *, long long));
494 LOAD_MPO(MPOAllProbabilities, int (*)(void *, double *));
495 LOAD_MPO(MPOExpectationValue,
496 double (*)(void *, const char *, int));
497 LOAD_MPO(MPOQubitProbability0, double (*)(void *, unsigned int));
498 LOAD_MPO(MPOPartialTrace, int (*)(void *, const int *, int, double *));
499 LOAD_MPO(MPOHilbertSchmidtOverlap, int (*)(void *, void *, double *, double *));
500 LOAD_MPO(MPOFidelityWithStatevector, int (*)(void *, const double *, double *));
501 LOAD_MPO(MPOTrace, double (*)(void *));
502 LOAD_MPO(MPOPurity, double (*)(void *));
503 LOAD_MPO(MPOHermiticityResidual, double (*)(void *));
504 LOAD_MPO(MPOIsHermitian, int (*)(void *, double));
505 LOAD_MPO(MPOTraceOfSquare, double (*)(void *));
506 LOAD_MPO(MPORestoreTrace, int (*)(void *));
507 LOAD_MPO(MPOHermitize, int (*)(void *));
508 LOAD_MPO(MPOSetKrausCompletenessCheck, int (*)(void *, int));
509 LOAD_MPO(MPOGetKrausCompletenessCheck, int (*)(void *));
510 LOAD_MPO(MPOApplyKraus,
511 int (*)(void *, int, const int *, int, const double *));
512#define LOAD_MPO_GATE1(name) LOAD_MPO(name, int (*)(void *, int))
513#define LOAD_MPO_GATE2(name) LOAD_MPO(name, int (*)(void *, int, int))
514#define LOAD_MPO_ROT1(name) LOAD_MPO(name, int (*)(void *, int, double))
515#define LOAD_MPO_ROT2(name) LOAD_MPO(name, int (*)(void *, int, int, double))
516 LOAD_MPO_GATE1(MPOApplyReset);
517 LOAD_MPO_ROT1(MPOApplyBitFlipNoise); LOAD_MPO_ROT1(MPOApplyPhaseFlipNoise);
518 LOAD_MPO_ROT1(MPOApplyDepolarizingNoise); LOAD_MPO_ROT1(MPOApplyAmplitudeDamping);
519 LOAD_MPO_ROT1(MPOApplyPhaseDamping);
520 LOAD_MPO_GATE1(MPOApplyNonSelectiveMeasurement);
521 LOAD_MPO_GATE1(MPOApplyX); LOAD_MPO_GATE1(MPOApplyY);
522 LOAD_MPO_GATE1(MPOApplyZ); LOAD_MPO_GATE1(MPOApplyH);
523 LOAD_MPO_GATE1(MPOApplyS); LOAD_MPO_GATE1(MPOApplySDG);
524 LOAD_MPO_GATE1(MPOApplyT); LOAD_MPO_GATE1(MPOApplyTDG);
525 LOAD_MPO_GATE1(MPOApplySX); LOAD_MPO_GATE1(MPOApplySXDG);
526 LOAD_MPO_GATE1(MPOApplyK);
527 LOAD_MPO_ROT1(MPOApplyP); LOAD_MPO_ROT1(MPOApplyRx);
528 LOAD_MPO_ROT1(MPOApplyRy); LOAD_MPO_ROT1(MPOApplyRz);
529 LOAD_MPO(MPOApplyU,
530 int (*)(void *, int, double, double, double, double));
531 LOAD_MPO(MPOApplyOneQubitMatrix,
532 int (*)(void *, int, const double *));
533 LOAD_MPO(MPOApplyTwoQubitMatrix,
534 int (*)(void *, int, int, const double *));
535 LOAD_MPO_GATE2(MPOApplyCX); LOAD_MPO_GATE2(MPOApplyCY);
536 LOAD_MPO_GATE2(MPOApplyCZ); LOAD_MPO_GATE2(MPOApplyCH);
537 LOAD_MPO_GATE2(MPOApplyCSX); LOAD_MPO_GATE2(MPOApplyCSXDG);
538 LOAD_MPO_ROT2(MPOApplyCP); LOAD_MPO_ROT2(MPOApplyCRx);
539 LOAD_MPO_ROT2(MPOApplyCRy); LOAD_MPO_ROT2(MPOApplyCRz);
540 LOAD_MPO_GATE2(MPOApplySwap);
541 LOAD_MPO(MPOApplyCU,
542 int (*)(void *, int, int, double, double, double, double));
543 // Note: the gpu MPO backend does not expose native 3-qubit gates
544 // (MPOApplyCCX / MPOApplyCSwap); those are decomposed into 1- and
545 // 2-qubit gates by GpuSimulator, matching the CPU MPOSimulator
546 // restriction to one- and two-qubit operators.
547#undef LOAD_MPO_ROT2
548#undef LOAD_MPO_ROT1
549#undef LOAD_MPO_GATE2
550#undef LOAD_MPO_GATE1
551#undef LOAD_MPO
552
553 // mps api functions
554
555 fCreateMPS = (void *(*)(void *))GetFunction("CreateMPS");
556 CheckFunction((void *)fCreateMPS, __LINE__);
557 fDestroyMPS = (void (*)(void *))GetFunction("DestroyMPS");
558 CheckFunction((void *)fDestroyMPS, __LINE__);
559
560 fMPSCreate = (int (*)(void *, unsigned int))GetFunction("MPSCreate");
561 CheckFunction((void *)fMPSCreate, __LINE__);
562 fMPSCreateWithBasisState =
563 (int (*)(void *, unsigned int, unsigned long long))GetFunction(
564 "MPSCreateWithBasisState");
565 CheckFunction((void *)fMPSCreateWithBasisState, __LINE__);
566 fMPSCreateWithBasisStateBits =
567 (int (*)(void *, unsigned int, const unsigned char *))
568 GetFunction("MPSCreateWithBasisStateBits");
569 CheckFunction((void *)fMPSCreateWithBasisStateBits, __LINE__);
570 fMPSReset = (int (*)(void *))GetFunction("MPSReset");
571 CheckFunction((void *)fMPSReset, __LINE__);
572 fMPSSetInitialQubitsMap =
573 (int (*)(void *, const long long int *, int))GetFunction(
574 "MPSSetInitialQubitsMap");
575 CheckFunction((void *)fMPSSetInitialQubitsMap, __LINE__);
576 fMPSSetUseOptimalMeetingPosition = (int (*)(void *, int))GetFunction(
577 "MPSSetUseOptimalMeetingPosition");
578 CheckFunction((void *)fMPSSetUseOptimalMeetingPosition, __LINE__);
579 fMPSGetUseOptimalMeetingPosition = (int (*)(void *))GetFunction(
580 "MPSGetUseOptimalMeetingPosition");
581 CheckFunction((void *)fMPSGetUseOptimalMeetingPosition, __LINE__);
582
583 fMPSIsValid = (int (*)(void *))GetFunction("MPSIsValid");
584 CheckFunction((void *)fMPSIsValid, __LINE__);
585 fMPSIsCreated = (int (*)(void *))GetFunction("MPSIsCreated");
586 CheckFunction((void *)fMPSIsCreated, __LINE__);
587
588 fMPSSetDataType = (int (*)(void *, int))GetFunction("MPSSetDataType");
589 CheckFunction((void *)fMPSSetDataType, __LINE__);
590 fMPSIsDoublePrecision =
591 (int (*)(void *))GetFunction("MPSIsDoublePrecision");
592 CheckFunction((void *)fMPSIsDoublePrecision, __LINE__);
593 fMPSSetCutoff = (int (*)(void *, double))GetFunction("MPSSetCutoff");
594 CheckFunction((void *)fMPSSetCutoff, __LINE__);
595 fMPSGetCutoff = (double (*)(void *))GetFunction("MPSGetCutoff");
596 CheckFunction((void *)fMPSGetCutoff, __LINE__);
597 fMPSSetTruncationMode =
598 (int (*)(void *, int))GetFunction("MPSSetTruncationMode");
599 CheckFunction((void *)fMPSSetTruncationMode, __LINE__);
600 fMPSGetTruncationMode =
601 (int (*)(void *))GetFunction("MPSGetTruncationMode");
602 CheckFunction((void *)fMPSGetTruncationMode, __LINE__);
603 fMPSSetGesvdJ = (int (*)(void *, int))GetFunction("MPSSetGesvdJ");
604 CheckFunction((void *)fMPSSetGesvdJ, __LINE__);
605 fMPSGetGesvdJ = (int (*)(void *))GetFunction("MPSGetGesvdJ");
606 CheckFunction((void *)fMPSGetGesvdJ, __LINE__);
607 // Optional in older plugins; checked when explicitly requested.
608 fMPSSetGesvdP = (int (*)(void *, int))GetFunction("MPSSetGesvdP");
609 fMPSGetGesvdP = (int (*)(void *))GetFunction("MPSGetGesvdP");
610 fMPSSetGesvdR = (int (*)(void *, int))GetFunction("MPSSetGesvdR");
611 fMPSGetGesvdR = (int (*)(void *))GetFunction("MPSGetGesvdR");
612 fMPSGetLastSvdAlgo = (int (*)(void *))GetFunction("MPSGetLastSvdAlgo");
613
614 fMPSSetMaxExtent =
615 (int (*)(void *, long int))GetFunction("MPSSetMaxExtent");
616 CheckFunction((void *)fMPSSetMaxExtent, __LINE__);
617 fMPSGetMaxExtent =
618 (long int (*)(void *))GetFunction("MPSGetMaxExtent");
619 CheckFunction((void *)fMPSGetMaxExtent, __LINE__);
620 fMPSGetNrQubits = (int (*)(void *))GetFunction("MPSGetNrQubits");
621 CheckFunction((void *)fMPSGetNrQubits, __LINE__);
622 fMPSGetBondDimensions =
623 (int (*)(void *, long long int *))GetFunction(
624 "MPSGetBondDimensions");
625 CheckFunction((void *)fMPSGetBondDimensions, __LINE__);
626 fMPSSetCallbackContext =
627 (int (*)(void *, void *))GetFunction("MPSSetCallbackContext");
628 CheckFunction((void *)fMPSSetCallbackContext, __LINE__);
629
630 fMPSSetMeetingPositionCallback =
631 (int (*)(void *, int64_t (*)(void *, const int64_t *)))
632 GetFunction("MPSSetMeetingPositionCallback");
633 CheckFunction((void *)fMPSSetMeetingPositionCallback, __LINE__);
634
635 fMPSSetBondDimensionsCallback =
636 (int (*)(void*, void (*)(void*, const int64_t*)))GetFunction(
637 "MPSSetBondDimensionsCallback");
638 CheckFunction((void *)fMPSSetBondDimensionsCallback, __LINE__);
639
640 fMPSAmplitude = (int (*)(void *, long int, long int *, double *,
641 double *))GetFunction("MPSAmplitude");
642 CheckFunction((void *)fMPSAmplitude, __LINE__);
643 fMPSProbability0 =
644 (double (*)(void *, unsigned int))GetFunction("MPSProbability0");
645 CheckFunction((void *)fMPSProbability0, __LINE__);
646 fMPSMeasure =
647 (int (*)(void *, unsigned int))GetFunction("MPSMeasure");
648 CheckFunction((void *)fMPSMeasure, __LINE__);
649 fMPSMeasureQubits = (int (*)(void *, long int, unsigned int *,
650 int *))GetFunction("MPSMeasureQubits");
651 CheckFunction((void *)fMPSMeasureQubits, __LINE__);
652
653 fMPSGetMapForSample = (void *(*)())GetFunction("MPSGetMapForSample");
654 CheckFunction((void *)fMPSGetMapForSample, __LINE__);
655 fMPSFreeMapForSample =
656 (int (*)(void *))GetFunction("MPSFreeMapForSample");
657 CheckFunction((void *)fMPSFreeMapForSample, __LINE__);
658 fMPSSample = (int (*)(void *, long int, long int, unsigned int *,
659 void *))GetFunction("MPSSample");
660 CheckFunction((void *)fMPSSample, __LINE__);
661 fMPSSampleRaw = (int (*)(void *, unsigned int, long int *,
662 unsigned int, const unsigned int *))
663 GetFunction("MPSSampleRaw");
664 CheckFunction((void *)fMPSSampleRaw, __LINE__);
665 fMPSSampleAll = (int (*)(void *, unsigned int, long int *))
666 GetFunction("MPSSampleAll");
667 CheckFunction((void *)fMPSSampleAll, __LINE__);
668
669 fMPSSaveState = (int (*)(void *))GetFunction("MPSSaveState");
670 CheckFunction((void *)fMPSSaveState, __LINE__);
671 fMPSRestoreState = (int (*)(void *))GetFunction("MPSRestoreState");
672 CheckFunction((void *)fMPSRestoreState, __LINE__);
673 fMPSCleanSavedState =
674 (int (*)(void *))GetFunction("MPSCleanSavedState");
675 CheckFunction((void *)fMPSCleanSavedState, __LINE__);
676 fMPSClone = (void *(*)(void *))GetFunction("MPSClone");
677 CheckFunction((void *)fMPSClone, __LINE__);
678 fMPSSetSeed = (int (*)(void *, unsigned long long))
679 GetFunction("MPSSetSeed");
680 CheckFunction((void *)fMPSSetSeed, __LINE__);
681
682 fMPSExpectationValue = (double (*)(
683 void *, const char *, int))GetFunction("MPSExpectationValue");
684 CheckFunction((void *)fMPSExpectationValue, __LINE__);
685 fMPSProjectOnZero =
686 (int (*)(void *, double *, double *))GetFunction("MPSProjectOnZero");
687 CheckFunction((void *)fMPSProjectOnZero, __LINE__);
688
689 fMPSApplyX = (int (*)(void *, unsigned int))GetFunction("MPSApplyX");
690 CheckFunction((void *)fMPSApplyX, __LINE__);
691 fMPSApplyY = (int (*)(void *, unsigned int))GetFunction("MPSApplyY");
692 CheckFunction((void *)fMPSApplyY, __LINE__);
693 fMPSApplyZ = (int (*)(void *, unsigned int))GetFunction("MPSApplyZ");
694 CheckFunction((void *)fMPSApplyZ, __LINE__);
695 fMPSApplyH = (int (*)(void *, unsigned int))GetFunction("MPSApplyH");
696 CheckFunction((void *)fMPSApplyH, __LINE__);
697 fMPSApplyS = (int (*)(void *, unsigned int))GetFunction("MPSApplyS");
698 CheckFunction((void *)fMPSApplyS, __LINE__);
699 fMPSApplySDG =
700 (int (*)(void *, unsigned int))GetFunction("MPSApplySDG");
701 CheckFunction((void *)fMPSApplySDG, __LINE__);
702 fMPSApplyT = (int (*)(void *, unsigned int))GetFunction("MPSApplyT");
703 CheckFunction((void *)fMPSApplyT, __LINE__);
704 fMPSApplyTDG =
705 (int (*)(void *, unsigned int))GetFunction("MPSApplyTDG");
706 CheckFunction((void *)fMPSApplyTDG, __LINE__);
707 fMPSApplySX =
708 (int (*)(void *, unsigned int))GetFunction("MPSApplySX");
709 CheckFunction((void *)fMPSApplySX, __LINE__);
710 fMPSApplySXDG =
711 (int (*)(void *, unsigned int))GetFunction("MPSApplySXDG");
712 CheckFunction((void *)fMPSApplySXDG, __LINE__);
713 fMPSApplyK = (int (*)(void *, unsigned int))GetFunction("MPSApplyK");
714 CheckFunction((void *)fMPSApplyK, __LINE__);
715 fMPSApplyP =
716 (int (*)(void *, unsigned int, double))GetFunction("MPSApplyP");
717 CheckFunction((void *)fMPSApplyP, __LINE__);
718 fMPSApplyRx =
719 (int (*)(void *, unsigned int, double))GetFunction("MPSApplyRx");
720 CheckFunction((void *)fMPSApplyRx, __LINE__);
721 fMPSApplyRy =
722 (int (*)(void *, unsigned int, double))GetFunction("MPSApplyRy");
723 CheckFunction((void *)fMPSApplyRy, __LINE__);
724 fMPSApplyRz =
725 (int (*)(void *, unsigned int, double))GetFunction("MPSApplyRz");
726 CheckFunction((void *)fMPSApplyRz, __LINE__);
727 fMPSApplyU = (int (*)(void *, unsigned int, double, double, double,
728 double))GetFunction("MPSApplyU");
729 CheckFunction((void *)fMPSApplyU, __LINE__);
730 fMPSApplyOneQubitMatrix =
731 (int (*)(void *, unsigned int, const double *))GetFunction(
732 "MPSApplyOneQubitMatrix");
733 CheckFunction((void *)fMPSApplyOneQubitMatrix, __LINE__);
734 fMPSApplyTwoQubitMatrix =
735 (int (*)(void *, unsigned int, unsigned int,
736 const double *))GetFunction("MPSApplyTwoQubitMatrix");
737 CheckFunction((void *)fMPSApplyTwoQubitMatrix, __LINE__);
738 fMPSApplySwap = (int (*)(void *, unsigned int,
739 unsigned int))GetFunction("MPSApplySwap");
740 CheckFunction((void *)fMPSApplySwap, __LINE__);
741 fMPSApplyCX = (int (*)(void *, unsigned int,
742 unsigned int))GetFunction("MPSApplyCX");
743 CheckFunction((void *)fMPSApplyCX, __LINE__);
744 fMPSApplyCY = (int (*)(void *, unsigned int,
745 unsigned int))GetFunction("MPSApplyCY");
746 CheckFunction((void *)fMPSApplyCY, __LINE__);
747 fMPSApplyCZ = (int (*)(void *, unsigned int,
748 unsigned int))GetFunction("MPSApplyCZ");
749 CheckFunction((void *)fMPSApplyCZ, __LINE__);
750 fMPSApplyCH = (int (*)(void *, unsigned int,
751 unsigned int))GetFunction("MPSApplyCH");
752 CheckFunction((void *)fMPSApplyCH, __LINE__);
753 fMPSApplyCSX = (int (*)(void *, unsigned int,
754 unsigned int))GetFunction("MPSApplyCSX");
755 CheckFunction((void *)fMPSApplyCSX, __LINE__);
756 fMPSApplyCSXDG = (int (*)(void *, unsigned int,
757 unsigned int))GetFunction("MPSApplyCSXDG");
758 CheckFunction((void *)fMPSApplyCSXDG, __LINE__);
759 fMPSApplyCP = (int (*)(void *, unsigned int, unsigned int,
760 double))GetFunction("MPSApplyCP");
761 CheckFunction((void *)fMPSApplyCP, __LINE__);
762 fMPSApplyCRx = (int (*)(void *, unsigned int, unsigned int,
763 double))GetFunction("MPSApplyCRx");
764 CheckFunction((void *)fMPSApplyCRx, __LINE__);
765 fMPSApplyCRy = (int (*)(void *, unsigned int, unsigned int,
766 double))GetFunction("MPSApplyCRy");
767 CheckFunction((void *)fMPSApplyCRy, __LINE__);
768 fMPSApplyCRz = (int (*)(void *, unsigned int, unsigned int,
769 double))GetFunction("MPSApplyCRz");
770 CheckFunction((void *)fMPSApplyCRz, __LINE__);
771 fMPSApplyCU =
772 (int (*)(void *, unsigned int, unsigned int, double, double,
773 double, double))GetFunction("MPSApplyCU");
774 CheckFunction((void *)fMPSApplyCU, __LINE__);
775
776 // tensor network api functions
777
778 fCreateTensorNet = (void *(*)(void *))GetFunction("CreateTensorNet");
779 CheckFunction((void *)fCreateTensorNet, __LINE__);
780 fDestroyTensorNet = (void (*)(void *))GetFunction("DestroyTensorNet");
781 CheckFunction((void *)fDestroyTensorNet, __LINE__);
782
783 fTNCreate = (int (*)(void *, unsigned int))GetFunction("TNCreate");
784 CheckFunction((void *)fTNCreate, __LINE__);
785 fTNReset = (int (*)(void *))GetFunction("TNReset");
786 CheckFunction((void *)fTNReset, __LINE__);
787
788 fTNIsValid = (int (*)(void *))GetFunction("TNIsValid");
789 CheckFunction((void *)fTNIsValid, __LINE__);
790 fTNIsCreated = (int (*)(void *))GetFunction("TNIsCreated");
791 CheckFunction((void *)fTNIsCreated, __LINE__);
792
793 fTNSetDataType = (int (*)(void *, int))GetFunction("TNSetDataType");
794 CheckFunction((void *)fTNSetDataType, __LINE__);
795 fTNIsDoublePrecision =
796 (int (*)(void *))GetFunction("TNIsDoublePrecision");
797 CheckFunction((void *)fTNIsDoublePrecision, __LINE__);
798 fTNSetCutoff = (int (*)(void *, double))GetFunction("TNSetCutoff");
799 CheckFunction((void *)fTNSetCutoff, __LINE__);
800 fTNGetCutoff = (double (*)(void *))GetFunction("TNGetCutoff");
801 CheckFunction((void *)fTNGetCutoff, __LINE__);
802 fTNSetTruncationMode =
803 (int (*)(void *, int))GetFunction("TNSetTruncationMode");
804 CheckFunction((void *)fTNSetTruncationMode, __LINE__);
805 fTNGetTruncationMode =
806 (int (*)(void *))GetFunction("TNGetTruncationMode");
807 CheckFunction((void *)fTNGetTruncationMode, __LINE__);
808 fTNSetGesvdJ = (int (*)(void *, int))GetFunction("TNSetGesvdJ");
809 CheckFunction((void *)fTNSetGesvdJ, __LINE__);
810 fTNGetGesvdJ = (int (*)(void *))GetFunction("TNGetGesvdJ");
811 CheckFunction((void *)fTNGetGesvdJ, __LINE__);
812 // Optional in older plugins; checked when explicitly requested.
813 fTNSetGesvdP = (int (*)(void *, int))GetFunction("TNSetGesvdP");
814 fTNGetGesvdP = (int (*)(void *))GetFunction("TNGetGesvdP");
815 fTNSetGesvdR = (int (*)(void *, int))GetFunction("TNSetGesvdR");
816 fTNGetGesvdR = (int (*)(void *))GetFunction("TNGetGesvdR");
817
818 fTNSetMaxExtent =
819 (int (*)(void *, long int))GetFunction("TNSetMaxExtent");
820 CheckFunction((void *)fTNSetMaxExtent, __LINE__);
821 fTNGetMaxExtent = (long int (*)(void *))GetFunction("TNGetMaxExtent");
822 CheckFunction((void *)fTNGetMaxExtent, __LINE__);
823 fTNGetNrQubits = (int (*)(void *))GetFunction("TNGetNrQubits");
824 CheckFunction((void *)fTNGetNrQubits, __LINE__);
825 fTNAmplitude = (int (*)(void *, long int, long int *, double *,
826 double *))GetFunction("TNAmplitude");
827 CheckFunction((void *)fTNAmplitude, __LINE__);
828 fTNProbability0 =
829 (double (*)(void *, unsigned int))GetFunction("TNProbability0");
830 CheckFunction((void *)fTNProbability0, __LINE__);
831 fTNMeasure = (int (*)(void *, unsigned int))GetFunction("TNMeasure");
832 CheckFunction((void *)fTNMeasure, __LINE__);
833 fTNMeasureQubits = (int (*)(void *, long int, unsigned int *,
834 int *))GetFunction("TNMeasureQubits");
835 CheckFunction((void *)fTNMeasureQubits, __LINE__);
836
837 fTNGetMapForSample = (void *(*)())GetFunction("TNGetMapForSample");
838 CheckFunction((void *)fTNGetMapForSample, __LINE__);
839 fTNFreeMapForSample =
840 (int (*)(void *))GetFunction("TNFreeMapForSample");
841 CheckFunction((void *)fTNFreeMapForSample, __LINE__);
842 fTNSample = (int (*)(void *, long int, long int, unsigned int *,
843 void *))GetFunction("TNSample");
844 CheckFunction((void *)fTNSample, __LINE__);
845
846 fTNSaveState = (int (*)(void *))GetFunction("TNSaveState");
847 CheckFunction((void *)fTNSaveState, __LINE__);
848 fTNRestoreState = (int (*)(void *))GetFunction("TNRestoreState");
849 CheckFunction((void *)fTNRestoreState, __LINE__);
850 fTNCleanSavedState =
851 (int (*)(void *))GetFunction("TNCleanSavedState");
852 CheckFunction((void *)fTNCleanSavedState, __LINE__);
853 fTNClone = (void *(*)(void *))GetFunction("TNClone");
854 CheckFunction((void *)fTNClone, __LINE__);
855 fTNSetSeed = (int (*)(void *, unsigned long long))
856 GetFunction("TNSetSeed");
857 CheckFunction((void *)fTNSetSeed, __LINE__);
858
859 fTNExpectationValue = (double (*)(
860 void *, const char *, int))GetFunction("TNExpectationValue");
861 CheckFunction((void *)fTNExpectationValue, __LINE__);
862
863 fTNApplyX = (int (*)(void *, unsigned int))GetFunction("TNApplyX");
864 CheckFunction((void *)fTNApplyX, __LINE__);
865 fTNApplyY = (int (*)(void *, unsigned int))GetFunction("TNApplyY");
866 CheckFunction((void *)fTNApplyY, __LINE__);
867 fTNApplyZ = (int (*)(void *, unsigned int))GetFunction("TNApplyZ");
868 CheckFunction((void *)fTNApplyZ, __LINE__);
869 fTNApplyH = (int (*)(void *, unsigned int))GetFunction("TNApplyH");
870 CheckFunction((void *)fTNApplyH, __LINE__);
871 fTNApplyS = (int (*)(void *, unsigned int))GetFunction("TNApplyS");
872 CheckFunction((void *)fTNApplyS, __LINE__);
873 fTNApplySDG =
874 (int (*)(void *, unsigned int))GetFunction("TNApplySDG");
875 CheckFunction((void *)fTNApplySDG, __LINE__);
876 fTNApplyT = (int (*)(void *, unsigned int))GetFunction("TNApplyT");
877 CheckFunction((void *)fTNApplyT, __LINE__);
878 fTNApplyTDG =
879 (int (*)(void *, unsigned int))GetFunction("TNApplyTDG");
880 CheckFunction((void *)fTNApplyTDG, __LINE__);
881 fTNApplySX = (int (*)(void *, unsigned int))GetFunction("TNApplySX");
882 CheckFunction((void *)fTNApplySX, __LINE__);
883 fTNApplySXDG =
884 (int (*)(void *, unsigned int))GetFunction("TNApplySXDG");
885 CheckFunction((void *)fTNApplySXDG, __LINE__);
886 fTNApplyK = (int (*)(void *, unsigned int))GetFunction("TNApplyK");
887 CheckFunction((void *)fTNApplyK, __LINE__);
888 fTNApplyP =
889 (int (*)(void *, unsigned int, double))GetFunction("TNApplyP");
890 CheckFunction((void *)fTNApplyP, __LINE__);
891 fTNApplyRx =
892 (int (*)(void *, unsigned int, double))GetFunction("TNApplyRx");
893 CheckFunction((void *)fTNApplyRx, __LINE__);
894 fTNApplyRy =
895 (int (*)(void *, unsigned int, double))GetFunction("TNApplyRy");
896 CheckFunction((void *)fTNApplyRy, __LINE__);
897 fTNApplyRz =
898 (int (*)(void *, unsigned int, double))GetFunction("TNApplyRz");
899 CheckFunction((void *)fTNApplyRz, __LINE__);
900 fTNApplyU = (int (*)(void *, unsigned int, double, double, double,
901 double))GetFunction("TNApplyU");
902 CheckFunction((void *)fTNApplyU, __LINE__);
903 fTNApplySwap = (int (*)(void *, unsigned int,
904 unsigned int))GetFunction("TNApplySwap");
905 CheckFunction((void *)fTNApplySwap, __LINE__);
906 fTNApplyCX = (int (*)(void *, unsigned int, unsigned int))GetFunction(
907 "TNApplyCX");
908 CheckFunction((void *)fTNApplyCX, __LINE__);
909 fTNApplyCY = (int (*)(void *, unsigned int, unsigned int))GetFunction(
910 "TNApplyCY");
911 CheckFunction((void *)fTNApplyCY, __LINE__);
912 fTNApplyCZ = (int (*)(void *, unsigned int, unsigned int))GetFunction(
913 "TNApplyCZ");
914 CheckFunction((void *)fTNApplyCZ, __LINE__);
915 fTNApplyCH = (int (*)(void *, unsigned int, unsigned int))GetFunction(
916 "TNApplyCH");
917 CheckFunction((void *)fTNApplyCH, __LINE__);
918 fTNApplyCSX = (int (*)(void *, unsigned int,
919 unsigned int))GetFunction("TNApplyCSX");
920 CheckFunction((void *)fTNApplyCSX, __LINE__);
921 fTNApplyCSXDG = (int (*)(void *, unsigned int,
922 unsigned int))GetFunction("TNApplyCSXDG");
923 CheckFunction((void *)fTNApplyCSXDG, __LINE__);
924 fTNApplyCP = (int (*)(void *, unsigned int, unsigned int,
925 double))GetFunction("TNApplyCP");
926 CheckFunction((void *)fTNApplyCP, __LINE__);
927 fTNApplyCRx = (int (*)(void *, unsigned int, unsigned int,
928 double))GetFunction("TNApplyCRx");
929 CheckFunction((void *)fTNApplyCRx, __LINE__);
930 fTNApplyCRy = (int (*)(void *, unsigned int, unsigned int,
931 double))GetFunction("TNApplyCRy");
932 CheckFunction((void *)fTNApplyCRy, __LINE__);
933 fTNApplyCRz = (int (*)(void *, unsigned int, unsigned int,
934 double))GetFunction("TNApplyCRz");
935 CheckFunction((void *)fTNApplyCRz, __LINE__);
936 fTNApplyCU =
937 (int (*)(void *, unsigned int, unsigned int, double, double,
938 double, double))GetFunction("TNApplyCU");
939 CheckFunction((void *)fTNApplyCU, __LINE__);
940
941 fTNApplyCCX = (int (*)(void *, unsigned int, unsigned int,
942 unsigned int))GetFunction("TNApplyCCX");
943 CheckFunction((void *)fTNApplyCCX, __LINE__);
944 fTNApplyCSwap = (int (*)(void *, unsigned int, unsigned int,
945 unsigned int))GetFunction("TNApplyCSwap");
946 CheckFunction((void *)fTNApplyCSwap, __LINE__);
947
948 // stabilizer simulator functions
949 fCreateStabilizerSimulator = (void *(*)(long long int, long long int,
950 long long int, long long int))
951 GetFunction("CreateStabilizerSimulator");
952 CheckFunction((void *)fCreateStabilizerSimulator, __LINE__);
953 fDestroyStabilizerSimulator =
954 (void (*)(void *))GetFunction("DestroyStabilizerSimulator");
955 CheckFunction((void *)fDestroyStabilizerSimulator, __LINE__);
956 fExecuteStabilizerCircuit = (int (*)(
957 void *, const char *, int,
958 unsigned long long int))GetFunction("ExecuteStabilizerCircuit");
959 CheckFunction((void *)fExecuteStabilizerCircuit, __LINE__);
960 fGetStabilizerXZTableSize =
961 (long long (*)(void *))GetFunction("GetStabilizerXZTableSize");
962 CheckFunction((void *)fGetStabilizerXZTableSize, __LINE__);
963 fGetStabilizerMTableSize =
964 (long long (*)(void *))GetFunction("GetStabilizerMTableSize");
965 CheckFunction((void *)fGetStabilizerMTableSize, __LINE__);
966
967 fGetStabilizerTableStrideMajor = (long long (*)(void *))GetFunction(
968 "GetStabilizerTableStrideMajor");
969 CheckFunction((void *)fGetStabilizerTableStrideMajor, __LINE__);
970
971 fGetStabilizerNumQubits =
972 (long long (*)(void *))GetFunction("GetStabilizerNumQubits");
973 CheckFunction((void *)fGetStabilizerNumQubits, __LINE__);
974 fGetStabilizerNumShots =
975 (long long (*)(void *))GetFunction("GetStabilizerNumShots");
976 CheckFunction((void *)fGetStabilizerNumShots, __LINE__);
977 fGetStabilizerNumMeasurements = (long long (*)(void *))GetFunction(
978 "GetStabilizerNumMeasurements");
979 CheckFunction((void *)fGetStabilizerNumMeasurements, __LINE__);
980 fGetStabilizerNumDetectors =
981 (long long (*)(void *))GetFunction("GetStabilizerNumDetectors");
982 CheckFunction((void *)fGetStabilizerNumDetectors, __LINE__);
983 fCopyStabilizerXTable = (int (*)(void *, unsigned int *))GetFunction(
984 "CopyStabilizerXTable");
985 CheckFunction((void *)fCopyStabilizerXTable, __LINE__);
986 fCopyStabilizerZTable = (int (*)(void *, unsigned int *))GetFunction(
987 "CopyStabilizerZTable");
988 CheckFunction((void *)fCopyStabilizerZTable, __LINE__);
989 fCopyStabilizerMTable = (int (*)(void *, unsigned int *))GetFunction(
990 "CopyStabilizerMTable");
991 CheckFunction((void *)fCopyStabilizerMTable, __LINE__);
992
993 fInitStabilizerXTable =
994 (int (*)(void *, const unsigned int *))GetFunction("InitXTable");
995 CheckFunction((void *)fInitStabilizerXTable, __LINE__);
996 fInitStabilizerZTable =
997 (int (*)(void *, const unsigned int *))GetFunction("InitZTable");
998 CheckFunction((void *)fInitStabilizerZTable, __LINE__);
999
1000 // pauli propagation functions
1001 fCreatePauliPropSimulator =
1002 (void *(*)(int))GetFunction("CreatePauliPropSimulator");
1003 CheckFunction((void *)fCreatePauliPropSimulator, __LINE__);
1004 fDestroyPauliPropSimulator =
1005 (void (*)(void *))GetFunction("DestroyPauliPropSimulator");
1006 CheckFunction((void *)fDestroyPauliPropSimulator, __LINE__);
1007
1008 fPauliPropGetNrQubits =
1009 (int (*)(void *))GetFunction("PauliPropGetNrQubits");
1010 CheckFunction((void *)fPauliPropGetNrQubits, __LINE__);
1011 fPauliPropSetWillUseSampling =
1012 (int (*)(void *, int))GetFunction("PauliPropSetWillUseSampling");
1013 CheckFunction((void *)fPauliPropSetWillUseSampling, __LINE__);
1014 fPauliPropGetWillUseSampling =
1015 (int (*)(void *))GetFunction("PauliPropGetWillUseSampling");
1016 CheckFunction((void *)fPauliPropGetWillUseSampling, __LINE__);
1017
1018 fPauliPropGetCoefficientTruncationCutoff = (double (*)(
1019 void *))GetFunction("PauliPropGetCoefficientTruncationCutoff");
1020 CheckFunction((void *)fPauliPropGetCoefficientTruncationCutoff,
1021 __LINE__);
1022 fPauliPropSetCoefficientTruncationCutoff =
1023 (void (*)(void *, double))GetFunction(
1024 "PauliPropSetCoefficientTruncationCutoff");
1025 CheckFunction((void *)fPauliPropSetCoefficientTruncationCutoff,
1026 __LINE__);
1027 fPauliPropGetWeightTruncationCutoff = (double (*)(void *))GetFunction(
1028 "PauliPropGetWeightTruncationCutoff");
1029 CheckFunction((void *)fPauliPropGetWeightTruncationCutoff, __LINE__);
1030 fPauliPropSetWeightTruncationCutoff = (void (*)(
1031 void *, double))GetFunction("PauliPropSetWeightTruncationCutoff");
1032 CheckFunction((void *)fPauliPropSetWeightTruncationCutoff, __LINE__);
1033 fPauliPropGetNumGatesBetweenTruncations = (int (*)(
1034 void *))GetFunction("PauliPropGetNumGatesBetweenTruncations");
1035 CheckFunction((void *)fPauliPropGetNumGatesBetweenTruncations,
1036 __LINE__);
1037 fPauliPropSetNumGatesBetweenTruncations =
1038 (void (*)(void *, int))GetFunction(
1039 "PauliPropSetNumGatesBetweenTruncations");
1040 CheckFunction((void *)fPauliPropSetNumGatesBetweenTruncations,
1041 __LINE__);
1042 fPauliPropGetNumGatesBetweenDeduplications = (int (*)(
1043 void *))GetFunction("PauliPropGetNumGatesBetweenDeduplications");
1044 CheckFunction((void *)fPauliPropGetNumGatesBetweenDeduplications,
1045 __LINE__);
1046 fPauliPropSetNumGatesBetweenDeduplications =
1047 (void (*)(void *, int))GetFunction(
1048 "PauliPropSetNumGatesBetweenDeduplications");
1049 CheckFunction((void *)fPauliPropSetNumGatesBetweenDeduplications,
1050 __LINE__);
1051
1052 fPauliPropClearOperators =
1053 (int (*)(void *))GetFunction("PauliPropClearOperators");
1054 CheckFunction((void *)fPauliPropClearOperators, __LINE__);
1055 fPauliPropAllocateMemory =
1056 (int (*)(void *, double))GetFunction("PauliPropAllocateMemory");
1057 CheckFunction((void *)fPauliPropAllocateMemory, __LINE__);
1058
1059 fPauliPropGetExpectationValue =
1060 (double (*)(void *))GetFunction("PauliPropGetExpectationValue");
1061 CheckFunction((void *)fPauliPropGetExpectationValue, __LINE__);
1062 fPauliPropExecute = (int (*)(void *))GetFunction("PauliPropExecute");
1063 CheckFunction((void *)fPauliPropExecute, __LINE__);
1064 fPauliPropSetSeed = (int (*)(void *, unsigned long long))
1065 GetFunction("PauliPropSetSeed");
1066 CheckFunction((void *)fPauliPropSetSeed, __LINE__);
1067 fPauliPropSetInPauliExpansionUnique =
1068 (int (*)(void *, const char *))GetFunction(
1069 "PauliPropSetInPauliExpansionUnique");
1070 CheckFunction((void *)fPauliPropSetInPauliExpansionUnique, __LINE__);
1071 fPauliPropSetInPauliExpansionMultiple =
1072 (int (*)(void *, const char **, const double *, int))GetFunction(
1073 "PauliPropSetInPauliExpansionMultiple");
1074 CheckFunction((void *)fPauliPropSetInPauliExpansionMultiple,
1075 __LINE__);
1076
1077 fPauliPropApplyX =
1078 (int (*)(void *, int))GetFunction("PauliPropApplyX");
1079 CheckFunction((void *)fPauliPropApplyX, __LINE__);
1080 fPauliPropApplyY =
1081 (int (*)(void *, int))GetFunction("PauliPropApplyY");
1082 CheckFunction((void *)fPauliPropApplyY, __LINE__);
1083 fPauliPropApplyZ =
1084 (int (*)(void *, int))GetFunction("PauliPropApplyZ");
1085 CheckFunction((void *)fPauliPropApplyZ, __LINE__);
1086 fPauliPropApplyH =
1087 (int (*)(void *, int))GetFunction("PauliPropApplyH");
1088 CheckFunction((void *)fPauliPropApplyH, __LINE__);
1089 fPauliPropApplyS =
1090 (int (*)(void *, int))GetFunction("PauliPropApplyS");
1091 CheckFunction((void *)fPauliPropApplyS, __LINE__);
1092
1093 fPauliPropApplySQRTX =
1094 (int (*)(void *, int))GetFunction("PauliPropApplySQRTX");
1095 CheckFunction((void *)fPauliPropApplySQRTX, __LINE__);
1096 fPauliPropApplySQRTY =
1097 (int (*)(void *, int))GetFunction("PauliPropApplySQRTY");
1098 CheckFunction((void *)fPauliPropApplySQRTY, __LINE__);
1099 fPauliPropApplySQRTZ =
1100 (int (*)(void *, int))GetFunction("PauliPropApplySQRTZ");
1101 CheckFunction((void *)fPauliPropApplySQRTZ, __LINE__);
1102 fPauliPropApplyCX =
1103 (int (*)(void *, int, int))GetFunction("PauliPropApplyCX");
1104 CheckFunction((void *)fPauliPropApplyCX, __LINE__);
1105 fPauliPropApplyCY =
1106 (int (*)(void *, int, int))GetFunction("PauliPropApplyCY");
1107 CheckFunction((void *)fPauliPropApplyCY, __LINE__);
1108 fPauliPropApplyCZ =
1109 (int (*)(void *, int, int))GetFunction("PauliPropApplyCZ");
1110 CheckFunction((void *)fPauliPropApplyCZ, __LINE__);
1111 fPauliPropApplySWAP =
1112 (int (*)(void *, int, int))GetFunction("PauliPropApplySWAP");
1113 CheckFunction((void *)fPauliPropApplySWAP, __LINE__);
1114 fPauliPropApplyISWAP =
1115 (int (*)(void *, int, int))GetFunction("PauliPropApplyISWAP");
1116 CheckFunction((void *)fPauliPropApplyISWAP, __LINE__);
1117 fPauliPropApplyRX =
1118 (int (*)(void *, int, double))GetFunction("PauliPropApplyRX");
1119 CheckFunction((void *)fPauliPropApplyRX, __LINE__);
1120 fPauliPropApplyRY =
1121 (int (*)(void *, int, double))GetFunction("PauliPropApplyRY");
1122 CheckFunction((void *)fPauliPropApplyRY, __LINE__);
1123 fPauliPropApplyRZ =
1124 (int (*)(void *, int, double))GetFunction("PauliPropApplyRZ");
1125 CheckFunction((void *)fPauliPropApplyRZ, __LINE__);
1126
1127 fPauliPropAddNoiseX =
1128 (int (*)(void *, int, double))GetFunction("PauliPropAddNoiseX");
1129 CheckFunction((void *)fPauliPropAddNoiseX, __LINE__);
1130 fPauliPropAddNoiseY =
1131 (int (*)(void *, int, double))GetFunction("PauliPropAddNoiseY");
1132 CheckFunction((void *)fPauliPropAddNoiseY, __LINE__);
1133 fPauliPropAddNoiseZ =
1134 (int (*)(void *, int, double))GetFunction("PauliPropAddNoiseZ");
1135 CheckFunction((void *)fPauliPropAddNoiseZ, __LINE__);
1136 fPauliPropAddNoiseXYZ =
1137 (int (*)(void *, int, double, double, double))GetFunction(
1138 "PauliPropAddNoiseXYZ");
1139 CheckFunction((void *)fPauliPropAddNoiseXYZ, __LINE__);
1140 fPauliPropAddAmplitudeDamping =
1141 (int (*)(void *, int, double, double))GetFunction(
1142 "PauliPropAddAmplitudeDamping");
1143 CheckFunction((void *)fPauliPropAddAmplitudeDamping, __LINE__);
1144 fPauliPropQubitProbability0 = (double (*)(void *, int))GetFunction(
1145 "PauliPropQubitProbability0");
1146 CheckFunction((void *)fPauliPropQubitProbability0, __LINE__);
1147 fPauliPropProbability =
1148 (double (*)(void *, unsigned long long int))GetFunction(
1149 "PauliPropProbability");
1150 CheckFunction((void *)fPauliPropProbability, __LINE__);
1151
1152 fPauliPropMeasureQubit =
1153 (int (*)(void *, int))GetFunction("PauliPropMeasureQubit");
1154 CheckFunction((void *)fPauliPropMeasureQubit, __LINE__);
1155
1156 fPauliPropSampleQubits =
1157 (unsigned char *(*)(void *, const int *, int))GetFunction(
1158 "PauliPropSampleQubits");
1159 CheckFunction((void *)fPauliPropSampleQubits, __LINE__);
1160 fPauliPropFreeSampledQubits = (void (*)(unsigned char *))GetFunction(
1161 "PauliPropFreeSampledQubits");
1162 CheckFunction((void *)fPauliPropFreeSampledQubits, __LINE__);
1163 fPauliPropSaveState =
1164 (void (*)(void *))GetFunction("PauliPropSaveState");
1165 CheckFunction((void *)fPauliPropSaveState, __LINE__);
1166 fPauliPropRestoreState =
1167 (void (*)(void *))GetFunction("PauliPropRestoreState");
1168 CheckFunction((void *)fPauliPropRestoreState, __LINE__);
1169
1170 return true;
1171 } else if (!IsMuted())
1172 std::cerr << "GpuLibrary: Unable to initialize gpu library"
1173 << std::endl;
1174 } else if (!IsMuted())
1175 std::cerr << "GpuLibrary: Unable to get initialization function for "
1176 "gpu library"
1177 << std::endl;
1178 }
1179
1180 return false;
1181 }
1182
1183 void CheckFunction(void *func, int line) const {
1184 if (!func && !IsMuted()) {
1185 std::cerr << "GpuLibrary: Unable to load function, line #: " << line;
1186 const char *dlsym_error = dlerror();
1187 if (dlsym_error) std::cerr << ", error: " << dlsym_error;
1188
1189 std::cerr << std::endl;
1190 }
1191 }
1192
1193 bool IsValid() const { return LibraryHandle != nullptr; }
1194
1195 // Number of CUDA-capable devices visible to the process, or 0 if none are
1196 // visible / the loaded library doesn't support device queries. A negative
1197 // result reports a CUDA discovery error, not absent hardware.
1198 int GetGpuDeviceCount() const {
1199 return fGetGpuDeviceCount ? fGetGpuDeviceCount() : 0;
1200 }
1201
1202 // Selection affects future native objects only. Capture it in wrappers that
1203 // defer native creation until CreateSimulator(). Never select around gates.
1204 bool SetGpuDevice(int device) {
1205 auto lock = LockInitialization();
1206 if (device < 0 || !fSetGpuDevice || !fSetGpuDevice(device)) return false;
1207 creationDevice = device;
1208 return true;
1209 }
1210 int GetCreationDevice() const { return creationDevice; }
1211
1212 int GetStateVectorGpuId(void* obj) const {
1213 return obj && fGetStateVectorGpuId ? fGetStateVectorGpuId(obj) : -1;
1214 }
1215 int MPSGetGpuId(void* obj) const {
1216 return obj && fMPSGetGpuId ? fMPSGetGpuId(obj) : -1;
1217 }
1218 int TNGetGpuId(void* obj) const {
1219 return obj && fTNGetGpuId ? fTNGetGpuId(obj) : -1;
1220 }
1221 int DMGetGpuId(void* obj) const {
1222 return obj && fDMGetGpuId ? fDMGetGpuId(obj) : -1;
1223 }
1224 int MPOGetGpuId(void* obj) const {
1225 return obj && fMPOGetGpuId ? fMPOGetGpuId(obj) : -1;
1226 }
1227 int GetStabilizerGpuId(void* obj) const {
1228 return obj && fGetStabilizerGpuId ? fGetStabilizerGpuId(obj) : -1;
1229 }
1230 int PauliPropGetGpuId(void* obj) const {
1231 return obj && fPauliPropGetGpuId ? fPauliPropGetGpuId(obj) : -1;
1232 }
1233
1234 bool HasDensityMatrixAPI() const {
1235 return IsValid() && fCreateDensityMatrix && fDestroyDensityMatrix &&
1236 fDMCreate && fDMCreateWithState && fDMReset && fDMIsCreated &&
1237 fDMSetDataType &&
1238 fDMSaveState && fDMRestoreState && fDMCleanSavedState && fDMClone &&
1239 fDMSetSeed &&
1240 fDMMeasureQubitCollapse && fDMSampleAll &&
1241 fDMBasisStateProbability && fDMAllProbabilities &&
1242 fDMExpectationValue && fDMTrace && fDMPurity && fDMIsHermitian &&
1243 fDMPartialTrace && fDMHilbertSchmidtOverlap &&
1244 fDMFidelityWithStatevector && fDMApplyKraus && fDMApplyReset &&
1245 fDMApplyX && fDMApplyY && fDMApplyZ && fDMApplyH && fDMApplyS &&
1246 fDMApplySDG && fDMApplyT && fDMApplyTDG && fDMApplySX &&
1247 fDMApplySXDG && fDMApplyK && fDMApplyP && fDMApplyRx &&
1248 fDMApplyRy && fDMApplyRz && fDMApplyU && fDMApplyCX &&
1249 fDMApplyCY && fDMApplyCZ && fDMApplyCH && fDMApplyCSX &&
1250 fDMApplyCSXDG && fDMApplyCP && fDMApplyCRx && fDMApplyCRy &&
1251 fDMApplyCRz && fDMApplyCCX && fDMApplySwap && fDMApplyCSwap &&
1252 fDMApplyCU;
1253 }
1254 bool HasMPOAPI() const {
1255 return IsValid() && fCreateMPO && fDestroyMPO &&
1256 fMPOCreate && fMPOCreateWithState && fMPOReset && fMPOIsCreated &&
1257 fMPOSetDataType &&
1258 fMPOSaveState && fMPORestoreState && fMPOCleanSavedState &&
1259 fMPOClone && fMPOSetSeed && fMPOMeasureQubitCollapse &&
1260 fMPOSampleAll &&
1261 fMPOBasisStateProbability && fMPOAllProbabilities &&
1262 fMPOExpectationValue && fMPOPartialTrace &&
1263 fMPOHilbertSchmidtOverlap && fMPOFidelityWithStatevector &&
1264 fMPOTrace && fMPOPurity && fMPOHermiticityResidual &&
1265 fMPOIsHermitian && fMPOTraceOfSquare && fMPORestoreTrace &&
1266 fMPOHermitize && fMPOReCanonicalize && fMPOTrim &&
1267 fMPOApplyKraus && fMPOApplyReset &&
1268 fMPOApplyX && fMPOApplyY && fMPOApplyZ && fMPOApplyH &&
1269 fMPOApplyS && fMPOApplySDG && fMPOApplyT && fMPOApplyTDG &&
1270 fMPOApplySX && fMPOApplySXDG && fMPOApplyK && fMPOApplyP &&
1271 fMPOApplyRx && fMPOApplyRy && fMPOApplyRz && fMPOApplyU &&
1272 fMPOApplyCX && fMPOApplyCY && fMPOApplyCZ && fMPOApplyCH &&
1273 fMPOApplyCSX && fMPOApplyCSXDG && fMPOApplyCP && fMPOApplyCRx &&
1274 fMPOApplyCRy && fMPOApplyCRz && fMPOApplySwap && fMPOApplyCU;
1275 }
1276
1277 // statevector functions
1278
1279 void *CreateStateVector() {
1280 if (LibraryHandle)
1281 return fCreateStateVector(LibraryHandle);
1282 else
1283 throw std::runtime_error("GpuLibrary: Unable to create state vector");
1284 }
1285
1286 void DestroyStateVector(void *obj) {
1287 if (LibraryHandle)
1288 fDestroyStateVector(obj);
1289 else
1290 throw std::runtime_error("GpuLibrary: Unable to destroy state vector");
1291 }
1292
1293 bool Create(void *obj, unsigned int nrQubits) {
1294 if (LibraryHandle)
1295 return fCreate(obj, nrQubits) == 1;
1296 else
1297 throw std::runtime_error(
1298 "GpuLibrary: Unable to create state vector state");
1299
1300 return false;
1301 }
1302
1303 bool CreateWithState(void *obj, unsigned int nrQubits, const double *state) {
1304 if (LibraryHandle)
1305 return fCreateWithState(obj, nrQubits, state) == 1;
1306 else
1307 throw std::runtime_error(
1308 "GpuLibrary: Unable to create state vector state with a state");
1309
1310 return false;
1311 }
1312
1313 bool Reset(void *obj) {
1314 if (LibraryHandle)
1315 return fReset(obj) == 1;
1316 else
1317 throw std::runtime_error("GpuLibrary: Unable to reset state vector");
1318
1319 return false;
1320 }
1321
1322 bool SetDataType(void *obj, int dataType) {
1323 if (LibraryHandle)
1324 return fSetDataType(obj, dataType) == 1;
1325 else
1326 throw std::runtime_error("GpuLibrary: Unable to set data type");
1327
1328 return false;
1329 }
1330
1331 bool IsDoublePrecision(void *obj) const {
1332 if (LibraryHandle)
1333 return fIsDoublePrecision(obj) == 1;
1334 else
1335 throw std::runtime_error(
1336 "GpuLibrary: Unable to check if double precision");
1337
1338 return false;
1339 }
1340
1341 int GetNrQubits(void *obj) const {
1342 if (LibraryHandle)
1343 return fGetNrQubits(obj);
1344 else
1345 throw std::runtime_error("GpuLibrary: Unable to get number of qubits");
1346 return 0;
1347 }
1348
1349 bool MeasureQubitCollapse(void *obj, int qubitIndex) {
1350 if (LibraryHandle)
1351 return fMeasureQubitCollapse(obj, qubitIndex) == 1;
1352 else
1353 throw std::runtime_error(
1354 "GpuLibrary: Unable to measure qubit with collapse");
1355
1356 return false;
1357 }
1358
1359 bool MeasureQubitNoCollapse(void *obj, int qubitIndex) {
1360 if (LibraryHandle)
1361 return fMeasureQubitNoCollapse(obj, qubitIndex) == 1;
1362 else
1363 throw std::runtime_error(
1364 "GpuLibrary: Unable to measure qubit no collapse");
1365
1366 return false;
1367 }
1368
1369 bool MeasureQubitsCollapse(void *obj, int *qubits, int *bitstring,
1370 int bitstringLen) {
1371 if (LibraryHandle)
1372 return fMeasureQubitsCollapse(obj, qubits, bitstring, bitstringLen) == 1;
1373 else
1374 throw std::runtime_error(
1375 "GpuLibrary: Unable to measure qubits with collapse");
1376
1377 return false;
1378 }
1379
1380 bool MeasureQubitsNoCollapse(void *obj, int *qubits, int *bitstring,
1381 int bitstringLen) {
1382 if (LibraryHandle)
1383 return fMeasureQubitsNoCollapse(obj, qubits, bitstring, bitstringLen) ==
1384 1;
1385 else
1386 throw std::runtime_error(
1387 "GpuLibrary: Unable to measure qubits with no collapse");
1388
1389 return false;
1390 }
1391
1392 unsigned long long MeasureAllQubitsCollapse(void *obj) {
1393 if (LibraryHandle)
1394 return fMeasureAllQubitsCollapse(obj);
1395 else
1396 throw std::runtime_error(
1397 "GpuLibrary: Unable to measure all qubits with collapse");
1398
1399 return 0;
1400 }
1401
1402 unsigned long long MeasureAllQubitsNoCollapse(void *obj) {
1403 if (LibraryHandle)
1404 return fMeasureAllQubitsNoCollapse(obj);
1405 else
1406 throw std::runtime_error(
1407 "GpuLibrary: Unable to measure all qubits with no collapse");
1408
1409 return 0;
1410 }
1411
1412 bool SaveState(void *obj) {
1413 if (LibraryHandle)
1414 return fSaveState(obj) == 1;
1415 else
1416 throw std::runtime_error("GpuLibrary: Unable to save state");
1417
1418 return false;
1419 }
1420
1421 bool SaveStateToHost(void *obj) {
1422 if (LibraryHandle)
1423 return fSaveStateToHost(obj) == 1;
1424 else
1425 throw std::runtime_error("GpuLibrary: Unable to save state to host");
1426
1427 return false;
1428 }
1429
1430 bool SaveStateDestructive(void *obj) {
1431 if (LibraryHandle)
1432 return fSaveStateDestructive(obj) == 1;
1433 else
1434 throw std::runtime_error(
1435 "GpuLibrary: Unable to save state destructively");
1436
1437 return false;
1438 }
1439
1440 bool RestoreStateFreeSaved(void *obj) {
1441 if (LibraryHandle)
1442 return fRestoreStateFreeSaved(obj) == 1;
1443 else
1444 throw std::runtime_error(
1445 "GpuLibrary: Unable to restore state free saved");
1446
1447 return false;
1448 }
1449
1450 bool RestoreStateNoFreeSaved(void *obj) {
1451 if (LibraryHandle)
1452 return fRestoreStateNoFreeSaved(obj) == 1;
1453 else
1454 throw std::runtime_error(
1455 "GpuLibrary: Unable to restore state no free saved");
1456
1457 return false;
1458 }
1459
1460 void FreeSavedState(void *obj) {
1461 if (LibraryHandle)
1462 fFreeSavedState(obj);
1463 else
1464 throw std::runtime_error("GpuLibrary: Unable to free saved state");
1465 }
1466
1467 void *Clone(void *obj) const {
1468 if (LibraryHandle)
1469 return fClone(obj);
1470 else
1471 throw std::runtime_error("GpuLibrary: Unable to clone state vector");
1472
1473 return nullptr;
1474 }
1475
1476 bool SetSeed(void *obj, unsigned long long seed) const {
1477 return obj && fSetSeed && fSetSeed(obj, seed) == 1;
1478 }
1479
1480 bool Sample(void *obj, unsigned int nSamples, long int *samples,
1481 unsigned int nBits, int *bits) {
1482 if (LibraryHandle)
1483 return fSample(obj, nSamples, samples, nBits, bits) == 1;
1484 else
1485 throw std::runtime_error("GpuLibrary: Unable to sample state vector");
1486
1487 return false;
1488 }
1489
1490 bool SampleAll(void *obj, unsigned int nSamples, long int *samples) {
1491 if (LibraryHandle)
1492 return fSampleAll(obj, nSamples, samples) == 1;
1493 else
1494 throw std::runtime_error("GpuLibrary: Unable to sample state vector");
1495
1496 return false;
1497 }
1498
1499 bool Amplitude(void *obj, long long int state, double *real,
1500 double *imaginary) const {
1501 if (LibraryHandle)
1502 return fAmplitude(obj, state, real, imaginary) == 1;
1503 else
1504 throw std::runtime_error("GpuLibrary: Unable to get amplitude");
1505
1506 return false;
1507 }
1508
1509 double Probability(void *obj, int *qubits, int *mask, int len) const {
1510 if (LibraryHandle)
1511 return fProbability(obj, qubits, mask, len);
1512 else
1513 throw std::runtime_error("GpuLibrary: Unable to get probability");
1514
1515 return 0;
1516 }
1517
1518 double BasisStateProbability(void *obj, long long int state) const {
1519 if (LibraryHandle)
1520 return fBasisStateProbability(obj, state);
1521 else
1522 throw std::runtime_error(
1523 "GpuLibrary: Unable to get basis state probability");
1524
1525 return 0;
1526 }
1527
1528 bool AllProbabilities(void *obj, double *probabilities) const {
1529 if (LibraryHandle)
1530 return fAllProbabilities(obj, probabilities) == 1;
1531 else
1532 throw std::runtime_error("GpuLibrary: Unable to get all probabilities");
1533
1534 return false;
1535 }
1536
1537 double ExpectationValue(void *obj, const char *pauliString, int len) const {
1538 if (LibraryHandle)
1539 return fExpectationValue(obj, pauliString, len);
1540 else
1541 throw std::runtime_error("GpuLibrary: Unable to get expectation value");
1542
1543 return 0;
1544 }
1545
1546 bool ApplyX(void *obj, int qubit) {
1547 if (LibraryHandle)
1548 return fApplyX(obj, qubit) == 1;
1549 else
1550 throw std::runtime_error("GpuLibrary: Unable to apply X gate");
1551
1552 return false;
1553 }
1554
1555 bool ApplyY(void *obj, int qubit) {
1556 if (LibraryHandle)
1557 return fApplyY(obj, qubit) == 1;
1558 else
1559 throw std::runtime_error("GpuLibrary: Unable to apply Y gate");
1560
1561 return false;
1562 }
1563
1564 bool ApplyZ(void *obj, int qubit) {
1565 if (LibraryHandle)
1566 return fApplyZ(obj, qubit) == 1;
1567 else
1568 throw std::runtime_error("GpuLibrary: Unable to apply Z gate");
1569
1570 return false;
1571 }
1572
1573 bool ApplyH(void *obj, int qubit) {
1574 if (LibraryHandle)
1575 return fApplyH(obj, qubit) == 1;
1576 else
1577 throw std::runtime_error("GpuLibrary: Unable to apply H gate");
1578
1579 return false;
1580 }
1581
1582 bool ApplyS(void *obj, int qubit) {
1583 if (LibraryHandle)
1584 return fApplyS(obj, qubit) == 1;
1585 else
1586 throw std::runtime_error("GpuLibrary: Unable to apply S gate");
1587
1588 return false;
1589 }
1590
1591 bool ApplySDG(void *obj, int qubit) {
1592 if (LibraryHandle)
1593 return fApplySDG(obj, qubit) == 1;
1594 else
1595 throw std::runtime_error("GpuLibrary: Unable to apply SDG gate");
1596
1597 return false;
1598 }
1599
1600 bool ApplyT(void *obj, int qubit) {
1601 if (LibraryHandle)
1602 return fApplyT(obj, qubit) == 1;
1603 else
1604 throw std::runtime_error("GpuLibrary: Unable to apply T gate");
1605
1606 return false;
1607 }
1608
1609 bool ApplyTDG(void *obj, int qubit) {
1610 if (LibraryHandle)
1611 return fApplyTDG(obj, qubit) == 1;
1612 else
1613 throw std::runtime_error("GpuLibrary: Unable to apply TDG gate");
1614
1615 return false;
1616 }
1617
1618 bool ApplySX(void *obj, int qubit) {
1619 if (LibraryHandle)
1620 return fApplySX(obj, qubit) == 1;
1621 else
1622 throw std::runtime_error("GpuLibrary: Unable to apply SX gate");
1623
1624 return false;
1625 }
1626
1627 bool ApplySXDG(void *obj, int qubit) {
1628 if (LibraryHandle)
1629 return fApplySXDG(obj, qubit) == 1;
1630 else
1631 throw std::runtime_error("GpuLibrary: Unable to apply SXDG gate");
1632
1633 return false;
1634 }
1635
1636 bool ApplyK(void *obj, int qubit) {
1637 if (LibraryHandle)
1638 return fApplyK(obj, qubit) == 1;
1639 else
1640 throw std::runtime_error("GpuLibrary: Unable to apply K gate");
1641
1642 return false;
1643 }
1644
1645 bool ApplyP(void *obj, int qubit, double theta) {
1646 if (LibraryHandle)
1647 return fApplyP(obj, qubit, theta) == 1;
1648 else
1649 throw std::runtime_error("GpuLibrary: Unable to apply P gate");
1650
1651 return false;
1652 }
1653
1654 bool ApplyRx(void *obj, int qubit, double theta) {
1655 if (LibraryHandle)
1656 return fApplyRx(obj, qubit, theta) == 1;
1657 else
1658 throw std::runtime_error("GpuLibrary: Unable to apply Rx gate");
1659
1660 return false;
1661 }
1662
1663 bool ApplyRy(void *obj, int qubit, double theta) {
1664 if (LibraryHandle)
1665 return fApplyRy(obj, qubit, theta) == 1;
1666 else
1667 throw std::runtime_error("GpuLibrary: Unable to apply Ry gate");
1668
1669 return false;
1670 }
1671
1672 bool ApplyRz(void *obj, int qubit, double theta) {
1673 if (LibraryHandle)
1674 return fApplyRz(obj, qubit, theta) == 1;
1675 else
1676 throw std::runtime_error("GpuLibrary: Unable to apply Rz gate");
1677
1678 return false;
1679 }
1680
1681 bool ApplyU(void *obj, int qubit, double theta, double phi, double lambda,
1682 double gamma) {
1683 if (LibraryHandle)
1684 return fApplyU(obj, qubit, theta, phi, lambda, gamma) == 1;
1685 else
1686 throw std::runtime_error("GpuLibrary: Unable to apply U gate");
1687
1688 return false;
1689 }
1690
1691 bool ApplyCX(void *obj, int controlQubit, int targetQubit) {
1692 if (LibraryHandle)
1693 return fApplyCX(obj, controlQubit, targetQubit) == 1;
1694 else
1695 throw std::runtime_error("GpuLibrary: Unable to apply CX gate");
1696
1697 return false;
1698 }
1699
1700 bool ApplyCY(void *obj, int controlQubit, int targetQubit) {
1701 if (LibraryHandle)
1702 return fApplyCY(obj, controlQubit, targetQubit) == 1;
1703 else
1704 throw std::runtime_error("GpuLibrary: Unable to apply CY gate");
1705
1706 return false;
1707 }
1708
1709 bool ApplyCZ(void *obj, int controlQubit, int targetQubit) {
1710 if (LibraryHandle)
1711 return fApplyCZ(obj, controlQubit, targetQubit) == 1;
1712 else
1713 throw std::runtime_error("GpuLibrary: Unable to apply CZ gate");
1714
1715 return false;
1716 }
1717
1718 bool ApplyCH(void *obj, int controlQubit, int targetQubit) {
1719 if (LibraryHandle)
1720 return fApplyCH(obj, controlQubit, targetQubit) == 1;
1721 else
1722 throw std::runtime_error("GpuLibrary: Unable to apply CH gate");
1723
1724 return false;
1725 }
1726
1727 bool ApplyCSX(void *obj, int controlQubit, int targetQubit) {
1728 if (LibraryHandle)
1729 return fApplyCSX(obj, controlQubit, targetQubit) == 1;
1730 else
1731 throw std::runtime_error("GpuLibrary: Unable to apply CSX gate");
1732
1733 return false;
1734 }
1735
1736 bool ApplyCSXDG(void *obj, int controlQubit, int targetQubit) {
1737 if (LibraryHandle)
1738 return fApplyCSXDG(obj, controlQubit, targetQubit) == 1;
1739 else
1740 throw std::runtime_error("GpuLibrary: Unable to apply CSXDG gate");
1741
1742 return false;
1743 }
1744
1745 bool ApplyCP(void *obj, int controlQubit, int targetQubit, double theta) {
1746 if (LibraryHandle)
1747 return fApplyCP(obj, controlQubit, targetQubit, theta) == 1;
1748 else
1749 throw std::runtime_error("GpuLibrary: Unable to apply CP gate");
1750
1751 return false;
1752 }
1753
1754 bool ApplyCRx(void *obj, int controlQubit, int targetQubit, double theta) {
1755 if (LibraryHandle)
1756 return fApplyCRx(obj, controlQubit, targetQubit, theta) == 1;
1757 else
1758 throw std::runtime_error("GpuLibrary: Unable to apply CRx gate");
1759
1760 return false;
1761 }
1762
1763 bool ApplyCRy(void *obj, int controlQubit, int targetQubit, double theta) {
1764 if (LibraryHandle)
1765 return fApplyCRy(obj, controlQubit, targetQubit, theta) == 1;
1766 else
1767 throw std::runtime_error("GpuLibrary: Unable to apply CRy gate");
1768
1769 return false;
1770 }
1771
1772 bool ApplyCRz(void *obj, int controlQubit, int targetQubit, double theta) {
1773 if (LibraryHandle)
1774 return fApplyCRz(obj, controlQubit, targetQubit, theta) == 1;
1775 else
1776 throw std::runtime_error("GpuLibrary: Unable to apply CRz gate");
1777
1778 return false;
1779 }
1780
1781 bool ApplyCCX(void *obj, int controlQubit1, int controlQubit2,
1782 int targetQubit) {
1783 if (LibraryHandle)
1784 return fApplyCCX(obj, controlQubit1, controlQubit2, targetQubit) == 1;
1785 else
1786 throw std::runtime_error("GpuLibrary: Unable to apply CCX gate");
1787
1788 return false;
1789 }
1790
1791 bool ApplySwap(void *obj, int qubit1, int qubit2) {
1792 if (LibraryHandle)
1793 return fApplySwap(obj, qubit1, qubit2) == 1;
1794 else
1795 throw std::runtime_error("GpuLibrary: Unable to apply Swap gate");
1796
1797 return false;
1798 }
1799
1800 bool ApplyCSwap(void *obj, int controlQubit, int qubit1, int qubit2) {
1801 if (LibraryHandle)
1802 return fApplyCSwap(obj, controlQubit, qubit1, qubit2) == 1;
1803 else
1804 throw std::runtime_error("GpuLibrary: Unable to apply CSwap gate");
1805
1806 return false;
1807 }
1808
1809 bool ApplyCU(void *obj, int controlQubit, int targetQubit, double theta,
1810 double phi, double lambda, double gamma) {
1811 if (LibraryHandle)
1812 return fApplyCU(obj, controlQubit, targetQubit, theta, phi, lambda,
1813 gamma) == 1;
1814 else
1815 throw std::runtime_error("GpuLibrary: Unable to apply CU gate");
1816
1817 return false;
1818 }
1819
1820 public:
1821 // density matrix functions
1822 void *CreateDensityMatrix() {
1823 if (!LibraryHandle || !fCreateDensityMatrix) return nullptr;
1824 return fCreateDensityMatrix(LibraryHandle);
1825 }
1826 void DestroyDensityMatrix(void *obj) {
1827 if (obj && fDestroyDensityMatrix) fDestroyDensityMatrix(obj);
1828 }
1829#define DM_BOOL0(name) \
1830 bool name(void *obj) { return obj && f##name && f##name(obj) == 1; }
1831#define DM_BOOL1(name, type) \
1832 bool name(void *obj, type a) { return obj && f##name && f##name(obj, a) == 1; }
1833#define DM_BOOL2(name, type1, type2) \
1834 bool name(void *obj, type1 a, type2 b) { \
1835 return obj && f##name && f##name(obj, a, b) == 1; \
1836 }
1837#define DM_BOOL3(name, type1, type2, type3) \
1838 bool name(void *obj, type1 a, type2 b, type3 c) { \
1839 return obj && f##name && f##name(obj, a, b, c) == 1; \
1840 }
1841 DM_BOOL1(DMCreate, unsigned int)
1842 bool DMCreateWithState(void *obj, unsigned int n, const double *data) {
1843 return obj && fDMCreateWithState && fDMCreateWithState(obj, n, data) == 1;
1844 }
1845 bool DMCreateWithBasisState(void *obj, unsigned int n,
1846 unsigned long long state) {
1847 return obj && fDMCreateWithBasisState &&
1848 fDMCreateWithBasisState(obj, n, state) == 1;
1849 }
1850 bool DMCreateWithMixtureOfBasisStates(void *obj, unsigned int n,
1851 const unsigned long long *states,
1852 const double *weights, int nTerms) {
1853 return obj && fDMCreateWithMixtureOfBasisStates &&
1854 fDMCreateWithMixtureOfBasisStates(obj, n, states, weights,
1855 nTerms) == 1;
1856 }
1857 DM_BOOL0(DMReset) DM_BOOL0(DMIsValid) DM_BOOL0(DMIsCreated)
1858 DM_BOOL1(DMSetDataType, int) DM_BOOL0(DMIsDoublePrecision)
1859 int DMGetNrQubits(void *obj) const {
1860 return obj && fDMGetNrQubits ? fDMGetNrQubits(obj) : 0;
1861 }
1862 DM_BOOL0(DMSaveState) DM_BOOL0(DMRestoreState)
1863 DM_BOOL0(DMCleanSavedState)
1864 void *DMClone(void *obj) { return obj && fDMClone ? fDMClone(obj) : nullptr; }
1865 bool DMSetSeed(void *obj, unsigned long long seed) const {
1866 return obj && fDMSetSeed && fDMSetSeed(obj, seed) == 1;
1867 }
1868 bool DMMeasureQubitCollapse(void *obj, int q) {
1869 return obj && fDMMeasureQubitCollapse && fDMMeasureQubitCollapse(obj, q);
1870 }
1871 DM_BOOL1(DMMeasureQubitNoCollapse, int)
1872 bool DMMeasureQubitsCollapse(void *obj, int *q, int *bits, int n) {
1873 return obj && fDMMeasureQubitsCollapse && fDMMeasureQubitsCollapse(obj, q, bits, n) == 1;
1874 }
1875 bool DMMeasureQubitsNoCollapse(void *obj, int *q, int *bits, int n) {
1876 return obj && fDMMeasureQubitsNoCollapse && fDMMeasureQubitsNoCollapse(obj, q, bits, n) == 1;
1877 }
1878 unsigned long long DMMeasureAllQubitsCollapse(void *obj) { return obj && fDMMeasureAllQubitsCollapse ? fDMMeasureAllQubitsCollapse(obj) : 0; }
1879 unsigned long long DMMeasureAllQubitsNoCollapse(void *obj) { return obj && fDMMeasureAllQubitsNoCollapse ? fDMMeasureAllQubitsNoCollapse(obj) : 0; }
1880 bool DMGetElement(void *obj, long long row, long long col, double *re, double *im) const {
1881 return obj && fDMGetElement && fDMGetElement(obj, row, col, re, im) == 1;
1882 }
1883 bool DMSample(void *obj, unsigned int n, long int *samples, unsigned int nBits, int *order) {
1884 return obj && fDMSample && fDMSample(obj, n, samples, nBits, order) == 1;
1885 }
1886 bool DMSampleAll(void *obj, unsigned int shots, long int *samples) {
1887 return obj && fDMSampleAll && fDMSampleAll(obj, shots, samples) == 1;
1888 }
1889 double DMBasisStateProbability(void *obj, long long state) const {
1890 return obj && fDMBasisStateProbability
1891 ? fDMBasisStateProbability(obj, state) : 0.0;
1892 }
1893 bool DMAllProbabilities(void *obj, double *values) {
1894 return obj && fDMAllProbabilities && fDMAllProbabilities(obj, values) == 1;
1895 }
1896 double DMExpectationValue(void *obj, const char *pauli, int len) const {
1897 return obj && fDMExpectationValue ? fDMExpectationValue(obj, pauli, len) : 0.0;
1898 }
1899 double DMQubitProbability0(void *obj, unsigned int q) const { return obj && fDMQubitProbability0 ? fDMQubitProbability0(obj, q) : 0.; }
1900 double DMTrace(void *obj) const { return obj && fDMTrace ? fDMTrace(obj) : 0.; }
1901 double DMPurity(void *obj) const { return obj && fDMPurity ? fDMPurity(obj) : 0.; }
1902 bool DMIsHermitian(void *obj, double eps) const { return obj && fDMIsHermitian && fDMIsHermitian(obj, eps) == 1; }
1903 bool DMPartialTrace(void *obj, const int *q, int n, double *out) { return obj && fDMPartialTrace && fDMPartialTrace(obj, q, n, out) == 1; }
1904 bool DMHilbertSchmidtOverlap(void *obj, void *other, double *re, double *im) { return obj && other && fDMHilbertSchmidtOverlap && fDMHilbertSchmidtOverlap(obj, other, re, im) == 1; }
1905 bool DMFidelityWithStatevector(void *obj, const double *state, double *out) { return obj && fDMFidelityWithStatevector && fDMFidelityWithStatevector(obj, state, out) == 1; }
1906 bool DMApplyKraus(void *obj, int n, const int *qubits, int count,
1907 const double *operators) {
1908 return obj && fDMApplyKraus &&
1909 fDMApplyKraus(obj, n, qubits, count, operators) == 1;
1910 }
1911 DM_BOOL1(DMApplyReset, int)
1912 DM_BOOL2(DMApplyBitFlipNoise, int, double) DM_BOOL2(DMApplyPhaseFlipNoise, int, double)
1913 DM_BOOL2(DMApplyDepolarizingNoise, int, double) DM_BOOL2(DMApplyAmplitudeDamping, int, double)
1914 DM_BOOL2(DMApplyPhaseDamping, int, double) DM_BOOL1(DMApplyNonSelectiveMeasurement, int)
1915 DM_BOOL1(DMApplyX, int) DM_BOOL1(DMApplyY, int)
1916 DM_BOOL1(DMApplyZ, int) DM_BOOL1(DMApplyH, int)
1917 DM_BOOL1(DMApplyS, int) DM_BOOL1(DMApplySDG, int)
1918 DM_BOOL1(DMApplyT, int) DM_BOOL1(DMApplyTDG, int)
1919 DM_BOOL1(DMApplySX, int) DM_BOOL1(DMApplySXDG, int)
1920 DM_BOOL1(DMApplyK, int)
1921 DM_BOOL2(DMApplyP, int, double) DM_BOOL2(DMApplyRx, int, double)
1922 DM_BOOL2(DMApplyRy, int, double) DM_BOOL2(DMApplyRz, int, double)
1923 bool DMApplyU(void *o, int q, double a, double b, double c, double d) {
1924 return o && fDMApplyU && fDMApplyU(o, q, a, b, c, d) == 1;
1925 }
1926 DM_BOOL2(DMApplyCX, int, int) DM_BOOL2(DMApplyCY, int, int)
1927 DM_BOOL2(DMApplyCZ, int, int) DM_BOOL2(DMApplyCH, int, int)
1928 DM_BOOL2(DMApplyCSX, int, int) DM_BOOL2(DMApplyCSXDG, int, int)
1929 DM_BOOL3(DMApplyCP, int, int, double)
1930 DM_BOOL3(DMApplyCRx, int, int, double)
1931 DM_BOOL3(DMApplyCRy, int, int, double)
1932 DM_BOOL3(DMApplyCRz, int, int, double)
1933 DM_BOOL3(DMApplyCCX, int, int, int)
1934 DM_BOOL2(DMApplySwap, int, int)
1935 DM_BOOL3(DMApplyCSwap, int, int, int)
1936 bool DMApplyCU(void *o, int c, int t, double a, double b, double d,
1937 double g) {
1938 return o && fDMApplyCU && fDMApplyCU(o, c, t, a, b, d, g) == 1;
1939 }
1940#undef DM_BOOL3
1941#undef DM_BOOL2
1942#undef DM_BOOL1
1943#undef DM_BOOL0
1944
1945 public:
1946 // matrix product operator (mpo) functions
1947 void *CreateMPO() {
1948 if (!LibraryHandle || !fCreateMPO) return nullptr;
1949 return fCreateMPO(LibraryHandle);
1950 }
1951 void DestroyMPO(void *obj) {
1952 if (obj && fDestroyMPO) fDestroyMPO(obj);
1953 }
1954#define MPO_BOOL0(name) \
1955 bool name(void *obj) { return obj && f##name && f##name(obj) == 1; }
1956#define MPO_BOOL1(name, type) \
1957 bool name(void *obj, type a) { return obj && f##name && f##name(obj, a) == 1; }
1958#define MPO_BOOL2(name, type1, type2) \
1959 bool name(void *obj, type1 a, type2 b) { \
1960 return obj && f##name && f##name(obj, a, b) == 1; \
1961 }
1962#define MPO_BOOL3(name, type1, type2, type3) \
1963 bool name(void *obj, type1 a, type2 b, type3 c) { \
1964 return obj && f##name && f##name(obj, a, b, c) == 1; \
1965 }
1966 MPO_BOOL1(MPOCreate, unsigned int)
1967 bool MPOCreateWithState(void *obj, unsigned int n, const double *data) {
1968 return obj && fMPOCreateWithState && fMPOCreateWithState(obj, n, data) == 1;
1969 }
1970 bool MPOCreateWithBasisState(void *obj, unsigned int n,
1971 unsigned long long state) {
1972 return obj && fMPOCreateWithBasisState &&
1973 fMPOCreateWithBasisState(obj, n, state) == 1;
1974 }
1975 bool MPOCreateWithBasisStateBits(void *obj, unsigned int n,
1976 const unsigned char *stateBits) {
1977 return obj && fMPOCreateWithBasisStateBits &&
1978 fMPOCreateWithBasisStateBits(obj, n, stateBits) == 1;
1979 }
1980 bool MPOCreateWithMixtureOfBasisStates(void *obj, unsigned int n,
1981 const unsigned long long *states,
1982 const double *weights, int nTerms) {
1983 return obj && fMPOCreateWithMixtureOfBasisStates &&
1984 fMPOCreateWithMixtureOfBasisStates(obj, n, states, weights,
1985 nTerms) == 1;
1986 }
1987 bool MPOCreateWithMixtureOfBasisStatesBits(void *obj, unsigned int n,
1988 const unsigned char *stateBitsFlat,
1989 const double *weights,
1990 int nTerms) {
1991 return obj && fMPOCreateWithMixtureOfBasisStatesBits &&
1992 fMPOCreateWithMixtureOfBasisStatesBits(obj, n, stateBitsFlat,
1993 weights, nTerms) == 1;
1994 }
1995 MPO_BOOL0(MPOReset)
1996 bool MPOSetInitialQubitsMap(void *obj,
1997 const std::vector<long long int> &initialMap) {
1998 return obj && fMPOSetInitialQubitsMap &&
1999 fMPOSetInitialQubitsMap(obj, initialMap.data(),
2000 static_cast<int>(initialMap.size())) == 1;
2001 }
2002 MPO_BOOL1(MPOSetUseOptimalMeetingPosition, int)
2003 bool MPOGetUseOptimalMeetingPosition(void *obj) const {
2004 return obj && fMPOGetUseOptimalMeetingPosition &&
2005 fMPOGetUseOptimalMeetingPosition(obj) == 1;
2006 }
2007 MPO_BOOL0(MPOIsValid) MPO_BOOL0(MPOIsCreated)
2008 MPO_BOOL1(MPOSetDataType, int) MPO_BOOL0(MPOIsDoublePrecision)
2009 int MPOGetNrQubits(void *obj) const {
2010 return obj && fMPOGetNrQubits ? fMPOGetNrQubits(obj) : 0;
2011 }
2012 MPO_BOOL1(MPOSetCutoff, double)
2013 double MPOGetCutoff(void *obj) const {
2014 return obj && fMPOGetCutoff ? fMPOGetCutoff(obj) : 0.0;
2015 }
2016 MPO_BOOL1(MPOSetTruncationMode, int)
2017 int MPOGetTruncationMode(void *obj) const {
2018 return obj && fMPOGetTruncationMode ? fMPOGetTruncationMode(obj) : 0;
2019 }
2020 MPO_BOOL1(MPOSetGesvdJ, int)
2021 bool MPOGetGesvdJ(void *obj) const { return obj && fMPOGetGesvdJ && fMPOGetGesvdJ(obj) == 1; }
2022 bool MPOSetGesvdP(void *obj, int val) {
2023 return LibraryHandle && obj && fMPOSetGesvdP &&
2024 fMPOSetGesvdP(obj, val) == 1;
2025 }
2026
2027 bool MPOGetGesvdP(void *obj) const {
2028 if (!LibraryHandle || !obj || !fMPOGetGesvdP)
2029 throw std::runtime_error("GpuLibrary: MPOGetGesvdP is unavailable");
2030 return fMPOGetGesvdP(obj) == 1;
2031 }
2032
2033 bool MPOSetGesvdR(void *obj, int val) {
2034 return LibraryHandle && obj && fMPOSetGesvdR &&
2035 fMPOSetGesvdR(obj, val) == 1;
2036 }
2037
2038 bool MPOGetGesvdR(void *obj) const {
2039 if (!LibraryHandle || !obj || !fMPOGetGesvdR)
2040 throw std::runtime_error("GpuLibrary: MPOGetGesvdR is unavailable");
2041 return fMPOGetGesvdR(obj) == 1;
2042 }
2043
2044 // 0=GESVD, 1=GESVDJ, 2=GESVDP, 3=GESVDR; -1 before the first split.
2045 int MPOGetLastSvdAlgo(void *obj) const {
2046 if (!LibraryHandle || !obj || !fMPOGetLastSvdAlgo)
2047 throw std::runtime_error("GpuLibrary: MPOGetLastSvdAlgo is unavailable");
2048 return fMPOGetLastSvdAlgo(obj);
2049 }
2050
2051 MPO_BOOL1(MPOSetMaxExtent, long int)
2052 long int MPOGetMaxExtent(void *obj) const {
2053 return obj && fMPOGetMaxExtent ? fMPOGetMaxExtent(obj) : 0;
2054 }
2055 bool MPOGetBondDimensions(void *obj, long long int *bondDims) {
2056 return obj && fMPOGetBondDimensions &&
2057 fMPOGetBondDimensions(obj, bondDims) == 1;
2058 }
2059 bool MPOSetCallbackContext(void *obj, void *context) {
2060 return obj && fMPOSetCallbackContext &&
2061 fMPOSetCallbackContext(obj, context) == 1;
2062 }
2063 bool MPOSetMeetingPositionCallback(
2064 void *obj, int64_t (*callback)(void *, const int64_t *)) {
2065 return obj && fMPOSetMeetingPositionCallback &&
2066 fMPOSetMeetingPositionCallback(obj, callback) == 1;
2067 }
2068 bool MPOSetBondDimensionsCallback(
2069 void *obj, void (*callback)(void *, const int64_t *)) {
2070 return obj && fMPOSetBondDimensionsCallback &&
2071 fMPOSetBondDimensionsCallback(obj, callback) == 1;
2072 }
2073 MPO_BOOL1(MPOReCanonicalize, int)
2074 bool MPOTrim(void *obj, double cutoff, long int maxExtent, int center) { return obj && fMPOTrim && fMPOTrim(obj, cutoff, maxExtent, center) == 1; }
2075 MPO_BOOL0(MPOSaveState) MPO_BOOL0(MPORestoreState)
2076 MPO_BOOL0(MPOCleanSavedState)
2077 void *MPOClone(void *obj) {
2078 return obj && fMPOClone ? fMPOClone(obj) : nullptr;
2079 }
2080 bool MPOSetSeed(void *obj, unsigned long long seed) const {
2081 return obj && fMPOSetSeed && fMPOSetSeed(obj, seed) == 1;
2082 }
2083 bool MPOMeasureQubitCollapse(void *obj, int q) {
2084 return obj && fMPOMeasureQubitCollapse && fMPOMeasureQubitCollapse(obj, q);
2085 }
2086 MPO_BOOL1(MPOMeasureQubitNoCollapse, int)
2087 bool MPOMeasureQubitsCollapse(void *obj, int *q, int *bits, int n) { return obj && fMPOMeasureQubitsCollapse && fMPOMeasureQubitsCollapse(obj, q, bits, n) == 1; }
2088 bool MPOMeasureQubitsNoCollapse(void *obj, int *q, int *bits, int n) { return obj && fMPOMeasureQubitsNoCollapse && fMPOMeasureQubitsNoCollapse(obj, q, bits, n) == 1; }
2089 unsigned long long MPOMeasureAllQubitsCollapse(void *obj) { return obj && fMPOMeasureAllQubitsCollapse ? fMPOMeasureAllQubitsCollapse(obj) : 0; }
2090 unsigned long long MPOMeasureAllQubitsNoCollapse(void *obj) { return obj && fMPOMeasureAllQubitsNoCollapse ? fMPOMeasureAllQubitsNoCollapse(obj) : 0; }
2091 bool MPOGetElement(void *obj, long long row, long long col, double *re, double *im) const {
2092 return obj && fMPOGetElement && fMPOGetElement(obj, row, col, re, im) == 1;
2093 }
2094 bool MPOSample(void *obj, unsigned int nSamples, long int *samples,
2095 unsigned int nBits, int *bitOrdering) {
2096 return obj && fMPOSample &&
2097 fMPOSample(obj, nSamples, samples, nBits, bitOrdering) == 1;
2098 }
2099 bool MPOSampleAll(void *obj, unsigned int shots, long int *samples) {
2100 return obj && fMPOSampleAll && fMPOSampleAll(obj, shots, samples) == 1;
2101 }
2102 double MPOBasisStateProbability(void *obj, long long state) const {
2103 return obj && fMPOBasisStateProbability
2104 ? fMPOBasisStateProbability(obj, state) : 0.0;
2105 }
2106 bool MPOAllProbabilities(void *obj, double *values) {
2107 return obj && fMPOAllProbabilities && fMPOAllProbabilities(obj, values) == 1;
2108 }
2109 double MPOExpectationValue(void *obj, const char *pauli, int len) const {
2110 return obj && fMPOExpectationValue ? fMPOExpectationValue(obj, pauli, len)
2111 : 0.0;
2112 }
2113 double MPOQubitProbability0(void *obj, unsigned int q) const { return obj && fMPOQubitProbability0 ? fMPOQubitProbability0(obj, q) : 0.; }
2114 bool MPOPartialTrace(void *obj, const int *q, int n, double *out) { return obj && fMPOPartialTrace && fMPOPartialTrace(obj, q, n, out) == 1; }
2115 bool MPOHilbertSchmidtOverlap(void *obj, void *other, double *re, double *im) { return obj && other && fMPOHilbertSchmidtOverlap && fMPOHilbertSchmidtOverlap(obj, other, re, im) == 1; }
2116 bool MPOFidelityWithStatevector(void *obj, const double *state, double *out) { return obj && fMPOFidelityWithStatevector && fMPOFidelityWithStatevector(obj, state, out) == 1; }
2117 double MPOTrace(void *obj) const { return obj && fMPOTrace ? fMPOTrace(obj) : 0.; }
2118 double MPOPurity(void *obj) const { return obj && fMPOPurity ? fMPOPurity(obj) : 0.; }
2119 double MPOHermiticityResidual(void *obj) const { return obj && fMPOHermiticityResidual ? fMPOHermiticityResidual(obj) : 0.; }
2120 bool MPOIsHermitian(void *obj, double eps) const { return obj && fMPOIsHermitian && fMPOIsHermitian(obj, eps) == 1; }
2121 double MPOTraceOfSquare(void *obj) const { return obj && fMPOTraceOfSquare ? fMPOTraceOfSquare(obj) : 0.; }
2122 MPO_BOOL0(MPORestoreTrace) MPO_BOOL0(MPOHermitize)
2123 MPO_BOOL1(MPOSetKrausCompletenessCheck, int)
2124 int MPOGetKrausCompletenessCheck(void *obj) const { return obj && fMPOGetKrausCompletenessCheck ? fMPOGetKrausCompletenessCheck(obj) : -1; }
2125 bool MPOApplyKraus(void *obj, int n, const int *qubits, int count,
2126 const double *operators) {
2127 return obj && fMPOApplyKraus &&
2128 fMPOApplyKraus(obj, n, qubits, count, operators) == 1;
2129 }
2130 MPO_BOOL1(MPOApplyReset, int)
2131 MPO_BOOL2(MPOApplyBitFlipNoise, int, double) MPO_BOOL2(MPOApplyPhaseFlipNoise, int, double)
2132 MPO_BOOL2(MPOApplyDepolarizingNoise, int, double) MPO_BOOL2(MPOApplyAmplitudeDamping, int, double)
2133 MPO_BOOL2(MPOApplyPhaseDamping, int, double) MPO_BOOL1(MPOApplyNonSelectiveMeasurement, int)
2134 MPO_BOOL1(MPOApplyX, int) MPO_BOOL1(MPOApplyY, int)
2135 MPO_BOOL1(MPOApplyZ, int) MPO_BOOL1(MPOApplyH, int)
2136 MPO_BOOL1(MPOApplyS, int) MPO_BOOL1(MPOApplySDG, int)
2137 MPO_BOOL1(MPOApplyT, int) MPO_BOOL1(MPOApplyTDG, int)
2138 MPO_BOOL1(MPOApplySX, int) MPO_BOOL1(MPOApplySXDG, int)
2139 MPO_BOOL1(MPOApplyK, int)
2140 MPO_BOOL2(MPOApplyP, int, double) MPO_BOOL2(MPOApplyRx, int, double)
2141 MPO_BOOL2(MPOApplyRy, int, double) MPO_BOOL2(MPOApplyRz, int, double)
2142 bool MPOApplyU(void *o, int q, double a, double b, double c, double d) {
2143 return o && fMPOApplyU && fMPOApplyU(o, q, a, b, c, d) == 1;
2144 }
2145 bool MPOApplyOneQubitMatrix(void *obj, int qubit,
2146 const double *matrixInterleaved) {
2147 return obj && fMPOApplyOneQubitMatrix &&
2148 fMPOApplyOneQubitMatrix(obj, qubit, matrixInterleaved) == 1;
2149 }
2150 bool MPOApplyTwoQubitMatrix(void *obj, int qubit1, int qubit2,
2151 const double *matrixInterleaved) {
2152 return obj && fMPOApplyTwoQubitMatrix &&
2153 fMPOApplyTwoQubitMatrix(obj, qubit1, qubit2, matrixInterleaved) ==
2154 1;
2155 }
2156 MPO_BOOL2(MPOApplyCX, int, int) MPO_BOOL2(MPOApplyCY, int, int)
2157 MPO_BOOL2(MPOApplyCZ, int, int) MPO_BOOL2(MPOApplyCH, int, int)
2158 MPO_BOOL2(MPOApplyCSX, int, int) MPO_BOOL2(MPOApplyCSXDG, int, int)
2159 MPO_BOOL3(MPOApplyCP, int, int, double)
2160 MPO_BOOL3(MPOApplyCRx, int, int, double)
2161 MPO_BOOL3(MPOApplyCRy, int, int, double)
2162 MPO_BOOL3(MPOApplyCRz, int, int, double)
2163 MPO_BOOL2(MPOApplySwap, int, int)
2164 bool MPOApplyCU(void *o, int c, int t, double a, double b, double d,
2165 double g) {
2166 return o && fMPOApplyCU && fMPOApplyCU(o, c, t, a, b, d, g) == 1;
2167 }
2168#undef MPO_BOOL3
2169#undef MPO_BOOL2
2170#undef MPO_BOOL1
2171#undef MPO_BOOL0
2172
2173 private:
2174 // density matrix function pointers
2175 void *(*fCreateDensityMatrix)(void *) = nullptr;
2176 void (*fDestroyDensityMatrix)(void *) = nullptr;
2177 int (*fDMCreate)(void *, unsigned int) = nullptr;
2178 int (*fDMCreateWithState)(void *, unsigned int, const double *) = nullptr;
2179 int (*fDMCreateWithBasisState)(void *, unsigned int,
2180 unsigned long long) = nullptr;
2181 int (*fDMCreateWithMixtureOfBasisStates)(void *, unsigned int,
2182 const unsigned long long *,
2183 const double *, int) = nullptr;
2184 int (*fDMReset)(void *) = nullptr;
2185 int (*fDMIsValid)(void *) = nullptr;
2186 int (*fDMIsCreated)(void *) = nullptr;
2187 int (*fDMSetDataType)(void *, int) = nullptr;
2188 int (*fDMIsDoublePrecision)(void *) = nullptr;
2189 int (*fDMGetNrQubits)(void *) = nullptr;
2190 int (*fDMSaveState)(void *) = nullptr;
2191 int (*fDMRestoreState)(void *) = nullptr;
2192 int (*fDMCleanSavedState)(void *) = nullptr;
2193 void *(*fDMClone)(void *) = nullptr;
2194 int (*fDMSetSeed)(void *, unsigned long long) = nullptr;
2195 int (*fDMMeasureQubitCollapse)(void *, int) = nullptr;
2196 int (*fDMMeasureQubitNoCollapse)(void *, int) = nullptr;
2197 int (*fDMMeasureQubitsCollapse)(void *, int *, int *, int) = nullptr;
2198 int (*fDMMeasureQubitsNoCollapse)(void *, int *, int *, int) = nullptr;
2199 unsigned long long (*fDMMeasureAllQubitsCollapse)(void *) = nullptr;
2200 unsigned long long (*fDMMeasureAllQubitsNoCollapse)(void *) = nullptr;
2201 int (*fDMSample)(void *, unsigned int, long int *, unsigned int, int *) = nullptr;
2202 int (*fDMSampleAll)(void *, unsigned int, long int *) = nullptr;
2203 int (*fDMGetElement)(void *, long long, long long, double *, double *) = nullptr;
2204 double (*fDMBasisStateProbability)(void *, long long) = nullptr;
2205 int (*fDMAllProbabilities)(void *, double *) = nullptr;
2206 double (*fDMExpectationValue)(void *, const char *, int) = nullptr;
2207 double (*fDMQubitProbability0)(void *, unsigned int) = nullptr;
2208 double (*fDMTrace)(void *) = nullptr;
2209 double (*fDMPurity)(void *) = nullptr;
2210 int (*fDMIsHermitian)(void *, double) = nullptr;
2211 int (*fDMPartialTrace)(void *, const int *, int, double *) = nullptr;
2212 int (*fDMHilbertSchmidtOverlap)(void *, void *, double *, double *) = nullptr;
2213 int (*fDMFidelityWithStatevector)(void *, const double *, double *) = nullptr;
2214 int (*fDMApplyKraus)(void *, int, const int *, int, const double *) = nullptr;
2215 int (*fDMApplyReset)(void *, int) = nullptr;
2216#define DECL_DM1(name) int (*f##name)(void *, int) = nullptr
2217#define DECL_DM2(name) int (*f##name)(void *, int, int) = nullptr
2218#define DECL_DMR1(name) int (*f##name)(void *, int, double) = nullptr
2219#define DECL_DMR2(name) int (*f##name)(void *, int, int, double) = nullptr
2220 DECL_DMR1(DMApplyBitFlipNoise); DECL_DMR1(DMApplyPhaseFlipNoise);
2221 DECL_DMR1(DMApplyDepolarizingNoise); DECL_DMR1(DMApplyAmplitudeDamping);
2222 DECL_DMR1(DMApplyPhaseDamping); DECL_DM1(DMApplyNonSelectiveMeasurement);
2223 DECL_DM1(DMApplyX); DECL_DM1(DMApplyY); DECL_DM1(DMApplyZ);
2224 DECL_DM1(DMApplyH); DECL_DM1(DMApplyS); DECL_DM1(DMApplySDG);
2225 DECL_DM1(DMApplyT); DECL_DM1(DMApplyTDG); DECL_DM1(DMApplySX);
2226 DECL_DM1(DMApplySXDG); DECL_DM1(DMApplyK);
2227 DECL_DMR1(DMApplyP); DECL_DMR1(DMApplyRx); DECL_DMR1(DMApplyRy);
2228 DECL_DMR1(DMApplyRz);
2229 int (*fDMApplyU)(void *, int, double, double, double, double) = nullptr;
2230 DECL_DM2(DMApplyCX); DECL_DM2(DMApplyCY); DECL_DM2(DMApplyCZ);
2231 DECL_DM2(DMApplyCH); DECL_DM2(DMApplyCSX); DECL_DM2(DMApplyCSXDG);
2232 DECL_DMR2(DMApplyCP); DECL_DMR2(DMApplyCRx); DECL_DMR2(DMApplyCRy);
2233 DECL_DMR2(DMApplyCRz);
2234 int (*fDMApplyCCX)(void *, int, int, int) = nullptr;
2235 DECL_DM2(DMApplySwap);
2236 int (*fDMApplyCSwap)(void *, int, int, int) = nullptr;
2237 int (*fDMApplyCU)(void *, int, int, double, double, double, double) = nullptr;
2238#undef DECL_DMR2
2239#undef DECL_DMR1
2240#undef DECL_DM2
2241#undef DECL_DM1
2242
2243 private:
2244 // matrix product operator (mpo) function pointers
2245 void *(*fCreateMPO)(void *) = nullptr;
2246 void (*fDestroyMPO)(void *) = nullptr;
2247 int (*fMPOCreate)(void *, unsigned int) = nullptr;
2248 int (*fMPOCreateWithState)(void *, unsigned int, const double *) = nullptr;
2249 int (*fMPOCreateWithBasisState)(void *, unsigned int,
2250 unsigned long long) = nullptr;
2251 int (*fMPOCreateWithBasisStateBits)(void *, unsigned int,
2252 const unsigned char *) = nullptr;
2253 int (*fMPOCreateWithMixtureOfBasisStates)(void *, unsigned int,
2254 const unsigned long long *,
2255 const double *, int) = nullptr;
2256 int (*fMPOCreateWithMixtureOfBasisStatesBits)(void *, unsigned int,
2257 const unsigned char *,
2258 const double *,
2259 int) = nullptr;
2260 int (*fMPOReset)(void *) = nullptr;
2261 int (*fMPOSetInitialQubitsMap)(void *, const long long int *,
2262 int) = nullptr;
2263 int (*fMPOSetUseOptimalMeetingPosition)(void *, int) = nullptr;
2264 int (*fMPOGetUseOptimalMeetingPosition)(void *) = nullptr;
2265 int (*fMPOIsValid)(void *) = nullptr;
2266 int (*fMPOIsCreated)(void *) = nullptr;
2267 int (*fMPOSetDataType)(void *, int) = nullptr;
2268 int (*fMPOIsDoublePrecision)(void *) = nullptr;
2269 int (*fMPOGetNrQubits)(void *) = nullptr;
2270 int (*fMPOSetCutoff)(void *, double) = nullptr;
2271 double (*fMPOGetCutoff)(void *) = nullptr;
2272 int (*fMPOSetTruncationMode)(void *, int) = nullptr;
2273 int (*fMPOGetTruncationMode)(void *) = nullptr;
2274 int (*fMPOSetGesvdJ)(void *, int) = nullptr;
2275 int (*fMPOGetGesvdJ)(void *) = nullptr;
2276 int (*fMPOSetGesvdP)(void *, int) = nullptr;
2277 int (*fMPOGetGesvdP)(void *) = nullptr;
2278 int (*fMPOSetGesvdR)(void *, int) = nullptr;
2279 int (*fMPOGetGesvdR)(void *) = nullptr;
2280 int (*fMPOGetLastSvdAlgo)(void *) = nullptr;
2281 int (*fMPOSetMaxExtent)(void *, long int) = nullptr;
2282 long int (*fMPOGetMaxExtent)(void *) = nullptr;
2283 int (*fMPOGetBondDimensions)(void *, long long int *) = nullptr;
2284 int (*fMPOSetCallbackContext)(void *, void *) = nullptr;
2285 int (*fMPOSetMeetingPositionCallback)(void *, int64_t (*)(void *, const int64_t *)) = nullptr;
2286 int (*fMPOSetBondDimensionsCallback)(void *, void (*)(void *, const int64_t *)) = nullptr;
2287 int (*fMPOReCanonicalize)(void *, int) = nullptr;
2288 int (*fMPOTrim)(void *, double, long int, int) = nullptr;
2289 int (*fMPOSaveState)(void *) = nullptr;
2290 int (*fMPORestoreState)(void *) = nullptr;
2291 int (*fMPOCleanSavedState)(void *) = nullptr;
2292 void *(*fMPOClone)(void *) = nullptr;
2293 int (*fMPOSetSeed)(void *, unsigned long long) = nullptr;
2294 int (*fMPOMeasureQubitCollapse)(void *, int) = nullptr;
2295 int (*fMPOMeasureQubitNoCollapse)(void *, int) = nullptr;
2296 int (*fMPOMeasureQubitsCollapse)(void *, int *, int *, int) = nullptr;
2297 int (*fMPOMeasureQubitsNoCollapse)(void *, int *, int *, int) = nullptr;
2298 unsigned long long (*fMPOMeasureAllQubitsCollapse)(void *) = nullptr;
2299 unsigned long long (*fMPOMeasureAllQubitsNoCollapse)(void *) = nullptr;
2300 int (*fMPOSample)(void *, unsigned int, long int *, unsigned int,
2301 int *) = nullptr;
2302 int (*fMPOSampleAll)(void *, unsigned int, long int *) = nullptr;
2303 int (*fMPOGetElement)(void *, long long, long long, double *,
2304 double *) = nullptr;
2305 double (*fMPOBasisStateProbability)(void *, long long) = nullptr;
2306 int (*fMPOAllProbabilities)(void *, double *) = nullptr;
2307 double (*fMPOExpectationValue)(void *, const char *, int) = nullptr;
2308 double (*fMPOQubitProbability0)(void *, unsigned int) = nullptr;
2309 int (*fMPOPartialTrace)(void *, const int *, int, double *) = nullptr;
2310 int (*fMPOHilbertSchmidtOverlap)(void *, void *, double *, double *) = nullptr;
2311 int (*fMPOFidelityWithStatevector)(void *, const double *, double *) = nullptr;
2312 double (*fMPOTrace)(void *) = nullptr;
2313 double (*fMPOPurity)(void *) = nullptr;
2314 double (*fMPOHermiticityResidual)(void *) = nullptr;
2315 int (*fMPOIsHermitian)(void *, double) = nullptr;
2316 double (*fMPOTraceOfSquare)(void *) = nullptr;
2317 int (*fMPORestoreTrace)(void *) = nullptr;
2318 int (*fMPOHermitize)(void *) = nullptr;
2319 int (*fMPOSetKrausCompletenessCheck)(void *, int) = nullptr;
2320 int (*fMPOGetKrausCompletenessCheck)(void *) = nullptr;
2321 int (*fMPOApplyKraus)(void *, int, const int *, int,
2322 const double *) = nullptr;
2323 int (*fMPOApplyReset)(void *, int) = nullptr;
2324#define DECL_MPO1(name) int (*f##name)(void *, int) = nullptr
2325#define DECL_MPO2(name) int (*f##name)(void *, int, int) = nullptr
2326#define DECL_MPOR1(name) int (*f##name)(void *, int, double) = nullptr
2327#define DECL_MPOR2(name) int (*f##name)(void *, int, int, double) = nullptr
2328 DECL_MPOR1(MPOApplyBitFlipNoise); DECL_MPOR1(MPOApplyPhaseFlipNoise);
2329 DECL_MPOR1(MPOApplyDepolarizingNoise); DECL_MPOR1(MPOApplyAmplitudeDamping);
2330 DECL_MPOR1(MPOApplyPhaseDamping); DECL_MPO1(MPOApplyNonSelectiveMeasurement);
2331 DECL_MPO1(MPOApplyX); DECL_MPO1(MPOApplyY); DECL_MPO1(MPOApplyZ);
2332 DECL_MPO1(MPOApplyH); DECL_MPO1(MPOApplyS); DECL_MPO1(MPOApplySDG);
2333 DECL_MPO1(MPOApplyT); DECL_MPO1(MPOApplyTDG); DECL_MPO1(MPOApplySX);
2334 DECL_MPO1(MPOApplySXDG); DECL_MPO1(MPOApplyK);
2335 DECL_MPOR1(MPOApplyP); DECL_MPOR1(MPOApplyRx); DECL_MPOR1(MPOApplyRy);
2336 DECL_MPOR1(MPOApplyRz);
2337 int (*fMPOApplyU)(void *, int, double, double, double, double) = nullptr;
2338 int (*fMPOApplyOneQubitMatrix)(void *, int, const double *) = nullptr;
2339 int (*fMPOApplyTwoQubitMatrix)(void *, int, int, const double *) = nullptr;
2340 DECL_MPO2(MPOApplyCX); DECL_MPO2(MPOApplyCY); DECL_MPO2(MPOApplyCZ);
2341 DECL_MPO2(MPOApplyCH); DECL_MPO2(MPOApplyCSX); DECL_MPO2(MPOApplyCSXDG);
2342 DECL_MPOR2(MPOApplyCP); DECL_MPOR2(MPOApplyCRx); DECL_MPOR2(MPOApplyCRy);
2343 DECL_MPOR2(MPOApplyCRz);
2344 DECL_MPO2(MPOApplySwap);
2345 int (*fMPOApplyCU)(void *, int, int, double, double, double,
2346 double) = nullptr;
2347#undef DECL_MPOR2
2348#undef DECL_MPOR1
2349#undef DECL_MPO2
2350#undef DECL_MPO1
2351
2352 public:
2353 // mps functions
2354
2355 void *CreateMPS() {
2356 if (LibraryHandle)
2357 return fCreateMPS(LibraryHandle);
2358 else
2359 throw std::runtime_error("GpuLibrary: Unable to create mps");
2360 }
2361
2362 void DestroyMPS(void *obj) {
2363 if (LibraryHandle)
2364 fDestroyMPS(obj);
2365 else
2366 throw std::runtime_error("GpuLibrary: Unable to destroy mps");
2367 }
2368
2369 bool MPSCreate(void *obj, unsigned int nrQubits) {
2370 if (LibraryHandle)
2371 return fMPSCreate(obj, nrQubits) == 1;
2372 else
2373 throw std::runtime_error(
2374 "GpuLibrary: Unable to create mps with the "
2375 "specified number of qubits");
2376
2377 return false;
2378 }
2379
2380 bool MPSCreateWithBasisState(void *obj, unsigned int nrQubits,
2381 unsigned long long state) {
2382 if (LibraryHandle)
2383 return fMPSCreateWithBasisState(obj, nrQubits, state) == 1;
2384 else
2385 throw std::runtime_error(
2386 "GpuLibrary: Unable to create mps with a basis state");
2387
2388 return false;
2389 }
2390
2391 bool MPSCreateWithBasisStateBits(void *obj, unsigned int nrQubits,
2392 const unsigned char *stateBits) {
2393 if (LibraryHandle)
2394 return fMPSCreateWithBasisStateBits(obj, nrQubits, stateBits) == 1;
2395 else
2396 throw std::runtime_error(
2397 "GpuLibrary: Unable to create mps with a basis state (bits)");
2398
2399 return false;
2400 }
2401
2402 bool MPSReset(void *obj) {
2403 if (LibraryHandle)
2404 return fMPSReset(obj) == 1;
2405 else
2406 throw std::runtime_error("GpuLibrary: Unable to reset mps");
2407
2408 return false;
2409 }
2410
2411 bool MPSSetInitialQubitsMap(void *obj,
2412 const std::vector<long long int> &initialMap) {
2413 if (LibraryHandle)
2414 return fMPSSetInitialQubitsMap(obj, initialMap.data(),
2415 initialMap.size()) == 1;
2416 else
2417 throw std::runtime_error(
2418 "GpuLibrary: Unable to set initial qubits map for mps");
2419
2420 return false;
2421 }
2422
2423 bool MPSSetUseOptimalMeetingPosition(void *obj, int val) {
2424 if (LibraryHandle)
2425 return fMPSSetUseOptimalMeetingPosition(obj, val) == 1;
2426 else
2427 throw std::runtime_error(
2428 "GpuLibrary: Unable to set use optimal meeting position for mps");
2429 return false;
2430 }
2431
2432 bool MPSGetUseOptimalMeetingPosition(void *obj) const {
2433 if (LibraryHandle)
2434 return fMPSGetUseOptimalMeetingPosition(obj) == 1;
2435 else
2436 throw std::runtime_error(
2437 "GpuLibrary: Unable to get use optimal meeting position for mps");
2438 return false;
2439 }
2440
2441 bool MPSIsValid(void *obj) const {
2442 if (LibraryHandle)
2443 return fMPSIsValid(obj) == 1;
2444 else
2445 throw std::runtime_error("GpuLibrary: Unable to check if mps is valid");
2446
2447 return false;
2448 }
2449
2450 bool MPSIsCreated(void *obj) const {
2451 if (LibraryHandle)
2452 return fMPSIsCreated(obj) == 1;
2453 else
2454 throw std::runtime_error("GpuLibrary: Unable to check if mps is created");
2455
2456 return false;
2457 }
2458
2459 bool MPSSetDataType(void *obj, int useDoublePrecision) {
2460 if (LibraryHandle)
2461 return fMPSSetDataType(obj, useDoublePrecision) == 1;
2462 else
2463 throw std::runtime_error("GpuLibrary: Unable to set precision for mps");
2464
2465 return false;
2466 }
2467
2468 bool MPSIsDoublePrecision(void *obj) const {
2469 if (LibraryHandle)
2470 return fMPSIsDoublePrecision(obj) == 1;
2471 else
2472 throw std::runtime_error("GpuLibrary: Unable to get precision for mps");
2473
2474 return false;
2475 }
2476
2477 bool MPSSetCutoff(void *obj, double val) {
2478 if (LibraryHandle)
2479 return fMPSSetCutoff(obj, val) == 1;
2480 else
2481 throw std::runtime_error("GpuLibrary: Unable to set cutoff for mps");
2482
2483 return false;
2484 }
2485
2486 double MPSGetCutoff(void *obj) const {
2487 if (LibraryHandle)
2488 return fMPSGetCutoff(obj);
2489 else
2490 throw std::runtime_error("GpuLibrary: Unable to get cutoff for mps");
2491 }
2492
2493 bool MPSSetTruncationMode(void *obj, int mode) {
2494 if (LibraryHandle)
2495 return fMPSSetTruncationMode(obj, mode) == 1;
2496 else
2497 throw std::runtime_error(
2498 "GpuLibrary: Unable to set truncation mode for mps");
2499
2500 return false;
2501 }
2502
2503 int MPSGetTruncationMode(void *obj) const {
2504 if (LibraryHandle)
2505 return fMPSGetTruncationMode(obj);
2506 else
2507 throw std::runtime_error(
2508 "GpuLibrary: Unable to get truncation mode for mps");
2509 }
2510
2511 bool MPSSetGesvdJ(void *obj, int val) {
2512 if (LibraryHandle && obj && fMPSSetGesvdJ)
2513 return fMPSSetGesvdJ(obj, val) == 1;
2514 else
2515 throw std::runtime_error("GpuLibrary: Unable to set GesvdJ for mps");
2516
2517 return false;
2518 }
2519
2520 bool MPSGetGesvdJ(void *obj) const {
2521 if (LibraryHandle && obj && fMPSGetGesvdJ)
2522 return fMPSGetGesvdJ(obj) == 1;
2523 else
2524 throw std::runtime_error("GpuLibrary: Unable to get GesvdJ for mps");
2525
2526 return false;
2527 }
2528
2529 bool MPSSetGesvdP(void *obj, int val) {
2530 return LibraryHandle && obj && fMPSSetGesvdP &&
2531 fMPSSetGesvdP(obj, val) == 1;
2532 }
2533
2534 bool MPSGetGesvdP(void *obj) const {
2535 if (!LibraryHandle || !obj || !fMPSGetGesvdP)
2536 throw std::runtime_error("GpuLibrary: MPSGetGesvdP is unavailable");
2537 return fMPSGetGesvdP(obj) == 1;
2538 }
2539
2540 bool MPSSetGesvdR(void *obj, int val) {
2541 return LibraryHandle && obj && fMPSSetGesvdR &&
2542 fMPSSetGesvdR(obj, val) == 1;
2543 }
2544
2545 bool MPSGetGesvdR(void *obj) const {
2546 if (!LibraryHandle || !obj || !fMPSGetGesvdR)
2547 throw std::runtime_error("GpuLibrary: MPSGetGesvdR is unavailable");
2548 return fMPSGetGesvdR(obj) == 1;
2549 }
2550
2551 // 0=GESVD, 1=GESVDJ, 2=GESVDP, 3=GESVDR; -1 before the first split.
2552 int MPSGetLastSvdAlgo(void *obj) const {
2553 if (!LibraryHandle || !obj || !fMPSGetLastSvdAlgo)
2554 throw std::runtime_error("GpuLibrary: MPSGetLastSvdAlgo is unavailable");
2555 return fMPSGetLastSvdAlgo(obj);
2556 }
2557
2558 bool MPSSetMaxExtent(void *obj, long int val) {
2559 if (LibraryHandle)
2560 return fMPSSetMaxExtent(obj, val) == 1;
2561 else
2562 throw std::runtime_error("GpuLibrary: Unable to set max extent for mps");
2563
2564 return false;
2565 }
2566
2567 long int MPSGetMaxExtent(void *obj) {
2568 if (LibraryHandle)
2569 return fMPSGetMaxExtent(obj);
2570 else
2571 throw std::runtime_error("GpuLibrary: Unable to get max extent for mps");
2572
2573 return 0;
2574 }
2575
2576 int MPSGetNrQubits(void *obj) {
2577 if (LibraryHandle)
2578 return fMPSGetNrQubits(obj);
2579 else
2580 throw std::runtime_error("GpuLibrary: Unable to get nr qubits for mps");
2581
2582 return 0;
2583 }
2584
2585 bool MPSGetBondDimensions(void *obj, long long int *bondDims) {
2586 if (LibraryHandle)
2587 return fMPSGetBondDimensions(obj, bondDims) == 1;
2588 else
2589 throw std::runtime_error(
2590 "GpuLibrary: Unable to get bond dimensions for mps");
2591
2592 return false;
2593 }
2594
2595 bool MPSSetCallbackContext(void *obj, void *context) {
2596 if (LibraryHandle)
2597 return fMPSSetCallbackContext(obj, context) == 1;
2598 else
2599 throw std::runtime_error(
2600 "GpuLibrary: Unable to set callback context for mps");
2601 return false;
2602 }
2603
2604 bool MPSSetMeetingPositionCallback(void *obj, int64_t(*callback)(void*, const int64_t*)) {
2605 if (LibraryHandle)
2606 return fMPSSetMeetingPositionCallback(obj, callback) == 1;
2607 else
2608 throw std::runtime_error(
2609 "GpuLibrary: Unable to set meeting position callback for mps");
2610 return false;
2611 }
2612
2613 bool MPSSetBondDimensionsCallback(void* obj, void (*callback)(void*, const int64_t*)) {
2614 if (LibraryHandle)
2615 return fMPSSetBondDimensionsCallback(obj, callback) == 1;
2616 else
2617 throw std::runtime_error(
2618 "GpuLibrary: Unable to set bond dimensions callback for mps");
2619 return false;
2620 }
2621
2622 bool MPSAmplitude(void *obj, long int numFixedValues, long int *fixedValues,
2623 double *real, double *imaginary) {
2624 if (LibraryHandle)
2625 return fMPSAmplitude(obj, numFixedValues, fixedValues, real, imaginary) ==
2626 1;
2627 else
2628 throw std::runtime_error("GpuLibrary: Unable to get mps amplitude");
2629
2630 return false;
2631 }
2632
2633 double MPSProbability0(void *obj, unsigned int qubit) {
2634 if (LibraryHandle)
2635 return fMPSProbability0(obj, qubit);
2636 else
2637 throw std::runtime_error(
2638 "GpuLibrary: Unable to get probability for 0 for mps");
2639
2640 return 0.0;
2641 }
2642
2643 bool MPSMeasure(void *obj, unsigned int qubit) {
2644 if (LibraryHandle)
2645 return fMPSMeasure(obj, qubit) == 1;
2646 else
2647 throw std::runtime_error("GpuLibrary: Unable to measure qubit on mps");
2648
2649 return false;
2650 }
2651
2652 bool MPSMeasureQubits(void *obj, long int numQubits, unsigned int *qubits,
2653 int *result) {
2654 if (LibraryHandle)
2655 return fMPSMeasureQubits(obj, numQubits, qubits, result) == 1;
2656 else
2657 throw std::runtime_error("GpuLibrary: Unable to measure qubits on mps");
2658
2659 return false;
2660 }
2661
2662 std::unordered_map<std::vector<bool>, int64_t> *MPSGetMapForSample() {
2663 if (LibraryHandle)
2664 return (std::unordered_map<std::vector<bool>, int64_t> *)
2665 fMPSGetMapForSample();
2666 else
2667 throw std::runtime_error(
2668 "GpuLibrary: Unable to get map for sample for mps");
2669
2670 return nullptr;
2671 }
2672
2673 bool MPSFreeMapForSample(
2674 std::unordered_map<std::vector<bool>, int64_t> *map) {
2675 if (LibraryHandle)
2676 return fMPSFreeMapForSample((void *)map) == 1;
2677 else
2678 throw std::runtime_error(
2679 "GpuLibrary: Unable to free map for sample for mps");
2680
2681 return false;
2682 }
2683
2684 bool MPSSample(void *obj, long int numShots, long int numQubits,
2685 unsigned int *qubits, void *resultMap) {
2686 if (LibraryHandle)
2687 return fMPSSample(obj, numShots, numQubits, qubits, resultMap) == 1;
2688 else
2689 throw std::runtime_error("GpuLibrary: Unable to sample mps");
2690
2691 return false;
2692 }
2693
2694 bool MPSSampleRaw(void *obj, unsigned int nSamples, long int *samples,
2695 unsigned int nBits, const unsigned int *bitOrdering) {
2696 if (LibraryHandle)
2697 return fMPSSampleRaw(obj, nSamples, samples, nBits, bitOrdering) == 1;
2698 else
2699 throw std::runtime_error("GpuLibrary: Unable to raw-sample mps");
2700
2701 return false;
2702 }
2703
2704 bool MPSSampleAll(void *obj, unsigned int nSamples, long int *samples) {
2705 if (LibraryHandle)
2706 return fMPSSampleAll(obj, nSamples, samples) == 1;
2707 else
2708 throw std::runtime_error("GpuLibrary: Unable to sample all for mps");
2709
2710 return false;
2711 }
2712
2713 bool MPSSaveState(void *obj) {
2714 if (LibraryHandle)
2715 return fMPSSaveState(obj) == 1;
2716 else
2717 throw std::runtime_error("GpuLibrary: Unable to save mps state");
2718
2719 return false;
2720 }
2721
2722 bool MPSRestoreState(void *obj) {
2723 if (LibraryHandle)
2724 return fMPSRestoreState(obj) == 1;
2725 else
2726 throw std::runtime_error("GpuLibrary: Unable to restore mps state");
2727
2728 return false;
2729 }
2730
2731 bool MPSCleanSavedState(void *obj) {
2732 if (LibraryHandle)
2733 return fMPSCleanSavedState(obj) == 1;
2734 else
2735 throw std::runtime_error("GpuLibrary: Unable to clean mps saved state");
2736
2737 return false;
2738 }
2739
2740 void *MPSClone(void *obj) {
2741 if (LibraryHandle)
2742 return fMPSClone(obj);
2743 else
2744 throw std::runtime_error("GpuLibrary: Unable to clone mps");
2745
2746 return nullptr;
2747 }
2748
2749 bool MPSSetSeed(void *obj, unsigned long long seed) const {
2750 return obj && fMPSSetSeed && fMPSSetSeed(obj, seed) == 1;
2751 }
2752
2753 double MPSExpectationValue(void *obj, const char *pauliString,
2754 int len) const {
2755 if (LibraryHandle)
2756 return fMPSExpectationValue(obj, pauliString, len);
2757 else
2758 throw std::runtime_error(
2759 "GpuLibrary: Unable to get mps expectation value");
2760
2761 return 0;
2762 }
2763
2764 std::complex<double> MPSProjectOnZero(void* obj)
2765 {
2766 if (LibraryHandle) {
2767 double real, imag;
2768 if (fMPSProjectOnZero(obj, &real, &imag) == 1)
2769 return std::complex<double>(real, imag);
2770 else
2771 throw std::runtime_error(
2772 "GpuLibrary: Unable to project on zero for mps");
2773 } else
2774 throw std::runtime_error(
2775 "GpuLibrary: Unable to project on zero for mps, library handle is null");
2776
2777 return std::complex<double>(0, 0);
2778 }
2779
2780 bool MPSApplyX(void *obj, unsigned int siteA) {
2781 if (LibraryHandle)
2782 return fMPSApplyX(obj, siteA) == 1;
2783 else
2784 throw std::runtime_error("GpuLibrary: Unable to apply X gate on mps");
2785
2786 return false;
2787 }
2788
2789 bool MPSApplyY(void *obj, unsigned int siteA) {
2790 if (LibraryHandle)
2791 return fMPSApplyY(obj, siteA) == 1;
2792 else
2793 throw std::runtime_error("GpuLibrary: Unable to apply Y gate on mps");
2794
2795 return false;
2796 }
2797
2798 bool MPSApplyZ(void *obj, unsigned int siteA) {
2799 if (LibraryHandle)
2800 return fMPSApplyZ(obj, siteA) == 1;
2801 else
2802 throw std::runtime_error("GpuLibrary: Unable to apply Z gate on mps");
2803
2804 return false;
2805 }
2806
2807 bool MPSApplyH(void *obj, unsigned int siteA) {
2808 if (LibraryHandle)
2809 return fMPSApplyH(obj, siteA) == 1;
2810 else
2811 throw std::runtime_error("GpuLibrary: Unable to apply H gate on mps");
2812
2813 return false;
2814 }
2815
2816 bool MPSApplyS(void *obj, unsigned int siteA) {
2817 if (LibraryHandle)
2818 return fMPSApplyS(obj, siteA) == 1;
2819 else
2820 throw std::runtime_error("GpuLibrary: Unable to apply S gate on mps");
2821
2822 return false;
2823 }
2824
2825 bool MPSApplySDG(void *obj, unsigned int siteA) {
2826 if (LibraryHandle)
2827 return fMPSApplySDG(obj, siteA) == 1;
2828 else
2829 throw std::runtime_error("GpuLibrary: Unable to apply sdg gate on mps");
2830
2831 return false;
2832 }
2833
2834 bool MPSApplyT(void *obj, unsigned int siteA) {
2835 if (LibraryHandle)
2836 return fMPSApplyT(obj, siteA) == 1;
2837 else
2838 throw std::runtime_error("GpuLibrary: Unable to apply t gate on mps");
2839
2840 return false;
2841 }
2842
2843 bool MPSApplyTDG(void *obj, unsigned int siteA) {
2844 if (LibraryHandle)
2845 return fMPSApplyTDG(obj, siteA) == 1;
2846 else
2847 throw std::runtime_error("GpuLibrary: Unable to appl tdg gate on mps");
2848
2849 return false;
2850 }
2851
2852 bool MPSApplySX(void *obj, unsigned int siteA) {
2853 if (LibraryHandle)
2854 return fMPSApplySX(obj, siteA) == 1;
2855 else
2856 throw std::runtime_error("GpuLibrary: Unable to apply sx gate on mps");
2857
2858 return false;
2859 }
2860
2861 bool MPSApplySXDG(void *obj, unsigned int siteA) {
2862 if (LibraryHandle)
2863 return fMPSApplySXDG(obj, siteA) == 1;
2864 else
2865 throw std::runtime_error("GpuLibrary: Unable to apply sxdg gate on mps");
2866
2867 return false;
2868 }
2869
2870 bool MPSApplyK(void *obj, unsigned int siteA) {
2871 if (LibraryHandle)
2872 return fMPSApplyK(obj, siteA) == 1;
2873 else
2874 throw std::runtime_error("GpuLibrary: Unable to apply k gate on mps");
2875
2876 return false;
2877 }
2878
2879 bool MPSApplyP(void *obj, unsigned int siteA, double theta) {
2880 if (LibraryHandle)
2881 return fMPSApplyP(obj, siteA, theta) == 1;
2882 else
2883 throw std::runtime_error("GpuLibrary: Unable to apply p gate on mps");
2884 return false;
2885 }
2886
2887 bool MPSApplyRx(void *obj, unsigned int siteA, double theta) {
2888 if (LibraryHandle)
2889 return fMPSApplyRx(obj, siteA, theta) == 1;
2890 else
2891 throw std::runtime_error("GpuLibrary: Unable to apply rx gate on mps");
2892
2893 return false;
2894 }
2895
2896 bool MPSApplyRy(void *obj, unsigned int siteA, double theta) {
2897 if (LibraryHandle)
2898 return fMPSApplyRy(obj, siteA, theta) == 1;
2899 else
2900 throw std::runtime_error("GpuLibrary: Unable to apply ry gate on mps");
2901
2902 return false;
2903 }
2904
2905 bool MPSApplyRz(void *obj, unsigned int siteA, double theta) {
2906 if (LibraryHandle)
2907 return fMPSApplyRz(obj, siteA, theta) == 1;
2908 else
2909 throw std::runtime_error("GpuLibrary: Unable to apply rz gate on mps");
2910
2911 return false;
2912 }
2913
2914 bool MPSApplyU(void *obj, unsigned int siteA, double theta, double phi,
2915 double lambda, double gamma) {
2916 if (LibraryHandle)
2917 return fMPSApplyU(obj, siteA, theta, phi, lambda, gamma) == 1;
2918 else
2919 throw std::runtime_error("GpuLibrary: Unable to apply u gate on mps");
2920
2921 return false;
2922 }
2923
2924 bool MPSApplyOneQubitMatrix(void *obj, unsigned int qubit,
2925 const double *matrixInterleaved) {
2926 if (LibraryHandle)
2927 return fMPSApplyOneQubitMatrix(obj, qubit, matrixInterleaved) == 1;
2928 else
2929 throw std::runtime_error(
2930 "GpuLibrary: Unable to apply one-qubit matrix on mps");
2931
2932 return false;
2933 }
2934
2935 bool MPSApplyTwoQubitMatrix(void *obj, unsigned int qubit1,
2936 unsigned int qubit2,
2937 const double *matrixInterleaved) {
2938 if (LibraryHandle)
2939 return fMPSApplyTwoQubitMatrix(obj, qubit1, qubit2,
2940 matrixInterleaved) == 1;
2941 else
2942 throw std::runtime_error(
2943 "GpuLibrary: Unable to apply two-qubit matrix on mps");
2944
2945 return false;
2946 }
2947
2948 bool MPSApplySwap(void *obj, unsigned int controlQubit,
2949 unsigned int targetQubit) {
2950 if (LibraryHandle)
2951 return fMPSApplySwap(obj, controlQubit, targetQubit) == 1;
2952 else
2953 throw std::runtime_error("GpuLibrary: Unable to apply swap gate on mps");
2954
2955 return false;
2956 }
2957
2958 bool MPSApplyCX(void *obj, unsigned int controlQubit,
2959 unsigned int targetQubit) {
2960 if (LibraryHandle)
2961 return fMPSApplyCX(obj, controlQubit, targetQubit) == 1;
2962 else
2963 throw std::runtime_error("GpuLibrary: Unable to apply cx gate on mps");
2964
2965 return false;
2966 }
2967
2968 bool MPSApplyCY(void *obj, unsigned int controlQubit,
2969 unsigned int targetQubit) {
2970 if (LibraryHandle)
2971 return fMPSApplyCY(obj, controlQubit, targetQubit) == 1;
2972 else
2973 throw std::runtime_error("GpuLibrary: Unable to apply cy gate on mps");
2974
2975 return false;
2976 }
2977
2978 bool MPSApplyCZ(void *obj, unsigned int controlQubit,
2979 unsigned int targetQubit) {
2980 if (LibraryHandle)
2981 return fMPSApplyCZ(obj, controlQubit, targetQubit) == 1;
2982 else
2983 throw std::runtime_error("GpuLibrary: Unable to apply cz gate on mps");
2984
2985 return false;
2986 }
2987
2988 bool MPSApplyCH(void *obj, unsigned int controlQubit,
2989 unsigned int targetQubit) {
2990 if (LibraryHandle)
2991 return fMPSApplyCH(obj, controlQubit, targetQubit) == 1;
2992 else
2993 throw std::runtime_error("GpuLibrary: Unable to apply ch gate on mps");
2994
2995 return false;
2996 }
2997
2998 bool MPSApplyCSX(void *obj, unsigned int controlQubit,
2999 unsigned int targetQubit) {
3000 if (LibraryHandle)
3001 return fMPSApplyCSX(obj, controlQubit, targetQubit) == 1;
3002 else
3003 throw std::runtime_error("GpuLibrary: Unable to apply csx gate on mps");
3004 }
3005
3006 bool MPSApplyCSXDG(void *obj, unsigned int controlQubit,
3007 unsigned int targetQubit) {
3008 if (LibraryHandle)
3009 return fMPSApplyCSXDG(obj, controlQubit, targetQubit) == 1;
3010 else
3011 throw std::runtime_error("GpuLibrary: Unable to apply csxdg gate on mps");
3012
3013 return false;
3014 }
3015
3016 bool MPSApplyCP(void *obj, unsigned int controlQubit,
3017 unsigned int targetQubit, double theta) {
3018 if (LibraryHandle)
3019 return fMPSApplyCP(obj, controlQubit, targetQubit, theta) == 1;
3020 else
3021 throw std::runtime_error("GpuLibrary: Unable to apply cp gate on mps");
3022
3023 return false;
3024 }
3025
3026 bool MPSApplyCRx(void *obj, unsigned int controlQubit,
3027 unsigned int targetQubit, double theta) {
3028 if (LibraryHandle)
3029 return fMPSApplyCRx(obj, controlQubit, targetQubit, theta) == 1;
3030 else
3031 throw std::runtime_error("GpuLibrary: Unable to apply crx gate on mps");
3032
3033 return false;
3034 }
3035
3036 bool MPSApplyCRy(void *obj, unsigned int controlQubit,
3037 unsigned int targetQubit, double theta) {
3038 if (LibraryHandle)
3039 return fMPSApplyCRy(obj, controlQubit, targetQubit, theta) == 1;
3040 else
3041 throw std::runtime_error("GpuLibrary: Unable to apply cry gate on mps");
3042
3043 return false;
3044 }
3045
3046 bool MPSApplyCRz(void *obj, unsigned int controlQubit,
3047 unsigned int targetQubit, double theta) {
3048 if (LibraryHandle)
3049 return fMPSApplyCRz(obj, controlQubit, targetQubit, theta) == 1;
3050 else
3051 throw std::runtime_error("GpuLibrary: Unable to apply crz gate on mps");
3052
3053 return false;
3054 }
3055
3056 bool MPSApplyCU(void *obj, unsigned int controlQubit,
3057 unsigned int targetQubit, double theta, double phi,
3058 double lambda, double gamma) {
3059 if (LibraryHandle)
3060 return fMPSApplyCU(obj, controlQubit, targetQubit, theta, phi, lambda,
3061 gamma) == 1;
3062 else
3063 throw std::runtime_error("GpuLibrary: Unable to apply cu gate on mps");
3064
3065 return false;
3066 }
3067
3068 // tensor network functions
3069
3070 void *CreateTensorNet() {
3071 if (LibraryHandle)
3072 return fCreateTensorNet(LibraryHandle);
3073 else
3074 throw std::runtime_error("GpuLibrary: Unable to create tensor network");
3075 }
3076
3077 void DestroyTensorNet(void *obj) {
3078 if (LibraryHandle)
3079 fDestroyTensorNet(obj);
3080 else
3081 throw std::runtime_error("GpuLibrary: Unable to destroy tensor network");
3082 }
3083
3084 bool TNCreate(void *obj, unsigned int nrQubits) {
3085 if (LibraryHandle)
3086 return fTNCreate(obj, nrQubits) == 1;
3087 else
3088 throw std::runtime_error(
3089 "GpuLibrary: Unable to create tensor network with the "
3090 "specified number of qubits");
3091
3092 return false;
3093 }
3094
3095 bool TNReset(void *obj) {
3096 if (LibraryHandle)
3097 return fTNReset(obj) == 1;
3098 else
3099 throw std::runtime_error("GpuLibrary: Unable to reset tensor network");
3100
3101 return false;
3102 }
3103
3104 bool TNIsValid(void *obj) const {
3105 if (LibraryHandle)
3106 return fTNIsValid(obj) == 1;
3107 else
3108 throw std::runtime_error(
3109 "GpuLibrary: Unable to check if tensor network is valid");
3110
3111 return false;
3112 }
3113
3114 bool TNIsCreated(void *obj) const {
3115 if (LibraryHandle)
3116 return fTNIsCreated(obj) == 1;
3117 else
3118 throw std::runtime_error(
3119 "GpuLibrary: Unable to check if tensor network is created");
3120
3121 return false;
3122 }
3123
3124 bool TNSetDataType(void *obj, int useDoublePrecision) {
3125 if (LibraryHandle)
3126 return fTNSetDataType(obj, useDoublePrecision) == 1;
3127 else
3128 throw std::runtime_error(
3129 "GpuLibrary: Unable to set precision for tensor network");
3130
3131 return false;
3132 }
3133
3134 bool TNIsDoublePrecision(void *obj) const {
3135 if (LibraryHandle)
3136 return fTNIsDoublePrecision(obj) == 1;
3137 else
3138 throw std::runtime_error(
3139 "GpuLibrary: Unable to get precision for tensor network");
3140
3141 return false;
3142 }
3143
3144 bool TNSetCutoff(void *obj, double val) {
3145 if (LibraryHandle)
3146 return fTNSetCutoff(obj, val) == 1;
3147 else
3148 throw std::runtime_error(
3149 "GpuLibrary: Unable to set cutoff for tensor network");
3150
3151 return false;
3152 }
3153
3154 double TNGetCutoff(void *obj) const {
3155 if (LibraryHandle)
3156 return fTNGetCutoff(obj);
3157 else
3158 throw std::runtime_error(
3159 "GpuLibrary: Unable to get cutoff for tensor network");
3160 }
3161
3162 bool TNSetTruncationMode(void *obj, int mode) {
3163 if (LibraryHandle)
3164 return fTNSetTruncationMode(obj, mode) == 1;
3165 else
3166 throw std::runtime_error(
3167 "GpuLibrary: Unable to set truncation mode for tensor network");
3168
3169 return false;
3170 }
3171
3172 int TNGetTruncationMode(void *obj) const {
3173 if (LibraryHandle)
3174 return fTNGetTruncationMode(obj);
3175 else
3176 throw std::runtime_error(
3177 "GpuLibrary: Unable to get truncation mode for tensor network");
3178 }
3179
3180 bool TNSetGesvdJ(void *obj, int val) {
3181 if (LibraryHandle && obj && fTNSetGesvdJ)
3182 return fTNSetGesvdJ(obj, val) == 1;
3183 else
3184 throw std::runtime_error(
3185 "GpuLibrary: Unable to set GesvdJ for tensor network");
3186
3187 return false;
3188 }
3189
3190 bool TNGetGesvdJ(void *obj) const {
3191 if (LibraryHandle && obj && fTNGetGesvdJ)
3192 return fTNGetGesvdJ(obj) == 1;
3193 else
3194 throw std::runtime_error(
3195 "GpuLibrary: Unable to get GesvdJ for tensor network");
3196
3197 return false;
3198 }
3199
3200 bool TNSetGesvdP(void *obj, int val) {
3201 return LibraryHandle && obj && fTNSetGesvdP &&
3202 fTNSetGesvdP(obj, val) == 1;
3203 }
3204
3205 bool TNGetGesvdP(void *obj) const {
3206 if (!LibraryHandle || !obj || !fTNGetGesvdP)
3207 throw std::runtime_error("GpuLibrary: TNGetGesvdP is unavailable");
3208 return fTNGetGesvdP(obj) == 1;
3209 }
3210
3211 bool TNSetGesvdR(void *obj, int val) {
3212 return LibraryHandle && obj && fTNSetGesvdR &&
3213 fTNSetGesvdR(obj, val) == 1;
3214 }
3215
3216 bool TNGetGesvdR(void *obj) const {
3217 if (!LibraryHandle || !obj || !fTNGetGesvdR)
3218 throw std::runtime_error("GpuLibrary: TNGetGesvdR is unavailable");
3219 return fTNGetGesvdR(obj) == 1;
3220 }
3221
3222 bool TNSetMaxExtent(void *obj, long int val) {
3223 if (LibraryHandle)
3224 return fTNSetMaxExtent(obj, val) == 1;
3225 else
3226 throw std::runtime_error(
3227 "GpuLibrary: Unable to set max extent for tensor network");
3228
3229 return false;
3230 }
3231
3232 long int TNGetMaxExtent(void *obj) {
3233 if (LibraryHandle)
3234 return fTNGetMaxExtent(obj);
3235 else
3236 throw std::runtime_error(
3237 "GpuLibrary: Unable to get max extent for tensor network");
3238
3239 return 0;
3240 }
3241
3242 int TNGetNrQubits(void *obj) {
3243 if (LibraryHandle)
3244 return fTNGetNrQubits(obj);
3245 else
3246 throw std::runtime_error(
3247 "GpuLibrary: Unable to get nr qubits for tensor network");
3248
3249 return 0;
3250 }
3251
3252 bool TNAmplitude(void *obj, long int numFixedValues, long int *fixedValues,
3253 double *real, double *imaginary) {
3254 if (LibraryHandle)
3255 return fTNAmplitude(obj, numFixedValues, fixedValues, real, imaginary) ==
3256 1;
3257 else
3258 throw std::runtime_error(
3259 "GpuLibrary: Unable to get tensor network amplitude");
3260
3261 return false;
3262 }
3263
3264 double TNProbability0(void *obj, unsigned int qubit) {
3265 if (LibraryHandle)
3266 return fTNProbability0(obj, qubit);
3267 else
3268 throw std::runtime_error(
3269 "GpuLibrary: Unable to get probability for 0 for tensor network");
3270
3271 return 0.0;
3272 }
3273
3274 bool TNMeasure(void *obj, unsigned int qubit) {
3275 if (LibraryHandle)
3276 return fTNMeasure(obj, qubit) == 1;
3277 else
3278 throw std::runtime_error(
3279 "GpuLibrary: Unable to measure qubit on tensor network");
3280
3281 return false;
3282 }
3283
3284 bool TNMeasureQubits(void *obj, long int numQubits, unsigned int *qubits,
3285 int *result) {
3286 if (LibraryHandle)
3287 return fTNMeasureQubits(obj, numQubits, qubits, result) == 1;
3288 else
3289 throw std::runtime_error(
3290 "GpuLibrary: Unable to measure qubits on tensor network");
3291
3292 return false;
3293 }
3294
3295 std::unordered_map<std::vector<bool>, int64_t> *TNGetMapForSample() {
3296 if (LibraryHandle)
3297 return (
3298 std::unordered_map<std::vector<bool>, int64_t> *)fTNGetMapForSample();
3299 else
3300 throw std::runtime_error(
3301 "GpuLibrary: Unable to get map for sample for tensor network");
3302
3303 return nullptr;
3304 }
3305
3306 bool TNFreeMapForSample(std::unordered_map<std::vector<bool>, int64_t> *map) {
3307 if (LibraryHandle)
3308 return fTNFreeMapForSample((void *)map) == 1;
3309 else
3310 throw std::runtime_error(
3311 "GpuLibrary: Unable to free map for sample for tensor network");
3312
3313 return false;
3314 }
3315
3316 bool TNSample(void *obj, long int numShots, long int numQubits,
3317 unsigned int *qubits, void *resultMap) {
3318 if (LibraryHandle)
3319 return fTNSample(obj, numShots, numQubits, qubits, resultMap) == 1;
3320 else
3321 throw std::runtime_error("GpuLibrary: Unable to sample tensor network");
3322
3323 return false;
3324 }
3325
3326 bool TNSaveState(void *obj) {
3327 if (LibraryHandle)
3328 return fTNSaveState(obj) == 1;
3329 else
3330 throw std::runtime_error(
3331 "GpuLibrary: Unable to save tensor network state");
3332
3333 return false;
3334 }
3335
3336 bool TNRestoreState(void *obj) {
3337 if (LibraryHandle)
3338 return fTNRestoreState(obj) == 1;
3339 else
3340 throw std::runtime_error(
3341 "GpuLibrary: Unable to restore tensor network state");
3342
3343 return false;
3344 }
3345
3346 bool TNCleanSavedState(void *obj) {
3347 if (LibraryHandle)
3348 return fTNCleanSavedState(obj) == 1;
3349 else
3350 throw std::runtime_error(
3351 "GpuLibrary: Unable to clean tensor network saved state");
3352
3353 return false;
3354 }
3355
3356 void *TNClone(void *obj) {
3357 if (LibraryHandle)
3358 return fTNClone(obj);
3359 else
3360 throw std::runtime_error("GpuLibrary: Unable to clone tensor network");
3361
3362 return nullptr;
3363 }
3364
3365 bool TNSetSeed(void *obj, unsigned long long seed) const {
3366 return obj && fTNSetSeed && fTNSetSeed(obj, seed) == 1;
3367 }
3368
3369 double TNExpectationValue(void *obj, const char *pauliString, int len) const {
3370 if (LibraryHandle)
3371 return fTNExpectationValue(obj, pauliString, len);
3372 else
3373 throw std::runtime_error(
3374 "GpuLibrary: Unable to get tensor network expectation value");
3375
3376 return 0;
3377 }
3378
3379 bool TNApplyX(void *obj, unsigned int siteA) {
3380 if (LibraryHandle)
3381 return fTNApplyX(obj, siteA) == 1;
3382 else
3383 throw std::runtime_error(
3384 "GpuLibrary: Unable to apply X gate on tensor network");
3385
3386 return false;
3387 }
3388
3389 bool TNApplyY(void *obj, unsigned int siteA) {
3390 if (LibraryHandle)
3391 return fTNApplyY(obj, siteA) == 1;
3392 else
3393 throw std::runtime_error(
3394 "GpuLibrary: Unable to apply Y gate on tensor network");
3395
3396 return false;
3397 }
3398
3399 bool TNApplyZ(void *obj, unsigned int siteA) {
3400 if (LibraryHandle)
3401 return fTNApplyZ(obj, siteA) == 1;
3402 else
3403 throw std::runtime_error(
3404 "GpuLibrary: Unable to apply Z gate on tensor network");
3405
3406 return false;
3407 }
3408
3409 bool TNApplyH(void *obj, unsigned int siteA) {
3410 if (LibraryHandle)
3411 return fTNApplyH(obj, siteA) == 1;
3412 else
3413 throw std::runtime_error(
3414 "GpuLibrary: Unable to apply H gate on tensor network");
3415
3416 return false;
3417 }
3418
3419 bool TNApplyS(void *obj, unsigned int siteA) {
3420 if (LibraryHandle)
3421 return fTNApplyS(obj, siteA) == 1;
3422 else
3423 throw std::runtime_error(
3424 "GpuLibrary: Unable to apply S gate on tensor network");
3425
3426 return false;
3427 }
3428
3429 bool TNApplySDG(void *obj, unsigned int siteA) {
3430 if (LibraryHandle)
3431 return fTNApplySDG(obj, siteA) == 1;
3432 else
3433 throw std::runtime_error(
3434 "GpuLibrary: Unable to apply sdg gate on tensor network");
3435
3436 return false;
3437 }
3438
3439 bool TNApplyT(void *obj, unsigned int siteA) {
3440 if (LibraryHandle)
3441 return fTNApplyT(obj, siteA) == 1;
3442 else
3443 throw std::runtime_error(
3444 "GpuLibrary: Unable to apply t gate on tensor network");
3445
3446 return false;
3447 }
3448
3449 bool TNApplyTDG(void *obj, unsigned int siteA) {
3450 if (LibraryHandle)
3451 return fTNApplyTDG(obj, siteA) == 1;
3452 else
3453 throw std::runtime_error(
3454 "GpuLibrary: Unable to apply tdg gate on tensor network");
3455
3456 return false;
3457 }
3458
3459 bool TNApplySX(void *obj, unsigned int siteA) {
3460 if (LibraryHandle)
3461 return fTNApplySX(obj, siteA) == 1;
3462 else
3463 throw std::runtime_error(
3464 "GpuLibrary: Unable to apply sx gate on tensor network");
3465
3466 return false;
3467 }
3468
3469 bool TNApplySXDG(void *obj, unsigned int siteA) {
3470 if (LibraryHandle)
3471 return fTNApplySXDG(obj, siteA) == 1;
3472 else
3473 throw std::runtime_error(
3474 "GpuLibrary: Unable to apply sxdg gate on tensor network");
3475
3476 return false;
3477 }
3478
3479 bool TNApplyK(void *obj, unsigned int siteA) {
3480 if (LibraryHandle)
3481 return fTNApplyK(obj, siteA) == 1;
3482 else
3483 throw std::runtime_error(
3484 "GpuLibrary: Unable to apply k gate on tensor network");
3485
3486 return false;
3487 }
3488
3489 bool TNApplyP(void *obj, unsigned int siteA, double theta) {
3490 if (LibraryHandle)
3491 return fTNApplyP(obj, siteA, theta) == 1;
3492 else
3493 throw std::runtime_error(
3494 "GpuLibrary: Unable to apply p gate on tensor network");
3495 return false;
3496 }
3497
3498 bool TNApplyRx(void *obj, unsigned int siteA, double theta) {
3499 if (LibraryHandle)
3500 return fTNApplyRx(obj, siteA, theta) == 1;
3501 else
3502 throw std::runtime_error(
3503 "GpuLibrary: Unable to apply rx gate on tensor network");
3504
3505 return false;
3506 }
3507
3508 bool TNApplyRy(void *obj, unsigned int siteA, double theta) {
3509 if (LibraryHandle)
3510 return fTNApplyRy(obj, siteA, theta) == 1;
3511 else
3512 throw std::runtime_error(
3513 "GpuLibrary: Unable to apply ry gate on tensor network");
3514
3515 return false;
3516 }
3517
3518 bool TNApplyRz(void *obj, unsigned int siteA, double theta) {
3519 if (LibraryHandle)
3520 return fTNApplyRz(obj, siteA, theta) == 1;
3521 else
3522 throw std::runtime_error(
3523 "GpuLibrary: Unable to apply rz gate on tensor network");
3524
3525 return false;
3526 }
3527
3528 bool TNApplyU(void *obj, unsigned int siteA, double theta, double phi,
3529 double lambda, double gamma) {
3530 if (LibraryHandle)
3531 return fTNApplyU(obj, siteA, theta, phi, lambda, gamma) == 1;
3532 else
3533 throw std::runtime_error(
3534 "GpuLibrary: Unable to apply u gate on tensor network");
3535
3536 return false;
3537 }
3538
3539 bool TNApplySwap(void *obj, unsigned int controlQubit,
3540 unsigned int targetQubit) {
3541 if (LibraryHandle)
3542 return fTNApplySwap(obj, controlQubit, targetQubit) == 1;
3543 else
3544 throw std::runtime_error(
3545 "GpuLibrary: Unable to apply swap gate on tensor network");
3546
3547 return false;
3548 }
3549
3550 bool TNApplyCX(void *obj, unsigned int controlQubit,
3551 unsigned int targetQubit) {
3552 if (LibraryHandle)
3553 return fTNApplyCX(obj, controlQubit, targetQubit) == 1;
3554 else
3555 throw std::runtime_error(
3556 "GpuLibrary: Unable to apply cx gate on tensor network");
3557
3558 return false;
3559 }
3560
3561 bool TNApplyCY(void *obj, unsigned int controlQubit,
3562 unsigned int targetQubit) {
3563 if (LibraryHandle)
3564 return fTNApplyCY(obj, controlQubit, targetQubit) == 1;
3565 else
3566 throw std::runtime_error(
3567 "GpuLibrary: Unable to apply cy gate on tensor network");
3568
3569 return false;
3570 }
3571
3572 bool TNApplyCZ(void *obj, unsigned int controlQubit,
3573 unsigned int targetQubit) {
3574 if (LibraryHandle)
3575 return fTNApplyCZ(obj, controlQubit, targetQubit) == 1;
3576 else
3577 throw std::runtime_error(
3578 "GpuLibrary: Unable to apply cz gate on tensor network");
3579
3580 return false;
3581 }
3582
3583 bool TNApplyCH(void *obj, unsigned int controlQubit,
3584 unsigned int targetQubit) {
3585 if (LibraryHandle)
3586 return fTNApplyCH(obj, controlQubit, targetQubit) == 1;
3587 else
3588 throw std::runtime_error(
3589 "GpuLibrary: Unable to apply ch gate on tensor network");
3590
3591 return false;
3592 }
3593
3594 bool TNApplyCSX(void *obj, unsigned int controlQubit,
3595 unsigned int targetQubit) {
3596 if (LibraryHandle)
3597 return fTNApplyCSX(obj, controlQubit, targetQubit) == 1;
3598 else
3599 throw std::runtime_error(
3600 "GpuLibrary: Unable to apply csx gate on tensor network");
3601 }
3602
3603 bool TNApplyCSXDG(void *obj, unsigned int controlQubit,
3604 unsigned int targetQubit) {
3605 if (LibraryHandle)
3606 return fTNApplyCSXDG(obj, controlQubit, targetQubit) == 1;
3607 else
3608 throw std::runtime_error(
3609 "GpuLibrary: Unable to apply csxdg gate on tensor network");
3610
3611 return false;
3612 }
3613
3614 bool TNApplyCP(void *obj, unsigned int controlQubit, unsigned int targetQubit,
3615 double theta) {
3616 if (LibraryHandle)
3617 return fTNApplyCP(obj, controlQubit, targetQubit, theta) == 1;
3618 else
3619 throw std::runtime_error(
3620 "GpuLibrary: Unable to apply cp gate on tensor network");
3621
3622 return false;
3623 }
3624
3625 bool TNApplyCRx(void *obj, unsigned int controlQubit,
3626 unsigned int targetQubit, double theta) {
3627 if (LibraryHandle)
3628 return fTNApplyCRx(obj, controlQubit, targetQubit, theta) == 1;
3629 else
3630 throw std::runtime_error(
3631 "GpuLibrary: Unable to apply crx gate on tensor network");
3632
3633 return false;
3634 }
3635
3636 bool TNApplyCRy(void *obj, unsigned int controlQubit,
3637 unsigned int targetQubit, double theta) {
3638 if (LibraryHandle)
3639 return fTNApplyCRy(obj, controlQubit, targetQubit, theta) == 1;
3640 else
3641 throw std::runtime_error(
3642 "GpuLibrary: Unable to apply cry gate on tensor network");
3643
3644 return false;
3645 }
3646
3647 bool TNApplyCRz(void *obj, unsigned int controlQubit,
3648 unsigned int targetQubit, double theta) {
3649 if (LibraryHandle)
3650 return fTNApplyCRz(obj, controlQubit, targetQubit, theta) == 1;
3651 else
3652 throw std::runtime_error(
3653 "GpuLibrary: Unable to apply crz gate on tensor network");
3654
3655 return false;
3656 }
3657
3658 bool TNApplyCU(void *obj, unsigned int controlQubit, unsigned int targetQubit,
3659 double theta, double phi, double lambda, double gamma) {
3660 if (LibraryHandle)
3661 return fTNApplyCU(obj, controlQubit, targetQubit, theta, phi, lambda,
3662 gamma) == 1;
3663 else
3664 throw std::runtime_error(
3665 "GpuLibrary: Unable to apply cu gate on tensor network");
3666
3667 return false;
3668 }
3669
3670 bool TNApplyCCX(void *obj, unsigned int controlQubit1,
3671 unsigned int controlQubit2, unsigned int targetQubit) {
3672 if (LibraryHandle)
3673 return fTNApplyCCX(obj, controlQubit1, controlQubit2, targetQubit) == 1;
3674 else
3675 throw std::runtime_error(
3676 "GpuLibrary: Unable to apply ccx gate on tensor network");
3677 return false;
3678 }
3679
3680 bool TNApplyCSwap(void *obj, unsigned int controlQubit,
3681 unsigned int targetQubit1, unsigned int targetQubit2) {
3682 if (LibraryHandle)
3683 return fTNApplyCSwap(obj, controlQubit, targetQubit1, targetQubit2) == 1;
3684 else
3685 throw std::runtime_error(
3686 "GpuLibrary: Unable to apply cswap gate on tensor network");
3687 return false;
3688 }
3689
3690 // stabilizer functions
3691 void *CreateStabilizerSimulator(long long int numQubits,
3692 long long int numShots,
3693 long long int numMeasurements,
3694 long long int numDetectors) {
3695 if (LibraryHandle)
3696 return fCreateStabilizerSimulator(numQubits, numShots, numMeasurements,
3697 numDetectors);
3698 else
3699 throw std::runtime_error(
3700 "GpuLibrary: Unable to create stabilizer simulator");
3701
3702 return nullptr;
3703 }
3704
3705 void DestroyStabilizerSimulator(void *obj) {
3706 if (!obj) return;
3707 if (LibraryHandle)
3708 fDestroyStabilizerSimulator(obj);
3709 else
3710 throw std::runtime_error(
3711 "GpuLibrary: Unable to destroy stabilizer simulator");
3712 }
3713
3714 bool ExecuteStabilizerCircuit(void *obj, const char *circuitStr,
3715 int randomizeMeasurements,
3716 unsigned long long int seed) {
3717 if (!obj) return false;
3718 if (LibraryHandle)
3719 return fExecuteStabilizerCircuit(obj, circuitStr, randomizeMeasurements,
3720 seed) == 1;
3721 else
3722 throw std::runtime_error(
3723 "GpuLibrary: Unable to execute stabilizer circuit");
3724
3725 return false;
3726 }
3727
3728 long long GetStabilizerXZTableSize(void *obj) {
3729 if (!obj) return 0;
3730 if (LibraryHandle)
3731 return fGetStabilizerXZTableSize(obj);
3732 else
3733 throw std::runtime_error(
3734 "GpuLibrary: Unable to get stabilizer XZ table size");
3735
3736 return 0;
3737 }
3738
3739 long long GetStabilizerMTableSize(void *obj) {
3740 if (!obj) return 0;
3741 if (LibraryHandle)
3742 return fGetStabilizerMTableSize(obj);
3743 else
3744 throw std::runtime_error(
3745 "GpuLibrary: Unable to get stabilizer M table size");
3746
3747 return 0;
3748 }
3749
3750 long long GetStabilizerTableStrideMajor(void *obj) {
3751 if (!obj) return 0;
3752 if (LibraryHandle)
3753 return fGetStabilizerTableStrideMajor(obj);
3754 else
3755 throw std::runtime_error(
3756 "GpuLibrary: Unable to get stabilizer table stride major");
3757 return 0;
3758 }
3759
3760 long long GetStabilizerNumQubits(void *obj) {
3761 if (!obj) return 0;
3762 if (LibraryHandle)
3763 return fGetStabilizerNumQubits(obj);
3764 else
3765 throw std::runtime_error(
3766 "GpuLibrary: Unable to get stabilizer number of qubits");
3767
3768 return 0;
3769 }
3770
3771 long long GetStabilizerNumShots(void *obj) {
3772 if (!obj) return 0;
3773 if (LibraryHandle)
3774 return fGetStabilizerNumShots(obj);
3775 else
3776 throw std::runtime_error(
3777 "GpuLibrary: Unable to get stabilizer number of shots");
3778
3779 return 0;
3780 }
3781
3782 long long GetStabilizerNumMeasurements(void *obj) {
3783 if (!obj) return 0;
3784 if (LibraryHandle)
3785 return fGetStabilizerNumMeasurements(obj);
3786 else
3787 throw std::runtime_error(
3788 "GpuLibrary: Unable to get stabilizer number of measurements");
3789
3790 return 0;
3791 }
3792
3793 long long GetStabilizerNumDetectors(void *obj) {
3794 if (!obj) return 0;
3795 if (LibraryHandle)
3796 return fGetStabilizerNumDetectors(obj);
3797 else
3798 throw std::runtime_error(
3799 "GpuLibrary: Unable to get stabilizer number of detectors");
3800
3801 return 0;
3802 }
3803
3804 int CopyStabilizerXTable(void *obj, unsigned int *xtable) {
3805 if (!obj) return 0;
3806 if (LibraryHandle)
3807 return fCopyStabilizerXTable(obj, xtable);
3808 else
3809 throw std::runtime_error("GpuLibrary: Unable to copy stabilizer X table");
3810 return 0;
3811 }
3812
3813 int CopyStabilizerZTable(void *obj, unsigned int *ztable) {
3814 if (!obj) return 0;
3815 if (LibraryHandle)
3816 return fCopyStabilizerZTable(obj, ztable);
3817 else
3818 throw std::runtime_error("GpuLibrary: Unable to copy stabilizer Z table");
3819 return 0;
3820 }
3821
3822 int CopyStabilizerMTable(void *obj, unsigned int *mtable) {
3823 if (!obj) return 0;
3824 if (LibraryHandle)
3825 return fCopyStabilizerMTable(obj, mtable);
3826 else
3827 throw std::runtime_error("GpuLibrary: Unable to copy stabilizer M table");
3828 return 0;
3829 }
3830
3831 int InitStabilizerXTable(void *obj, const unsigned int *xtable) {
3832 if (!obj) return 0;
3833 if (LibraryHandle)
3834 return fInitStabilizerXTable(obj, xtable);
3835 else
3836 throw std::runtime_error(
3837 "GpuLibrary: Unable to initialize stabilizer X table");
3838 return 0;
3839 }
3840
3841 int InitStabilizerZTable(void *obj, const unsigned int *ztable) {
3842 if (!obj) return 0;
3843 if (LibraryHandle)
3844 return fInitStabilizerZTable(obj, ztable);
3845 else
3846 throw std::runtime_error(
3847 "GpuLibrary: Unable to initialize stabilizer Z table");
3848 return 0;
3849 }
3850
3851 // pauli propagation functions
3852 void *CreatePauliPropSimulator(int nrQubits) {
3853 if (LibraryHandle)
3854 return fCreatePauliPropSimulator(nrQubits);
3855 else
3856 throw std::runtime_error(
3857 "GpuLibrary: Unable to create pauli propagation simulator");
3858 return nullptr;
3859 }
3860
3861 void DestroyPauliPropSimulator(void *obj) {
3862 if (!obj) return;
3863 if (LibraryHandle)
3864 fDestroyPauliPropSimulator(obj);
3865 else
3866 throw std::runtime_error(
3867 "GpuLibrary: Unable to destroy pauli propagation simulator");
3868 }
3869
3870 int PauliPropGetNrQubits(void *obj) {
3871 if (!obj) return 0;
3872 if (LibraryHandle)
3873 return fPauliPropGetNrQubits(obj);
3874 else
3875 throw std::runtime_error(
3876 "GpuLibrary: Unable to get number of qubits in pauli propagation "
3877 "simulator");
3878 return 0;
3879 }
3880
3881 int PauliPropSetWillUseSampling(void *obj, int willUseSampling) {
3882 if (!obj) return 0;
3883 if (LibraryHandle)
3884 return fPauliPropSetWillUseSampling(obj, willUseSampling) == 1;
3885 else
3886 throw std::runtime_error(
3887 "GpuLibrary: Unable to set 'will use sampling' in pauli propagation "
3888 "simulator");
3889 return 0;
3890 }
3891
3892 int PauliPropGetWillUseSampling(void *obj) {
3893 if (!obj) return 0;
3894 if (LibraryHandle)
3895 return fPauliPropGetWillUseSampling(obj);
3896 else
3897 throw std::runtime_error(
3898 "GpuLibrary: Unable to get 'will use sampling' in pauli propagation "
3899 "simulator");
3900 return 0;
3901 }
3902
3903 double PauliPropGetCoefficientTruncationCutoff(void *obj) {
3904 if (!obj) return 0.0;
3905 if (LibraryHandle)
3906 return fPauliPropGetCoefficientTruncationCutoff(obj);
3907 else
3908 throw std::runtime_error(
3909 "GpuLibrary: Unable to get coefficient truncation cutoff in pauli "
3910 "propagation simulator");
3911 return 0.0;
3912 }
3913
3914 void PauliPropSetCoefficientTruncationCutoff(void *obj, double cutoff) {
3915 if (!obj) return;
3916 if (LibraryHandle)
3917 fPauliPropSetCoefficientTruncationCutoff(obj, cutoff);
3918 else
3919 throw std::runtime_error(
3920 "GpuLibrary: Unable to set coefficient truncation cutoff in pauli "
3921 "propagation simulator");
3922 }
3923
3924 double PauliPropGetWeightTruncationCutoff(void *obj) {
3925 if (!obj) return 0.0;
3926 if (LibraryHandle)
3927 return fPauliPropGetWeightTruncationCutoff(obj);
3928 else
3929 throw std::runtime_error(
3930 "GpuLibrary: Unable to get weight truncation cutoff in pauli "
3931 "propagation simulator");
3932 return 0.0;
3933 }
3934
3935 void PauliPropSetWeightTruncationCutoff(void *obj, double cutoff) {
3936 if (!obj) return;
3937 if (LibraryHandle)
3938 fPauliPropSetWeightTruncationCutoff(obj, cutoff);
3939 else
3940 throw std::runtime_error(
3941 "GpuLibrary: Unable to set weight truncation cutoff in pauli "
3942 "propagation simulator");
3943 }
3944
3945 int PauliPropGetNumGatesBetweenTruncations(void *obj) {
3946 if (!obj) return 0;
3947 if (LibraryHandle)
3948 return fPauliPropGetNumGatesBetweenTruncations(obj);
3949 else
3950 throw std::runtime_error(
3951 "GpuLibrary: Unable to get number of gates between truncations in "
3952 "pauli propagation simulator");
3953 return 0;
3954 }
3955
3956 void PauliPropSetNumGatesBetweenTruncations(void *obj, int numGates) {
3957 if (!obj) return;
3958 if (LibraryHandle)
3959 fPauliPropSetNumGatesBetweenTruncations(obj, numGates);
3960 else
3961 throw std::runtime_error(
3962 "GpuLibrary: Unable to set number of gates between truncations in "
3963 "pauli "
3964 "propagation simulator");
3965 }
3966
3967 int PauliPropGetNumGatesBetweenDeduplications(void *obj) {
3968 if (!obj) return 0;
3969 if (LibraryHandle)
3970 return fPauliPropGetNumGatesBetweenDeduplications(obj);
3971 else
3972 throw std::runtime_error(
3973 "GpuLibrary: Unable to get number of gates between deduplications in "
3974 "pauli propagation simulator");
3975 return 0;
3976 }
3977
3978 void PauliPropSetNumGatesBetweenDeduplications(void *obj, int numGates) {
3979 if (!obj) return;
3980 if (LibraryHandle)
3981 fPauliPropSetNumGatesBetweenDeduplications(obj, numGates);
3982 else
3983 throw std::runtime_error(
3984 "GpuLibrary: Unable to set number of gates between deduplications in "
3985 "pauli "
3986 "propagation simulator");
3987 }
3988
3989 bool PauliPropClearOperators(void *obj) {
3990 if (!obj) return false;
3991 if (LibraryHandle)
3992 return fPauliPropClearOperators(obj) == 1;
3993 else
3994 throw std::runtime_error(
3995 "GpuLibrary: Unable to clear operators in pauli propagation "
3996 "simulator");
3997 return false;
3998 }
3999
4000 bool PauliPropAllocateMemory(void *obj, double percentage) {
4001 if (!obj) return false;
4002 if (LibraryHandle)
4003 return fPauliPropAllocateMemory(obj, percentage) == 1;
4004 else
4005 throw std::runtime_error(
4006 "GpuLibrary: Unable to allocate memory in pauli propagation "
4007 "simulator");
4008 return false;
4009 }
4010
4011 double PauliPropGetExpectationValue(void *obj) {
4012 if (!obj) return 0.0;
4013 if (LibraryHandle)
4014 return fPauliPropGetExpectationValue(obj);
4015 else
4016 throw std::runtime_error(
4017 "GpuLibrary: Unable to get expectation value in pauli propagation "
4018 "simulator");
4019 return 0.0;
4020 }
4021
4022 bool PauliPropExecute(void *obj) {
4023 if (!obj) return false;
4024 if (LibraryHandle)
4025 return fPauliPropExecute(obj) == 1;
4026 else
4027 throw std::runtime_error(
4028 "GpuLibrary: Unable to execute pauli propagation simulator");
4029 return false;
4030 }
4031
4032 bool PauliPropSetSeed(void *obj, unsigned long long seed) const {
4033 return obj && fPauliPropSetSeed && fPauliPropSetSeed(obj, seed) == 1;
4034 }
4035
4036 bool PauliPropSetInPauliExpansionUnique(void *obj, const char *pauliString) {
4037 if (!obj) return false;
4038 if (LibraryHandle)
4039 return fPauliPropSetInPauliExpansionUnique(obj, pauliString) == 1;
4040 else
4041 throw std::runtime_error(
4042 "GpuLibrary: Unable to set unique pauli in pauli propagation "
4043 "simulator");
4044 return false;
4045 }
4046
4047 bool PauliPropSetInPauliExpansionMultiple(void *obj,
4048 const char **pauliStrings,
4049 const double *coefficients,
4050 int nrPaulis) {
4051 if (!obj) return false;
4052 if (LibraryHandle)
4053 return fPauliPropSetInPauliExpansionMultiple(obj, pauliStrings,
4054 coefficients, nrPaulis) == 1;
4055 else
4056 throw std::runtime_error(
4057 "GpuLibrary: Unable to set multiple pauli in pauli propagation "
4058 "simulator");
4059 return false;
4060 }
4061
4062 bool PauliPropApplyX(void *obj, int qubit) {
4063 if (!obj) return false;
4064 if (LibraryHandle)
4065 return fPauliPropApplyX(obj, qubit) == 1;
4066 else
4067 throw std::runtime_error("GpuLibrary: Unable to apply X gate on mps");
4068 return false;
4069 }
4070
4071 bool PauliPropApplyY(void *obj, int qubit) {
4072 if (!obj) return false;
4073 if (LibraryHandle)
4074 return fPauliPropApplyY(obj, qubit) == 1;
4075 else
4076 throw std::runtime_error("GpuLibrary: Unable to apply Y gate on mps");
4077 return false;
4078 }
4079
4080 bool PauliPropApplyZ(void *obj, int qubit) {
4081 if (!obj) return false;
4082 if (LibraryHandle)
4083 return fPauliPropApplyZ(obj, qubit) == 1;
4084 else
4085 throw std::runtime_error("GpuLibrary: Unable to apply Z gate on mps");
4086 return false;
4087 }
4088
4089 bool PauliPropApplyH(void *obj, int qubit) {
4090 if (!obj) return false;
4091 if (LibraryHandle)
4092 return fPauliPropApplyH(obj, qubit) == 1;
4093 else
4094 throw std::runtime_error("GpuLibrary: Unable to apply H gate on mps");
4095 return false;
4096 }
4097
4098 bool PauliPropApplyS(void *obj, int qubit) {
4099 if (!obj) return false;
4100 if (LibraryHandle)
4101 return fPauliPropApplyS(obj, qubit) == 1;
4102 else
4103 throw std::runtime_error("GpuLibrary: Unable to apply S gate on mps");
4104 return false;
4105 }
4106
4107 bool PauliPropApplySQRTX(void *obj, int qubit) {
4108 if (!obj) return false;
4109 if (LibraryHandle)
4110 return fPauliPropApplySQRTX(obj, qubit) == 1;
4111 else
4112 throw std::runtime_error("GpuLibrary: Unable to apply SQRTX gate on mps");
4113 return false;
4114 }
4115
4116 bool PauliPropApplySQRTY(void *obj, int qubit) {
4117 if (!obj) return false;
4118 if (LibraryHandle)
4119 return fPauliPropApplySQRTY(obj, qubit) == 1;
4120 else
4121 throw std::runtime_error("GpuLibrary: Unable to apply SQRTY gate on mps");
4122 return false;
4123 }
4124
4125 bool PauliPropApplySQRTZ(void *obj, int qubit) {
4126 if (!obj) return false;
4127 if (LibraryHandle)
4128 return fPauliPropApplySQRTZ(obj, qubit) == 1;
4129 else
4130 throw std::runtime_error("GpuLibrary: Unable to apply SQRTZ gate on mps");
4131 return false;
4132 }
4133
4134 bool PauliPropApplyCX(void *obj, int targetQubit, int controlQubit) {
4135 if (!obj) return false;
4136 if (LibraryHandle)
4137 return fPauliPropApplyCX(obj, targetQubit, controlQubit) == 1;
4138 else
4139 throw std::runtime_error("GpuLibrary: Unable to apply CX gate on mps");
4140 return false;
4141 }
4142
4143 bool PauliPropApplyCY(void *obj, int targetQubit, int controlQubit) {
4144 if (!obj) return false;
4145 if (LibraryHandle)
4146 return fPauliPropApplyCY(obj, targetQubit, controlQubit) == 1;
4147 else
4148 throw std::runtime_error("GpuLibrary: Unable to apply CY gate on mps");
4149 return false;
4150 }
4151
4152 bool PauliPropApplyCZ(void *obj, int targetQubit, int controlQubit) {
4153 if (!obj) return false;
4154 if (LibraryHandle)
4155 return fPauliPropApplyCZ(obj, targetQubit, controlQubit) == 1;
4156 else
4157 throw std::runtime_error("GpuLibrary: Unable to apply CZ gate on mps");
4158 return false;
4159 }
4160
4161 bool PauliPropApplySWAP(void *obj, int qubit1, int qubit2) {
4162 if (!obj) return false;
4163 if (LibraryHandle)
4164 return fPauliPropApplySWAP(obj, qubit1, qubit2) == 1;
4165 else
4166 throw std::runtime_error("GpuLibrary: Unable to apply SWAP gate on mps");
4167 return false;
4168 }
4169
4170 bool PauliPropApplyISWAP(void *obj, int qubit1, int qubit2) {
4171 if (!obj) return false;
4172 if (LibraryHandle)
4173 return fPauliPropApplyISWAP(obj, qubit1, qubit2) == 1;
4174 else
4175 throw std::runtime_error("GpuLibrary: Unable to apply ISWAP gate on mps");
4176 return false;
4177 }
4178
4179 bool PauliPropApplyRX(void *obj, int qubit, double angle) {
4180 if (!obj) return false;
4181 if (LibraryHandle)
4182 return fPauliPropApplyRX(obj, qubit, angle) == 1;
4183 else
4184 throw std::runtime_error("GpuLibrary: Unable to apply RX gate on mps");
4185 return false;
4186 }
4187
4188 bool PauliPropApplyRY(void *obj, int qubit, double angle) {
4189 if (!obj) return false;
4190 if (LibraryHandle)
4191 return fPauliPropApplyRY(obj, qubit, angle) == 1;
4192 else
4193 throw std::runtime_error("GpuLibrary: Unable to apply RY gate on mps");
4194 return false;
4195 }
4196
4197 bool PauliPropApplyRZ(void *obj, int qubit, double angle) {
4198 if (!obj) return false;
4199 if (LibraryHandle)
4200 return fPauliPropApplyRZ(obj, qubit, angle) == 1;
4201 else
4202 throw std::runtime_error("GpuLibrary: Unable to apply RZ gate on mps");
4203 return false;
4204 }
4205
4206 bool PauliPropAddNoiseX(void *obj, int qubit, double probability) {
4207 if (!obj) return false;
4208 if (LibraryHandle)
4209 return fPauliPropAddNoiseX(obj, qubit, probability) == 1;
4210 else
4211 throw std::runtime_error("GpuLibrary: Unable to add X noise on mps");
4212 return false;
4213 }
4214
4215 bool PauliPropAddNoiseY(void *obj, int qubit, double probability) {
4216 if (!obj) return false;
4217 if (LibraryHandle)
4218 return fPauliPropAddNoiseY(obj, qubit, probability) == 1;
4219 else
4220 throw std::runtime_error("GpuLibrary: Unable to add Y noise on mps");
4221 return false;
4222 }
4223
4224 bool PauliPropAddNoiseZ(void *obj, int qubit, double probability) {
4225 if (!obj) return false;
4226 if (LibraryHandle)
4227 return fPauliPropAddNoiseZ(obj, qubit, probability) == 1;
4228 else
4229 throw std::runtime_error("GpuLibrary: Unable to add Z noise on mps");
4230 return false;
4231 }
4232
4233 bool PauliPropAddNoiseXYZ(void *obj, int qubit, double probabilityX,
4234 double probabilityY, double probabilityZ) {
4235 if (!obj) return false;
4236 if (LibraryHandle)
4237 return fPauliPropAddNoiseXYZ(obj, qubit, probabilityX, probabilityY,
4238 probabilityZ) == 1;
4239 else
4240 throw std::runtime_error("GpuLibrary: Unable to add XYZ noise on mps");
4241 return false;
4242 }
4243
4244 bool PauliPropAddAmplitudeDamping(void *obj, int qubit, double dampingProb,
4245 double exciteProb) {
4246 if (!obj) return false;
4247 if (LibraryHandle)
4248 return fPauliPropAddAmplitudeDamping(obj, qubit, dampingProb,
4249 exciteProb) == 1;
4250 else
4251 throw std::runtime_error(
4252 "GpuLibrary: Unable to add amplitude damping on mps");
4253 return false;
4254 }
4255
4256 double PauliPropQubitProbability0(void *obj, int qubit) {
4257 if (!obj) return 0.0;
4258 if (LibraryHandle)
4259 return fPauliPropQubitProbability0(obj, qubit);
4260 else
4261 throw std::runtime_error(
4262 "GpuLibrary: Unable to get qubit probability 0 in pauli propagation "
4263 "simulator");
4264 return 0.0;
4265 }
4266
4267 double PauliPropProbability(void *obj, unsigned long long int outcome) {
4268 if (!obj) return 0.0;
4269 if (LibraryHandle)
4270 return fPauliPropProbability(obj, outcome);
4271 else
4272 throw std::runtime_error(
4273 "GpuLibrary: Unable to get probability of outcome in pauli "
4274 "propagation simulator");
4275 return 0.0;
4276 }
4277
4278 bool PauliPropMeasureQubit(void *obj, int qubit) {
4279 if (!obj) return false;
4280 if (LibraryHandle)
4281 return fPauliPropMeasureQubit(obj, qubit) == 1;
4282 else
4283 throw std::runtime_error(
4284 "GpuLibrary: Unable to measure qubit in pauli propagation simulator");
4285 return false;
4286 }
4287
4288 unsigned char *PauliPropSampleQubits(void *obj, const int *qubits,
4289 int nrQubits) {
4290 if (!obj) return nullptr;
4291 if (LibraryHandle)
4292 return fPauliPropSampleQubits(obj, qubits, nrQubits);
4293 else
4294 throw std::runtime_error(
4295 "GpuLibrary: Unable to sample qubits in pauli propagation simulator");
4296 return nullptr;
4297 }
4298
4299 void PauliPropFreeSampledQubits(unsigned char *samples) {
4300 if (!samples) return;
4301 if (LibraryHandle)
4302 fPauliPropFreeSampledQubits(samples);
4303 else
4304 throw std::runtime_error(
4305 "GpuLibrary: Unable to free sampled qubits in pauli propagation "
4306 "simulator");
4307 }
4308
4309 void PauliPropSaveState(void *obj) {
4310 if (!obj) return;
4311 if (LibraryHandle)
4312 fPauliPropSaveState(obj);
4313 else
4314 throw std::runtime_error(
4315 "GpuLibrary: Unable to save state in pauli propagation simulator");
4316 }
4317
4318 void PauliPropRestoreState(void *obj) {
4319 if (!obj) return;
4320 if (LibraryHandle)
4321 fPauliPropRestoreState(obj);
4322 else
4323 throw std::runtime_error(
4324 "GpuLibrary: Unable to restore state in pauli propagation simulator");
4325 }
4326
4327 private:
4328 std::recursive_mutex initializationMutex;
4329 std::string loadedPath;
4330 void *LibraryHandle = nullptr;
4331
4332 int (*fValidateLicense)(const char *) = nullptr;
4333 void *(*InitLib)() = nullptr;
4334 void (*FreeLib)() = nullptr;
4335
4336 inline static thread_local int creationDevice = 0;
4337 int (*fGetStateVectorGpuId)(void*) = nullptr;
4338 int (*fMPSGetGpuId)(void*) = nullptr;
4339 int (*fTNGetGpuId)(void*) = nullptr;
4340 int (*fDMGetGpuId)(void*) = nullptr;
4341 int (*fMPOGetGpuId)(void*) = nullptr;
4342 int (*fGetStabilizerGpuId)(void*) = nullptr;
4343 int (*fPauliPropGetGpuId)(void*) = nullptr;
4344 int (*fSetGpuDevice)(int) = nullptr;
4345 int (*fGetGpuDeviceCount)() = nullptr;
4346
4347 void *(*fCreateStateVector)(void *) = nullptr;
4348 void (*fDestroyStateVector)(void *) = nullptr;
4349 // statevector functions
4350 int (*fSetDataType)(void *, int) = nullptr;
4351 int (*fIsDoublePrecision)(void *) = nullptr;
4352 int (*fGetNrQubits)(void *) = nullptr;
4353 int (*fCreate)(void *, unsigned int) = nullptr;
4354 int (*fReset)(void *) = nullptr;
4355 int (*fCreateWithState)(void *, unsigned int, const double *) = nullptr;
4356 int (*fMeasureQubitCollapse)(void *, int) = nullptr;
4357 int (*fMeasureQubitNoCollapse)(void *, int) = nullptr;
4358 int (*fMeasureQubitsCollapse)(void *, int *, int *, int) = nullptr;
4359 int (*fMeasureQubitsNoCollapse)(void *, int *, int *, int) = nullptr;
4360 unsigned long long (*fMeasureAllQubitsCollapse)(void *) = nullptr;
4361 unsigned long long (*fMeasureAllQubitsNoCollapse)(void *) = nullptr;
4362
4363 int (*fSaveState)(void *) = nullptr;
4364 int (*fSaveStateToHost)(void *) = nullptr;
4365 int (*fSaveStateDestructive)(void *) = nullptr;
4366 int (*fRestoreStateFreeSaved)(void *) = nullptr;
4367 int (*fRestoreStateNoFreeSaved)(void *) = nullptr;
4368 void (*fFreeSavedState)(void *obj) = nullptr;
4369 void *(*fClone)(void *) = nullptr;
4370 int (*fSetSeed)(void *, unsigned long long) = nullptr;
4371 int (*fSample)(void *, unsigned int, long int *, unsigned int,
4372 int *) = nullptr;
4373 int (*fSampleAll)(void *, unsigned int, long int *) = nullptr;
4374 int (*fAmplitude)(void *, long long int, double *, double *) = nullptr;
4375 double (*fProbability)(void *, int *, int *, int) = nullptr;
4376 double (*fBasisStateProbability)(void *, long long int) = nullptr;
4377 int (*fAllProbabilities)(void *, double *) = nullptr;
4378 double (*fExpectationValue)(void *, const char *, int) = nullptr;
4379
4380 int (*fApplyX)(void *, int) = nullptr;
4381 int (*fApplyY)(void *, int) = nullptr;
4382 int (*fApplyZ)(void *, int) = nullptr;
4383 int (*fApplyH)(void *, int) = nullptr;
4384 int (*fApplyS)(void *, int) = nullptr;
4385 int (*fApplySDG)(void *, int) = nullptr;
4386 int (*fApplyT)(void *, int) = nullptr;
4387 int (*fApplyTDG)(void *, int) = nullptr;
4388 int (*fApplySX)(void *, int) = nullptr;
4389 int (*fApplySXDG)(void *, int) = nullptr;
4390 int (*fApplyK)(void *, int) = nullptr;
4391 int (*fApplyP)(void *, int, double) = nullptr;
4392 int (*fApplyRx)(void *, int, double) = nullptr;
4393 int (*fApplyRy)(void *, int, double) = nullptr;
4394 int (*fApplyRz)(void *, int, double) = nullptr;
4395 int (*fApplyU)(void *, int, double, double, double, double) = nullptr;
4396 int (*fApplyCX)(void *, int, int) = nullptr;
4397 int (*fApplyCY)(void *, int, int) = nullptr;
4398 int (*fApplyCZ)(void *, int, int) = nullptr;
4399 int (*fApplyCH)(void *, int, int) = nullptr;
4400 int (*fApplyCSX)(void *, int, int) = nullptr;
4401 int (*fApplyCSXDG)(void *, int, int) = nullptr;
4402 int (*fApplyCP)(void *, int, int, double) = nullptr;
4403 int (*fApplyCRx)(void *, int, int, double) = nullptr;
4404 int (*fApplyCRy)(void *, int, int, double) = nullptr;
4405 int (*fApplyCRz)(void *, int, int, double) = nullptr;
4406 int (*fApplyCCX)(void *, int, int, int) = nullptr;
4407 int (*fApplySwap)(void *, int, int) = nullptr;
4408 int (*fApplyCSwap)(void *, int, int, int) = nullptr;
4409 int (*fApplyCU)(void *, int, int, double, double, double, double) = nullptr;
4410 // mps functions
4411 void *(*fCreateMPS)(void *) = nullptr;
4412 void (*fDestroyMPS)(void *) = nullptr;
4413
4414 int (*fMPSCreate)(void *, unsigned int) = nullptr;
4415 int (*fMPSCreateWithBasisState)(void *, unsigned int,
4416 unsigned long long) = nullptr;
4417 int (*fMPSCreateWithBasisStateBits)(void *, unsigned int,
4418 const unsigned char *) = nullptr;
4419 int (*fMPSReset)(void *) = nullptr;
4420 int (*fMPSSetInitialQubitsMap)(void *, const long long int *,
4421 int) = nullptr;
4422 int (*fMPSSetUseOptimalMeetingPosition)(void *, int) = nullptr;
4423 int (*fMPSGetUseOptimalMeetingPosition)(void *) = nullptr;
4424
4425 int (*fMPSIsValid)(void *) = nullptr;
4426 int (*fMPSIsCreated)(void *) = nullptr;
4427
4428 int (*fMPSSetDataType)(void *, int) = nullptr;
4429 int (*fMPSIsDoublePrecision)(void *) = nullptr;
4430 int (*fMPSSetCutoff)(void *, double) = nullptr;
4431 double (*fMPSGetCutoff)(void *) = nullptr;
4432 int (*fMPSSetTruncationMode)(void *, int) = nullptr;
4433 int (*fMPSGetTruncationMode)(void *) = nullptr;
4434 int (*fMPSSetGesvdJ)(void *, int) = nullptr;
4435 int (*fMPSGetGesvdJ)(void *) = nullptr;
4436 int (*fMPSSetGesvdP)(void *, int) = nullptr;
4437 int (*fMPSGetGesvdP)(void *) = nullptr;
4438 int (*fMPSSetGesvdR)(void *, int) = nullptr;
4439 int (*fMPSGetGesvdR)(void *) = nullptr;
4440 int (*fMPSGetLastSvdAlgo)(void *) = nullptr;
4441 int (*fMPSSetMaxExtent)(void *, long int) = nullptr;
4442 long int (*fMPSGetMaxExtent)(void *) = nullptr;
4443 int (*fMPSGetNrQubits)(void *) = nullptr;
4444 int (*fMPSGetBondDimensions)(void *, long long int *) = nullptr;
4445 int (*fMPSSetCallbackContext)(void *, void *) = nullptr;
4446 int (*fMPSSetMeetingPositionCallback)(void *, int64_t (*)(void *, const int64_t *)) = nullptr;
4447 int (*fMPSSetBondDimensionsCallback)(void *, void (*)(void *, const int64_t *)) = nullptr;
4448
4449 int (*fMPSAmplitude)(void *, long int, long int *, double *,
4450 double *) = nullptr;
4451 double (*fMPSProbability0)(void *, unsigned int) = nullptr;
4452 int (*fMPSMeasure)(void *, unsigned int) = nullptr;
4453 int (*fMPSMeasureQubits)(void *, long int, unsigned int *, int *) = nullptr;
4454 void *(*fMPSGetMapForSample)() = nullptr;
4455 int (*fMPSFreeMapForSample)(void *) = nullptr;
4456 int (*fMPSSample)(void *, long int, long int, unsigned int *,
4457 void *) = nullptr;
4458 int (*fMPSSampleRaw)(void *, unsigned int, long int *, unsigned int,
4459 const unsigned int *) = nullptr;
4460 int (*fMPSSampleAll)(void *, unsigned int, long int *) = nullptr;
4461
4462 int (*fMPSSaveState)(void *) = nullptr;
4463 int (*fMPSRestoreState)(void *) = nullptr;
4464 int (*fMPSCleanSavedState)(void *) = nullptr;
4465 void *(*fMPSClone)(void *) = nullptr;
4466 int (*fMPSSetSeed)(void *, unsigned long long) = nullptr;
4467
4468 double (*fMPSExpectationValue)(void *, const char *, int) = nullptr;
4469 int (*fMPSProjectOnZero)(void *, double *, double *) = nullptr;
4470
4471 int (*fMPSApplyX)(void *, unsigned int) = nullptr;
4472 int (*fMPSApplyY)(void *, unsigned int) = nullptr;
4473 int (*fMPSApplyZ)(void *, unsigned int) = nullptr;
4474 int (*fMPSApplyH)(void *, unsigned int) = nullptr;
4475 int (*fMPSApplyS)(void *, unsigned int) = nullptr;
4476 int (*fMPSApplySDG)(void *, unsigned int) = nullptr;
4477 int (*fMPSApplyT)(void *, unsigned int) = nullptr;
4478 int (*fMPSApplyTDG)(void *, unsigned int) = nullptr;
4479 int (*fMPSApplySX)(void *, unsigned int) = nullptr;
4480 int (*fMPSApplySXDG)(void *, unsigned int) = nullptr;
4481 int (*fMPSApplyK)(void *, unsigned int) = nullptr;
4482 int (*fMPSApplyP)(void *, unsigned int, double) = nullptr;
4483 int (*fMPSApplyRx)(void *, unsigned int, double) = nullptr;
4484 int (*fMPSApplyRy)(void *, unsigned int, double) = nullptr;
4485 int (*fMPSApplyRz)(void *, unsigned int, double) = nullptr;
4486 int (*fMPSApplyU)(void *, unsigned int, double, double, double,
4487 double) = nullptr;
4488 int (*fMPSApplyOneQubitMatrix)(void *, unsigned int,
4489 const double *) = nullptr;
4490 int (*fMPSApplyTwoQubitMatrix)(void *, unsigned int, unsigned int,
4491 const double *) = nullptr;
4492 int (*fMPSApplySwap)(void *, unsigned int, unsigned int) = nullptr;
4493 int (*fMPSApplyCX)(void *, unsigned int, unsigned int) = nullptr;
4494 int (*fMPSApplyCY)(void *, unsigned int, unsigned int) = nullptr;
4495 int (*fMPSApplyCZ)(void *, unsigned int, unsigned int) = nullptr;
4496 int (*fMPSApplyCH)(void *, unsigned int, unsigned int) = nullptr;
4497 int (*fMPSApplyCSX)(void *, unsigned int, unsigned int) = nullptr;
4498 int (*fMPSApplyCSXDG)(void *, unsigned int, unsigned int) = nullptr;
4499 int (*fMPSApplyCP)(void *, unsigned int, unsigned int, double) = nullptr;
4500 int (*fMPSApplyCRx)(void *, unsigned int, unsigned int, double) = nullptr;
4501 int (*fMPSApplyCRy)(void *, unsigned int, unsigned int, double) = nullptr;
4502 int (*fMPSApplyCRz)(void *, unsigned int, unsigned int, double) = nullptr;
4503 int (*fMPSApplyCU)(void *, unsigned int, unsigned int, double, double, double,
4504 double) = nullptr;
4505
4506 // tensor network functions
4507 void *(*fCreateTensorNet)(void *) = nullptr;
4508 void (*fDestroyTensorNet)(void *) = nullptr;
4509
4510 int (*fTNCreate)(void *, unsigned int) = nullptr;
4511 int (*fTNReset)(void *) = nullptr;
4512 int (*fTNIsValid)(void *) = nullptr;
4513 int (*fTNIsCreated)(void *) = nullptr;
4514
4515 int (*fTNSetDataType)(void *, int) = nullptr;
4516 int (*fTNIsDoublePrecision)(void *) = nullptr;
4517 int (*fTNSetCutoff)(void *, double) = nullptr;
4518 double (*fTNGetCutoff)(void *) = nullptr;
4519 int (*fTNSetTruncationMode)(void *, int) = nullptr;
4520 int (*fTNGetTruncationMode)(void *) = nullptr;
4521 int (*fTNSetGesvdJ)(void *, int) = nullptr;
4522 int (*fTNGetGesvdJ)(void *) = nullptr;
4523 int (*fTNSetGesvdP)(void *, int) = nullptr;
4524 int (*fTNGetGesvdP)(void *) = nullptr;
4525 int (*fTNSetGesvdR)(void *, int) = nullptr;
4526 int (*fTNGetGesvdR)(void *) = nullptr;
4527 int (*fTNSetMaxExtent)(void *, long int) = nullptr;
4528 long int (*fTNGetMaxExtent)(void *) = nullptr;
4529 int (*fTNGetNrQubits)(void *) = nullptr;
4530 int (*fTNAmplitude)(void *, long int, long int *, double *,
4531 double *) = nullptr;
4532 double (*fTNProbability0)(void *, unsigned int) = nullptr;
4533 int (*fTNMeasure)(void *, unsigned int) = nullptr;
4534 int (*fTNMeasureQubits)(void *, long int, unsigned int *, int *) = nullptr;
4535 void *(*fTNGetMapForSample)() = nullptr;
4536 int (*fTNFreeMapForSample)(void *) = nullptr;
4537 int (*fTNSample)(void *, long int, long int, unsigned int *,
4538 void *) = nullptr;
4539
4540 int (*fTNSaveState)(void *) = nullptr;
4541 int (*fTNRestoreState)(void *) = nullptr;
4542 int (*fTNCleanSavedState)(void *) = nullptr;
4543 void *(*fTNClone)(void *) = nullptr;
4544 int (*fTNSetSeed)(void *, unsigned long long) = nullptr;
4545
4546 double (*fTNExpectationValue)(void *, const char *, int) = nullptr;
4547
4548 int (*fTNApplyX)(void *, unsigned int) = nullptr;
4549 int (*fTNApplyY)(void *, unsigned int) = nullptr;
4550 int (*fTNApplyZ)(void *, unsigned int) = nullptr;
4551 int (*fTNApplyH)(void *, unsigned int) = nullptr;
4552 int (*fTNApplyS)(void *, unsigned int) = nullptr;
4553 int (*fTNApplySDG)(void *, unsigned int) = nullptr;
4554 int (*fTNApplyT)(void *, unsigned int) = nullptr;
4555 int (*fTNApplyTDG)(void *, unsigned int) = nullptr;
4556 int (*fTNApplySX)(void *, unsigned int) = nullptr;
4557 int (*fTNApplySXDG)(void *, unsigned int) = nullptr;
4558 int (*fTNApplyK)(void *, unsigned int) = nullptr;
4559 int (*fTNApplyP)(void *, unsigned int, double) = nullptr;
4560 int (*fTNApplyRx)(void *, unsigned int, double) = nullptr;
4561 int (*fTNApplyRy)(void *, unsigned int, double) = nullptr;
4562 int (*fTNApplyRz)(void *, unsigned int, double) = nullptr;
4563 int (*fTNApplyU)(void *, unsigned int, double, double, double,
4564 double) = nullptr;
4565 int (*fTNApplySwap)(void *, unsigned int, unsigned int) = nullptr;
4566 int (*fTNApplyCX)(void *, unsigned int, unsigned int) = nullptr;
4567 int (*fTNApplyCY)(void *, unsigned int, unsigned int) = nullptr;
4568 int (*fTNApplyCZ)(void *, unsigned int, unsigned int) = nullptr;
4569 int (*fTNApplyCH)(void *, unsigned int, unsigned int) = nullptr;
4570 int (*fTNApplyCSX)(void *, unsigned int, unsigned int) = nullptr;
4571 int (*fTNApplyCSXDG)(void *, unsigned int, unsigned int) = nullptr;
4572 int (*fTNApplyCP)(void *, unsigned int, unsigned int, double) = nullptr;
4573 int (*fTNApplyCRx)(void *, unsigned int, unsigned int, double) = nullptr;
4574 int (*fTNApplyCRy)(void *, unsigned int, unsigned int, double) = nullptr;
4575 int (*fTNApplyCRz)(void *, unsigned int, unsigned int, double) = nullptr;
4576 int (*fTNApplyCU)(void *, unsigned int, unsigned int, double, double, double,
4577 double) = nullptr;
4578 int (*fTNApplyCCX)(void *, unsigned int, unsigned int,
4579 unsigned int) = nullptr;
4580 int (*fTNApplyCSwap)(void *, unsigned int, unsigned int,
4581 unsigned int) = nullptr;
4582 // stabilizer functions
4583 void *(*fCreateStabilizerSimulator)(long long int, long long int,
4584 long long int, long long int) = nullptr;
4585 void (*fDestroyStabilizerSimulator)(void *) = nullptr;
4586 int (*fExecuteStabilizerCircuit)(void *, const char *, int,
4587 unsigned long long int) = nullptr;
4588 long long (*fGetStabilizerXZTableSize)(void *) = nullptr;
4589 long long (*fGetStabilizerMTableSize)(void *) = nullptr;
4590 long long (*fGetStabilizerTableStrideMajor)(void *) = nullptr;
4591 long long (*fGetStabilizerNumQubits)(void *) = nullptr;
4592 long long (*fGetStabilizerNumShots)(void *) = nullptr;
4593 long long (*fGetStabilizerNumMeasurements)(void *) = nullptr;
4594 long long (*fGetStabilizerNumDetectors)(void *) = nullptr;
4595 int (*fCopyStabilizerXTable)(void *, unsigned int *) = nullptr;
4596 int (*fCopyStabilizerZTable)(void *, unsigned int *) = nullptr;
4597 int (*fCopyStabilizerMTable)(void *, unsigned int *) = nullptr;
4598 int (*fInitStabilizerXTable)(void *, const unsigned int *) = nullptr;
4599 int (*fInitStabilizerZTable)(void *, const unsigned int *) = nullptr;
4600 // Pauli propagation functions
4601 void *(*fCreatePauliPropSimulator)(int) = nullptr;
4602 void (*fDestroyPauliPropSimulator)(void *) = nullptr;
4603
4604 int (*fPauliPropGetNrQubits)(void *) = nullptr;
4605 int (*fPauliPropSetWillUseSampling)(void *, int) = nullptr;
4606 int (*fPauliPropGetWillUseSampling)(void *) = nullptr;
4607 double (*fPauliPropGetCoefficientTruncationCutoff)(void *) = nullptr;
4608 void (*fPauliPropSetCoefficientTruncationCutoff)(void *, double) = nullptr;
4609 double (*fPauliPropGetWeightTruncationCutoff)(void *) = nullptr;
4610 void (*fPauliPropSetWeightTruncationCutoff)(void *, double) = nullptr;
4611 int (*fPauliPropGetNumGatesBetweenTruncations)(void *) = nullptr;
4612 void (*fPauliPropSetNumGatesBetweenTruncations)(void *, int) = nullptr;
4613 int (*fPauliPropGetNumGatesBetweenDeduplications)(void *) = nullptr;
4614 void (*fPauliPropSetNumGatesBetweenDeduplications)(void *, int) = nullptr;
4615 int (*fPauliPropClearOperators)(void *) = nullptr;
4616 int (*fPauliPropAllocateMemory)(void *, double) = nullptr;
4617 double (*fPauliPropGetExpectationValue)(void *) = nullptr;
4618 int (*fPauliPropExecute)(void *) = nullptr;
4619 int (*fPauliPropSetSeed)(void *, unsigned long long) = nullptr;
4620 int (*fPauliPropSetInPauliExpansionUnique)(void *, const char *) = nullptr;
4621 int (*fPauliPropSetInPauliExpansionMultiple)(void *, const char **,
4622 const double *, int) = nullptr;
4623
4624 int (*fPauliPropApplyX)(void *, int) = nullptr;
4625 int (*fPauliPropApplyY)(void *, int) = nullptr;
4626 int (*fPauliPropApplyZ)(void *, int) = nullptr;
4627 int (*fPauliPropApplyH)(void *, int) = nullptr;
4628 int (*fPauliPropApplyS)(void *, int) = nullptr;
4629 int (*fPauliPropApplySQRTX)(void *, int) = nullptr;
4630 int (*fPauliPropApplySQRTY)(void *, int) = nullptr;
4631 int (*fPauliPropApplySQRTZ)(void *, int) = nullptr;
4632 int (*fPauliPropApplyCX)(void *, int, int) = nullptr;
4633 int (*fPauliPropApplyCY)(void *, int, int) = nullptr;
4634 int (*fPauliPropApplyCZ)(void *, int, int) = nullptr;
4635 int (*fPauliPropApplySWAP)(void *, int, int) = nullptr;
4636 int (*fPauliPropApplyISWAP)(void *, int, int) = nullptr;
4637 int (*fPauliPropApplyRX)(void *, int, double) = nullptr;
4638 int (*fPauliPropApplyRY)(void *, int, double) = nullptr;
4639 int (*fPauliPropApplyRZ)(void *, int, double) = nullptr;
4640 int (*fPauliPropAddNoiseX)(void *, int, double) = nullptr;
4641 int (*fPauliPropAddNoiseY)(void *, int, double) = nullptr;
4642 int (*fPauliPropAddNoiseZ)(void *, int, double) = nullptr;
4643 int (*fPauliPropAddNoiseXYZ)(void *, int, double, double, double) = nullptr;
4644 int (*fPauliPropAddAmplitudeDamping)(void *, int, double, double) = nullptr;
4645 double (*fPauliPropQubitProbability0)(void *, int) = nullptr;
4646 double (*fPauliPropProbability)(void *, unsigned long long int) = nullptr;
4647
4648 int (*fPauliPropMeasureQubit)(void *, int) = nullptr;
4649 unsigned char *(*fPauliPropSampleQubits)(void *, const int *, int) = nullptr;
4650 void (*fPauliPropFreeSampledQubits)(unsigned char *) = nullptr;
4651 void (*fPauliPropSaveState)(void *) = nullptr;
4652 void (*fPauliPropRestoreState)(void *) = nullptr;
4653};
4654} // namespace Simulators
4655
4656#endif
4657#endif
int ApplyK(void *sim, int qubit)
double Probability(void *sim, unsigned long long int outcome)
int ApplyRx(void *sim, int qubit, double theta)
int ApplyX(void *sim, int qubit)
int ApplyU(void *sim, int qubit, double theta, double phi, double lambda, double gamma)
int ApplyCRy(void *sim, int controlQubit, int targetQubit, double theta)
int ApplyTDG(void *sim, int qubit)
int ApplyCSXDG(void *sim, int controlQubit, int targetQubit)
int ApplyS(void *sim, int qubit)
int ApplyCX(void *sim, int controlQubit, int targetQubit)
int ApplyCRz(void *sim, int controlQubit, int targetQubit, double theta)
double * AllProbabilities(void *sim)
int ApplyCP(void *sim, int controlQubit, int targetQubit, double theta)
int ApplySXDG(void *sim, int qubit)
int ApplySDG(void *sim, int qubit)
int ApplyCSwap(void *sim, int controlQubit, int qubit1, int qubit2)
int ApplyCCX(void *sim, int controlQubit1, int controlQubit2, int targetQubit)
int ApplyY(void *sim, int qubit)
double * Amplitude(void *sim, unsigned long long int outcome)
int ApplyZ(void *sim, int qubit)
int ApplyH(void *sim, int qubit)
int ApplyCY(void *sim, int controlQubit, int targetQubit)
int ApplyCU(void *sim, int controlQubit, int targetQubit, double theta, double phi, double lambda, double gamma)
int ApplySwap(void *sim, int qubit1, int qubit2)
int ApplyRy(void *sim, int qubit, double theta)
int ApplyP(void *sim, int qubit, double theta)
int ApplyCH(void *sim, int controlQubit, int targetQubit)
int ApplySX(void *sim, int qubit)
int ApplyCZ(void *sim, int controlQubit, int targetQubit)
int ApplyRz(void *sim, int qubit, double theta)
int ApplyT(void *sim, int qubit)
int ApplyCRx(void *sim, int controlQubit, int targetQubit, double theta)
int ApplyCSX(void *sim, int controlQubit, int targetQubit)
int SaveState(void *sim)
virtual bool Init(const char *libName) noexcept
Definition Library.h:78