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