Maestro 0.1.0
Unified interface for quantum circuit simulation
Loading...
Searching...
No Matches
GpuLibMPSSim.h
Go to the documentation of this file.
1
12
13#pragma once
14
15#ifndef _GPU_LIB_MPS_SIM_H_
16#define _GPU_LIB_MPS_SIM_H_
17
18#ifdef __linux__
19
20#include <memory>
21
22#include "GpuLibrary.h"
23
24namespace Simulators {
25
26class GpuLibMPSSim {
27public:
28 explicit GpuLibMPSSim(const std::shared_ptr<GpuLibrary> &lib) : lib(lib) {
29 if (lib)
30 obj = lib->CreateMPS();
31 else
32 obj = nullptr;
33 }
34
35 GpuLibMPSSim(const std::shared_ptr<GpuLibrary> &lib, void *obj)
36 : lib(lib), obj(obj) {}
37
38 GpuLibMPSSim() = delete;
39 GpuLibMPSSim(const GpuLibMPSSim &) = delete;
40 GpuLibMPSSim &operator=(const GpuLibMPSSim &) = delete;
41 GpuLibMPSSim(GpuLibMPSSim &&) = default;
42 GpuLibMPSSim &operator=(GpuLibMPSSim &&) = default;
43
44 ~GpuLibMPSSim() {
45 if (lib && obj)
46 lib->DestroyMPS(obj);
47 }
48
49 bool Create(unsigned int nrQubits) {
50 if (obj)
51 return lib->MPSCreate(obj, nrQubits);
52
53 return false;
54 }
55
56 bool Reset() {
57 if (obj)
58 return lib->MPSReset(obj);
59
60 return false;
61 }
62
63 bool IsValid() const {
64 if (obj)
65 return lib->MPSIsValid(obj);
66
67 return false;
68 }
69
70 bool IsCreated() const {
71 if (obj)
72 return lib->MPSIsCreated(obj);
73
74 return false;
75 }
76
77 bool SetDataType(int useDoublePrecision) {
78 if (obj)
79 return lib->MPSSetDataType(obj, useDoublePrecision);
80
81 return false;
82 }
83
84 bool IsDoublePrecision() const {
85 if (obj)
86 return lib->MPSIsDoublePrecision(obj);
87
88 return false;
89 }
90
91 bool SetCutoff(double val) {
92 if (obj)
93 return lib->MPSSetCutoff(obj, val);
94
95 return false;
96 }
97
98 double GetCutoff() const {
99 if (obj)
100 return lib->MPSGetCutoff(obj);
101
102 return 0.;
103 }
104
105 bool SetGesvdJ(int val) {
106 if (obj)
107 return lib->MPSSetGesvdJ(obj, val);
108
109 return false;
110 }
111
112 bool GetGesvdJ() const {
113 if (obj)
114 return lib->MPSGetGesvdJ(obj);
115
116 return false;
117 }
118
119 bool SetMaxExtent(long int val) {
120 if (obj)
121 return lib->MPSSetMaxExtent(obj, val);
122
123 return false;
124 }
125
126 long int GetMaxExtent() const {
127 if (obj)
128 return lib->MPSGetMaxExtent(obj);
129
130 return 0;
131 }
132
133 int GetNrQubits() const {
134 if (obj)
135 return lib->MPSGetNrQubits(obj);
136
137 return 0;
138 }
139
140 bool Amplitude(long int numFixedValues, long int *fixedValues, double *real,
141 double *imaginary) const {
142 if (obj)
143 return lib->MPSAmplitude(obj, numFixedValues, fixedValues, real,
144 imaginary);
145
146 return false;
147 }
148
149 double Probability0(unsigned int qubit) const {
150 if (obj)
151 return lib->MPSProbability0(obj, qubit);
152
153 return 0.;
154 }
155
156 bool Measure(unsigned int qubit) {
157 if (obj)
158 return lib->MPSMeasure(obj, qubit);
159
160 return 0;
161 }
162
163 bool MeasureQubits(long int numQubits, unsigned int *qubits, int *result) {
164 if (obj)
165 return lib->MPSMeasureQubits(obj, numQubits, qubits, result);
166
167 return false;
168 }
169
170 std::unordered_map<std::vector<bool>, int64_t> *GetMapForSample() const {
171 if (lib)
172 return lib->MPSGetMapForSample();
173
174 return nullptr;
175 }
176
177 bool
178 FreeMapForSample(std::unordered_map<std::vector<bool>, int64_t> *map) const {
179 if (lib)
180 return lib->MPSFreeMapForSample(map);
181
182 return false;
183 }
184
185 bool Sample(long int numShots, long int numQubits, unsigned int *qubits,
186 void *resultMap) {
187 if (obj)
188 return lib->MPSSample(obj, numShots, numQubits, qubits, resultMap);
189
190 return false;
191 }
192
193 bool SaveState() {
194 if (obj)
195 return lib->MPSSaveState(obj);
196
197 return false;
198 }
199
200 bool RestoreState() {
201 if (obj)
202 return lib->MPSRestoreState(obj);
203
204 return false;
205 }
206
207 bool CleanSavedState() {
208 if (obj)
209 return lib->MPSCleanSavedState(obj);
210
211 return false;
212 }
213
214 std::unique_ptr<GpuLibMPSSim> Clone() const {
215 if (obj)
216 return std::make_unique<GpuLibMPSSim>(lib, lib->MPSClone(obj));
217
218 return nullptr;
219 }
220
221 double ExpectationValue(const std::string &pauliString) const {
222 if (obj)
223 return lib->MPSExpectationValue(obj, pauliString.c_str(),
224 pauliString.length());
225
226 return 0.0;
227 }
228
229 bool ApplyX(unsigned int siteA) {
230 if (obj)
231 return lib->MPSApplyX(obj, siteA);
232
233 return false;
234 }
235
236 bool ApplyY(unsigned int siteA) {
237 if (obj)
238 return lib->MPSApplyY(obj, siteA);
239
240 return false;
241 }
242
243 bool ApplyZ(unsigned int siteA) {
244 if (obj)
245 return lib->MPSApplyZ(obj, siteA);
246
247 return false;
248 }
249
250 bool ApplyH(unsigned int siteA) {
251 if (obj)
252 return lib->MPSApplyH(obj, siteA);
253
254 return false;
255 }
256
257 bool ApplyS(unsigned int siteA) {
258 if (obj)
259 return lib->MPSApplyS(obj, siteA);
260
261 return false;
262 }
263
264 bool ApplySDG(unsigned int siteA) {
265 if (obj)
266 return lib->MPSApplySDG(obj, siteA);
267
268 return false;
269 }
270
271 bool ApplyT(unsigned int siteA) {
272 if (obj)
273 return lib->MPSApplyT(obj, siteA);
274
275 return false;
276 }
277
278 bool ApplyTDG(unsigned int siteA) {
279 if (obj)
280 return lib->MPSApplyTDG(obj, siteA);
281
282 return false;
283 }
284
285 bool ApplySX(unsigned int siteA) {
286 if (obj)
287 return lib->MPSApplySX(obj, siteA);
288
289 return false;
290 }
291
292 bool ApplySXDG(unsigned int siteA) {
293 if (obj)
294 return lib->MPSApplySXDG(obj, siteA);
295
296 return false;
297 }
298
299 bool ApplyK(unsigned int siteA) {
300 if (obj)
301 return lib->MPSApplyK(obj, siteA);
302
303 return false;
304 }
305
306 bool ApplyP(unsigned int siteA, double theta) {
307 if (obj)
308 return lib->MPSApplyP(obj, siteA, theta);
309
310 return false;
311 }
312
313 bool ApplyRx(unsigned int siteA, double theta) {
314 if (obj)
315 return lib->MPSApplyRx(obj, siteA, theta);
316
317 return false;
318 }
319
320 bool ApplyRy(unsigned int siteA, double theta) {
321 if (obj)
322 return lib->MPSApplyRy(obj, siteA, theta);
323
324 return false;
325 }
326
327 bool ApplyRz(unsigned int siteA, double theta) {
328 if (obj)
329 return lib->MPSApplyRz(obj, siteA, theta);
330
331 return false;
332 }
333
334 bool ApplyU(unsigned int siteA, double theta, double phi, double lambda,
335 double gamma) {
336 if (obj)
337 return lib->MPSApplyU(obj, siteA, theta, phi, lambda, gamma);
338
339 return false;
340 }
341
342 bool ApplySwap(unsigned int controlQubit, unsigned int targetQubit) {
343 if (obj)
344 return lib->MPSApplySwap(obj, controlQubit, targetQubit);
345
346 return false;
347 }
348
349 bool ApplyCX(unsigned int controlQubit, unsigned int targetQubit) {
350 if (obj)
351 return lib->MPSApplyCX(obj, controlQubit, targetQubit);
352
353 return false;
354 }
355
356 bool ApplyCY(unsigned int controlQubit, unsigned int targetQubit) {
357 if (obj)
358 return lib->MPSApplyCY(obj, controlQubit, targetQubit);
359
360 return false;
361 }
362
363 bool ApplyCZ(unsigned int controlQubit, unsigned int targetQubit) {
364 if (obj)
365 return lib->MPSApplyCZ(obj, controlQubit, targetQubit);
366
367 return false;
368 }
369
370 bool ApplyCH(unsigned int controlQubit, unsigned int targetQubit) {
371 if (obj)
372 return lib->MPSApplyCH(obj, controlQubit, targetQubit);
373
374 return false;
375 }
376
377 bool ApplyCSX(unsigned int controlQubit, unsigned int targetQubit) {
378 if (obj)
379 return lib->MPSApplyCSX(obj, controlQubit, targetQubit);
380
381 return false;
382 }
383
384 bool ApplyCSXDG(unsigned int controlQubit, unsigned int targetQubit) {
385 if (obj)
386 return lib->MPSApplyCSXDG(obj, controlQubit, targetQubit);
387
388 return false;
389 }
390
391 bool ApplyCP(unsigned int controlQubit, unsigned int targetQubit,
392 double theta) {
393 if (obj)
394 return lib->MPSApplyCP(obj, controlQubit, targetQubit, theta);
395
396 return false;
397 }
398
399 bool ApplyCRx(unsigned int controlQubit, unsigned int targetQubit,
400 double theta) {
401 if (obj)
402 return lib->MPSApplyCRx(obj, controlQubit, targetQubit, theta);
403
404 return false;
405 }
406
407 bool ApplyCRy(unsigned int controlQubit, unsigned int targetQubit,
408 double theta) {
409 if (obj)
410 return lib->MPSApplyCRy(obj, controlQubit, targetQubit, theta);
411
412 return false;
413 }
414
415 bool ApplyCRz(unsigned int controlQubit, unsigned int targetQubit,
416 double theta) {
417 if (obj)
418 return lib->MPSApplyCRz(obj, controlQubit, targetQubit, theta);
419
420 return false;
421 }
422
423 bool ApplyCU(unsigned int controlQubit, unsigned int targetQubit,
424 double theta, double phi, double lambda, double gamma) {
425 if (obj)
426 return lib->MPSApplyCU(obj, controlQubit, targetQubit, theta, phi, lambda,
427 gamma);
428
429 return false;
430 }
431
432private:
433 std::shared_ptr<GpuLibrary> lib;
434 void *obj;
435};
436
437} // namespace Simulators
438
439#endif // __linux__
440
441#endif // _GPU_LIB_MPS_SIM_H_
int ApplyK(void *sim, int qubit)
int RestoreState(void *sim)
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)
int ApplyCP(void *sim, int controlQubit, int targetQubit, double theta)
int ApplySXDG(void *sim, int qubit)
int ApplySDG(void *sim, int qubit)
unsigned long long int Measure(void *sim, const unsigned long int *qubits, unsigned long int nrQubits)
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)