pyqrack-cpu-complex128 1.71.1__py3-none-win_amd64.whl → 1.78.3__py3-none-win_amd64.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.
- pyqrack/__init__.py +3 -2
- pyqrack/qrack_ace_backend.py +28 -24
- pyqrack/qrack_circuit.py +49 -34
- pyqrack/qrack_neuron.py +93 -5
- pyqrack/qrack_neuron_torch_layer.py +294 -104
- pyqrack/qrack_simulator.py +232 -183
- pyqrack/qrack_system/qrack_lib/qrack_pinvoke.dll +0 -0
- pyqrack/qrack_system/qrack_system.py +6 -0
- {pyqrack_cpu_complex128-1.71.1.dist-info → pyqrack_cpu_complex128-1.78.3.dist-info}/METADATA +2 -4
- pyqrack_cpu_complex128-1.78.3.dist-info/RECORD +21 -0
- pyqrack_cpu_complex128-1.71.1.dist-info/RECORD +0 -21
- {pyqrack_cpu_complex128-1.71.1.dist-info → pyqrack_cpu_complex128-1.78.3.dist-info}/LICENSE +0 -0
- {pyqrack_cpu_complex128-1.71.1.dist-info → pyqrack_cpu_complex128-1.78.3.dist-info}/WHEEL +0 -0
- {pyqrack_cpu_complex128-1.71.1.dist-info → pyqrack_cpu_complex128-1.78.3.dist-info}/top_level.txt +0 -0
pyqrack/qrack_simulator.py
CHANGED
|
@@ -118,36 +118,45 @@ class QrackSimulator:
|
|
|
118
118
|
Qrack.qrack_lib.destroy(self.sid)
|
|
119
119
|
self.sid = None
|
|
120
120
|
|
|
121
|
-
|
|
121
|
+
@staticmethod
|
|
122
|
+
def _int_byref(a):
|
|
122
123
|
return (ctypes.c_int * len(a))(*a)
|
|
123
124
|
|
|
124
|
-
|
|
125
|
+
@staticmethod
|
|
126
|
+
def _ulonglong_byref(a):
|
|
125
127
|
return (ctypes.c_ulonglong * len(a))(*a)
|
|
126
128
|
|
|
127
|
-
|
|
129
|
+
@staticmethod
|
|
130
|
+
def _longlong_byref(a):
|
|
128
131
|
return (ctypes.c_longlong * len(a))(*a)
|
|
129
132
|
|
|
130
|
-
|
|
133
|
+
@staticmethod
|
|
134
|
+
def _double_byref(a):
|
|
131
135
|
return (ctypes.c_double * len(a))(*a)
|
|
132
136
|
|
|
133
|
-
|
|
137
|
+
@staticmethod
|
|
138
|
+
def _complex_byref(a):
|
|
134
139
|
t = [(c.real, c.imag) for c in a]
|
|
135
|
-
return
|
|
140
|
+
return QrackSimulator._double_byref([float(item) for sublist in t for item in sublist])
|
|
136
141
|
|
|
137
|
-
|
|
142
|
+
@staticmethod
|
|
143
|
+
def _real1_byref(a):
|
|
138
144
|
# This needs to be c_double, if PyQrack is built with fp64.
|
|
139
145
|
if Qrack.fppow < 6:
|
|
140
146
|
return (ctypes.c_float * len(a))(*a)
|
|
141
147
|
return (ctypes.c_double * len(a))(*a)
|
|
142
148
|
|
|
143
|
-
|
|
149
|
+
@staticmethod
|
|
150
|
+
def _bool_byref(a):
|
|
144
151
|
return (ctypes.c_bool * len(a))(*a)
|
|
145
152
|
|
|
146
|
-
|
|
153
|
+
@staticmethod
|
|
154
|
+
def _qrack_complex_byref(a):
|
|
147
155
|
t = [(c.real, c.imag) for c in a]
|
|
148
|
-
return
|
|
156
|
+
return QrackSimulator._real1_byref([float(item) for sublist in t for item in sublist])
|
|
149
157
|
|
|
150
|
-
|
|
158
|
+
@staticmethod
|
|
159
|
+
def _to_ubyte(nv, v):
|
|
151
160
|
c = math.floor((nv - 1) / 8) + 1
|
|
152
161
|
b = (ctypes.c_ubyte * (c * (1 << nv)))()
|
|
153
162
|
n = 0
|
|
@@ -159,7 +168,8 @@ class QrackSimulator:
|
|
|
159
168
|
|
|
160
169
|
return b
|
|
161
170
|
|
|
162
|
-
|
|
171
|
+
@staticmethod
|
|
172
|
+
def _to_ulonglong(m, v):
|
|
163
173
|
b = (ctypes.c_ulonglong * (m * len(v)))()
|
|
164
174
|
n = 0
|
|
165
175
|
for u in v:
|
|
@@ -171,7 +181,8 @@ class QrackSimulator:
|
|
|
171
181
|
return b
|
|
172
182
|
|
|
173
183
|
# See https://stackoverflow.com/questions/5389507/iterating-over-every-two-elements-in-a-list#answer-30426000
|
|
174
|
-
|
|
184
|
+
@staticmethod
|
|
185
|
+
def _pairwise(it):
|
|
175
186
|
it = iter(it)
|
|
176
187
|
while True:
|
|
177
188
|
try:
|
|
@@ -197,7 +208,7 @@ class QrackSimulator:
|
|
|
197
208
|
|
|
198
209
|
def set_device_list(self, d):
|
|
199
210
|
"""Set the GPU device ID"""
|
|
200
|
-
Qrack.qrack_lib.set_device_list(self.sid, len(d),
|
|
211
|
+
Qrack.qrack_lib.set_device_list(self.sid, len(d), QrackSimulator._longlong_byref(d))
|
|
201
212
|
self._throw_if_error()
|
|
202
213
|
|
|
203
214
|
def clone(self):
|
|
@@ -361,7 +372,7 @@ class QrackSimulator:
|
|
|
361
372
|
raise ValueError(
|
|
362
373
|
"2x2 matrix 'm' in QrackSimulator.mtrx() must contain at least 4 elements."
|
|
363
374
|
)
|
|
364
|
-
Qrack.qrack_lib.Mtrx(self.sid,
|
|
375
|
+
Qrack.qrack_lib.Mtrx(self.sid, QrackSimulator._complex_byref(m), q)
|
|
365
376
|
self._throw_if_error()
|
|
366
377
|
|
|
367
378
|
def r(self, b, ph, q):
|
|
@@ -401,9 +412,9 @@ class QrackSimulator:
|
|
|
401
412
|
Qrack.qrack_lib.Exp(
|
|
402
413
|
self.sid,
|
|
403
414
|
len(b),
|
|
404
|
-
|
|
415
|
+
QrackSimulator._ulonglong_byref(b),
|
|
405
416
|
ctypes.c_double(ph),
|
|
406
|
-
|
|
417
|
+
QrackSimulator._ulonglong_byref(q),
|
|
407
418
|
)
|
|
408
419
|
self._throw_if_error()
|
|
409
420
|
|
|
@@ -420,7 +431,7 @@ class QrackSimulator:
|
|
|
420
431
|
Raises:
|
|
421
432
|
RuntimeError: QrackSimulator raised an exception.
|
|
422
433
|
"""
|
|
423
|
-
Qrack.qrack_lib.MCX(self.sid, len(c),
|
|
434
|
+
Qrack.qrack_lib.MCX(self.sid, len(c), QrackSimulator._ulonglong_byref(c), q)
|
|
424
435
|
self._throw_if_error()
|
|
425
436
|
|
|
426
437
|
def mcy(self, c, q):
|
|
@@ -436,7 +447,7 @@ class QrackSimulator:
|
|
|
436
447
|
Raises:
|
|
437
448
|
RuntimeError: QrackSimulator raised an exception.
|
|
438
449
|
"""
|
|
439
|
-
Qrack.qrack_lib.MCY(self.sid, len(c),
|
|
450
|
+
Qrack.qrack_lib.MCY(self.sid, len(c), QrackSimulator._ulonglong_byref(c), q)
|
|
440
451
|
self._throw_if_error()
|
|
441
452
|
|
|
442
453
|
def mcz(self, c, q):
|
|
@@ -452,7 +463,7 @@ class QrackSimulator:
|
|
|
452
463
|
Raises:
|
|
453
464
|
RuntimeError: QrackSimulator raised an exception.
|
|
454
465
|
"""
|
|
455
|
-
Qrack.qrack_lib.MCZ(self.sid, len(c),
|
|
466
|
+
Qrack.qrack_lib.MCZ(self.sid, len(c), QrackSimulator._ulonglong_byref(c), q)
|
|
456
467
|
self._throw_if_error()
|
|
457
468
|
|
|
458
469
|
def mch(self, c, q):
|
|
@@ -468,7 +479,7 @@ class QrackSimulator:
|
|
|
468
479
|
Raises:
|
|
469
480
|
RuntimeError: QrackSimulator raised an exception.
|
|
470
481
|
"""
|
|
471
|
-
Qrack.qrack_lib.MCH(self.sid, len(c),
|
|
482
|
+
Qrack.qrack_lib.MCH(self.sid, len(c), QrackSimulator._ulonglong_byref(c), q)
|
|
472
483
|
self._throw_if_error()
|
|
473
484
|
|
|
474
485
|
def mcs(self, c, q):
|
|
@@ -484,7 +495,7 @@ class QrackSimulator:
|
|
|
484
495
|
Raises:
|
|
485
496
|
RuntimeError: QrackSimulator raised an exception.
|
|
486
497
|
"""
|
|
487
|
-
Qrack.qrack_lib.MCS(self.sid, len(c),
|
|
498
|
+
Qrack.qrack_lib.MCS(self.sid, len(c), QrackSimulator._ulonglong_byref(c), q)
|
|
488
499
|
self._throw_if_error()
|
|
489
500
|
|
|
490
501
|
def mct(self, c, q):
|
|
@@ -500,7 +511,7 @@ class QrackSimulator:
|
|
|
500
511
|
Raises:
|
|
501
512
|
RuntimeError: QrackSimulator raised an exception.
|
|
502
513
|
"""
|
|
503
|
-
Qrack.qrack_lib.MCT(self.sid, len(c),
|
|
514
|
+
Qrack.qrack_lib.MCT(self.sid, len(c), QrackSimulator._ulonglong_byref(c), q)
|
|
504
515
|
self._throw_if_error()
|
|
505
516
|
|
|
506
517
|
def mcadjs(self, c, q):
|
|
@@ -516,7 +527,7 @@ class QrackSimulator:
|
|
|
516
527
|
Raises:
|
|
517
528
|
RuntimeError: QrackSimulator raised an exception.
|
|
518
529
|
"""
|
|
519
|
-
Qrack.qrack_lib.MCAdjS(self.sid, len(c),
|
|
530
|
+
Qrack.qrack_lib.MCAdjS(self.sid, len(c), QrackSimulator._ulonglong_byref(c), q)
|
|
520
531
|
self._throw_if_error()
|
|
521
532
|
|
|
522
533
|
def mcadjt(self, c, q):
|
|
@@ -532,7 +543,7 @@ class QrackSimulator:
|
|
|
532
543
|
Raises:
|
|
533
544
|
RuntimeError: QrackSimulator raised an exception.
|
|
534
545
|
"""
|
|
535
|
-
Qrack.qrack_lib.MCAdjT(self.sid, len(c),
|
|
546
|
+
Qrack.qrack_lib.MCAdjT(self.sid, len(c), QrackSimulator._ulonglong_byref(c), q)
|
|
536
547
|
self._throw_if_error()
|
|
537
548
|
|
|
538
549
|
def mcu(self, c, q, th, ph, la):
|
|
@@ -554,7 +565,7 @@ class QrackSimulator:
|
|
|
554
565
|
Qrack.qrack_lib.MCU(
|
|
555
566
|
self.sid,
|
|
556
567
|
len(c),
|
|
557
|
-
|
|
568
|
+
QrackSimulator._ulonglong_byref(c),
|
|
558
569
|
q,
|
|
559
570
|
ctypes.c_double(th),
|
|
560
571
|
ctypes.c_double(ph),
|
|
@@ -582,7 +593,7 @@ class QrackSimulator:
|
|
|
582
593
|
"2x2 matrix 'm' in QrackSimulator.mcmtrx() must contain at least 4 elements."
|
|
583
594
|
)
|
|
584
595
|
Qrack.qrack_lib.MCMtrx(
|
|
585
|
-
self.sid, len(c),
|
|
596
|
+
self.sid, len(c), QrackSimulator._ulonglong_byref(c), QrackSimulator._complex_byref(m), q
|
|
586
597
|
)
|
|
587
598
|
self._throw_if_error()
|
|
588
599
|
|
|
@@ -598,7 +609,7 @@ class QrackSimulator:
|
|
|
598
609
|
Raises:
|
|
599
610
|
RuntimeError: QrackSimulator raised an exception.
|
|
600
611
|
"""
|
|
601
|
-
Qrack.qrack_lib.MACX(self.sid, len(c),
|
|
612
|
+
Qrack.qrack_lib.MACX(self.sid, len(c), QrackSimulator._ulonglong_byref(c), q)
|
|
602
613
|
self._throw_if_error()
|
|
603
614
|
|
|
604
615
|
def macy(self, c, q):
|
|
@@ -614,7 +625,7 @@ class QrackSimulator:
|
|
|
614
625
|
Raises:
|
|
615
626
|
RuntimeError: QrackSimulator raised an exception.
|
|
616
627
|
"""
|
|
617
|
-
Qrack.qrack_lib.MACY(self.sid, len(c),
|
|
628
|
+
Qrack.qrack_lib.MACY(self.sid, len(c), QrackSimulator._ulonglong_byref(c), q)
|
|
618
629
|
self._throw_if_error()
|
|
619
630
|
|
|
620
631
|
def macz(self, c, q):
|
|
@@ -630,7 +641,7 @@ class QrackSimulator:
|
|
|
630
641
|
Raises:
|
|
631
642
|
RuntimeError: QrackSimulator raised an exception.
|
|
632
643
|
"""
|
|
633
|
-
Qrack.qrack_lib.MACZ(self.sid, len(c),
|
|
644
|
+
Qrack.qrack_lib.MACZ(self.sid, len(c), QrackSimulator._ulonglong_byref(c), q)
|
|
634
645
|
self._throw_if_error()
|
|
635
646
|
|
|
636
647
|
def mach(self, c, q):
|
|
@@ -646,7 +657,7 @@ class QrackSimulator:
|
|
|
646
657
|
Raises:
|
|
647
658
|
RuntimeError: QrackSimulator raised an exception.
|
|
648
659
|
"""
|
|
649
|
-
Qrack.qrack_lib.MACH(self.sid, len(c),
|
|
660
|
+
Qrack.qrack_lib.MACH(self.sid, len(c), QrackSimulator._ulonglong_byref(c), q)
|
|
650
661
|
self._throw_if_error()
|
|
651
662
|
|
|
652
663
|
def macs(self, c, q):
|
|
@@ -662,7 +673,7 @@ class QrackSimulator:
|
|
|
662
673
|
Raises:
|
|
663
674
|
RuntimeError: QrackSimulator raised an exception.
|
|
664
675
|
"""
|
|
665
|
-
Qrack.qrack_lib.MACS(self.sid, len(c),
|
|
676
|
+
Qrack.qrack_lib.MACS(self.sid, len(c), QrackSimulator._ulonglong_byref(c), q)
|
|
666
677
|
self._throw_if_error()
|
|
667
678
|
|
|
668
679
|
def mact(self, c, q):
|
|
@@ -678,7 +689,7 @@ class QrackSimulator:
|
|
|
678
689
|
Raises:
|
|
679
690
|
RuntimeError: QrackSimulator raised an exception.
|
|
680
691
|
"""
|
|
681
|
-
Qrack.qrack_lib.MACT(self.sid, len(c),
|
|
692
|
+
Qrack.qrack_lib.MACT(self.sid, len(c), QrackSimulator._ulonglong_byref(c), q)
|
|
682
693
|
self._throw_if_error()
|
|
683
694
|
|
|
684
695
|
def macadjs(self, c, q):
|
|
@@ -694,7 +705,7 @@ class QrackSimulator:
|
|
|
694
705
|
Raises:
|
|
695
706
|
RuntimeError: QrackSimulator raised an exception.
|
|
696
707
|
"""
|
|
697
|
-
Qrack.qrack_lib.MACAdjS(self.sid, len(c),
|
|
708
|
+
Qrack.qrack_lib.MACAdjS(self.sid, len(c), QrackSimulator._ulonglong_byref(c), q)
|
|
698
709
|
self._throw_if_error()
|
|
699
710
|
|
|
700
711
|
def macadjt(self, c, q):
|
|
@@ -710,7 +721,7 @@ class QrackSimulator:
|
|
|
710
721
|
Raises:
|
|
711
722
|
RuntimeError: QrackSimulator raised an exception.
|
|
712
723
|
"""
|
|
713
|
-
Qrack.qrack_lib.MACAdjT(self.sid, len(c),
|
|
724
|
+
Qrack.qrack_lib.MACAdjT(self.sid, len(c), QrackSimulator._ulonglong_byref(c), q)
|
|
714
725
|
self._throw_if_error()
|
|
715
726
|
|
|
716
727
|
def macu(self, c, q, th, ph, la):
|
|
@@ -732,7 +743,7 @@ class QrackSimulator:
|
|
|
732
743
|
Qrack.qrack_lib.MACU(
|
|
733
744
|
self.sid,
|
|
734
745
|
len(c),
|
|
735
|
-
|
|
746
|
+
QrackSimulator._ulonglong_byref(c),
|
|
736
747
|
q,
|
|
737
748
|
ctypes.c_double(th),
|
|
738
749
|
ctypes.c_double(ph),
|
|
@@ -760,7 +771,7 @@ class QrackSimulator:
|
|
|
760
771
|
"2x2 matrix 'm' in QrackSimulator.macmtrx() must contain at least 4 elements."
|
|
761
772
|
)
|
|
762
773
|
Qrack.qrack_lib.MACMtrx(
|
|
763
|
-
self.sid, len(c),
|
|
774
|
+
self.sid, len(c), QrackSimulator._ulonglong_byref(c), QrackSimulator._complex_byref(m), q
|
|
764
775
|
)
|
|
765
776
|
self._throw_if_error()
|
|
766
777
|
|
|
@@ -785,7 +796,7 @@ class QrackSimulator:
|
|
|
785
796
|
"2x2 matrix 'm' in QrackSimulator.ucmtrx() must contain at least 4 elements."
|
|
786
797
|
)
|
|
787
798
|
Qrack.qrack_lib.UCMtrx(
|
|
788
|
-
self.sid, len(c),
|
|
799
|
+
self.sid, len(c), QrackSimulator._ulonglong_byref(c), QrackSimulator._complex_byref(m), q, p
|
|
789
800
|
)
|
|
790
801
|
self._throw_if_error()
|
|
791
802
|
|
|
@@ -809,7 +820,7 @@ class QrackSimulator:
|
|
|
809
820
|
"Multiplex matrix 'm' in QrackSimulator.multiplex1_mtrx() must contain at least (4 * 2 ** len(c)) elements."
|
|
810
821
|
)
|
|
811
822
|
Qrack.qrack_lib.Multiplex1Mtrx(
|
|
812
|
-
self.sid, len(c),
|
|
823
|
+
self.sid, len(c), QrackSimulator._ulonglong_byref(c), q, QrackSimulator._complex_byref(m)
|
|
813
824
|
)
|
|
814
825
|
self._throw_if_error()
|
|
815
826
|
|
|
@@ -824,7 +835,7 @@ class QrackSimulator:
|
|
|
824
835
|
Raises:
|
|
825
836
|
RuntimeError: QrackSimulator raised an exception.
|
|
826
837
|
"""
|
|
827
|
-
Qrack.qrack_lib.MX(self.sid, len(q),
|
|
838
|
+
Qrack.qrack_lib.MX(self.sid, len(q), QrackSimulator._ulonglong_byref(q))
|
|
828
839
|
self._throw_if_error()
|
|
829
840
|
|
|
830
841
|
def my(self, q):
|
|
@@ -838,7 +849,7 @@ class QrackSimulator:
|
|
|
838
849
|
Raises:
|
|
839
850
|
RuntimeError: QrackSimulator raised an exception.
|
|
840
851
|
"""
|
|
841
|
-
Qrack.qrack_lib.MY(self.sid, len(q),
|
|
852
|
+
Qrack.qrack_lib.MY(self.sid, len(q), QrackSimulator._ulonglong_byref(q))
|
|
842
853
|
self._throw_if_error()
|
|
843
854
|
|
|
844
855
|
def mz(self, q):
|
|
@@ -852,7 +863,7 @@ class QrackSimulator:
|
|
|
852
863
|
Raises:
|
|
853
864
|
RuntimeError: QrackSimulator raised an exception.
|
|
854
865
|
"""
|
|
855
|
-
Qrack.qrack_lib.MZ(self.sid, len(q),
|
|
866
|
+
Qrack.qrack_lib.MZ(self.sid, len(q), QrackSimulator._ulonglong_byref(q))
|
|
856
867
|
self._throw_if_error()
|
|
857
868
|
|
|
858
869
|
def mcr(self, b, ph, c, q):
|
|
@@ -875,7 +886,7 @@ class QrackSimulator:
|
|
|
875
886
|
ctypes.c_ulonglong(b),
|
|
876
887
|
ctypes.c_double(ph),
|
|
877
888
|
len(c),
|
|
878
|
-
|
|
889
|
+
QrackSimulator._ulonglong_byref(c),
|
|
879
890
|
q,
|
|
880
891
|
)
|
|
881
892
|
self._throw_if_error()
|
|
@@ -899,11 +910,11 @@ class QrackSimulator:
|
|
|
899
910
|
Qrack.qrack_lib.MCExp(
|
|
900
911
|
self.sid,
|
|
901
912
|
len(b),
|
|
902
|
-
|
|
913
|
+
QrackSimulator._ulonglong_byref(b),
|
|
903
914
|
ctypes.c_double(ph),
|
|
904
915
|
len(cs),
|
|
905
|
-
|
|
906
|
-
|
|
916
|
+
QrackSimulator._ulonglong_byref(cs),
|
|
917
|
+
QrackSimulator._ulonglong_byref(q),
|
|
907
918
|
)
|
|
908
919
|
self._throw_if_error()
|
|
909
920
|
|
|
@@ -985,7 +996,7 @@ class QrackSimulator:
|
|
|
985
996
|
Raises:
|
|
986
997
|
RuntimeError: QrackSimulator raised an exception.
|
|
987
998
|
"""
|
|
988
|
-
Qrack.qrack_lib.CSWAP(self.sid, len(c),
|
|
999
|
+
Qrack.qrack_lib.CSWAP(self.sid, len(c), QrackSimulator._ulonglong_byref(c), qi1, qi2)
|
|
989
1000
|
self._throw_if_error()
|
|
990
1001
|
|
|
991
1002
|
def acswap(self, c, qi1, qi2):
|
|
@@ -1001,7 +1012,7 @@ class QrackSimulator:
|
|
|
1001
1012
|
Raises:
|
|
1002
1013
|
RuntimeError: QrackSimulator raised an exception.
|
|
1003
1014
|
"""
|
|
1004
|
-
Qrack.qrack_lib.ACSWAP(self.sid, len(c),
|
|
1015
|
+
Qrack.qrack_lib.ACSWAP(self.sid, len(c), QrackSimulator._ulonglong_byref(c), qi1, qi2)
|
|
1005
1016
|
self._throw_if_error()
|
|
1006
1017
|
|
|
1007
1018
|
# standard operations
|
|
@@ -1085,7 +1096,7 @@ class QrackSimulator:
|
|
|
1085
1096
|
if len(b) != len(q):
|
|
1086
1097
|
raise RuntimeError("Lengths of list parameters are mismatched.")
|
|
1087
1098
|
result = Qrack.qrack_lib.Measure(
|
|
1088
|
-
self.sid, len(b),
|
|
1099
|
+
self.sid, len(b), QrackSimulator._int_byref(b), QrackSimulator._ulonglong_byref(q)
|
|
1089
1100
|
)
|
|
1090
1101
|
self._throw_if_error()
|
|
1091
1102
|
return result
|
|
@@ -1106,8 +1117,8 @@ class QrackSimulator:
|
|
|
1106
1117
|
Returns:
|
|
1107
1118
|
list of measurement result.
|
|
1108
1119
|
"""
|
|
1109
|
-
m =
|
|
1110
|
-
Qrack.qrack_lib.MeasureShots(self.sid, len(q),
|
|
1120
|
+
m = QrackSimulator._ulonglong_byref([0] * s)
|
|
1121
|
+
Qrack.qrack_lib.MeasureShots(self.sid, len(q), QrackSimulator._ulonglong_byref(q), s, m)
|
|
1111
1122
|
self._throw_if_error()
|
|
1112
1123
|
return [m[i] for i in range(s)]
|
|
1113
1124
|
|
|
@@ -1123,7 +1134,8 @@ class QrackSimulator:
|
|
|
1123
1134
|
self._throw_if_error()
|
|
1124
1135
|
|
|
1125
1136
|
# arithmetic-logic-unit (ALU)
|
|
1126
|
-
|
|
1137
|
+
@staticmethod
|
|
1138
|
+
def _split_longs(a):
|
|
1127
1139
|
"""Split operation
|
|
1128
1140
|
|
|
1129
1141
|
Splits the given integer into 64 bit numbers.
|
|
@@ -1146,7 +1158,8 @@ class QrackSimulator:
|
|
|
1146
1158
|
a = a >> 64
|
|
1147
1159
|
return aParts
|
|
1148
1160
|
|
|
1149
|
-
|
|
1161
|
+
@staticmethod
|
|
1162
|
+
def _split_longs_2(a, m):
|
|
1150
1163
|
"""Split simultanoues operation
|
|
1151
1164
|
|
|
1152
1165
|
Splits 2 integers into same number of 64 bit numbers.
|
|
@@ -1185,13 +1198,13 @@ class QrackSimulator:
|
|
|
1185
1198
|
Raises:
|
|
1186
1199
|
RuntimeError: QrackSimulator raised an exception.
|
|
1187
1200
|
"""
|
|
1188
|
-
aParts =
|
|
1201
|
+
aParts = QrackSimulator._split_longs(a)
|
|
1189
1202
|
Qrack.qrack_lib.ADD(
|
|
1190
1203
|
self.sid,
|
|
1191
1204
|
len(aParts),
|
|
1192
|
-
|
|
1205
|
+
QrackSimulator._ulonglong_byref(aParts),
|
|
1193
1206
|
len(q),
|
|
1194
|
-
|
|
1207
|
+
QrackSimulator._ulonglong_byref(q),
|
|
1195
1208
|
)
|
|
1196
1209
|
self._throw_if_error()
|
|
1197
1210
|
|
|
@@ -1207,13 +1220,13 @@ class QrackSimulator:
|
|
|
1207
1220
|
Raises:
|
|
1208
1221
|
RuntimeError: QrackSimulator raised an exception.
|
|
1209
1222
|
"""
|
|
1210
|
-
aParts =
|
|
1223
|
+
aParts = QrackSimulator._split_longs(a)
|
|
1211
1224
|
Qrack.qrack_lib.SUB(
|
|
1212
1225
|
self.sid,
|
|
1213
1226
|
len(aParts),
|
|
1214
|
-
|
|
1227
|
+
QrackSimulator._ulonglong_byref(aParts),
|
|
1215
1228
|
len(q),
|
|
1216
|
-
|
|
1229
|
+
QrackSimulator._ulonglong_byref(q),
|
|
1217
1230
|
)
|
|
1218
1231
|
self._throw_if_error()
|
|
1219
1232
|
|
|
@@ -1231,14 +1244,14 @@ class QrackSimulator:
|
|
|
1231
1244
|
Raises:
|
|
1232
1245
|
RuntimeError: QrackSimulator raised an exception.
|
|
1233
1246
|
"""
|
|
1234
|
-
aParts =
|
|
1247
|
+
aParts = QrackSimulator._split_longs(a)
|
|
1235
1248
|
Qrack.qrack_lib.ADDS(
|
|
1236
1249
|
self.sid,
|
|
1237
1250
|
len(aParts),
|
|
1238
|
-
|
|
1251
|
+
QrackSimulator._ulonglong_byref(aParts),
|
|
1239
1252
|
s,
|
|
1240
1253
|
len(q),
|
|
1241
|
-
|
|
1254
|
+
QrackSimulator._ulonglong_byref(q),
|
|
1242
1255
|
)
|
|
1243
1256
|
self._throw_if_error()
|
|
1244
1257
|
|
|
@@ -1256,14 +1269,14 @@ class QrackSimulator:
|
|
|
1256
1269
|
Raises:
|
|
1257
1270
|
RuntimeError: QrackSimulator raised an exception.
|
|
1258
1271
|
"""
|
|
1259
|
-
aParts =
|
|
1272
|
+
aParts = QrackSimulator._split_longs(a)
|
|
1260
1273
|
Qrack.qrack_lib.SUBS(
|
|
1261
1274
|
self.sid,
|
|
1262
1275
|
len(aParts),
|
|
1263
|
-
|
|
1276
|
+
QrackSimulator._ulonglong_byref(aParts),
|
|
1264
1277
|
s,
|
|
1265
1278
|
len(q),
|
|
1266
|
-
|
|
1279
|
+
QrackSimulator._ulonglong_byref(q),
|
|
1267
1280
|
)
|
|
1268
1281
|
self._throw_if_error()
|
|
1269
1282
|
|
|
@@ -1294,14 +1307,14 @@ class QrackSimulator:
|
|
|
1294
1307
|
|
|
1295
1308
|
if len(q) != len(o):
|
|
1296
1309
|
raise RuntimeError("Lengths of list parameters are mismatched.")
|
|
1297
|
-
aParts =
|
|
1310
|
+
aParts = QrackSimulator._split_longs(a)
|
|
1298
1311
|
Qrack.qrack_lib.MUL(
|
|
1299
1312
|
self.sid,
|
|
1300
1313
|
len(aParts),
|
|
1301
|
-
|
|
1314
|
+
QrackSimulator._ulonglong_byref(aParts),
|
|
1302
1315
|
len(q),
|
|
1303
|
-
|
|
1304
|
-
|
|
1316
|
+
QrackSimulator._ulonglong_byref(q),
|
|
1317
|
+
QrackSimulator._ulonglong_byref(o),
|
|
1305
1318
|
)
|
|
1306
1319
|
self._throw_if_error()
|
|
1307
1320
|
|
|
@@ -1333,14 +1346,14 @@ class QrackSimulator:
|
|
|
1333
1346
|
|
|
1334
1347
|
if len(q) != len(o):
|
|
1335
1348
|
raise RuntimeError("Lengths of list parameters are mismatched.")
|
|
1336
|
-
aParts =
|
|
1349
|
+
aParts = QrackSimulator._split_longs(a)
|
|
1337
1350
|
Qrack.qrack_lib.DIV(
|
|
1338
1351
|
self.sid,
|
|
1339
1352
|
len(aParts),
|
|
1340
|
-
|
|
1353
|
+
QrackSimulator._ulonglong_byref(aParts),
|
|
1341
1354
|
len(q),
|
|
1342
|
-
|
|
1343
|
-
|
|
1355
|
+
QrackSimulator._ulonglong_byref(q),
|
|
1356
|
+
QrackSimulator._ulonglong_byref(o),
|
|
1344
1357
|
)
|
|
1345
1358
|
self._throw_if_error()
|
|
1346
1359
|
|
|
@@ -1361,15 +1374,15 @@ class QrackSimulator:
|
|
|
1361
1374
|
"""
|
|
1362
1375
|
if len(q) != len(o):
|
|
1363
1376
|
raise RuntimeError("Lengths of list parameters are mismatched.")
|
|
1364
|
-
aParts, mParts =
|
|
1377
|
+
aParts, mParts = QrackSimulator._split_longs_2(a, m)
|
|
1365
1378
|
Qrack.qrack_lib.MULN(
|
|
1366
1379
|
self.sid,
|
|
1367
1380
|
len(aParts),
|
|
1368
|
-
|
|
1369
|
-
|
|
1381
|
+
QrackSimulator._ulonglong_byref(aParts),
|
|
1382
|
+
QrackSimulator._ulonglong_byref(mParts),
|
|
1370
1383
|
len(q),
|
|
1371
|
-
|
|
1372
|
-
|
|
1384
|
+
QrackSimulator._ulonglong_byref(q),
|
|
1385
|
+
QrackSimulator._ulonglong_byref(o),
|
|
1373
1386
|
)
|
|
1374
1387
|
self._throw_if_error()
|
|
1375
1388
|
|
|
@@ -1391,15 +1404,15 @@ class QrackSimulator:
|
|
|
1391
1404
|
"""
|
|
1392
1405
|
if len(q) != len(o):
|
|
1393
1406
|
raise RuntimeError("Lengths of list parameters are mismatched.")
|
|
1394
|
-
aParts, mParts =
|
|
1407
|
+
aParts, mParts = QrackSimulator._split_longs_2(a, m)
|
|
1395
1408
|
Qrack.qrack_lib.DIVN(
|
|
1396
1409
|
self.sid,
|
|
1397
1410
|
len(aParts),
|
|
1398
|
-
|
|
1399
|
-
|
|
1411
|
+
QrackSimulator._ulonglong_byref(aParts),
|
|
1412
|
+
QrackSimulator._ulonglong_byref(mParts),
|
|
1400
1413
|
len(q),
|
|
1401
|
-
|
|
1402
|
-
|
|
1414
|
+
QrackSimulator._ulonglong_byref(q),
|
|
1415
|
+
QrackSimulator._ulonglong_byref(o),
|
|
1403
1416
|
)
|
|
1404
1417
|
self._throw_if_error()
|
|
1405
1418
|
|
|
@@ -1430,15 +1443,15 @@ class QrackSimulator:
|
|
|
1430
1443
|
|
|
1431
1444
|
if len(q) != len(o):
|
|
1432
1445
|
raise RuntimeError("Lengths of list parameters are mismatched.")
|
|
1433
|
-
aParts, mParts =
|
|
1446
|
+
aParts, mParts = QrackSimulator._split_longs_2(a, m)
|
|
1434
1447
|
Qrack.qrack_lib.POWN(
|
|
1435
1448
|
self.sid,
|
|
1436
1449
|
len(aParts),
|
|
1437
|
-
|
|
1438
|
-
|
|
1450
|
+
QrackSimulator._ulonglong_byref(aParts),
|
|
1451
|
+
QrackSimulator._ulonglong_byref(mParts),
|
|
1439
1452
|
len(q),
|
|
1440
|
-
|
|
1441
|
-
|
|
1453
|
+
QrackSimulator._ulonglong_byref(q),
|
|
1454
|
+
QrackSimulator._ulonglong_byref(o),
|
|
1442
1455
|
)
|
|
1443
1456
|
self._throw_if_error()
|
|
1444
1457
|
|
|
@@ -1456,15 +1469,15 @@ class QrackSimulator:
|
|
|
1456
1469
|
Raises:
|
|
1457
1470
|
RuntimeError: QrackSimulator raised an exception.
|
|
1458
1471
|
"""
|
|
1459
|
-
aParts =
|
|
1472
|
+
aParts = QrackSimulator._split_longs(a)
|
|
1460
1473
|
Qrack.qrack_lib.MCADD(
|
|
1461
1474
|
self.sid,
|
|
1462
1475
|
len(aParts),
|
|
1463
|
-
|
|
1476
|
+
QrackSimulator._ulonglong_byref(aParts),
|
|
1464
1477
|
len(c),
|
|
1465
|
-
|
|
1478
|
+
QrackSimulator._ulonglong_byref(c),
|
|
1466
1479
|
len(q),
|
|
1467
|
-
|
|
1480
|
+
QrackSimulator._ulonglong_byref(q),
|
|
1468
1481
|
)
|
|
1469
1482
|
self._throw_if_error()
|
|
1470
1483
|
|
|
@@ -1482,15 +1495,15 @@ class QrackSimulator:
|
|
|
1482
1495
|
Raises:
|
|
1483
1496
|
RuntimeError: QrackSimulator raised an exception.
|
|
1484
1497
|
"""
|
|
1485
|
-
aParts =
|
|
1498
|
+
aParts = QrackSimulator._split_longs(a)
|
|
1486
1499
|
Qrack.qrack_lib.MCSUB(
|
|
1487
1500
|
self.sid,
|
|
1488
1501
|
len(aParts),
|
|
1489
|
-
|
|
1502
|
+
QrackSimulator._ulonglong_byref(aParts),
|
|
1490
1503
|
len(c),
|
|
1491
|
-
|
|
1504
|
+
QrackSimulator._ulonglong_byref(c),
|
|
1492
1505
|
len(q),
|
|
1493
|
-
|
|
1506
|
+
QrackSimulator._ulonglong_byref(q),
|
|
1494
1507
|
)
|
|
1495
1508
|
self._throw_if_error()
|
|
1496
1509
|
|
|
@@ -1523,15 +1536,15 @@ class QrackSimulator:
|
|
|
1523
1536
|
|
|
1524
1537
|
if len(q) != len(o):
|
|
1525
1538
|
raise RuntimeError("Lengths of list parameters are mismatched.")
|
|
1526
|
-
aParts =
|
|
1539
|
+
aParts = QrackSimulator._split_longs(a)
|
|
1527
1540
|
Qrack.qrack_lib.MCMUL(
|
|
1528
1541
|
self.sid,
|
|
1529
1542
|
len(aParts),
|
|
1530
|
-
|
|
1543
|
+
QrackSimulator._ulonglong_byref(aParts),
|
|
1531
1544
|
len(c),
|
|
1532
|
-
|
|
1545
|
+
QrackSimulator._ulonglong_byref(c),
|
|
1533
1546
|
len(q),
|
|
1534
|
-
|
|
1547
|
+
QrackSimulator._ulonglong_byref(q),
|
|
1535
1548
|
)
|
|
1536
1549
|
self._throw_if_error()
|
|
1537
1550
|
|
|
@@ -1565,15 +1578,15 @@ class QrackSimulator:
|
|
|
1565
1578
|
|
|
1566
1579
|
if len(q) != len(o):
|
|
1567
1580
|
raise RuntimeError("Lengths of list parameters are mismatched.")
|
|
1568
|
-
aParts =
|
|
1581
|
+
aParts = QrackSimulator._split_longs(a)
|
|
1569
1582
|
Qrack.qrack_lib.MCDIV(
|
|
1570
1583
|
self.sid,
|
|
1571
1584
|
len(aParts),
|
|
1572
|
-
|
|
1585
|
+
QrackSimulator._ulonglong_byref(aParts),
|
|
1573
1586
|
len(c),
|
|
1574
|
-
|
|
1587
|
+
QrackSimulator._ulonglong_byref(c),
|
|
1575
1588
|
len(q),
|
|
1576
|
-
|
|
1589
|
+
QrackSimulator._ulonglong_byref(q),
|
|
1577
1590
|
)
|
|
1578
1591
|
self._throw_if_error()
|
|
1579
1592
|
|
|
@@ -1596,17 +1609,17 @@ class QrackSimulator:
|
|
|
1596
1609
|
"""
|
|
1597
1610
|
if len(q) != len(o):
|
|
1598
1611
|
raise RuntimeError("Lengths of list parameters are mismatched.")
|
|
1599
|
-
aParts, mParts =
|
|
1612
|
+
aParts, mParts = QrackSimulator._split_longs_2(a, m)
|
|
1600
1613
|
Qrack.qrack_lib.MCMULN(
|
|
1601
1614
|
self.sid,
|
|
1602
1615
|
len(aParts),
|
|
1603
|
-
|
|
1616
|
+
QrackSimulator._ulonglong_byref(aParts),
|
|
1604
1617
|
len(c),
|
|
1605
|
-
|
|
1606
|
-
|
|
1618
|
+
QrackSimulator._ulonglong_byref(c),
|
|
1619
|
+
QrackSimulator._ulonglong_byref(mParts),
|
|
1607
1620
|
len(q),
|
|
1608
|
-
|
|
1609
|
-
|
|
1621
|
+
QrackSimulator._ulonglong_byref(q),
|
|
1622
|
+
QrackSimulator._ulonglong_byref(o),
|
|
1610
1623
|
)
|
|
1611
1624
|
self._throw_if_error()
|
|
1612
1625
|
|
|
@@ -1630,17 +1643,17 @@ class QrackSimulator:
|
|
|
1630
1643
|
"""
|
|
1631
1644
|
if len(q) != len(o):
|
|
1632
1645
|
raise RuntimeError("Lengths of list parameters are mismatched.")
|
|
1633
|
-
aParts, mParts =
|
|
1646
|
+
aParts, mParts = QrackSimulator._split_longs_2(a, m)
|
|
1634
1647
|
Qrack.qrack_lib.MCDIVN(
|
|
1635
1648
|
self.sid,
|
|
1636
1649
|
len(aParts),
|
|
1637
|
-
|
|
1650
|
+
QrackSimulator._ulonglong_byref(aParts),
|
|
1638
1651
|
len(c),
|
|
1639
|
-
|
|
1640
|
-
|
|
1652
|
+
QrackSimulator._ulonglong_byref(c),
|
|
1653
|
+
QrackSimulator._ulonglong_byref(mParts),
|
|
1641
1654
|
len(q),
|
|
1642
|
-
|
|
1643
|
-
|
|
1655
|
+
QrackSimulator._ulonglong_byref(q),
|
|
1656
|
+
QrackSimulator._ulonglong_byref(o),
|
|
1644
1657
|
)
|
|
1645
1658
|
self._throw_if_error()
|
|
1646
1659
|
|
|
@@ -1673,17 +1686,17 @@ class QrackSimulator:
|
|
|
1673
1686
|
|
|
1674
1687
|
if len(q) != len(o):
|
|
1675
1688
|
raise RuntimeError("Lengths of list parameters are mismatched.")
|
|
1676
|
-
aParts, mParts =
|
|
1689
|
+
aParts, mParts = QrackSimulator._split_longs_2(a, m)
|
|
1677
1690
|
Qrack.qrack_lib.MCPOWN(
|
|
1678
1691
|
self.sid,
|
|
1679
1692
|
len(aParts),
|
|
1680
|
-
|
|
1693
|
+
QrackSimulator._ulonglong_byref(aParts),
|
|
1681
1694
|
len(c),
|
|
1682
|
-
|
|
1683
|
-
|
|
1695
|
+
QrackSimulator._ulonglong_byref(c),
|
|
1696
|
+
QrackSimulator._ulonglong_byref(mParts),
|
|
1684
1697
|
len(q),
|
|
1685
|
-
|
|
1686
|
-
|
|
1698
|
+
QrackSimulator._ulonglong_byref(q),
|
|
1699
|
+
QrackSimulator._ulonglong_byref(o),
|
|
1687
1700
|
)
|
|
1688
1701
|
self._throw_if_error()
|
|
1689
1702
|
|
|
@@ -1715,10 +1728,10 @@ class QrackSimulator:
|
|
|
1715
1728
|
Qrack.qrack_lib.LDA(
|
|
1716
1729
|
self.sid,
|
|
1717
1730
|
len(qi),
|
|
1718
|
-
|
|
1731
|
+
QrackSimulator._ulonglong_byref(qi),
|
|
1719
1732
|
len(qv),
|
|
1720
|
-
|
|
1721
|
-
|
|
1733
|
+
QrackSimulator._ulonglong_byref(qv),
|
|
1734
|
+
QrackSimulator._to_ubyte(len(qv), t),
|
|
1722
1735
|
)
|
|
1723
1736
|
self._throw_if_error()
|
|
1724
1737
|
|
|
@@ -1750,10 +1763,10 @@ class QrackSimulator:
|
|
|
1750
1763
|
self.sid,
|
|
1751
1764
|
s,
|
|
1752
1765
|
len(qi),
|
|
1753
|
-
|
|
1766
|
+
QrackSimulator._ulonglong_byref(qi),
|
|
1754
1767
|
len(qv),
|
|
1755
|
-
|
|
1756
|
-
|
|
1768
|
+
QrackSimulator._ulonglong_byref(qv),
|
|
1769
|
+
QrackSimulator._to_ubyte(len(qv), t),
|
|
1757
1770
|
)
|
|
1758
1771
|
self._throw_if_error()
|
|
1759
1772
|
|
|
@@ -1785,10 +1798,10 @@ class QrackSimulator:
|
|
|
1785
1798
|
self.sid,
|
|
1786
1799
|
s,
|
|
1787
1800
|
len(qi),
|
|
1788
|
-
|
|
1801
|
+
QrackSimulator._ulonglong_byref(qi),
|
|
1789
1802
|
len(qv),
|
|
1790
|
-
|
|
1791
|
-
|
|
1803
|
+
QrackSimulator._ulonglong_byref(qv),
|
|
1804
|
+
QrackSimulator._to_ubyte(len(qv), t),
|
|
1792
1805
|
)
|
|
1793
1806
|
self._throw_if_error()
|
|
1794
1807
|
|
|
@@ -1818,7 +1831,7 @@ class QrackSimulator:
|
|
|
1818
1831
|
)
|
|
1819
1832
|
|
|
1820
1833
|
Qrack.qrack_lib.Hash(
|
|
1821
|
-
self.sid, len(q),
|
|
1834
|
+
self.sid, len(q), QrackSimulator._ulonglong_byref(q), QrackSimulator._to_ubyte(len(q), t)
|
|
1822
1835
|
)
|
|
1823
1836
|
self._throw_if_error()
|
|
1824
1837
|
|
|
@@ -2039,7 +2052,7 @@ class QrackSimulator:
|
|
|
2039
2052
|
Raises:
|
|
2040
2053
|
RuntimeError: QrackSimulator raised an exception.
|
|
2041
2054
|
"""
|
|
2042
|
-
Qrack.qrack_lib.QFT(self.sid, len(qs),
|
|
2055
|
+
Qrack.qrack_lib.QFT(self.sid, len(qs), QrackSimulator._ulonglong_byref(qs))
|
|
2043
2056
|
self._throw_if_error()
|
|
2044
2057
|
|
|
2045
2058
|
def iqft(self, qs):
|
|
@@ -2054,7 +2067,7 @@ class QrackSimulator:
|
|
|
2054
2067
|
Raises:
|
|
2055
2068
|
RuntimeError: QrackSimulator raised an exception.
|
|
2056
2069
|
"""
|
|
2057
|
-
Qrack.qrack_lib.IQFT(self.sid, len(qs),
|
|
2070
|
+
Qrack.qrack_lib.IQFT(self.sid, len(qs), QrackSimulator._ulonglong_byref(qs))
|
|
2058
2071
|
self._throw_if_error()
|
|
2059
2072
|
|
|
2060
2073
|
# pseudo-quantum
|
|
@@ -2128,7 +2141,7 @@ class QrackSimulator:
|
|
|
2128
2141
|
"QrackSimulator with isTensorNetwork=True option cannot compose()! (Turn off just this option, in the constructor.)"
|
|
2129
2142
|
)
|
|
2130
2143
|
|
|
2131
|
-
Qrack.qrack_lib.Compose(self.sid, other.sid,
|
|
2144
|
+
Qrack.qrack_lib.Compose(self.sid, other.sid, QrackSimulator._ulonglong_byref(q))
|
|
2132
2145
|
self._throw_if_error()
|
|
2133
2146
|
|
|
2134
2147
|
def decompose(self, q):
|
|
@@ -2154,7 +2167,7 @@ class QrackSimulator:
|
|
|
2154
2167
|
other = QrackSimulator()
|
|
2155
2168
|
Qrack.qrack_lib.destroy(other.sid)
|
|
2156
2169
|
l = len(q)
|
|
2157
|
-
other.sid = Qrack.qrack_lib.Decompose(self.sid, l,
|
|
2170
|
+
other.sid = Qrack.qrack_lib.Decompose(self.sid, l, QrackSimulator._ulonglong_byref(q))
|
|
2158
2171
|
self._throw_if_error()
|
|
2159
2172
|
return other
|
|
2160
2173
|
|
|
@@ -2177,7 +2190,7 @@ class QrackSimulator:
|
|
|
2177
2190
|
)
|
|
2178
2191
|
|
|
2179
2192
|
l = len(q)
|
|
2180
|
-
Qrack.qrack_lib.Dispose(self.sid, l,
|
|
2193
|
+
Qrack.qrack_lib.Dispose(self.sid, l, QrackSimulator._ulonglong_byref(q))
|
|
2181
2194
|
self._throw_if_error()
|
|
2182
2195
|
|
|
2183
2196
|
## miscellaneous
|
|
@@ -2247,7 +2260,7 @@ class QrackSimulator:
|
|
|
2247
2260
|
Raises:
|
|
2248
2261
|
RuntimeError: QrackSimulator raised an exception.
|
|
2249
2262
|
"""
|
|
2250
|
-
Qrack.qrack_lib.InKet(self.sid,
|
|
2263
|
+
Qrack.qrack_lib.InKet(self.sid, QrackSimulator._qrack_complex_byref(ket))
|
|
2251
2264
|
self._throw_if_error()
|
|
2252
2265
|
|
|
2253
2266
|
def out_ket(self):
|
|
@@ -2264,10 +2277,10 @@ class QrackSimulator:
|
|
|
2264
2277
|
list representing the state vector.
|
|
2265
2278
|
"""
|
|
2266
2279
|
amp_count = 1 << self.num_qubits()
|
|
2267
|
-
ket =
|
|
2280
|
+
ket = QrackSimulator._qrack_complex_byref([complex(0, 0)] * amp_count)
|
|
2268
2281
|
Qrack.qrack_lib.OutKet(self.sid, ket)
|
|
2269
2282
|
self._throw_if_error()
|
|
2270
|
-
return [complex(r, i) for r, i in
|
|
2283
|
+
return [complex(r, i) for r, i in QrackSimulator._pairwise(ket)]
|
|
2271
2284
|
|
|
2272
2285
|
def out_probs(self):
|
|
2273
2286
|
"""Get basis dimension probabilities
|
|
@@ -2282,7 +2295,7 @@ class QrackSimulator:
|
|
|
2282
2295
|
list representing the basis dimension probabilities.
|
|
2283
2296
|
"""
|
|
2284
2297
|
prob_count = 1 << self.num_qubits()
|
|
2285
|
-
probs =
|
|
2298
|
+
probs = QrackSimulator._real1_byref([0.0] * prob_count)
|
|
2286
2299
|
Qrack.qrack_lib.OutProbs(self.sid, probs)
|
|
2287
2300
|
self._throw_if_error()
|
|
2288
2301
|
return list(probs)
|
|
@@ -2302,10 +2315,10 @@ class QrackSimulator:
|
|
|
2302
2315
|
"""
|
|
2303
2316
|
amp_count = 1 << len(q)
|
|
2304
2317
|
sqr_amp_count = amp_count * amp_count
|
|
2305
|
-
flat_rdm =
|
|
2306
|
-
Qrack.qrack_lib.OutReducedDensityMatrix(self.sid, len(q),
|
|
2318
|
+
flat_rdm = QrackSimulator._qrack_complex_byref([complex(0, 0)] * sqr_amp_count)
|
|
2319
|
+
Qrack.qrack_lib.OutReducedDensityMatrix(self.sid, len(q), QrackSimulator._ulonglong_byref(q), flat_rdm)
|
|
2307
2320
|
self._throw_if_error()
|
|
2308
|
-
return [complex(r, i) for r, i in
|
|
2321
|
+
return [complex(r, i) for r, i in QrackSimulator._pairwise(flat_rdm)]
|
|
2309
2322
|
|
|
2310
2323
|
def highest_prob_perm(self):
|
|
2311
2324
|
"""Get the permutation (bit string) with the highest probability
|
|
@@ -2367,8 +2380,8 @@ class QrackSimulator:
|
|
|
2367
2380
|
Returns:
|
|
2368
2381
|
list representing the state vector.
|
|
2369
2382
|
"""
|
|
2370
|
-
probs =
|
|
2371
|
-
Qrack.qrack_lib.ProbAll(self.sid, len(q),
|
|
2383
|
+
probs = QrackSimulator._real1_byref([0.0] * (1 << len(q)))
|
|
2384
|
+
Qrack.qrack_lib.ProbAll(self.sid, len(q), QrackSimulator._ulonglong_byref(q), probs)
|
|
2372
2385
|
self._throw_if_error()
|
|
2373
2386
|
return list(probs)
|
|
2374
2387
|
|
|
@@ -2430,7 +2443,7 @@ class QrackSimulator:
|
|
|
2430
2443
|
if len(q) != len(c):
|
|
2431
2444
|
raise RuntimeError("prob_perm argument lengths do not match.")
|
|
2432
2445
|
result = Qrack.qrack_lib.PermutationProb(
|
|
2433
|
-
self.sid, len(q),
|
|
2446
|
+
self.sid, len(q), QrackSimulator._ulonglong_byref(q), QrackSimulator._bool_byref(c)
|
|
2434
2447
|
)
|
|
2435
2448
|
self._throw_if_error()
|
|
2436
2449
|
return result
|
|
@@ -2458,7 +2471,7 @@ class QrackSimulator:
|
|
|
2458
2471
|
if len(q) != len(c):
|
|
2459
2472
|
raise RuntimeError("prob_perm argument lengths do not match.")
|
|
2460
2473
|
result = Qrack.qrack_lib.PermutationProbRdm(
|
|
2461
|
-
self.sid, len(q),
|
|
2474
|
+
self.sid, len(q), QrackSimulator._ulonglong_byref(q), QrackSimulator._bool_byref(c), r
|
|
2462
2475
|
)
|
|
2463
2476
|
self._throw_if_error()
|
|
2464
2477
|
return result
|
|
@@ -2479,7 +2492,7 @@ class QrackSimulator:
|
|
|
2479
2492
|
Expectation value
|
|
2480
2493
|
"""
|
|
2481
2494
|
result = Qrack.qrack_lib.PermutationExpectation(
|
|
2482
|
-
self.sid, len(q),
|
|
2495
|
+
self.sid, len(q), QrackSimulator._ulonglong_byref(q)
|
|
2483
2496
|
)
|
|
2484
2497
|
self._throw_if_error()
|
|
2485
2498
|
return result
|
|
@@ -2502,7 +2515,7 @@ class QrackSimulator:
|
|
|
2502
2515
|
Expectation value
|
|
2503
2516
|
"""
|
|
2504
2517
|
result = Qrack.qrack_lib.PermutationExpectationRdm(
|
|
2505
|
-
self.sid, len(q),
|
|
2518
|
+
self.sid, len(q), QrackSimulator._ulonglong_byref(q), r
|
|
2506
2519
|
)
|
|
2507
2520
|
self._throw_if_error()
|
|
2508
2521
|
return result
|
|
@@ -2528,7 +2541,7 @@ class QrackSimulator:
|
|
|
2528
2541
|
raise RuntimeError("factorized_expectation argument lengths do not match.")
|
|
2529
2542
|
m = max([(x.bit_length() + 63) // 64 for x in c])
|
|
2530
2543
|
result = Qrack.qrack_lib.FactorizedExpectation(
|
|
2531
|
-
self.sid, len(q),
|
|
2544
|
+
self.sid, len(q), QrackSimulator._ulonglong_byref(q), m, QrackSimulator._to_ulonglong(m, c)
|
|
2532
2545
|
)
|
|
2533
2546
|
self._throw_if_error()
|
|
2534
2547
|
return result
|
|
@@ -2558,7 +2571,7 @@ class QrackSimulator:
|
|
|
2558
2571
|
)
|
|
2559
2572
|
m = max([(x.bit_length() + 63) // 64 for x in c])
|
|
2560
2573
|
result = Qrack.qrack_lib.FactorizedExpectationRdm(
|
|
2561
|
-
self.sid, len(q),
|
|
2574
|
+
self.sid, len(q), QrackSimulator._ulonglong_byref(q), m, QrackSimulator._to_ulonglong(m, c), r
|
|
2562
2575
|
)
|
|
2563
2576
|
self._throw_if_error()
|
|
2564
2577
|
return result
|
|
@@ -2585,7 +2598,7 @@ class QrackSimulator:
|
|
|
2585
2598
|
"factorized_expectation_rdm argument lengths do not match."
|
|
2586
2599
|
)
|
|
2587
2600
|
result = Qrack.qrack_lib.FactorizedExpectationFp(
|
|
2588
|
-
self.sid, len(q),
|
|
2601
|
+
self.sid, len(q), QrackSimulator._ulonglong_byref(q), QrackSimulator._real1_byref(c)
|
|
2589
2602
|
)
|
|
2590
2603
|
self._throw_if_error()
|
|
2591
2604
|
return result
|
|
@@ -2614,7 +2627,7 @@ class QrackSimulator:
|
|
|
2614
2627
|
"factorized_expectation_fp_rdm argument lengths do not match."
|
|
2615
2628
|
)
|
|
2616
2629
|
result = Qrack.qrack_lib.FactorizedExpectationFpRdm(
|
|
2617
|
-
self.sid, len(q),
|
|
2630
|
+
self.sid, len(q), QrackSimulator._ulonglong_byref(q), QrackSimulator._real1_byref(c), r
|
|
2618
2631
|
)
|
|
2619
2632
|
self._throw_if_error()
|
|
2620
2633
|
return result
|
|
@@ -2638,7 +2651,7 @@ class QrackSimulator:
|
|
|
2638
2651
|
if (3 * len(q)) != len(b):
|
|
2639
2652
|
raise RuntimeError("unitary_expectation argument lengths do not match.")
|
|
2640
2653
|
result = Qrack.qrack_lib.UnitaryExpectation(
|
|
2641
|
-
self.sid, len(q),
|
|
2654
|
+
self.sid, len(q), QrackSimulator._ulonglong_byref(q), QrackSimulator._real1_byref(b)
|
|
2642
2655
|
)
|
|
2643
2656
|
self._throw_if_error()
|
|
2644
2657
|
return result
|
|
@@ -2662,7 +2675,7 @@ class QrackSimulator:
|
|
|
2662
2675
|
if (len(q) << 2) != len(b):
|
|
2663
2676
|
raise RuntimeError("matrix_expectation argument lengths do not match.")
|
|
2664
2677
|
result = Qrack.qrack_lib.MatrixExpectation(
|
|
2665
|
-
self.sid, len(q),
|
|
2678
|
+
self.sid, len(q), QrackSimulator._ulonglong_byref(q), QrackSimulator._complex_byref(b)
|
|
2666
2679
|
)
|
|
2667
2680
|
self._throw_if_error()
|
|
2668
2681
|
return result
|
|
@@ -2694,9 +2707,9 @@ class QrackSimulator:
|
|
|
2694
2707
|
result = Qrack.qrack_lib.UnitaryExpectationEigenVal(
|
|
2695
2708
|
self.sid,
|
|
2696
2709
|
len(q),
|
|
2697
|
-
|
|
2698
|
-
|
|
2699
|
-
|
|
2710
|
+
QrackSimulator._ulonglong_byref(q),
|
|
2711
|
+
QrackSimulator._real1_byref(b),
|
|
2712
|
+
QrackSimulator._real1_byref(e),
|
|
2700
2713
|
)
|
|
2701
2714
|
self._throw_if_error()
|
|
2702
2715
|
return result
|
|
@@ -2728,9 +2741,9 @@ class QrackSimulator:
|
|
|
2728
2741
|
result = Qrack.qrack_lib.MatrixExpectationEigenVal(
|
|
2729
2742
|
self.sid,
|
|
2730
2743
|
len(q),
|
|
2731
|
-
|
|
2732
|
-
|
|
2733
|
-
|
|
2744
|
+
QrackSimulator._ulonglong_byref(q),
|
|
2745
|
+
QrackSimulator._complex_byref(b),
|
|
2746
|
+
QrackSimulator._real1_byref(e),
|
|
2734
2747
|
)
|
|
2735
2748
|
self._throw_if_error()
|
|
2736
2749
|
return result
|
|
@@ -2755,7 +2768,7 @@ class QrackSimulator:
|
|
|
2755
2768
|
if len(q) != len(b):
|
|
2756
2769
|
raise RuntimeError("pauli_expectation argument lengths do not match.")
|
|
2757
2770
|
result = Qrack.qrack_lib.PauliExpectation(
|
|
2758
|
-
self.sid, len(q),
|
|
2771
|
+
self.sid, len(q), QrackSimulator._ulonglong_byref(q), QrackSimulator._ulonglong_byref(b)
|
|
2759
2772
|
)
|
|
2760
2773
|
self._throw_if_error()
|
|
2761
2774
|
return result
|
|
@@ -2775,7 +2788,7 @@ class QrackSimulator:
|
|
|
2775
2788
|
Returns:
|
|
2776
2789
|
float variance
|
|
2777
2790
|
"""
|
|
2778
|
-
result = Qrack.qrack_lib.Variance(self.sid, len(q),
|
|
2791
|
+
result = Qrack.qrack_lib.Variance(self.sid, len(q), QrackSimulator._ulonglong_byref(q))
|
|
2779
2792
|
self._throw_if_error()
|
|
2780
2793
|
return result
|
|
2781
2794
|
|
|
@@ -2797,7 +2810,7 @@ class QrackSimulator:
|
|
|
2797
2810
|
variance
|
|
2798
2811
|
"""
|
|
2799
2812
|
result = Qrack.qrack_lib.VarianceRdm(
|
|
2800
|
-
self.sid, len(q),
|
|
2813
|
+
self.sid, len(q), QrackSimulator._ulonglong_byref(q), r
|
|
2801
2814
|
)
|
|
2802
2815
|
self._throw_if_error()
|
|
2803
2816
|
return result
|
|
@@ -2823,7 +2836,7 @@ class QrackSimulator:
|
|
|
2823
2836
|
raise RuntimeError("factorized_variance argument lengths do not match.")
|
|
2824
2837
|
m = max([(x.bit_length() + 63) // 64 for x in c])
|
|
2825
2838
|
result = Qrack.qrack_lib.FactorizedVariance(
|
|
2826
|
-
self.sid, len(q),
|
|
2839
|
+
self.sid, len(q), QrackSimulator._ulonglong_byref(q), m, QrackSimulator._to_ulonglong(m, c)
|
|
2827
2840
|
)
|
|
2828
2841
|
self._throw_if_error()
|
|
2829
2842
|
return result
|
|
@@ -2851,7 +2864,7 @@ class QrackSimulator:
|
|
|
2851
2864
|
raise RuntimeError("factorized_variance_rdm argument lengths do not match.")
|
|
2852
2865
|
m = max([(x.bit_length() + 63) // 64 for x in c])
|
|
2853
2866
|
result = Qrack.qrack_lib.FactorizedVarianceRdm(
|
|
2854
|
-
self.sid, len(q),
|
|
2867
|
+
self.sid, len(q), QrackSimulator._ulonglong_byref(q), m, QrackSimulator._to_ulonglong(m, c), r
|
|
2855
2868
|
)
|
|
2856
2869
|
self._throw_if_error()
|
|
2857
2870
|
return result
|
|
@@ -2876,7 +2889,7 @@ class QrackSimulator:
|
|
|
2876
2889
|
if (len(q) << 1) != len(c):
|
|
2877
2890
|
raise RuntimeError("factorized_variance_rdm argument lengths do not match.")
|
|
2878
2891
|
result = Qrack.qrack_lib.FactorizedVarianceFp(
|
|
2879
|
-
self.sid, len(q),
|
|
2892
|
+
self.sid, len(q), QrackSimulator._ulonglong_byref(q), QrackSimulator._real1_byref(c)
|
|
2880
2893
|
)
|
|
2881
2894
|
self._throw_if_error()
|
|
2882
2895
|
return result
|
|
@@ -2905,7 +2918,7 @@ class QrackSimulator:
|
|
|
2905
2918
|
"factorized_variance_fp_rdm argument lengths do not match."
|
|
2906
2919
|
)
|
|
2907
2920
|
result = Qrack.qrack_lib.FactorizedVarianceFpRdm(
|
|
2908
|
-
self.sid, len(q),
|
|
2921
|
+
self.sid, len(q), QrackSimulator._ulonglong_byref(q), QrackSimulator._real1_byref(c), r
|
|
2909
2922
|
)
|
|
2910
2923
|
self._throw_if_error()
|
|
2911
2924
|
return result
|
|
@@ -2929,7 +2942,7 @@ class QrackSimulator:
|
|
|
2929
2942
|
if (3 * len(q)) != len(b):
|
|
2930
2943
|
raise RuntimeError("unitary_variance argument lengths do not match.")
|
|
2931
2944
|
result = Qrack.qrack_lib.UnitaryVariance(
|
|
2932
|
-
self.sid, len(q),
|
|
2945
|
+
self.sid, len(q), QrackSimulator._ulonglong_byref(q), QrackSimulator._real1_byref(b)
|
|
2933
2946
|
)
|
|
2934
2947
|
self._throw_if_error()
|
|
2935
2948
|
return result
|
|
@@ -2953,7 +2966,7 @@ class QrackSimulator:
|
|
|
2953
2966
|
if (len(q) << 2) != len(b):
|
|
2954
2967
|
raise RuntimeError("matrix_variance argument lengths do not match.")
|
|
2955
2968
|
result = Qrack.qrack_lib.MatrixVariance(
|
|
2956
|
-
self.sid, len(q),
|
|
2969
|
+
self.sid, len(q), QrackSimulator._ulonglong_byref(q), QrackSimulator._complex_byref(b)
|
|
2957
2970
|
)
|
|
2958
2971
|
self._throw_if_error()
|
|
2959
2972
|
return result
|
|
@@ -2985,9 +2998,9 @@ class QrackSimulator:
|
|
|
2985
2998
|
result = Qrack.qrack_lib.UnitaryVarianceEigenVal(
|
|
2986
2999
|
self.sid,
|
|
2987
3000
|
len(q),
|
|
2988
|
-
|
|
2989
|
-
|
|
2990
|
-
|
|
3001
|
+
QrackSimulator._ulonglong_byref(q),
|
|
3002
|
+
QrackSimulator._real1_byref(b),
|
|
3003
|
+
QrackSimulator._real1_byref(e),
|
|
2991
3004
|
)
|
|
2992
3005
|
self._throw_if_error()
|
|
2993
3006
|
return result
|
|
@@ -3019,9 +3032,9 @@ class QrackSimulator:
|
|
|
3019
3032
|
result = Qrack.qrack_lib.MatrixVarianceEigenVal(
|
|
3020
3033
|
self.sid,
|
|
3021
3034
|
len(q),
|
|
3022
|
-
|
|
3023
|
-
|
|
3024
|
-
|
|
3035
|
+
QrackSimulator._ulonglong_byref(q),
|
|
3036
|
+
QrackSimulator._complex_byref(b),
|
|
3037
|
+
QrackSimulator._real1_byref(e),
|
|
3025
3038
|
)
|
|
3026
3039
|
self._throw_if_error()
|
|
3027
3040
|
return result
|
|
@@ -3046,7 +3059,7 @@ class QrackSimulator:
|
|
|
3046
3059
|
if len(q) != len(b):
|
|
3047
3060
|
raise RuntimeError("pauli_variance argument lengths do not match.")
|
|
3048
3061
|
result = Qrack.qrack_lib.PauliVariance(
|
|
3049
|
-
self.sid, len(q),
|
|
3062
|
+
self.sid, len(q), QrackSimulator._ulonglong_byref(q), QrackSimulator._ulonglong_byref(b)
|
|
3050
3063
|
)
|
|
3051
3064
|
self._throw_if_error()
|
|
3052
3065
|
return result
|
|
@@ -3070,7 +3083,7 @@ class QrackSimulator:
|
|
|
3070
3083
|
if len(b) != len(q):
|
|
3071
3084
|
raise RuntimeError("Lengths of list parameters are mismatched.")
|
|
3072
3085
|
result = Qrack.qrack_lib.JointEnsembleProbability(
|
|
3073
|
-
self.sid, len(b),
|
|
3086
|
+
self.sid, len(b), QrackSimulator._ulonglong_byref(b), q
|
|
3074
3087
|
)
|
|
3075
3088
|
self._throw_if_error()
|
|
3076
3089
|
return result
|
|
@@ -3099,7 +3112,7 @@ class QrackSimulator:
|
|
|
3099
3112
|
)
|
|
3100
3113
|
|
|
3101
3114
|
Qrack.qrack_lib.PhaseParity(
|
|
3102
|
-
self.sid, ctypes.c_double(la), len(q),
|
|
3115
|
+
self.sid, ctypes.c_double(la), len(q), QrackSimulator._ulonglong_byref(q)
|
|
3103
3116
|
)
|
|
3104
3117
|
self._throw_if_error()
|
|
3105
3118
|
|
|
@@ -3125,7 +3138,7 @@ class QrackSimulator:
|
|
|
3125
3138
|
"QrackStabilizer cannot phase_root_n()! (Create a QrackSimulator instead, also with isTensorNetwork=False.)"
|
|
3126
3139
|
)
|
|
3127
3140
|
|
|
3128
|
-
Qrack.qrack_lib.PhaseRootN(self.sid, n, len(q),
|
|
3141
|
+
Qrack.qrack_lib.PhaseRootN(self.sid, n, len(q), QrackSimulator._ulonglong_byref(q))
|
|
3129
3142
|
self._throw_if_error()
|
|
3130
3143
|
|
|
3131
3144
|
def try_separate_1qb(self, qi1):
|
|
@@ -3182,7 +3195,7 @@ class QrackSimulator:
|
|
|
3182
3195
|
State of all the qubits.
|
|
3183
3196
|
"""
|
|
3184
3197
|
result = Qrack.qrack_lib.TrySeparateTol(
|
|
3185
|
-
self.sid, len(qs),
|
|
3198
|
+
self.sid, len(qs), QrackSimulator._ulonglong_byref(qs), t
|
|
3186
3199
|
)
|
|
3187
3200
|
self._throw_if_error()
|
|
3188
3201
|
return result
|
|
@@ -3198,7 +3211,7 @@ class QrackSimulator:
|
|
|
3198
3211
|
Raises:
|
|
3199
3212
|
Runtimeerror: QrackSimulator raised an exception.
|
|
3200
3213
|
"""
|
|
3201
|
-
result = Qrack.qrack_lib.Separate(self.sid, len(qs),
|
|
3214
|
+
result = Qrack.qrack_lib.Separate(self.sid, len(qs), QrackSimulator._ulonglong_byref(qs))
|
|
3202
3215
|
self._throw_if_error()
|
|
3203
3216
|
|
|
3204
3217
|
def get_unitary_fidelity(self):
|
|
@@ -3322,6 +3335,41 @@ class QrackSimulator:
|
|
|
3322
3335
|
Qrack.qrack_lib.SetNoiseParameter(self.sid, np)
|
|
3323
3336
|
self._throw_if_error()
|
|
3324
3337
|
|
|
3338
|
+
def set_ace_max_qb(self, qb):
|
|
3339
|
+
"""Set "automatic circuit elision" (ACE) max qubits
|
|
3340
|
+
|
|
3341
|
+
If isSchmidtDecompose=True, maximum entangled subsytem size
|
|
3342
|
+
of this simulator will be capped to 'qb', and entangling
|
|
3343
|
+
gates that would exceed that size are replaced with gate
|
|
3344
|
+
shadows.
|
|
3345
|
+
|
|
3346
|
+
Args:
|
|
3347
|
+
qb: maximum subsystem qubits
|
|
3348
|
+
|
|
3349
|
+
Raises:
|
|
3350
|
+
RuntimeError: QrackSimulator raised an exception.
|
|
3351
|
+
"""
|
|
3352
|
+
Qrack.qrack_lib.SetAceMaxQb(self.sid, qb)
|
|
3353
|
+
self._throw_if_error()
|
|
3354
|
+
|
|
3355
|
+
def set_sparse_ace_max_mb(self, mb):
|
|
3356
|
+
"""Set sparse "automatic circuit elision" (ACE) max memory
|
|
3357
|
+
|
|
3358
|
+
If isSchmidtDecompose=True, isSparse=True, and
|
|
3359
|
+
isOpenCL=False, maximum subsytem size memory MB of this
|
|
3360
|
+
simulator will be capped to 'mb', and entangling gates
|
|
3361
|
+
that would exceed that size are replaced with gate
|
|
3362
|
+
shadows.
|
|
3363
|
+
|
|
3364
|
+
Args:
|
|
3365
|
+
mb: maximum subsystem memory in MB
|
|
3366
|
+
|
|
3367
|
+
Raises:
|
|
3368
|
+
RuntimeError: QrackSimulator raised an exception.
|
|
3369
|
+
"""
|
|
3370
|
+
Qrack.qrack_lib.SetSparseAceMaxMb(self.sid, mb)
|
|
3371
|
+
self._throw_if_error()
|
|
3372
|
+
|
|
3325
3373
|
def normalize(self):
|
|
3326
3374
|
"""Normalize the state
|
|
3327
3375
|
|
|
@@ -4457,6 +4505,7 @@ class QrackSimulator:
|
|
|
4457
4505
|
|
|
4458
4506
|
return _data
|
|
4459
4507
|
|
|
4508
|
+
@staticmethod
|
|
4460
4509
|
def get_qiskit_basis_gates():
|
|
4461
4510
|
return [
|
|
4462
4511
|
"id",
|