pyqrack-cuda 1.27.0__py3-none-manylinux_2_35_x86_64.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,1063 @@
1
+ # (C) Daniel Strano and the Qrack contributors 2017-2021. All rights reserved.
2
+ #
3
+ # "QrackSystem" is a central access point, in Python, to the vm6502q/qrack
4
+ # shared library, in C++11. For ease, it wraps all Qrack shared library
5
+ # functions with native Python method signatures.
6
+ #
7
+ # The "QrackSystem" references underlying distinct Qrack simulator instances
8
+ # via integer IDs that are created upon request to allocate a new simulator.
9
+ # While you can directly use QrackSystem to manage all your simulators, we
10
+ # suggest that you instead instantiate an instance of "QrackSimulator", which
11
+ # requests its own new simulator ID and supplies it to "QrackSystem" for all
12
+ # Qrack shared library calls, therefore acting as an independent Qrack
13
+ # simulator object.
14
+ #
15
+ # Use of this source code is governed by an MIT-style license that can be
16
+ # found in the LICENSE file or at https://opensource.org/licenses/MIT.
17
+
18
+ import os
19
+ from ctypes import *
20
+ from packaging import version
21
+ from sys import platform as _platform
22
+ import platform
23
+ import struct
24
+
25
+
26
+ class QrackSystem:
27
+ def __init__(self):
28
+ shared_lib_path = "/usr/local/lib/qrack/libqrack_pinvoke.so"
29
+ if os.environ.get('PYQRACK_SHARED_LIB_PATH') != None:
30
+ shared_lib_path = os.environ.get('PYQRACK_SHARED_LIB_PATH')
31
+ elif _platform == "linux" or _platform == "linux2":
32
+ machine = platform.machine()
33
+ if machine == "armv7l":
34
+ shared_lib_path = "qrack_lib/Linux/ARMv7/libqrack_pinvoke.so"
35
+ elif machine == "aarch64":
36
+ shared_lib_path = "qrack_lib/Linux/ARM64/libqrack_pinvoke.so"
37
+ elif version.parse(os.confstr('CS_GNU_LIBC_VERSION')[6:]) >= version.parse("2.35"):
38
+ shared_lib_path = "qrack_lib/Linux/2_35/libqrack_pinvoke.so"
39
+ else:
40
+ shared_lib_path = "qrack_lib/Linux/x86_64/libqrack_pinvoke.so"
41
+ elif _platform == "darwin":
42
+ shared_lib_path = "qrack_lib/Mac/M2/libqrack_pinvoke.dylib"
43
+ elif _platform == "win32":
44
+ struct_size = struct.calcsize("P") * 8
45
+ if struct_size == 32:
46
+ shared_lib_path = "qrack_lib\\Windows\\x86\\qrack_pinvoke.dll"
47
+ else:
48
+ shared_lib_path = "qrack_lib\\Windows\\x86_64\\qrack_pinvoke.dll"
49
+ else:
50
+ print(
51
+ "No Qrack binary for your platform, attempting to use /usr/lib/libqrack_pinvoke.so"
52
+ )
53
+ print(
54
+ "You can choose the binary file to load with the environment variable: PYQRACK_SHARED_LIB_PATH"
55
+ )
56
+
57
+ basedir = os.path.abspath(os.path.dirname(__file__))
58
+ if shared_lib_path.startswith("/") or shared_lib_path[1:3] == ":\\":
59
+ basedir = ""
60
+ try:
61
+ self.qrack_lib = CDLL(os.path.join(basedir, shared_lib_path))
62
+ except Exception as e:
63
+ print(e)
64
+
65
+ self.fppow = 5
66
+ if "QRACK_FPPOW" in os.environ:
67
+ self.fppow = int(os.environ.get('QRACK_FPPOW'))
68
+ if self.fppow < 4 or self.fppow > 7:
69
+ raise ValueError(
70
+ "QRACK_FPPOW environment variable must be an integer >3 and <8. (Qrack builds from 4 for fp16/half, up to 7 for fp128/quad."
71
+ )
72
+
73
+ # Define function signatures, up front
74
+
75
+ # non-quantum
76
+
77
+ self.qrack_lib.DumpIds.restype = None
78
+ self.qrack_lib.DumpIds.argtypes = [c_ulonglong, CFUNCTYPE(None, c_ulonglong)]
79
+
80
+ self.qrack_lib.Dump.restype = None
81
+ self.qrack_lib.Dump.argtypes = [
82
+ c_ulonglong,
83
+ CFUNCTYPE(c_ulonglong, c_double, c_double)
84
+ ]
85
+
86
+ # These next two methods need to have c_double pointers, if PyQrack is built with fp64.
87
+ self.qrack_lib.InKet.restype = None
88
+ self.qrack_lib.OutKet.restype = None
89
+
90
+ if self.fppow < 6:
91
+ self.qrack_lib.InKet.argtypes = [c_ulonglong, POINTER(c_float)]
92
+ self.qrack_lib.OutKet.argtypes = [c_ulonglong, POINTER(c_float)]
93
+ else:
94
+ self.qrack_lib.InKet.argtypes = [c_ulonglong, POINTER(c_double)]
95
+ self.qrack_lib.OutKet.argtypes = [c_ulonglong, POINTER(c_double)]
96
+
97
+ self.qrack_lib.init.restype = c_ulonglong
98
+ self.qrack_lib.init.argtypes = []
99
+
100
+ self.qrack_lib.get_error.restype = c_int
101
+ self.qrack_lib.get_error.argtypes = [c_ulonglong]
102
+
103
+ self.qrack_lib.init_count.restype = c_ulonglong
104
+ self.qrack_lib.init_count.argtypes = [c_ulonglong, c_bool]
105
+
106
+ self.qrack_lib.init_count_pager.restype = c_ulonglong
107
+ self.qrack_lib.init_count_pager.argtypes = [c_ulonglong, c_bool]
108
+
109
+ self.qrack_lib.init_count_type.restype = c_ulonglong
110
+ self.qrack_lib.init_count_type.argtypes = [
111
+ c_ulonglong,
112
+ c_bool,
113
+ c_bool,
114
+ c_bool,
115
+ c_bool,
116
+ c_bool,
117
+ c_bool,
118
+ c_bool,
119
+ c_bool,
120
+ c_bool,
121
+ c_bool
122
+ ]
123
+
124
+ self.qrack_lib.init_clone.restype = c_ulonglong
125
+ self.qrack_lib.init_clone.argtypes = [c_ulonglong]
126
+
127
+ self.qrack_lib.destroy.restype = None
128
+ self.qrack_lib.destroy.argtypes = [c_ulonglong]
129
+
130
+ self.qrack_lib.seed.restype = None
131
+ self.qrack_lib.seed.argtypes = [c_ulonglong, c_ulonglong]
132
+
133
+ self.qrack_lib.set_concurrency.restype = None
134
+ self.qrack_lib.set_concurrency.argtypes = [c_ulonglong, c_ulonglong]
135
+
136
+ # pseudo-quantum
137
+
138
+ self.qrack_lib.ProbAll.restype = None
139
+ if self.fppow == 5:
140
+ self.qrack_lib.ProbAll.argtypes = [
141
+ c_ulonglong,
142
+ c_ulonglong,
143
+ POINTER(c_ulonglong),
144
+ POINTER(c_float)
145
+ ]
146
+ elif self.fppow == 6:
147
+ self.qrack_lib.ProbAll.argtypes = [
148
+ c_ulonglong,
149
+ c_ulonglong,
150
+ POINTER(c_ulonglong),
151
+ POINTER(c_double)
152
+ ]
153
+
154
+ self.qrack_lib.Variance.restype = c_double
155
+ self.qrack_lib.Variance.argtypes = [
156
+ c_ulonglong,
157
+ c_ulonglong,
158
+ POINTER(c_ulonglong)
159
+ ]
160
+
161
+ self.qrack_lib.Prob.restype = c_double
162
+ self.qrack_lib.Prob.argtypes = [c_ulonglong, c_ulonglong]
163
+
164
+ self.qrack_lib.ProbRdm.restype = c_double
165
+ self.qrack_lib.ProbRdm.argtypes = [c_ulonglong, c_ulonglong]
166
+
167
+ self.qrack_lib.PermutationProb.restype = c_double
168
+ self.qrack_lib.PermutationProb.argtypes = [
169
+ c_ulonglong,
170
+ c_ulonglong,
171
+ POINTER(c_ulonglong),
172
+ POINTER(c_bool)
173
+ ]
174
+
175
+ self.qrack_lib.PermutationProbRdm.restype = c_double
176
+ self.qrack_lib.PermutationProbRdm.argtypes = [
177
+ c_ulonglong,
178
+ c_ulonglong,
179
+ POINTER(c_ulonglong),
180
+ POINTER(c_bool),
181
+ c_bool
182
+ ]
183
+
184
+ self.qrack_lib.PermutationExpectation.restype = c_double
185
+ self.qrack_lib.PermutationExpectation.argtypes = [
186
+ c_ulonglong,
187
+ c_ulonglong,
188
+ POINTER(c_ulonglong)
189
+ ]
190
+
191
+ self.qrack_lib.PermutationExpectationRdm.restype = c_double
192
+ self.qrack_lib.PermutationExpectationRdm.argtypes = [
193
+ c_ulonglong,
194
+ c_ulonglong,
195
+ POINTER(c_ulonglong),
196
+ c_bool
197
+ ]
198
+
199
+ self.qrack_lib.FactorizedExpectation.restype = c_double
200
+ self.qrack_lib.FactorizedExpectation.argtypes = [
201
+ c_ulonglong,
202
+ c_ulonglong,
203
+ POINTER(c_ulonglong),
204
+ c_ulonglong,
205
+ POINTER(c_ulonglong)
206
+ ]
207
+
208
+ self.qrack_lib.FactorizedExpectationRdm.restype = c_double
209
+ self.qrack_lib.FactorizedExpectationRdm.argtypes = [
210
+ c_ulonglong,
211
+ c_ulonglong,
212
+ POINTER(c_ulonglong),
213
+ c_ulonglong,
214
+ POINTER(c_ulonglong),
215
+ c_bool
216
+ ]
217
+
218
+ if self.fppow == 5:
219
+ self.qrack_lib.FactorizedExpectationFp.restype = c_double
220
+ self.qrack_lib.FactorizedExpectationFp.argtypes = [
221
+ c_ulonglong,
222
+ c_ulonglong,
223
+ POINTER(c_ulonglong),
224
+ POINTER(c_float)
225
+ ]
226
+
227
+ self.qrack_lib.FactorizedExpectationFpRdm.restype = c_double
228
+ self.qrack_lib.FactorizedExpectationFpRdm.argtypes = [
229
+ c_ulonglong,
230
+ c_ulonglong,
231
+ POINTER(c_ulonglong),
232
+ POINTER(c_float),
233
+ c_bool
234
+ ]
235
+ elif self.fppow == 6:
236
+ self.qrack_lib.FactorizedExpectationFp.restype = c_double
237
+ self.qrack_lib.FactorizedExpectationFp.argtypes = [
238
+ c_ulonglong,
239
+ c_ulonglong,
240
+ POINTER(c_ulonglong),
241
+ POINTER(c_double)
242
+ ]
243
+
244
+ self.qrack_lib.FactorizedExpectationFpRdm.restype = c_double
245
+ self.qrack_lib.FactorizedExpectationFpRdm.argtypes = [
246
+ c_ulonglong,
247
+ c_ulonglong,
248
+ POINTER(c_ulonglong),
249
+ POINTER(c_double),
250
+ c_bool
251
+ ]
252
+
253
+ self.qrack_lib.JointEnsembleProbability.restype = c_double
254
+ self.qrack_lib.JointEnsembleProbability.argtypes = [
255
+ c_ulonglong,
256
+ c_ulonglong,
257
+ POINTER(c_int),
258
+ c_ulonglong
259
+ ]
260
+
261
+ self.qrack_lib.PhaseParity.restype = None
262
+ self.qrack_lib.PhaseParity.argtypes = [
263
+ c_ulonglong,
264
+ c_double,
265
+ c_ulonglong,
266
+ POINTER(c_ulonglong)
267
+ ]
268
+
269
+ self.qrack_lib.ResetAll.restype = None
270
+ self.qrack_lib.ResetAll.argtypes = [c_ulonglong]
271
+
272
+ # allocate and release
273
+
274
+ self.qrack_lib.allocateQubit.restype = None
275
+ self.qrack_lib.allocateQubit.argtypes = [c_ulonglong, c_ulonglong]
276
+
277
+ self.qrack_lib.release.restype = c_bool
278
+ self.qrack_lib.release.argtypes = [c_ulonglong, c_ulonglong]
279
+
280
+ self.qrack_lib.num_qubits.restype = c_ulonglong
281
+ self.qrack_lib.num_qubits.argtypes = [c_ulonglong]
282
+
283
+ # single-qubit gates
284
+
285
+ self.qrack_lib.X.restype = None
286
+ self.qrack_lib.X.argtypes = [c_ulonglong, c_ulonglong]
287
+
288
+ self.qrack_lib.Y.restype = None
289
+ self.qrack_lib.Y.argtypes = [c_ulonglong, c_ulonglong]
290
+
291
+ self.qrack_lib.Z.restype = None
292
+ self.qrack_lib.Z.argtypes = [c_ulonglong, c_ulonglong]
293
+
294
+ self.qrack_lib.H.restype = None
295
+ self.qrack_lib.H.argtypes = [c_ulonglong, c_ulonglong]
296
+
297
+ self.qrack_lib.S.restype = None
298
+ self.qrack_lib.S.argtypes = [c_ulonglong, c_ulonglong]
299
+
300
+ self.qrack_lib.T.restype = None
301
+ self.qrack_lib.T.argtypes = [c_ulonglong, c_ulonglong]
302
+
303
+ self.qrack_lib.AdjS.restype = None
304
+ self.qrack_lib.AdjS.argtypes = [c_ulonglong, c_ulonglong]
305
+
306
+ self.qrack_lib.AdjT.restype = None
307
+ self.qrack_lib.AdjT.argtypes = [c_ulonglong, c_ulonglong]
308
+
309
+ self.qrack_lib.U.restype = None
310
+ self.qrack_lib.U.argtypes = [
311
+ c_ulonglong,
312
+ c_ulonglong,
313
+ c_double,
314
+ c_double,
315
+ c_double
316
+ ]
317
+
318
+ self.qrack_lib.Mtrx.restype = None
319
+ self.qrack_lib.Mtrx.argtypes = [c_ulonglong, POINTER(c_double), c_ulonglong]
320
+
321
+ # multi-controlled single-qubit gates
322
+
323
+ self.qrack_lib.MCX.restype = None
324
+ self.qrack_lib.MCX.argtypes = [
325
+ c_ulonglong,
326
+ c_ulonglong,
327
+ POINTER(c_ulonglong),
328
+ c_ulonglong
329
+ ]
330
+
331
+ self.qrack_lib.MCY.restype = None
332
+ self.qrack_lib.MCY.argtypes = [
333
+ c_ulonglong,
334
+ c_ulonglong,
335
+ POINTER(c_ulonglong),
336
+ c_ulonglong
337
+ ]
338
+
339
+ self.qrack_lib.MCZ.restype = None
340
+ self.qrack_lib.MCZ.argtypes = [
341
+ c_ulonglong,
342
+ c_ulonglong,
343
+ POINTER(c_ulonglong),
344
+ c_ulonglong
345
+ ]
346
+
347
+ self.qrack_lib.MCH.restype = None
348
+ self.qrack_lib.MCH.argtypes = [
349
+ c_ulonglong,
350
+ c_ulonglong,
351
+ POINTER(c_ulonglong),
352
+ c_ulonglong
353
+ ]
354
+
355
+ self.qrack_lib.MCS.restype = None
356
+ self.qrack_lib.MCS.argtypes = [
357
+ c_ulonglong,
358
+ c_ulonglong,
359
+ POINTER(c_ulonglong),
360
+ c_ulonglong
361
+ ]
362
+
363
+ self.qrack_lib.MCT.restype = None
364
+ self.qrack_lib.MCT.argtypes = [
365
+ c_ulonglong,
366
+ c_ulonglong,
367
+ POINTER(c_ulonglong),
368
+ c_ulonglong
369
+ ]
370
+
371
+ self.qrack_lib.MCAdjS.restype = None
372
+ self.qrack_lib.MCAdjS.argtypes = [
373
+ c_ulonglong,
374
+ c_ulonglong,
375
+ POINTER(c_ulonglong),
376
+ c_ulonglong
377
+ ]
378
+
379
+ self.qrack_lib.MCAdjT.restype = None
380
+ self.qrack_lib.MCAdjT.argtypes = [
381
+ c_ulonglong,
382
+ c_ulonglong,
383
+ POINTER(c_ulonglong),
384
+ c_ulonglong
385
+ ]
386
+
387
+ self.qrack_lib.MCU.restype = None
388
+ self.qrack_lib.MCU.argtypes = [
389
+ c_ulonglong,
390
+ c_ulonglong,
391
+ POINTER(c_ulonglong),
392
+ c_ulonglong,
393
+ c_double,
394
+ c_double,
395
+ c_double
396
+ ]
397
+
398
+ self.qrack_lib.MCMtrx.restype = None
399
+ self.qrack_lib.MCMtrx.argtypes = [
400
+ c_ulonglong,
401
+ c_ulonglong,
402
+ POINTER(c_ulonglong),
403
+ POINTER(c_double),
404
+ c_ulonglong
405
+ ]
406
+
407
+ # multi-anti-controlled single-qubit gates
408
+
409
+ self.qrack_lib.MACX.restype = None
410
+ self.qrack_lib.MACX.argtypes = [
411
+ c_ulonglong,
412
+ c_ulonglong,
413
+ POINTER(c_ulonglong),
414
+ c_ulonglong
415
+ ]
416
+
417
+ self.qrack_lib.MACY.restype = None
418
+ self.qrack_lib.MACY.argtypes = [
419
+ c_ulonglong,
420
+ c_ulonglong,
421
+ POINTER(c_ulonglong),
422
+ c_ulonglong
423
+ ]
424
+
425
+ self.qrack_lib.MACZ.restype = None
426
+ self.qrack_lib.MACZ.argtypes = [
427
+ c_ulonglong,
428
+ c_ulonglong,
429
+ POINTER(c_ulonglong),
430
+ c_ulonglong
431
+ ]
432
+
433
+ self.qrack_lib.MACH.restype = None
434
+ self.qrack_lib.MACH.argtypes = [
435
+ c_ulonglong,
436
+ c_ulonglong,
437
+ POINTER(c_ulonglong),
438
+ c_ulonglong
439
+ ]
440
+
441
+ self.qrack_lib.MACS.restype = None
442
+ self.qrack_lib.MACS.argtypes = [
443
+ c_ulonglong,
444
+ c_ulonglong,
445
+ POINTER(c_ulonglong),
446
+ c_ulonglong
447
+ ]
448
+
449
+ self.qrack_lib.MACT.restype = None
450
+ self.qrack_lib.MACT.argtypes = [
451
+ c_ulonglong,
452
+ c_ulonglong,
453
+ POINTER(c_ulonglong),
454
+ c_ulonglong
455
+ ]
456
+
457
+ self.qrack_lib.MACAdjS.restype = None
458
+ self.qrack_lib.MACAdjS.argtypes = [
459
+ c_ulonglong,
460
+ c_ulonglong,
461
+ POINTER(c_ulonglong),
462
+ c_ulonglong
463
+ ]
464
+
465
+ self.qrack_lib.MACAdjT.restype = None
466
+ self.qrack_lib.MACAdjT.argtypes = [
467
+ c_ulonglong,
468
+ c_ulonglong,
469
+ POINTER(c_ulonglong),
470
+ c_ulonglong
471
+ ]
472
+
473
+ self.qrack_lib.MACU.restype = None
474
+ self.qrack_lib.MACU.argtypes = [
475
+ c_ulonglong,
476
+ c_ulonglong,
477
+ POINTER(c_ulonglong),
478
+ c_ulonglong,
479
+ c_double,
480
+ c_double,
481
+ c_double
482
+ ]
483
+
484
+ self.qrack_lib.MACMtrx.restype = None
485
+ self.qrack_lib.MACMtrx.argtypes = [
486
+ c_ulonglong,
487
+ c_ulonglong,
488
+ POINTER(c_ulonglong),
489
+ POINTER(c_double),
490
+ c_ulonglong
491
+ ]
492
+
493
+ self.qrack_lib.UCMtrx.restype = None
494
+ self.qrack_lib.UCMtrx.argtypes = [
495
+ c_ulonglong,
496
+ c_ulonglong,
497
+ POINTER(c_ulonglong),
498
+ POINTER(c_double),
499
+ c_ulonglong,
500
+ c_ulonglong
501
+ ]
502
+
503
+ self.qrack_lib.Multiplex1Mtrx.restype = None
504
+ self.qrack_lib.Multiplex1Mtrx.argtypes = [
505
+ c_ulonglong,
506
+ c_ulonglong,
507
+ POINTER(c_ulonglong),
508
+ c_ulonglong,
509
+ POINTER(c_double)
510
+ ]
511
+
512
+ # coalesced single qubit gates
513
+
514
+ self.qrack_lib.MX.restype = None
515
+ self.qrack_lib.MX.argtypes = [c_ulonglong, c_ulonglong, POINTER(c_ulonglong)]
516
+
517
+ self.qrack_lib.MY.restype = None
518
+ self.qrack_lib.MY.argtypes = [c_ulonglong, c_ulonglong, POINTER(c_ulonglong)]
519
+
520
+ self.qrack_lib.MZ.restype = None
521
+ self.qrack_lib.MZ.argtypes = [c_ulonglong, c_ulonglong, POINTER(c_ulonglong)]
522
+
523
+ # rotations
524
+
525
+ self.qrack_lib.R.restype = None
526
+ self.qrack_lib.R.argtypes = [c_ulonglong, c_ulonglong, c_double, c_ulonglong]
527
+
528
+ self.qrack_lib.MCR.restype = None
529
+ self.qrack_lib.MCR.argtypes = [
530
+ c_ulonglong,
531
+ c_ulonglong,
532
+ c_double,
533
+ c_ulonglong,
534
+ POINTER(c_ulonglong),
535
+ c_ulonglong
536
+ ]
537
+
538
+ # exponential of Pauli operators
539
+
540
+ self.qrack_lib.Exp.restype = None
541
+ self.qrack_lib.Exp.argtypes = [
542
+ c_ulonglong,
543
+ c_ulonglong,
544
+ POINTER(c_int),
545
+ c_double,
546
+ POINTER(c_ulonglong)
547
+ ]
548
+
549
+ self.qrack_lib.MCExp.restype = None
550
+ self.qrack_lib.MCExp.argtypes = [
551
+ c_ulonglong,
552
+ c_ulonglong,
553
+ POINTER(c_int),
554
+ c_double,
555
+ c_ulonglong,
556
+ POINTER(c_ulonglong),
557
+ POINTER(c_ulonglong)
558
+ ]
559
+
560
+ # measurements
561
+
562
+ self.qrack_lib.M.restype = c_ulonglong
563
+ self.qrack_lib.M.argtypes = [c_ulonglong, c_ulonglong]
564
+
565
+ self.qrack_lib.ForceM.restype = c_ulonglong
566
+ self.qrack_lib.ForceM.argtypes = [c_ulonglong, c_ulonglong, c_bool]
567
+
568
+ self.qrack_lib.MAll.restype = c_ulonglong
569
+ self.qrack_lib.MAll.argtypes = [c_ulonglong]
570
+
571
+ self.qrack_lib.Measure.restype = c_ulonglong
572
+ self.qrack_lib.Measure.argtypes = [
573
+ c_ulonglong,
574
+ c_ulonglong,
575
+ POINTER(c_int),
576
+ POINTER(c_ulonglong)
577
+ ]
578
+
579
+ self.qrack_lib.MeasureShots.restype = None
580
+ self.qrack_lib.MeasureShots.argtypes = [
581
+ c_ulonglong,
582
+ c_ulonglong,
583
+ POINTER(c_ulonglong),
584
+ c_ulonglong,
585
+ POINTER(c_ulonglong)
586
+ ]
587
+
588
+ # swap
589
+
590
+ self.qrack_lib.SWAP.restype = None
591
+ self.qrack_lib.SWAP.argtypes = [c_ulonglong, c_ulonglong, c_ulonglong]
592
+
593
+ self.qrack_lib.ISWAP.restype = None
594
+ self.qrack_lib.ISWAP.argtypes = [c_ulonglong, c_ulonglong, c_ulonglong]
595
+
596
+ self.qrack_lib.AdjISWAP.restype = None
597
+ self.qrack_lib.AdjISWAP.argtypes = [c_ulonglong, c_ulonglong, c_ulonglong]
598
+
599
+ self.qrack_lib.FSim.restype = None
600
+ self.qrack_lib.FSim.argtypes = [
601
+ c_ulonglong,
602
+ c_double,
603
+ c_double,
604
+ c_ulonglong,
605
+ c_ulonglong
606
+ ]
607
+
608
+ self.qrack_lib.CSWAP.restype = None
609
+ self.qrack_lib.CSWAP.argtypes = [
610
+ c_ulonglong,
611
+ c_ulonglong,
612
+ POINTER(c_ulonglong),
613
+ c_ulonglong,
614
+ c_ulonglong
615
+ ]
616
+
617
+ self.qrack_lib.ACSWAP.restype = None
618
+ self.qrack_lib.ACSWAP.argtypes = [
619
+ c_ulonglong,
620
+ c_ulonglong,
621
+ POINTER(c_ulonglong),
622
+ c_ulonglong,
623
+ c_ulonglong
624
+ ]
625
+
626
+ # Schmidt decomposition
627
+
628
+ self.qrack_lib.Compose.restype = None
629
+ self.qrack_lib.Compose.argtypes = [
630
+ c_ulonglong,
631
+ c_ulonglong,
632
+ POINTER(c_ulonglong)
633
+ ]
634
+
635
+ self.qrack_lib.Decompose.restype = c_ulonglong
636
+ self.qrack_lib.Decompose.argtypes = [
637
+ c_ulonglong,
638
+ c_ulonglong,
639
+ POINTER(c_ulonglong)
640
+ ]
641
+
642
+ self.qrack_lib.Dispose.restype = None
643
+ self.qrack_lib.Dispose.argtypes = [
644
+ c_ulonglong,
645
+ c_ulonglong,
646
+ POINTER(c_ulonglong)
647
+ ]
648
+
649
+ # (quasi-)Boolean gates
650
+
651
+ self.qrack_lib.AND.restype = None
652
+ self.qrack_lib.AND.argtypes = [
653
+ c_ulonglong,
654
+ c_ulonglong,
655
+ c_ulonglong,
656
+ c_ulonglong
657
+ ]
658
+
659
+ self.qrack_lib.OR.restype = None
660
+ self.qrack_lib.OR.argtypes = [
661
+ c_ulonglong,
662
+ c_ulonglong,
663
+ c_ulonglong,
664
+ c_ulonglong
665
+ ]
666
+
667
+ self.qrack_lib.XOR.restype = None
668
+ self.qrack_lib.XOR.argtypes = [
669
+ c_ulonglong,
670
+ c_ulonglong,
671
+ c_ulonglong,
672
+ c_ulonglong
673
+ ]
674
+
675
+ self.qrack_lib.NAND.restype = None
676
+ self.qrack_lib.NAND.argtypes = [
677
+ c_ulonglong,
678
+ c_ulonglong,
679
+ c_ulonglong,
680
+ c_ulonglong
681
+ ]
682
+
683
+ self.qrack_lib.NOR.restype = None
684
+ self.qrack_lib.NOR.argtypes = [
685
+ c_ulonglong,
686
+ c_ulonglong,
687
+ c_ulonglong,
688
+ c_ulonglong
689
+ ]
690
+
691
+ self.qrack_lib.XNOR.restype = None
692
+ self.qrack_lib.XNOR.argtypes = [
693
+ c_ulonglong,
694
+ c_ulonglong,
695
+ c_ulonglong,
696
+ c_ulonglong
697
+ ]
698
+
699
+ # half classical (quasi-)Boolean gates
700
+
701
+ self.qrack_lib.CLAND.restype = None
702
+ self.qrack_lib.CLAND.argtypes = [c_ulonglong, c_bool, c_ulonglong, c_ulonglong]
703
+
704
+ self.qrack_lib.CLOR.restype = None
705
+ self.qrack_lib.CLOR.argtypes = [c_ulonglong, c_bool, c_ulonglong, c_ulonglong]
706
+
707
+ self.qrack_lib.CLXOR.restype = None
708
+ self.qrack_lib.CLXOR.argtypes = [c_ulonglong, c_bool, c_ulonglong, c_ulonglong]
709
+
710
+ self.qrack_lib.CLNAND.restype = None
711
+ self.qrack_lib.CLNAND.argtypes = [c_ulonglong, c_bool, c_ulonglong, c_ulonglong]
712
+
713
+ self.qrack_lib.CLNOR.restype = None
714
+ self.qrack_lib.CLNOR.argtypes = [c_ulonglong, c_bool, c_ulonglong, c_ulonglong]
715
+
716
+ self.qrack_lib.CLXNOR.restype = None
717
+ self.qrack_lib.CLXNOR.argtypes = [c_ulonglong, c_bool, c_ulonglong, c_ulonglong]
718
+
719
+ # Fourier transform
720
+
721
+ self.qrack_lib.QFT.restype = None
722
+ self.qrack_lib.QFT.argtypes = [c_ulonglong, c_ulonglong, POINTER(c_ulonglong)]
723
+
724
+ self.qrack_lib.IQFT.restype = None
725
+ self.qrack_lib.IQFT.argtypes = [c_ulonglong, c_ulonglong, POINTER(c_ulonglong)]
726
+
727
+ # Arithmetic-Logic-Unit (ALU)
728
+
729
+ self.qrack_lib.ADD.restype = None
730
+ self.qrack_lib.ADD.argtypes = [
731
+ c_ulonglong,
732
+ c_ulonglong,
733
+ POINTER(c_ulonglong),
734
+ c_ulonglong,
735
+ POINTER(c_ulonglong)
736
+ ]
737
+
738
+ self.qrack_lib.SUB.restype = None
739
+ self.qrack_lib.SUB.argtypes = [
740
+ c_ulonglong,
741
+ c_ulonglong,
742
+ POINTER(c_ulonglong),
743
+ c_ulonglong,
744
+ POINTER(c_ulonglong)
745
+ ]
746
+
747
+ self.qrack_lib.ADDS.restype = None
748
+ self.qrack_lib.ADDS.argtypes = [
749
+ c_ulonglong,
750
+ c_ulonglong,
751
+ POINTER(c_ulonglong),
752
+ c_ulonglong,
753
+ c_ulonglong,
754
+ POINTER(c_ulonglong)
755
+ ]
756
+
757
+ self.qrack_lib.SUBS.restype = None
758
+ self.qrack_lib.SUBS.argtypes = [
759
+ c_ulonglong,
760
+ c_ulonglong,
761
+ POINTER(c_ulonglong),
762
+ c_ulonglong,
763
+ c_ulonglong,
764
+ POINTER(c_ulonglong)
765
+ ]
766
+
767
+ self.qrack_lib.MUL.restype = None
768
+ self.qrack_lib.MUL.argtypes = [
769
+ c_ulonglong,
770
+ c_ulonglong,
771
+ POINTER(c_ulonglong),
772
+ c_ulonglong,
773
+ POINTER(c_ulonglong),
774
+ POINTER(c_ulonglong)
775
+ ]
776
+
777
+ self.qrack_lib.DIV.restype = None
778
+ self.qrack_lib.DIV.argtypes = [
779
+ c_ulonglong,
780
+ c_ulonglong,
781
+ POINTER(c_ulonglong),
782
+ c_ulonglong,
783
+ POINTER(c_ulonglong),
784
+ POINTER(c_ulonglong)
785
+ ]
786
+
787
+ self.qrack_lib.MULN.restype = None
788
+ self.qrack_lib.MULN.argtypes = [
789
+ c_ulonglong,
790
+ c_ulonglong,
791
+ POINTER(c_ulonglong),
792
+ POINTER(c_ulonglong),
793
+ c_ulonglong,
794
+ POINTER(c_ulonglong),
795
+ POINTER(c_ulonglong)
796
+ ]
797
+
798
+ self.qrack_lib.DIVN.restype = None
799
+ self.qrack_lib.DIVN.argtypes = [
800
+ c_ulonglong,
801
+ c_ulonglong,
802
+ POINTER(c_ulonglong),
803
+ POINTER(c_ulonglong),
804
+ c_ulonglong,
805
+ POINTER(c_ulonglong),
806
+ POINTER(c_ulonglong)
807
+ ]
808
+
809
+ self.qrack_lib.POWN.restype = None
810
+ self.qrack_lib.POWN.argtypes = [
811
+ c_ulonglong,
812
+ c_ulonglong,
813
+ POINTER(c_ulonglong),
814
+ POINTER(c_ulonglong),
815
+ c_ulonglong,
816
+ POINTER(c_ulonglong),
817
+ POINTER(c_ulonglong)
818
+ ]
819
+
820
+ self.qrack_lib.MCADD.restype = None
821
+ self.qrack_lib.MCADD.argtypes = [
822
+ c_ulonglong,
823
+ c_ulonglong,
824
+ POINTER(c_ulonglong),
825
+ c_ulonglong,
826
+ POINTER(c_ulonglong),
827
+ c_ulonglong,
828
+ POINTER(c_ulonglong)
829
+ ]
830
+
831
+ self.qrack_lib.MCSUB.restype = None
832
+ self.qrack_lib.MCSUB.argtypes = [
833
+ c_ulonglong,
834
+ c_ulonglong,
835
+ POINTER(c_ulonglong),
836
+ c_ulonglong,
837
+ POINTER(c_ulonglong),
838
+ c_ulonglong,
839
+ POINTER(c_ulonglong)
840
+ ]
841
+
842
+ self.qrack_lib.MCMUL.restype = None
843
+ self.qrack_lib.MCMUL.argtypes = [
844
+ c_ulonglong,
845
+ c_ulonglong,
846
+ POINTER(c_ulonglong),
847
+ c_ulonglong,
848
+ POINTER(c_ulonglong),
849
+ c_ulonglong,
850
+ POINTER(c_ulonglong)
851
+ ]
852
+
853
+ self.qrack_lib.MCDIV.restype = None
854
+ self.qrack_lib.MCDIV.argtypes = [
855
+ c_ulonglong,
856
+ c_ulonglong,
857
+ POINTER(c_ulonglong),
858
+ c_ulonglong,
859
+ POINTER(c_ulonglong),
860
+ c_ulonglong,
861
+ POINTER(c_ulonglong)
862
+ ]
863
+
864
+ self.qrack_lib.MCMULN.restype = None
865
+ self.qrack_lib.MCMULN.argtypes = [
866
+ c_ulonglong,
867
+ c_ulonglong,
868
+ POINTER(c_ulonglong),
869
+ c_ulonglong,
870
+ POINTER(c_ulonglong),
871
+ POINTER(c_ulonglong),
872
+ c_ulonglong,
873
+ POINTER(c_ulonglong),
874
+ POINTER(c_ulonglong)
875
+ ]
876
+
877
+ self.qrack_lib.MCDIVN.restype = None
878
+ self.qrack_lib.MCDIVN.argtypes = [
879
+ c_ulonglong,
880
+ c_ulonglong,
881
+ POINTER(c_ulonglong),
882
+ c_ulonglong,
883
+ POINTER(c_ulonglong),
884
+ POINTER(c_ulonglong),
885
+ c_ulonglong,
886
+ POINTER(c_ulonglong),
887
+ POINTER(c_ulonglong)
888
+ ]
889
+
890
+ self.qrack_lib.MCPOWN.restype = None
891
+ self.qrack_lib.MCPOWN.argtypes = [
892
+ c_ulonglong,
893
+ c_ulonglong,
894
+ POINTER(c_ulonglong),
895
+ c_ulonglong,
896
+ POINTER(c_ulonglong),
897
+ POINTER(c_ulonglong),
898
+ c_ulonglong,
899
+ POINTER(c_ulonglong),
900
+ POINTER(c_ulonglong)
901
+ ]
902
+
903
+ self.qrack_lib.LDA.restype = None
904
+ self.qrack_lib.LDA.argType = [
905
+ c_ulonglong,
906
+ c_ulonglong,
907
+ POINTER(c_ulonglong),
908
+ c_ulonglong,
909
+ POINTER(c_ulonglong),
910
+ POINTER(c_ubyte)
911
+ ]
912
+
913
+ self.qrack_lib.ADC.restype = None
914
+ self.qrack_lib.ADC.argType = [
915
+ c_ulonglong,
916
+ c_ulonglong,
917
+ c_ulonglong,
918
+ POINTER(c_ulonglong),
919
+ c_ulonglong,
920
+ POINTER(c_ulonglong),
921
+ POINTER(c_ubyte)
922
+ ]
923
+
924
+ self.qrack_lib.SBC.restype = None
925
+ self.qrack_lib.SBC.argType = [
926
+ c_ulonglong,
927
+ c_ulonglong,
928
+ c_ulonglong,
929
+ POINTER(c_ulonglong),
930
+ c_ulonglong,
931
+ POINTER(c_ulonglong),
932
+ POINTER(c_ubyte)
933
+ ]
934
+
935
+ self.qrack_lib.Hash.restype = None
936
+ self.qrack_lib.Hash.argType = [
937
+ c_ulonglong,
938
+ c_ulonglong,
939
+ POINTER(c_ulonglong),
940
+ POINTER(c_ubyte)
941
+ ]
942
+
943
+ # miscellaneous
944
+
945
+ self.qrack_lib.TrySeparate1Qb.restype = c_bool
946
+ self.qrack_lib.TrySeparate1Qb.argtypes = [c_ulonglong, c_ulonglong]
947
+
948
+ self.qrack_lib.TrySeparate2Qb.restype = c_bool
949
+ self.qrack_lib.TrySeparate2Qb.argtypes = [c_ulonglong, c_ulonglong, c_ulonglong]
950
+
951
+ self.qrack_lib.TrySeparateTol.restype = c_bool
952
+ self.qrack_lib.TrySeparateTol.argtypes = [
953
+ c_ulonglong,
954
+ c_ulonglong,
955
+ POINTER(c_ulonglong),
956
+ c_double
957
+ ]
958
+
959
+ self.qrack_lib.GetUnitaryFidelity.restype = c_double
960
+ self.qrack_lib.GetUnitaryFidelity.argtypes = [c_ulonglong]
961
+
962
+ self.qrack_lib.ResetUnitaryFidelity.restype = None
963
+ self.qrack_lib.ResetUnitaryFidelity.argtypes = [c_ulonglong]
964
+
965
+ self.qrack_lib.SetSdrp.restype = None
966
+ self.qrack_lib.SetSdrp.argtypes = [c_ulonglong, c_double]
967
+
968
+ self.qrack_lib.SetNcrp.restype = None
969
+ self.qrack_lib.SetNcrp.argtypes = [c_ulonglong, c_double]
970
+
971
+ self.qrack_lib.SetReactiveSeparate.restype = c_bool
972
+ self.qrack_lib.SetReactiveSeparate.argtypes = [c_ulonglong, c_bool]
973
+
974
+ self.qrack_lib.SetTInjection.restype = c_bool
975
+ self.qrack_lib.SetTInjection.argtypes = [c_ulonglong, c_bool]
976
+
977
+ self.qrack_lib.qstabilizer_out_to_file.restype = None
978
+ self.qrack_lib.qstabilizer_out_to_file.argtypes = [c_ulonglong, c_char_p]
979
+
980
+ self.qrack_lib.qstabilizer_in_from_file.restype = None
981
+ self.qrack_lib.qstabilizer_in_from_file.argtypes = [c_ulonglong, c_char_p]
982
+
983
+ self.qrack_lib.init_qneuron.restype = c_ulonglong
984
+ self.qrack_lib.init_qneuron.argtypes = [c_ulonglong, c_ulonglong, POINTER(c_ulonglong), c_ulonglong, c_ulonglong, c_double, c_double]
985
+
986
+ self.qrack_lib.clone_qneuron.restype = c_ulonglong
987
+ self.qrack_lib.clone_qneuron.argtypes = [c_ulonglong]
988
+
989
+ self.qrack_lib.destroy_qneuron.restype = None
990
+ self.qrack_lib.destroy_qneuron.argtypes = [c_ulonglong]
991
+
992
+ self.qrack_lib.set_qneuron_angles.restype = None
993
+ self.qrack_lib.get_qneuron_angles.restype = None
994
+
995
+ if self.fppow == 5:
996
+ self.qrack_lib.set_qneuron_angles.argtypes = [c_ulonglong, POINTER(c_float)]
997
+ self.qrack_lib.get_qneuron_angles.argtypes = [c_ulonglong, POINTER(c_float)]
998
+ elif self.fppow == 6:
999
+ self.qrack_lib.set_qneuron_angles.argtypes = [c_ulonglong, POINTER(c_double)]
1000
+ self.qrack_lib.get_qneuron_angles.argtypes = [c_ulonglong, POINTER(c_double)]
1001
+
1002
+ self.qrack_lib.set_qneuron_alpha.restype = None
1003
+ self.qrack_lib.set_qneuron_alpha.argtypes = [c_ulonglong, c_double]
1004
+
1005
+ self.qrack_lib.get_qneuron_alpha.restype = c_double
1006
+ self.qrack_lib.get_qneuron_alpha.argtypes = [c_ulonglong]
1007
+
1008
+ self.qrack_lib.set_qneuron_activation_fn.restype = None
1009
+ self.qrack_lib.set_qneuron_activation_fn.argtypes = [c_ulonglong, c_ulonglong]
1010
+
1011
+ self.qrack_lib.get_qneuron_activation_fn.restype = c_ulonglong
1012
+ self.qrack_lib.get_qneuron_activation_fn.argtypes = [c_ulonglong]
1013
+
1014
+ self.qrack_lib.qneuron_predict.restype = c_double
1015
+ self.qrack_lib.qneuron_predict.argtypes = [c_ulonglong, c_bool, c_bool]
1016
+
1017
+ self.qrack_lib.qneuron_unpredict.restype = c_double
1018
+ self.qrack_lib.qneuron_unpredict.argtypes = [c_ulonglong, c_bool]
1019
+
1020
+ self.qrack_lib.qneuron_learn_cycle.restype = c_double
1021
+ self.qrack_lib.qneuron_learn_cycle.argtypes = [c_ulonglong, c_bool]
1022
+
1023
+ self.qrack_lib.qneuron_learn.restype = None
1024
+ self.qrack_lib.qneuron_learn.argtypes = [c_ulonglong, c_double, c_bool, c_bool]
1025
+
1026
+ self.qrack_lib.qneuron_learn_permutation.restype = None
1027
+ self.qrack_lib.qneuron_learn_permutation.argtypes = [c_ulonglong, c_double, c_bool, c_bool]
1028
+
1029
+ self.qrack_lib.init_qcircuit.restype = c_ulonglong
1030
+ self.qrack_lib.init_qcircuit.argtypes = [c_bool, c_bool]
1031
+
1032
+ self.qrack_lib.init_qcircuit_clone.restype = c_ulonglong
1033
+ self.qrack_lib.init_qcircuit_clone.argtypes = [c_ulonglong]
1034
+
1035
+ self.qrack_lib.qcircuit_inverse.restype = c_ulonglong
1036
+ self.qrack_lib.qcircuit_inverse.argtypes = [c_ulonglong]
1037
+
1038
+ self.qrack_lib.qcircuit_past_light_cone.restype = c_ulonglong
1039
+ self.qrack_lib.qcircuit_past_light_cone.argtypes = [c_ulonglong, c_ulonglong, POINTER(c_ulonglong)]
1040
+
1041
+ self.qrack_lib.destroy_qcircuit.restype = None
1042
+ self.qrack_lib.destroy_qcircuit.argtypes = [c_ulonglong]
1043
+
1044
+ self.qrack_lib.get_qcircuit_qubit_count.restype = c_ulonglong
1045
+ self.qrack_lib.get_qcircuit_qubit_count.argtypes = [c_ulonglong]
1046
+
1047
+ self.qrack_lib.qcircuit_swap.restype = None
1048
+ self.qrack_lib.qcircuit_swap.argtypes = [c_ulonglong, c_ulonglong, c_ulonglong]
1049
+
1050
+ self.qrack_lib.qcircuit_append_1qb.restype = None
1051
+ self.qrack_lib.qcircuit_append_1qb.argtypes = [c_ulonglong, POINTER(c_double), c_ulonglong]
1052
+
1053
+ self.qrack_lib.qcircuit_append_mc.restype = None
1054
+ self.qrack_lib.qcircuit_append_mc.argtypes = [c_ulonglong, POINTER(c_double), c_ulonglong, POINTER(c_ulonglong), c_ulonglong, c_ulonglong]
1055
+
1056
+ self.qrack_lib.qcircuit_run.restype = None
1057
+ self.qrack_lib.qcircuit_run.argtypes = [c_ulonglong, c_ulonglong]
1058
+
1059
+ self.qrack_lib.qcircuit_out_to_file.restype = None
1060
+ self.qrack_lib.qcircuit_out_to_file.argtypes = [c_ulonglong, c_char_p]
1061
+
1062
+ self.qrack_lib.qcircuit_in_from_file.restype = None
1063
+ self.qrack_lib.qcircuit_in_from_file.argtypes = [c_ulonglong, c_char_p]