pyqrack-complex128 1.65.2__py3-none-macosx_14_0_arm64.whl → 1.81.0__py3-none-macosx_14_0_arm64.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.
Potentially problematic release.
This version of pyqrack-complex128 might be problematic. Click here for more details.
- pyqrack/__init__.py +2 -2
- pyqrack/qrack_ace_backend.py +44 -70
- pyqrack/qrack_circuit.py +51 -40
- pyqrack/qrack_neuron.py +129 -34
- pyqrack/qrack_neuron_torch_layer.py +194 -107
- pyqrack/qrack_simulator.py +372 -278
- pyqrack/qrack_system/qrack_lib/libqrack_pinvoke.10.0.0.dylib +0 -0
- pyqrack/qrack_system/qrack_lib/libqrack_pinvoke.dylib +0 -0
- pyqrack/qrack_system/qrack_system.py +84 -59
- pyqrack/stats/load_quantized_data.py +1 -3
- pyqrack/stats/quantize_by_range.py +2 -6
- {pyqrack_complex128-1.65.2.dist-info → pyqrack_complex128-1.81.0.dist-info}/METADATA +4 -4
- pyqrack_complex128-1.81.0.dist-info/RECORD +23 -0
- pyqrack/qrack_system/qrack_lib/libqrack_pinvoke.9.24.0.dylib +0 -0
- pyqrack_complex128-1.65.2.dist-info/RECORD +0 -23
- {pyqrack_complex128-1.65.2.dist-info → pyqrack_complex128-1.81.0.dist-info}/LICENSE +0 -0
- {pyqrack_complex128-1.65.2.dist-info → pyqrack_complex128-1.81.0.dist-info}/WHEEL +0 -0
- {pyqrack_complex128-1.65.2.dist-info → pyqrack_complex128-1.81.0.dist-info}/top_level.txt +0 -0
pyqrack/qrack_simulator.py
CHANGED
|
@@ -57,9 +57,8 @@ class QrackSimulator:
|
|
|
57
57
|
isPaged=True,
|
|
58
58
|
isCpuGpuHybrid=True,
|
|
59
59
|
isOpenCL=True,
|
|
60
|
-
isHostPointer=(
|
|
61
|
-
|
|
62
|
-
),
|
|
60
|
+
isHostPointer=(True if os.environ.get("PYQRACK_HOST_POINTER_DEFAULT_ON") else False),
|
|
61
|
+
isSparse=False,
|
|
63
62
|
noise=0,
|
|
64
63
|
pyzxCircuit=None,
|
|
65
64
|
qiskitCircuit=None,
|
|
@@ -99,6 +98,7 @@ class QrackSimulator:
|
|
|
99
98
|
isCpuGpuHybrid,
|
|
100
99
|
isOpenCL,
|
|
101
100
|
isHostPointer,
|
|
101
|
+
isSparse,
|
|
102
102
|
)
|
|
103
103
|
|
|
104
104
|
self._throw_if_error()
|
|
@@ -116,36 +116,45 @@ class QrackSimulator:
|
|
|
116
116
|
Qrack.qrack_lib.destroy(self.sid)
|
|
117
117
|
self.sid = None
|
|
118
118
|
|
|
119
|
-
|
|
119
|
+
@staticmethod
|
|
120
|
+
def _int_byref(a):
|
|
120
121
|
return (ctypes.c_int * len(a))(*a)
|
|
121
122
|
|
|
122
|
-
|
|
123
|
+
@staticmethod
|
|
124
|
+
def _ulonglong_byref(a):
|
|
123
125
|
return (ctypes.c_ulonglong * len(a))(*a)
|
|
124
126
|
|
|
125
|
-
|
|
127
|
+
@staticmethod
|
|
128
|
+
def _longlong_byref(a):
|
|
126
129
|
return (ctypes.c_longlong * len(a))(*a)
|
|
127
130
|
|
|
128
|
-
|
|
131
|
+
@staticmethod
|
|
132
|
+
def _double_byref(a):
|
|
129
133
|
return (ctypes.c_double * len(a))(*a)
|
|
130
134
|
|
|
131
|
-
|
|
135
|
+
@staticmethod
|
|
136
|
+
def _complex_byref(a):
|
|
132
137
|
t = [(c.real, c.imag) for c in a]
|
|
133
|
-
return
|
|
138
|
+
return QrackSimulator._double_byref([float(item) for sublist in t for item in sublist])
|
|
134
139
|
|
|
135
|
-
|
|
140
|
+
@staticmethod
|
|
141
|
+
def _real1_byref(a):
|
|
136
142
|
# This needs to be c_double, if PyQrack is built with fp64.
|
|
137
143
|
if Qrack.fppow < 6:
|
|
138
144
|
return (ctypes.c_float * len(a))(*a)
|
|
139
145
|
return (ctypes.c_double * len(a))(*a)
|
|
140
146
|
|
|
141
|
-
|
|
147
|
+
@staticmethod
|
|
148
|
+
def _bool_byref(a):
|
|
142
149
|
return (ctypes.c_bool * len(a))(*a)
|
|
143
150
|
|
|
144
|
-
|
|
151
|
+
@staticmethod
|
|
152
|
+
def _qrack_complex_byref(a):
|
|
145
153
|
t = [(c.real, c.imag) for c in a]
|
|
146
|
-
return
|
|
154
|
+
return QrackSimulator._real1_byref([float(item) for sublist in t for item in sublist])
|
|
147
155
|
|
|
148
|
-
|
|
156
|
+
@staticmethod
|
|
157
|
+
def _to_ubyte(nv, v):
|
|
149
158
|
c = math.floor((nv - 1) / 8) + 1
|
|
150
159
|
b = (ctypes.c_ubyte * (c * (1 << nv)))()
|
|
151
160
|
n = 0
|
|
@@ -157,7 +166,8 @@ class QrackSimulator:
|
|
|
157
166
|
|
|
158
167
|
return b
|
|
159
168
|
|
|
160
|
-
|
|
169
|
+
@staticmethod
|
|
170
|
+
def _to_ulonglong(m, v):
|
|
161
171
|
b = (ctypes.c_ulonglong * (m * len(v)))()
|
|
162
172
|
n = 0
|
|
163
173
|
for u in v:
|
|
@@ -169,7 +179,8 @@ class QrackSimulator:
|
|
|
169
179
|
return b
|
|
170
180
|
|
|
171
181
|
# See https://stackoverflow.com/questions/5389507/iterating-over-every-two-elements-in-a-list#answer-30426000
|
|
172
|
-
|
|
182
|
+
@staticmethod
|
|
183
|
+
def _pairwise(it):
|
|
173
184
|
it = iter(it)
|
|
174
185
|
while True:
|
|
175
186
|
try:
|
|
@@ -195,7 +206,7 @@ class QrackSimulator:
|
|
|
195
206
|
|
|
196
207
|
def set_device_list(self, d):
|
|
197
208
|
"""Set the GPU device ID"""
|
|
198
|
-
Qrack.qrack_lib.set_device_list(self.sid, len(d),
|
|
209
|
+
Qrack.qrack_lib.set_device_list(self.sid, len(d), QrackSimulator._longlong_byref(d))
|
|
199
210
|
self._throw_if_error()
|
|
200
211
|
|
|
201
212
|
def clone(self):
|
|
@@ -359,7 +370,7 @@ class QrackSimulator:
|
|
|
359
370
|
raise ValueError(
|
|
360
371
|
"2x2 matrix 'm' in QrackSimulator.mtrx() must contain at least 4 elements."
|
|
361
372
|
)
|
|
362
|
-
Qrack.qrack_lib.Mtrx(self.sid,
|
|
373
|
+
Qrack.qrack_lib.Mtrx(self.sid, QrackSimulator._complex_byref(m), q)
|
|
363
374
|
self._throw_if_error()
|
|
364
375
|
|
|
365
376
|
def r(self, b, ph, q):
|
|
@@ -399,9 +410,9 @@ class QrackSimulator:
|
|
|
399
410
|
Qrack.qrack_lib.Exp(
|
|
400
411
|
self.sid,
|
|
401
412
|
len(b),
|
|
402
|
-
|
|
413
|
+
QrackSimulator._ulonglong_byref(b),
|
|
403
414
|
ctypes.c_double(ph),
|
|
404
|
-
|
|
415
|
+
QrackSimulator._ulonglong_byref(q),
|
|
405
416
|
)
|
|
406
417
|
self._throw_if_error()
|
|
407
418
|
|
|
@@ -418,7 +429,7 @@ class QrackSimulator:
|
|
|
418
429
|
Raises:
|
|
419
430
|
RuntimeError: QrackSimulator raised an exception.
|
|
420
431
|
"""
|
|
421
|
-
Qrack.qrack_lib.MCX(self.sid, len(c),
|
|
432
|
+
Qrack.qrack_lib.MCX(self.sid, len(c), QrackSimulator._ulonglong_byref(c), q)
|
|
422
433
|
self._throw_if_error()
|
|
423
434
|
|
|
424
435
|
def mcy(self, c, q):
|
|
@@ -434,7 +445,7 @@ class QrackSimulator:
|
|
|
434
445
|
Raises:
|
|
435
446
|
RuntimeError: QrackSimulator raised an exception.
|
|
436
447
|
"""
|
|
437
|
-
Qrack.qrack_lib.MCY(self.sid, len(c),
|
|
448
|
+
Qrack.qrack_lib.MCY(self.sid, len(c), QrackSimulator._ulonglong_byref(c), q)
|
|
438
449
|
self._throw_if_error()
|
|
439
450
|
|
|
440
451
|
def mcz(self, c, q):
|
|
@@ -450,7 +461,7 @@ class QrackSimulator:
|
|
|
450
461
|
Raises:
|
|
451
462
|
RuntimeError: QrackSimulator raised an exception.
|
|
452
463
|
"""
|
|
453
|
-
Qrack.qrack_lib.MCZ(self.sid, len(c),
|
|
464
|
+
Qrack.qrack_lib.MCZ(self.sid, len(c), QrackSimulator._ulonglong_byref(c), q)
|
|
454
465
|
self._throw_if_error()
|
|
455
466
|
|
|
456
467
|
def mch(self, c, q):
|
|
@@ -466,7 +477,7 @@ class QrackSimulator:
|
|
|
466
477
|
Raises:
|
|
467
478
|
RuntimeError: QrackSimulator raised an exception.
|
|
468
479
|
"""
|
|
469
|
-
Qrack.qrack_lib.MCH(self.sid, len(c),
|
|
480
|
+
Qrack.qrack_lib.MCH(self.sid, len(c), QrackSimulator._ulonglong_byref(c), q)
|
|
470
481
|
self._throw_if_error()
|
|
471
482
|
|
|
472
483
|
def mcs(self, c, q):
|
|
@@ -482,7 +493,7 @@ class QrackSimulator:
|
|
|
482
493
|
Raises:
|
|
483
494
|
RuntimeError: QrackSimulator raised an exception.
|
|
484
495
|
"""
|
|
485
|
-
Qrack.qrack_lib.MCS(self.sid, len(c),
|
|
496
|
+
Qrack.qrack_lib.MCS(self.sid, len(c), QrackSimulator._ulonglong_byref(c), q)
|
|
486
497
|
self._throw_if_error()
|
|
487
498
|
|
|
488
499
|
def mct(self, c, q):
|
|
@@ -498,7 +509,7 @@ class QrackSimulator:
|
|
|
498
509
|
Raises:
|
|
499
510
|
RuntimeError: QrackSimulator raised an exception.
|
|
500
511
|
"""
|
|
501
|
-
Qrack.qrack_lib.MCT(self.sid, len(c),
|
|
512
|
+
Qrack.qrack_lib.MCT(self.sid, len(c), QrackSimulator._ulonglong_byref(c), q)
|
|
502
513
|
self._throw_if_error()
|
|
503
514
|
|
|
504
515
|
def mcadjs(self, c, q):
|
|
@@ -514,7 +525,7 @@ class QrackSimulator:
|
|
|
514
525
|
Raises:
|
|
515
526
|
RuntimeError: QrackSimulator raised an exception.
|
|
516
527
|
"""
|
|
517
|
-
Qrack.qrack_lib.MCAdjS(self.sid, len(c),
|
|
528
|
+
Qrack.qrack_lib.MCAdjS(self.sid, len(c), QrackSimulator._ulonglong_byref(c), q)
|
|
518
529
|
self._throw_if_error()
|
|
519
530
|
|
|
520
531
|
def mcadjt(self, c, q):
|
|
@@ -530,7 +541,7 @@ class QrackSimulator:
|
|
|
530
541
|
Raises:
|
|
531
542
|
RuntimeError: QrackSimulator raised an exception.
|
|
532
543
|
"""
|
|
533
|
-
Qrack.qrack_lib.MCAdjT(self.sid, len(c),
|
|
544
|
+
Qrack.qrack_lib.MCAdjT(self.sid, len(c), QrackSimulator._ulonglong_byref(c), q)
|
|
534
545
|
self._throw_if_error()
|
|
535
546
|
|
|
536
547
|
def mcu(self, c, q, th, ph, la):
|
|
@@ -552,7 +563,7 @@ class QrackSimulator:
|
|
|
552
563
|
Qrack.qrack_lib.MCU(
|
|
553
564
|
self.sid,
|
|
554
565
|
len(c),
|
|
555
|
-
|
|
566
|
+
QrackSimulator._ulonglong_byref(c),
|
|
556
567
|
q,
|
|
557
568
|
ctypes.c_double(th),
|
|
558
569
|
ctypes.c_double(ph),
|
|
@@ -580,7 +591,11 @@ class QrackSimulator:
|
|
|
580
591
|
"2x2 matrix 'm' in QrackSimulator.mcmtrx() must contain at least 4 elements."
|
|
581
592
|
)
|
|
582
593
|
Qrack.qrack_lib.MCMtrx(
|
|
583
|
-
self.sid,
|
|
594
|
+
self.sid,
|
|
595
|
+
len(c),
|
|
596
|
+
QrackSimulator._ulonglong_byref(c),
|
|
597
|
+
QrackSimulator._complex_byref(m),
|
|
598
|
+
q,
|
|
584
599
|
)
|
|
585
600
|
self._throw_if_error()
|
|
586
601
|
|
|
@@ -596,7 +611,7 @@ class QrackSimulator:
|
|
|
596
611
|
Raises:
|
|
597
612
|
RuntimeError: QrackSimulator raised an exception.
|
|
598
613
|
"""
|
|
599
|
-
Qrack.qrack_lib.MACX(self.sid, len(c),
|
|
614
|
+
Qrack.qrack_lib.MACX(self.sid, len(c), QrackSimulator._ulonglong_byref(c), q)
|
|
600
615
|
self._throw_if_error()
|
|
601
616
|
|
|
602
617
|
def macy(self, c, q):
|
|
@@ -612,7 +627,7 @@ class QrackSimulator:
|
|
|
612
627
|
Raises:
|
|
613
628
|
RuntimeError: QrackSimulator raised an exception.
|
|
614
629
|
"""
|
|
615
|
-
Qrack.qrack_lib.MACY(self.sid, len(c),
|
|
630
|
+
Qrack.qrack_lib.MACY(self.sid, len(c), QrackSimulator._ulonglong_byref(c), q)
|
|
616
631
|
self._throw_if_error()
|
|
617
632
|
|
|
618
633
|
def macz(self, c, q):
|
|
@@ -628,7 +643,7 @@ class QrackSimulator:
|
|
|
628
643
|
Raises:
|
|
629
644
|
RuntimeError: QrackSimulator raised an exception.
|
|
630
645
|
"""
|
|
631
|
-
Qrack.qrack_lib.MACZ(self.sid, len(c),
|
|
646
|
+
Qrack.qrack_lib.MACZ(self.sid, len(c), QrackSimulator._ulonglong_byref(c), q)
|
|
632
647
|
self._throw_if_error()
|
|
633
648
|
|
|
634
649
|
def mach(self, c, q):
|
|
@@ -644,7 +659,7 @@ class QrackSimulator:
|
|
|
644
659
|
Raises:
|
|
645
660
|
RuntimeError: QrackSimulator raised an exception.
|
|
646
661
|
"""
|
|
647
|
-
Qrack.qrack_lib.MACH(self.sid, len(c),
|
|
662
|
+
Qrack.qrack_lib.MACH(self.sid, len(c), QrackSimulator._ulonglong_byref(c), q)
|
|
648
663
|
self._throw_if_error()
|
|
649
664
|
|
|
650
665
|
def macs(self, c, q):
|
|
@@ -660,7 +675,7 @@ class QrackSimulator:
|
|
|
660
675
|
Raises:
|
|
661
676
|
RuntimeError: QrackSimulator raised an exception.
|
|
662
677
|
"""
|
|
663
|
-
Qrack.qrack_lib.MACS(self.sid, len(c),
|
|
678
|
+
Qrack.qrack_lib.MACS(self.sid, len(c), QrackSimulator._ulonglong_byref(c), q)
|
|
664
679
|
self._throw_if_error()
|
|
665
680
|
|
|
666
681
|
def mact(self, c, q):
|
|
@@ -676,7 +691,7 @@ class QrackSimulator:
|
|
|
676
691
|
Raises:
|
|
677
692
|
RuntimeError: QrackSimulator raised an exception.
|
|
678
693
|
"""
|
|
679
|
-
Qrack.qrack_lib.MACT(self.sid, len(c),
|
|
694
|
+
Qrack.qrack_lib.MACT(self.sid, len(c), QrackSimulator._ulonglong_byref(c), q)
|
|
680
695
|
self._throw_if_error()
|
|
681
696
|
|
|
682
697
|
def macadjs(self, c, q):
|
|
@@ -692,7 +707,7 @@ class QrackSimulator:
|
|
|
692
707
|
Raises:
|
|
693
708
|
RuntimeError: QrackSimulator raised an exception.
|
|
694
709
|
"""
|
|
695
|
-
Qrack.qrack_lib.MACAdjS(self.sid, len(c),
|
|
710
|
+
Qrack.qrack_lib.MACAdjS(self.sid, len(c), QrackSimulator._ulonglong_byref(c), q)
|
|
696
711
|
self._throw_if_error()
|
|
697
712
|
|
|
698
713
|
def macadjt(self, c, q):
|
|
@@ -708,7 +723,7 @@ class QrackSimulator:
|
|
|
708
723
|
Raises:
|
|
709
724
|
RuntimeError: QrackSimulator raised an exception.
|
|
710
725
|
"""
|
|
711
|
-
Qrack.qrack_lib.MACAdjT(self.sid, len(c),
|
|
726
|
+
Qrack.qrack_lib.MACAdjT(self.sid, len(c), QrackSimulator._ulonglong_byref(c), q)
|
|
712
727
|
self._throw_if_error()
|
|
713
728
|
|
|
714
729
|
def macu(self, c, q, th, ph, la):
|
|
@@ -730,7 +745,7 @@ class QrackSimulator:
|
|
|
730
745
|
Qrack.qrack_lib.MACU(
|
|
731
746
|
self.sid,
|
|
732
747
|
len(c),
|
|
733
|
-
|
|
748
|
+
QrackSimulator._ulonglong_byref(c),
|
|
734
749
|
q,
|
|
735
750
|
ctypes.c_double(th),
|
|
736
751
|
ctypes.c_double(ph),
|
|
@@ -758,7 +773,11 @@ class QrackSimulator:
|
|
|
758
773
|
"2x2 matrix 'm' in QrackSimulator.macmtrx() must contain at least 4 elements."
|
|
759
774
|
)
|
|
760
775
|
Qrack.qrack_lib.MACMtrx(
|
|
761
|
-
self.sid,
|
|
776
|
+
self.sid,
|
|
777
|
+
len(c),
|
|
778
|
+
QrackSimulator._ulonglong_byref(c),
|
|
779
|
+
QrackSimulator._complex_byref(m),
|
|
780
|
+
q,
|
|
762
781
|
)
|
|
763
782
|
self._throw_if_error()
|
|
764
783
|
|
|
@@ -783,7 +802,12 @@ class QrackSimulator:
|
|
|
783
802
|
"2x2 matrix 'm' in QrackSimulator.ucmtrx() must contain at least 4 elements."
|
|
784
803
|
)
|
|
785
804
|
Qrack.qrack_lib.UCMtrx(
|
|
786
|
-
self.sid,
|
|
805
|
+
self.sid,
|
|
806
|
+
len(c),
|
|
807
|
+
QrackSimulator._ulonglong_byref(c),
|
|
808
|
+
QrackSimulator._complex_byref(m),
|
|
809
|
+
q,
|
|
810
|
+
p,
|
|
787
811
|
)
|
|
788
812
|
self._throw_if_error()
|
|
789
813
|
|
|
@@ -807,7 +831,11 @@ class QrackSimulator:
|
|
|
807
831
|
"Multiplex matrix 'm' in QrackSimulator.multiplex1_mtrx() must contain at least (4 * 2 ** len(c)) elements."
|
|
808
832
|
)
|
|
809
833
|
Qrack.qrack_lib.Multiplex1Mtrx(
|
|
810
|
-
self.sid,
|
|
834
|
+
self.sid,
|
|
835
|
+
len(c),
|
|
836
|
+
QrackSimulator._ulonglong_byref(c),
|
|
837
|
+
q,
|
|
838
|
+
QrackSimulator._complex_byref(m),
|
|
811
839
|
)
|
|
812
840
|
self._throw_if_error()
|
|
813
841
|
|
|
@@ -822,7 +850,7 @@ class QrackSimulator:
|
|
|
822
850
|
Raises:
|
|
823
851
|
RuntimeError: QrackSimulator raised an exception.
|
|
824
852
|
"""
|
|
825
|
-
Qrack.qrack_lib.MX(self.sid, len(q),
|
|
853
|
+
Qrack.qrack_lib.MX(self.sid, len(q), QrackSimulator._ulonglong_byref(q))
|
|
826
854
|
self._throw_if_error()
|
|
827
855
|
|
|
828
856
|
def my(self, q):
|
|
@@ -836,7 +864,7 @@ class QrackSimulator:
|
|
|
836
864
|
Raises:
|
|
837
865
|
RuntimeError: QrackSimulator raised an exception.
|
|
838
866
|
"""
|
|
839
|
-
Qrack.qrack_lib.MY(self.sid, len(q),
|
|
867
|
+
Qrack.qrack_lib.MY(self.sid, len(q), QrackSimulator._ulonglong_byref(q))
|
|
840
868
|
self._throw_if_error()
|
|
841
869
|
|
|
842
870
|
def mz(self, q):
|
|
@@ -850,7 +878,7 @@ class QrackSimulator:
|
|
|
850
878
|
Raises:
|
|
851
879
|
RuntimeError: QrackSimulator raised an exception.
|
|
852
880
|
"""
|
|
853
|
-
Qrack.qrack_lib.MZ(self.sid, len(q),
|
|
881
|
+
Qrack.qrack_lib.MZ(self.sid, len(q), QrackSimulator._ulonglong_byref(q))
|
|
854
882
|
self._throw_if_error()
|
|
855
883
|
|
|
856
884
|
def mcr(self, b, ph, c, q):
|
|
@@ -873,7 +901,7 @@ class QrackSimulator:
|
|
|
873
901
|
ctypes.c_ulonglong(b),
|
|
874
902
|
ctypes.c_double(ph),
|
|
875
903
|
len(c),
|
|
876
|
-
|
|
904
|
+
QrackSimulator._ulonglong_byref(c),
|
|
877
905
|
q,
|
|
878
906
|
)
|
|
879
907
|
self._throw_if_error()
|
|
@@ -897,11 +925,11 @@ class QrackSimulator:
|
|
|
897
925
|
Qrack.qrack_lib.MCExp(
|
|
898
926
|
self.sid,
|
|
899
927
|
len(b),
|
|
900
|
-
|
|
928
|
+
QrackSimulator._ulonglong_byref(b),
|
|
901
929
|
ctypes.c_double(ph),
|
|
902
930
|
len(cs),
|
|
903
|
-
|
|
904
|
-
|
|
931
|
+
QrackSimulator._ulonglong_byref(cs),
|
|
932
|
+
QrackSimulator._ulonglong_byref(q),
|
|
905
933
|
)
|
|
906
934
|
self._throw_if_error()
|
|
907
935
|
|
|
@@ -965,9 +993,7 @@ class QrackSimulator:
|
|
|
965
993
|
Raises:
|
|
966
994
|
RuntimeError: QrackSimulator raised an exception.
|
|
967
995
|
"""
|
|
968
|
-
Qrack.qrack_lib.FSim(
|
|
969
|
-
self.sid, ctypes.c_double(th), ctypes.c_double(ph), qi1, qi2
|
|
970
|
-
)
|
|
996
|
+
Qrack.qrack_lib.FSim(self.sid, ctypes.c_double(th), ctypes.c_double(ph), qi1, qi2)
|
|
971
997
|
self._throw_if_error()
|
|
972
998
|
|
|
973
999
|
def cswap(self, c, qi1, qi2):
|
|
@@ -983,7 +1009,7 @@ class QrackSimulator:
|
|
|
983
1009
|
Raises:
|
|
984
1010
|
RuntimeError: QrackSimulator raised an exception.
|
|
985
1011
|
"""
|
|
986
|
-
Qrack.qrack_lib.CSWAP(self.sid, len(c),
|
|
1012
|
+
Qrack.qrack_lib.CSWAP(self.sid, len(c), QrackSimulator._ulonglong_byref(c), qi1, qi2)
|
|
987
1013
|
self._throw_if_error()
|
|
988
1014
|
|
|
989
1015
|
def acswap(self, c, qi1, qi2):
|
|
@@ -999,7 +1025,7 @@ class QrackSimulator:
|
|
|
999
1025
|
Raises:
|
|
1000
1026
|
RuntimeError: QrackSimulator raised an exception.
|
|
1001
1027
|
"""
|
|
1002
|
-
Qrack.qrack_lib.ACSWAP(self.sid, len(c),
|
|
1028
|
+
Qrack.qrack_lib.ACSWAP(self.sid, len(c), QrackSimulator._ulonglong_byref(c), qi1, qi2)
|
|
1003
1029
|
self._throw_if_error()
|
|
1004
1030
|
|
|
1005
1031
|
# standard operations
|
|
@@ -1083,7 +1109,7 @@ class QrackSimulator:
|
|
|
1083
1109
|
if len(b) != len(q):
|
|
1084
1110
|
raise RuntimeError("Lengths of list parameters are mismatched.")
|
|
1085
1111
|
result = Qrack.qrack_lib.Measure(
|
|
1086
|
-
self.sid, len(b),
|
|
1112
|
+
self.sid, len(b), QrackSimulator._int_byref(b), QrackSimulator._ulonglong_byref(q)
|
|
1087
1113
|
)
|
|
1088
1114
|
self._throw_if_error()
|
|
1089
1115
|
return result
|
|
@@ -1104,8 +1130,8 @@ class QrackSimulator:
|
|
|
1104
1130
|
Returns:
|
|
1105
1131
|
list of measurement result.
|
|
1106
1132
|
"""
|
|
1107
|
-
m =
|
|
1108
|
-
Qrack.qrack_lib.MeasureShots(self.sid, len(q),
|
|
1133
|
+
m = QrackSimulator._ulonglong_byref([0] * s)
|
|
1134
|
+
Qrack.qrack_lib.MeasureShots(self.sid, len(q), QrackSimulator._ulonglong_byref(q), s, m)
|
|
1109
1135
|
self._throw_if_error()
|
|
1110
1136
|
return [m[i] for i in range(s)]
|
|
1111
1137
|
|
|
@@ -1121,7 +1147,8 @@ class QrackSimulator:
|
|
|
1121
1147
|
self._throw_if_error()
|
|
1122
1148
|
|
|
1123
1149
|
# arithmetic-logic-unit (ALU)
|
|
1124
|
-
|
|
1150
|
+
@staticmethod
|
|
1151
|
+
def _split_longs(a):
|
|
1125
1152
|
"""Split operation
|
|
1126
1153
|
|
|
1127
1154
|
Splits the given integer into 64 bit numbers.
|
|
@@ -1144,7 +1171,8 @@ class QrackSimulator:
|
|
|
1144
1171
|
a = a >> 64
|
|
1145
1172
|
return aParts
|
|
1146
1173
|
|
|
1147
|
-
|
|
1174
|
+
@staticmethod
|
|
1175
|
+
def _split_longs_2(a, m):
|
|
1148
1176
|
"""Split simultanoues operation
|
|
1149
1177
|
|
|
1150
1178
|
Splits 2 integers into same number of 64 bit numbers.
|
|
@@ -1183,13 +1211,13 @@ class QrackSimulator:
|
|
|
1183
1211
|
Raises:
|
|
1184
1212
|
RuntimeError: QrackSimulator raised an exception.
|
|
1185
1213
|
"""
|
|
1186
|
-
aParts =
|
|
1214
|
+
aParts = QrackSimulator._split_longs(a)
|
|
1187
1215
|
Qrack.qrack_lib.ADD(
|
|
1188
1216
|
self.sid,
|
|
1189
1217
|
len(aParts),
|
|
1190
|
-
|
|
1218
|
+
QrackSimulator._ulonglong_byref(aParts),
|
|
1191
1219
|
len(q),
|
|
1192
|
-
|
|
1220
|
+
QrackSimulator._ulonglong_byref(q),
|
|
1193
1221
|
)
|
|
1194
1222
|
self._throw_if_error()
|
|
1195
1223
|
|
|
@@ -1205,13 +1233,13 @@ class QrackSimulator:
|
|
|
1205
1233
|
Raises:
|
|
1206
1234
|
RuntimeError: QrackSimulator raised an exception.
|
|
1207
1235
|
"""
|
|
1208
|
-
aParts =
|
|
1236
|
+
aParts = QrackSimulator._split_longs(a)
|
|
1209
1237
|
Qrack.qrack_lib.SUB(
|
|
1210
1238
|
self.sid,
|
|
1211
1239
|
len(aParts),
|
|
1212
|
-
|
|
1240
|
+
QrackSimulator._ulonglong_byref(aParts),
|
|
1213
1241
|
len(q),
|
|
1214
|
-
|
|
1242
|
+
QrackSimulator._ulonglong_byref(q),
|
|
1215
1243
|
)
|
|
1216
1244
|
self._throw_if_error()
|
|
1217
1245
|
|
|
@@ -1229,14 +1257,14 @@ class QrackSimulator:
|
|
|
1229
1257
|
Raises:
|
|
1230
1258
|
RuntimeError: QrackSimulator raised an exception.
|
|
1231
1259
|
"""
|
|
1232
|
-
aParts =
|
|
1260
|
+
aParts = QrackSimulator._split_longs(a)
|
|
1233
1261
|
Qrack.qrack_lib.ADDS(
|
|
1234
1262
|
self.sid,
|
|
1235
1263
|
len(aParts),
|
|
1236
|
-
|
|
1264
|
+
QrackSimulator._ulonglong_byref(aParts),
|
|
1237
1265
|
s,
|
|
1238
1266
|
len(q),
|
|
1239
|
-
|
|
1267
|
+
QrackSimulator._ulonglong_byref(q),
|
|
1240
1268
|
)
|
|
1241
1269
|
self._throw_if_error()
|
|
1242
1270
|
|
|
@@ -1254,14 +1282,14 @@ class QrackSimulator:
|
|
|
1254
1282
|
Raises:
|
|
1255
1283
|
RuntimeError: QrackSimulator raised an exception.
|
|
1256
1284
|
"""
|
|
1257
|
-
aParts =
|
|
1285
|
+
aParts = QrackSimulator._split_longs(a)
|
|
1258
1286
|
Qrack.qrack_lib.SUBS(
|
|
1259
1287
|
self.sid,
|
|
1260
1288
|
len(aParts),
|
|
1261
|
-
|
|
1289
|
+
QrackSimulator._ulonglong_byref(aParts),
|
|
1262
1290
|
s,
|
|
1263
1291
|
len(q),
|
|
1264
|
-
|
|
1292
|
+
QrackSimulator._ulonglong_byref(q),
|
|
1265
1293
|
)
|
|
1266
1294
|
self._throw_if_error()
|
|
1267
1295
|
|
|
@@ -1292,14 +1320,14 @@ class QrackSimulator:
|
|
|
1292
1320
|
|
|
1293
1321
|
if len(q) != len(o):
|
|
1294
1322
|
raise RuntimeError("Lengths of list parameters are mismatched.")
|
|
1295
|
-
aParts =
|
|
1323
|
+
aParts = QrackSimulator._split_longs(a)
|
|
1296
1324
|
Qrack.qrack_lib.MUL(
|
|
1297
1325
|
self.sid,
|
|
1298
1326
|
len(aParts),
|
|
1299
|
-
|
|
1327
|
+
QrackSimulator._ulonglong_byref(aParts),
|
|
1300
1328
|
len(q),
|
|
1301
|
-
|
|
1302
|
-
|
|
1329
|
+
QrackSimulator._ulonglong_byref(q),
|
|
1330
|
+
QrackSimulator._ulonglong_byref(o),
|
|
1303
1331
|
)
|
|
1304
1332
|
self._throw_if_error()
|
|
1305
1333
|
|
|
@@ -1331,14 +1359,14 @@ class QrackSimulator:
|
|
|
1331
1359
|
|
|
1332
1360
|
if len(q) != len(o):
|
|
1333
1361
|
raise RuntimeError("Lengths of list parameters are mismatched.")
|
|
1334
|
-
aParts =
|
|
1362
|
+
aParts = QrackSimulator._split_longs(a)
|
|
1335
1363
|
Qrack.qrack_lib.DIV(
|
|
1336
1364
|
self.sid,
|
|
1337
1365
|
len(aParts),
|
|
1338
|
-
|
|
1366
|
+
QrackSimulator._ulonglong_byref(aParts),
|
|
1339
1367
|
len(q),
|
|
1340
|
-
|
|
1341
|
-
|
|
1368
|
+
QrackSimulator._ulonglong_byref(q),
|
|
1369
|
+
QrackSimulator._ulonglong_byref(o),
|
|
1342
1370
|
)
|
|
1343
1371
|
self._throw_if_error()
|
|
1344
1372
|
|
|
@@ -1359,15 +1387,15 @@ class QrackSimulator:
|
|
|
1359
1387
|
"""
|
|
1360
1388
|
if len(q) != len(o):
|
|
1361
1389
|
raise RuntimeError("Lengths of list parameters are mismatched.")
|
|
1362
|
-
aParts, mParts =
|
|
1390
|
+
aParts, mParts = QrackSimulator._split_longs_2(a, m)
|
|
1363
1391
|
Qrack.qrack_lib.MULN(
|
|
1364
1392
|
self.sid,
|
|
1365
1393
|
len(aParts),
|
|
1366
|
-
|
|
1367
|
-
|
|
1394
|
+
QrackSimulator._ulonglong_byref(aParts),
|
|
1395
|
+
QrackSimulator._ulonglong_byref(mParts),
|
|
1368
1396
|
len(q),
|
|
1369
|
-
|
|
1370
|
-
|
|
1397
|
+
QrackSimulator._ulonglong_byref(q),
|
|
1398
|
+
QrackSimulator._ulonglong_byref(o),
|
|
1371
1399
|
)
|
|
1372
1400
|
self._throw_if_error()
|
|
1373
1401
|
|
|
@@ -1389,15 +1417,15 @@ class QrackSimulator:
|
|
|
1389
1417
|
"""
|
|
1390
1418
|
if len(q) != len(o):
|
|
1391
1419
|
raise RuntimeError("Lengths of list parameters are mismatched.")
|
|
1392
|
-
aParts, mParts =
|
|
1420
|
+
aParts, mParts = QrackSimulator._split_longs_2(a, m)
|
|
1393
1421
|
Qrack.qrack_lib.DIVN(
|
|
1394
1422
|
self.sid,
|
|
1395
1423
|
len(aParts),
|
|
1396
|
-
|
|
1397
|
-
|
|
1424
|
+
QrackSimulator._ulonglong_byref(aParts),
|
|
1425
|
+
QrackSimulator._ulonglong_byref(mParts),
|
|
1398
1426
|
len(q),
|
|
1399
|
-
|
|
1400
|
-
|
|
1427
|
+
QrackSimulator._ulonglong_byref(q),
|
|
1428
|
+
QrackSimulator._ulonglong_byref(o),
|
|
1401
1429
|
)
|
|
1402
1430
|
self._throw_if_error()
|
|
1403
1431
|
|
|
@@ -1428,15 +1456,15 @@ class QrackSimulator:
|
|
|
1428
1456
|
|
|
1429
1457
|
if len(q) != len(o):
|
|
1430
1458
|
raise RuntimeError("Lengths of list parameters are mismatched.")
|
|
1431
|
-
aParts, mParts =
|
|
1459
|
+
aParts, mParts = QrackSimulator._split_longs_2(a, m)
|
|
1432
1460
|
Qrack.qrack_lib.POWN(
|
|
1433
1461
|
self.sid,
|
|
1434
1462
|
len(aParts),
|
|
1435
|
-
|
|
1436
|
-
|
|
1463
|
+
QrackSimulator._ulonglong_byref(aParts),
|
|
1464
|
+
QrackSimulator._ulonglong_byref(mParts),
|
|
1437
1465
|
len(q),
|
|
1438
|
-
|
|
1439
|
-
|
|
1466
|
+
QrackSimulator._ulonglong_byref(q),
|
|
1467
|
+
QrackSimulator._ulonglong_byref(o),
|
|
1440
1468
|
)
|
|
1441
1469
|
self._throw_if_error()
|
|
1442
1470
|
|
|
@@ -1454,15 +1482,15 @@ class QrackSimulator:
|
|
|
1454
1482
|
Raises:
|
|
1455
1483
|
RuntimeError: QrackSimulator raised an exception.
|
|
1456
1484
|
"""
|
|
1457
|
-
aParts =
|
|
1485
|
+
aParts = QrackSimulator._split_longs(a)
|
|
1458
1486
|
Qrack.qrack_lib.MCADD(
|
|
1459
1487
|
self.sid,
|
|
1460
1488
|
len(aParts),
|
|
1461
|
-
|
|
1489
|
+
QrackSimulator._ulonglong_byref(aParts),
|
|
1462
1490
|
len(c),
|
|
1463
|
-
|
|
1491
|
+
QrackSimulator._ulonglong_byref(c),
|
|
1464
1492
|
len(q),
|
|
1465
|
-
|
|
1493
|
+
QrackSimulator._ulonglong_byref(q),
|
|
1466
1494
|
)
|
|
1467
1495
|
self._throw_if_error()
|
|
1468
1496
|
|
|
@@ -1480,15 +1508,15 @@ class QrackSimulator:
|
|
|
1480
1508
|
Raises:
|
|
1481
1509
|
RuntimeError: QrackSimulator raised an exception.
|
|
1482
1510
|
"""
|
|
1483
|
-
aParts =
|
|
1511
|
+
aParts = QrackSimulator._split_longs(a)
|
|
1484
1512
|
Qrack.qrack_lib.MCSUB(
|
|
1485
1513
|
self.sid,
|
|
1486
1514
|
len(aParts),
|
|
1487
|
-
|
|
1515
|
+
QrackSimulator._ulonglong_byref(aParts),
|
|
1488
1516
|
len(c),
|
|
1489
|
-
|
|
1517
|
+
QrackSimulator._ulonglong_byref(c),
|
|
1490
1518
|
len(q),
|
|
1491
|
-
|
|
1519
|
+
QrackSimulator._ulonglong_byref(q),
|
|
1492
1520
|
)
|
|
1493
1521
|
self._throw_if_error()
|
|
1494
1522
|
|
|
@@ -1521,15 +1549,15 @@ class QrackSimulator:
|
|
|
1521
1549
|
|
|
1522
1550
|
if len(q) != len(o):
|
|
1523
1551
|
raise RuntimeError("Lengths of list parameters are mismatched.")
|
|
1524
|
-
aParts =
|
|
1552
|
+
aParts = QrackSimulator._split_longs(a)
|
|
1525
1553
|
Qrack.qrack_lib.MCMUL(
|
|
1526
1554
|
self.sid,
|
|
1527
1555
|
len(aParts),
|
|
1528
|
-
|
|
1556
|
+
QrackSimulator._ulonglong_byref(aParts),
|
|
1529
1557
|
len(c),
|
|
1530
|
-
|
|
1558
|
+
QrackSimulator._ulonglong_byref(c),
|
|
1531
1559
|
len(q),
|
|
1532
|
-
|
|
1560
|
+
QrackSimulator._ulonglong_byref(q),
|
|
1533
1561
|
)
|
|
1534
1562
|
self._throw_if_error()
|
|
1535
1563
|
|
|
@@ -1563,15 +1591,15 @@ class QrackSimulator:
|
|
|
1563
1591
|
|
|
1564
1592
|
if len(q) != len(o):
|
|
1565
1593
|
raise RuntimeError("Lengths of list parameters are mismatched.")
|
|
1566
|
-
aParts =
|
|
1594
|
+
aParts = QrackSimulator._split_longs(a)
|
|
1567
1595
|
Qrack.qrack_lib.MCDIV(
|
|
1568
1596
|
self.sid,
|
|
1569
1597
|
len(aParts),
|
|
1570
|
-
|
|
1598
|
+
QrackSimulator._ulonglong_byref(aParts),
|
|
1571
1599
|
len(c),
|
|
1572
|
-
|
|
1600
|
+
QrackSimulator._ulonglong_byref(c),
|
|
1573
1601
|
len(q),
|
|
1574
|
-
|
|
1602
|
+
QrackSimulator._ulonglong_byref(q),
|
|
1575
1603
|
)
|
|
1576
1604
|
self._throw_if_error()
|
|
1577
1605
|
|
|
@@ -1594,17 +1622,17 @@ class QrackSimulator:
|
|
|
1594
1622
|
"""
|
|
1595
1623
|
if len(q) != len(o):
|
|
1596
1624
|
raise RuntimeError("Lengths of list parameters are mismatched.")
|
|
1597
|
-
aParts, mParts =
|
|
1625
|
+
aParts, mParts = QrackSimulator._split_longs_2(a, m)
|
|
1598
1626
|
Qrack.qrack_lib.MCMULN(
|
|
1599
1627
|
self.sid,
|
|
1600
1628
|
len(aParts),
|
|
1601
|
-
|
|
1629
|
+
QrackSimulator._ulonglong_byref(aParts),
|
|
1602
1630
|
len(c),
|
|
1603
|
-
|
|
1604
|
-
|
|
1631
|
+
QrackSimulator._ulonglong_byref(c),
|
|
1632
|
+
QrackSimulator._ulonglong_byref(mParts),
|
|
1605
1633
|
len(q),
|
|
1606
|
-
|
|
1607
|
-
|
|
1634
|
+
QrackSimulator._ulonglong_byref(q),
|
|
1635
|
+
QrackSimulator._ulonglong_byref(o),
|
|
1608
1636
|
)
|
|
1609
1637
|
self._throw_if_error()
|
|
1610
1638
|
|
|
@@ -1628,17 +1656,17 @@ class QrackSimulator:
|
|
|
1628
1656
|
"""
|
|
1629
1657
|
if len(q) != len(o):
|
|
1630
1658
|
raise RuntimeError("Lengths of list parameters are mismatched.")
|
|
1631
|
-
aParts, mParts =
|
|
1659
|
+
aParts, mParts = QrackSimulator._split_longs_2(a, m)
|
|
1632
1660
|
Qrack.qrack_lib.MCDIVN(
|
|
1633
1661
|
self.sid,
|
|
1634
1662
|
len(aParts),
|
|
1635
|
-
|
|
1663
|
+
QrackSimulator._ulonglong_byref(aParts),
|
|
1636
1664
|
len(c),
|
|
1637
|
-
|
|
1638
|
-
|
|
1665
|
+
QrackSimulator._ulonglong_byref(c),
|
|
1666
|
+
QrackSimulator._ulonglong_byref(mParts),
|
|
1639
1667
|
len(q),
|
|
1640
|
-
|
|
1641
|
-
|
|
1668
|
+
QrackSimulator._ulonglong_byref(q),
|
|
1669
|
+
QrackSimulator._ulonglong_byref(o),
|
|
1642
1670
|
)
|
|
1643
1671
|
self._throw_if_error()
|
|
1644
1672
|
|
|
@@ -1671,17 +1699,17 @@ class QrackSimulator:
|
|
|
1671
1699
|
|
|
1672
1700
|
if len(q) != len(o):
|
|
1673
1701
|
raise RuntimeError("Lengths of list parameters are mismatched.")
|
|
1674
|
-
aParts, mParts =
|
|
1702
|
+
aParts, mParts = QrackSimulator._split_longs_2(a, m)
|
|
1675
1703
|
Qrack.qrack_lib.MCPOWN(
|
|
1676
1704
|
self.sid,
|
|
1677
1705
|
len(aParts),
|
|
1678
|
-
|
|
1706
|
+
QrackSimulator._ulonglong_byref(aParts),
|
|
1679
1707
|
len(c),
|
|
1680
|
-
|
|
1681
|
-
|
|
1708
|
+
QrackSimulator._ulonglong_byref(c),
|
|
1709
|
+
QrackSimulator._ulonglong_byref(mParts),
|
|
1682
1710
|
len(q),
|
|
1683
|
-
|
|
1684
|
-
|
|
1711
|
+
QrackSimulator._ulonglong_byref(q),
|
|
1712
|
+
QrackSimulator._ulonglong_byref(o),
|
|
1685
1713
|
)
|
|
1686
1714
|
self._throw_if_error()
|
|
1687
1715
|
|
|
@@ -1713,10 +1741,10 @@ class QrackSimulator:
|
|
|
1713
1741
|
Qrack.qrack_lib.LDA(
|
|
1714
1742
|
self.sid,
|
|
1715
1743
|
len(qi),
|
|
1716
|
-
|
|
1744
|
+
QrackSimulator._ulonglong_byref(qi),
|
|
1717
1745
|
len(qv),
|
|
1718
|
-
|
|
1719
|
-
|
|
1746
|
+
QrackSimulator._ulonglong_byref(qv),
|
|
1747
|
+
QrackSimulator._to_ubyte(len(qv), t),
|
|
1720
1748
|
)
|
|
1721
1749
|
self._throw_if_error()
|
|
1722
1750
|
|
|
@@ -1748,10 +1776,10 @@ class QrackSimulator:
|
|
|
1748
1776
|
self.sid,
|
|
1749
1777
|
s,
|
|
1750
1778
|
len(qi),
|
|
1751
|
-
|
|
1779
|
+
QrackSimulator._ulonglong_byref(qi),
|
|
1752
1780
|
len(qv),
|
|
1753
|
-
|
|
1754
|
-
|
|
1781
|
+
QrackSimulator._ulonglong_byref(qv),
|
|
1782
|
+
QrackSimulator._to_ubyte(len(qv), t),
|
|
1755
1783
|
)
|
|
1756
1784
|
self._throw_if_error()
|
|
1757
1785
|
|
|
@@ -1783,10 +1811,10 @@ class QrackSimulator:
|
|
|
1783
1811
|
self.sid,
|
|
1784
1812
|
s,
|
|
1785
1813
|
len(qi),
|
|
1786
|
-
|
|
1814
|
+
QrackSimulator._ulonglong_byref(qi),
|
|
1787
1815
|
len(qv),
|
|
1788
|
-
|
|
1789
|
-
|
|
1816
|
+
QrackSimulator._ulonglong_byref(qv),
|
|
1817
|
+
QrackSimulator._to_ubyte(len(qv), t),
|
|
1790
1818
|
)
|
|
1791
1819
|
self._throw_if_error()
|
|
1792
1820
|
|
|
@@ -1816,7 +1844,10 @@ class QrackSimulator:
|
|
|
1816
1844
|
)
|
|
1817
1845
|
|
|
1818
1846
|
Qrack.qrack_lib.Hash(
|
|
1819
|
-
self.sid,
|
|
1847
|
+
self.sid,
|
|
1848
|
+
len(q),
|
|
1849
|
+
QrackSimulator._ulonglong_byref(q),
|
|
1850
|
+
QrackSimulator._to_ubyte(len(q), t),
|
|
1820
1851
|
)
|
|
1821
1852
|
self._throw_if_error()
|
|
1822
1853
|
|
|
@@ -2037,7 +2068,7 @@ class QrackSimulator:
|
|
|
2037
2068
|
Raises:
|
|
2038
2069
|
RuntimeError: QrackSimulator raised an exception.
|
|
2039
2070
|
"""
|
|
2040
|
-
Qrack.qrack_lib.QFT(self.sid, len(qs),
|
|
2071
|
+
Qrack.qrack_lib.QFT(self.sid, len(qs), QrackSimulator._ulonglong_byref(qs))
|
|
2041
2072
|
self._throw_if_error()
|
|
2042
2073
|
|
|
2043
2074
|
def iqft(self, qs):
|
|
@@ -2052,7 +2083,7 @@ class QrackSimulator:
|
|
|
2052
2083
|
Raises:
|
|
2053
2084
|
RuntimeError: QrackSimulator raised an exception.
|
|
2054
2085
|
"""
|
|
2055
|
-
Qrack.qrack_lib.IQFT(self.sid, len(qs),
|
|
2086
|
+
Qrack.qrack_lib.IQFT(self.sid, len(qs), QrackSimulator._ulonglong_byref(qs))
|
|
2056
2087
|
self._throw_if_error()
|
|
2057
2088
|
|
|
2058
2089
|
# pseudo-quantum
|
|
@@ -2126,15 +2157,13 @@ class QrackSimulator:
|
|
|
2126
2157
|
"QrackSimulator with isTensorNetwork=True option cannot compose()! (Turn off just this option, in the constructor.)"
|
|
2127
2158
|
)
|
|
2128
2159
|
|
|
2129
|
-
Qrack.qrack_lib.Compose(self.sid, other.sid,
|
|
2160
|
+
Qrack.qrack_lib.Compose(self.sid, other.sid, QrackSimulator._ulonglong_byref(q))
|
|
2130
2161
|
self._throw_if_error()
|
|
2131
2162
|
|
|
2132
2163
|
def decompose(self, q):
|
|
2133
2164
|
"""Decompose system
|
|
2134
2165
|
|
|
2135
|
-
|
|
2136
|
-
Warning: The qubit subsystem state must be separable, or the behavior
|
|
2137
|
-
of this method is undefined.
|
|
2166
|
+
Factorize a set of contiguous bits with minimal fidelity loss.
|
|
2138
2167
|
|
|
2139
2168
|
Args:
|
|
2140
2169
|
q: qubit id
|
|
@@ -2144,7 +2173,7 @@ class QrackSimulator:
|
|
|
2144
2173
|
RuntimeError: QrackSimulator with isTensorNetwork=True option cannot decompose()! (Turn off just this option, in the constructor.)
|
|
2145
2174
|
|
|
2146
2175
|
Returns:
|
|
2147
|
-
|
|
2176
|
+
Decomposed subsystem simulator.
|
|
2148
2177
|
"""
|
|
2149
2178
|
if self.is_tensor_network:
|
|
2150
2179
|
raise RuntimeError(
|
|
@@ -2154,17 +2183,15 @@ class QrackSimulator:
|
|
|
2154
2183
|
other = QrackSimulator()
|
|
2155
2184
|
Qrack.qrack_lib.destroy(other.sid)
|
|
2156
2185
|
l = len(q)
|
|
2157
|
-
other.sid = Qrack.qrack_lib.Decompose(self.sid, l,
|
|
2186
|
+
other.sid = Qrack.qrack_lib.Decompose(self.sid, l, QrackSimulator._ulonglong_byref(q))
|
|
2158
2187
|
self._throw_if_error()
|
|
2159
2188
|
return other
|
|
2160
2189
|
|
|
2161
2190
|
def dispose(self, q):
|
|
2162
2191
|
"""Dispose qubits
|
|
2163
2192
|
|
|
2164
|
-
|
|
2165
|
-
|
|
2166
|
-
Warning: The qubit subsystem state must be separable, or the behavior
|
|
2167
|
-
of this method is undefined.
|
|
2193
|
+
Factorize a set of contiguous bits with minimal fidelity loss,
|
|
2194
|
+
and discard the separable bits.
|
|
2168
2195
|
|
|
2169
2196
|
Args:
|
|
2170
2197
|
q: qubit
|
|
@@ -2172,9 +2199,6 @@ class QrackSimulator:
|
|
|
2172
2199
|
Raises:
|
|
2173
2200
|
RuntimeError: QrackSimulator raised an exception.
|
|
2174
2201
|
RuntimeError: QrackSimulator with isTensorNetwork=True option cannot dispose()! (Turn off just this option, in the constructor.)
|
|
2175
|
-
|
|
2176
|
-
Returns:
|
|
2177
|
-
State of the systems.
|
|
2178
2202
|
"""
|
|
2179
2203
|
if self.is_tensor_network:
|
|
2180
2204
|
raise RuntimeError(
|
|
@@ -2182,7 +2206,7 @@ class QrackSimulator:
|
|
|
2182
2206
|
)
|
|
2183
2207
|
|
|
2184
2208
|
l = len(q)
|
|
2185
|
-
Qrack.qrack_lib.Dispose(self.sid, l,
|
|
2209
|
+
Qrack.qrack_lib.Dispose(self.sid, l, QrackSimulator._ulonglong_byref(q))
|
|
2186
2210
|
self._throw_if_error()
|
|
2187
2211
|
|
|
2188
2212
|
## miscellaneous
|
|
@@ -2252,7 +2276,7 @@ class QrackSimulator:
|
|
|
2252
2276
|
Raises:
|
|
2253
2277
|
RuntimeError: QrackSimulator raised an exception.
|
|
2254
2278
|
"""
|
|
2255
|
-
Qrack.qrack_lib.InKet(self.sid,
|
|
2279
|
+
Qrack.qrack_lib.InKet(self.sid, QrackSimulator._qrack_complex_byref(ket))
|
|
2256
2280
|
self._throw_if_error()
|
|
2257
2281
|
|
|
2258
2282
|
def out_ket(self):
|
|
@@ -2269,10 +2293,10 @@ class QrackSimulator:
|
|
|
2269
2293
|
list representing the state vector.
|
|
2270
2294
|
"""
|
|
2271
2295
|
amp_count = 1 << self.num_qubits()
|
|
2272
|
-
ket =
|
|
2296
|
+
ket = QrackSimulator._qrack_complex_byref([complex(0, 0)] * amp_count)
|
|
2273
2297
|
Qrack.qrack_lib.OutKet(self.sid, ket)
|
|
2274
2298
|
self._throw_if_error()
|
|
2275
|
-
return [complex(r, i) for r, i in
|
|
2299
|
+
return [complex(r, i) for r, i in QrackSimulator._pairwise(ket)]
|
|
2276
2300
|
|
|
2277
2301
|
def out_probs(self):
|
|
2278
2302
|
"""Get basis dimension probabilities
|
|
@@ -2287,11 +2311,79 @@ class QrackSimulator:
|
|
|
2287
2311
|
list representing the basis dimension probabilities.
|
|
2288
2312
|
"""
|
|
2289
2313
|
prob_count = 1 << self.num_qubits()
|
|
2290
|
-
probs =
|
|
2314
|
+
probs = QrackSimulator._real1_byref([0.0] * prob_count)
|
|
2291
2315
|
Qrack.qrack_lib.OutProbs(self.sid, probs)
|
|
2292
2316
|
self._throw_if_error()
|
|
2293
2317
|
return list(probs)
|
|
2294
2318
|
|
|
2319
|
+
def out_rdm(self, q):
|
|
2320
|
+
"""Get reduced density matrix
|
|
2321
|
+
|
|
2322
|
+
Returns the raw reduced density matrix of the simulator, for the qubit list.
|
|
2323
|
+
Warning: State vector or is not always the internal representation leading
|
|
2324
|
+
to sub-optimal performance of the method.
|
|
2325
|
+
|
|
2326
|
+
Raises:
|
|
2327
|
+
RuntimeError: QrackSimulator raised an exception.
|
|
2328
|
+
|
|
2329
|
+
Returns:
|
|
2330
|
+
flat list structure representing the reduced density matrix.
|
|
2331
|
+
"""
|
|
2332
|
+
amp_count = 1 << len(q)
|
|
2333
|
+
sqr_amp_count = amp_count * amp_count
|
|
2334
|
+
flat_rdm = QrackSimulator._qrack_complex_byref([complex(0, 0)] * sqr_amp_count)
|
|
2335
|
+
Qrack.qrack_lib.OutReducedDensityMatrix(
|
|
2336
|
+
self.sid, len(q), QrackSimulator._ulonglong_byref(q), flat_rdm
|
|
2337
|
+
)
|
|
2338
|
+
self._throw_if_error()
|
|
2339
|
+
return [complex(r, i) for r, i in QrackSimulator._pairwise(flat_rdm)]
|
|
2340
|
+
|
|
2341
|
+
def highest_prob_perm(self):
|
|
2342
|
+
"""Get the permutation (bit string) with the highest probability
|
|
2343
|
+
|
|
2344
|
+
Returns the single highest-probability bit string in the Hilbert space
|
|
2345
|
+
|
|
2346
|
+
Raises:
|
|
2347
|
+
RuntimeError: QrackSimulator raised an exception.
|
|
2348
|
+
|
|
2349
|
+
Returns:
|
|
2350
|
+
Highest probability dimension index
|
|
2351
|
+
"""
|
|
2352
|
+
num_q = self.num_qubits()
|
|
2353
|
+
num_words = (num_q + 63) // 64
|
|
2354
|
+
_r = (ctypes.c_ulonglong * num_words)()
|
|
2355
|
+
Qrack.qrack_lib.HighestProbAll(self.sid, _r)
|
|
2356
|
+
self._throw_if_error()
|
|
2357
|
+
r = 0
|
|
2358
|
+
for w in range(num_words):
|
|
2359
|
+
r <<= 64
|
|
2360
|
+
r |= _r[w]
|
|
2361
|
+
return r
|
|
2362
|
+
|
|
2363
|
+
def highest_n_prob_perm(self, n):
|
|
2364
|
+
"""Get the top n permutations (bit strings) with the highest probability
|
|
2365
|
+
|
|
2366
|
+
Returns the top n highest-probability bit strings in the Hilbert space
|
|
2367
|
+
|
|
2368
|
+
Raises:
|
|
2369
|
+
RuntimeError: QrackSimulator raised an exception.
|
|
2370
|
+
|
|
2371
|
+
Returns:
|
|
2372
|
+
Top n highest probability dimension indices
|
|
2373
|
+
"""
|
|
2374
|
+
num_q = self.num_qubits()
|
|
2375
|
+
num_words = (num_q + 63) // 64
|
|
2376
|
+
_r = (ctypes.c_ulonglong * (num_words * n))()
|
|
2377
|
+
Qrack.qrack_lib.HighestProbAllN(self.sid, n, _r)
|
|
2378
|
+
self._throw_if_error()
|
|
2379
|
+
r = [0] * n
|
|
2380
|
+
for i in range(n):
|
|
2381
|
+
r[i] = 0
|
|
2382
|
+
for w in range(num_words):
|
|
2383
|
+
r[i] <<= 64
|
|
2384
|
+
r[i] |= _r[(i * num_words) + w]
|
|
2385
|
+
return r
|
|
2386
|
+
|
|
2295
2387
|
def prob_all(self, q):
|
|
2296
2388
|
"""Probabilities of all subset permutations
|
|
2297
2389
|
|
|
@@ -2306,8 +2398,8 @@ class QrackSimulator:
|
|
|
2306
2398
|
Returns:
|
|
2307
2399
|
list representing the state vector.
|
|
2308
2400
|
"""
|
|
2309
|
-
probs =
|
|
2310
|
-
Qrack.qrack_lib.ProbAll(self.sid, len(q),
|
|
2401
|
+
probs = QrackSimulator._real1_byref([0.0] * (1 << len(q)))
|
|
2402
|
+
Qrack.qrack_lib.ProbAll(self.sid, len(q), QrackSimulator._ulonglong_byref(q), probs)
|
|
2311
2403
|
self._throw_if_error()
|
|
2312
2404
|
return list(probs)
|
|
2313
2405
|
|
|
@@ -2369,7 +2461,7 @@ class QrackSimulator:
|
|
|
2369
2461
|
if len(q) != len(c):
|
|
2370
2462
|
raise RuntimeError("prob_perm argument lengths do not match.")
|
|
2371
2463
|
result = Qrack.qrack_lib.PermutationProb(
|
|
2372
|
-
self.sid, len(q),
|
|
2464
|
+
self.sid, len(q), QrackSimulator._ulonglong_byref(q), QrackSimulator._bool_byref(c)
|
|
2373
2465
|
)
|
|
2374
2466
|
self._throw_if_error()
|
|
2375
2467
|
return result
|
|
@@ -2397,7 +2489,7 @@ class QrackSimulator:
|
|
|
2397
2489
|
if len(q) != len(c):
|
|
2398
2490
|
raise RuntimeError("prob_perm argument lengths do not match.")
|
|
2399
2491
|
result = Qrack.qrack_lib.PermutationProbRdm(
|
|
2400
|
-
self.sid, len(q),
|
|
2492
|
+
self.sid, len(q), QrackSimulator._ulonglong_byref(q), QrackSimulator._bool_byref(c), r
|
|
2401
2493
|
)
|
|
2402
2494
|
self._throw_if_error()
|
|
2403
2495
|
return result
|
|
@@ -2418,7 +2510,7 @@ class QrackSimulator:
|
|
|
2418
2510
|
Expectation value
|
|
2419
2511
|
"""
|
|
2420
2512
|
result = Qrack.qrack_lib.PermutationExpectation(
|
|
2421
|
-
self.sid, len(q),
|
|
2513
|
+
self.sid, len(q), QrackSimulator._ulonglong_byref(q)
|
|
2422
2514
|
)
|
|
2423
2515
|
self._throw_if_error()
|
|
2424
2516
|
return result
|
|
@@ -2441,7 +2533,7 @@ class QrackSimulator:
|
|
|
2441
2533
|
Expectation value
|
|
2442
2534
|
"""
|
|
2443
2535
|
result = Qrack.qrack_lib.PermutationExpectationRdm(
|
|
2444
|
-
self.sid, len(q),
|
|
2536
|
+
self.sid, len(q), QrackSimulator._ulonglong_byref(q), r
|
|
2445
2537
|
)
|
|
2446
2538
|
self._throw_if_error()
|
|
2447
2539
|
return result
|
|
@@ -2467,7 +2559,11 @@ class QrackSimulator:
|
|
|
2467
2559
|
raise RuntimeError("factorized_expectation argument lengths do not match.")
|
|
2468
2560
|
m = max([(x.bit_length() + 63) // 64 for x in c])
|
|
2469
2561
|
result = Qrack.qrack_lib.FactorizedExpectation(
|
|
2470
|
-
self.sid,
|
|
2562
|
+
self.sid,
|
|
2563
|
+
len(q),
|
|
2564
|
+
QrackSimulator._ulonglong_byref(q),
|
|
2565
|
+
m,
|
|
2566
|
+
QrackSimulator._to_ulonglong(m, c),
|
|
2471
2567
|
)
|
|
2472
2568
|
self._throw_if_error()
|
|
2473
2569
|
return result
|
|
@@ -2492,12 +2588,15 @@ class QrackSimulator:
|
|
|
2492
2588
|
Expectation value
|
|
2493
2589
|
"""
|
|
2494
2590
|
if (len(q) << 1) != len(c):
|
|
2495
|
-
raise RuntimeError(
|
|
2496
|
-
"factorized_expectation_rdm argument lengths do not match."
|
|
2497
|
-
)
|
|
2591
|
+
raise RuntimeError("factorized_expectation_rdm argument lengths do not match.")
|
|
2498
2592
|
m = max([(x.bit_length() + 63) // 64 for x in c])
|
|
2499
2593
|
result = Qrack.qrack_lib.FactorizedExpectationRdm(
|
|
2500
|
-
self.sid,
|
|
2594
|
+
self.sid,
|
|
2595
|
+
len(q),
|
|
2596
|
+
QrackSimulator._ulonglong_byref(q),
|
|
2597
|
+
m,
|
|
2598
|
+
QrackSimulator._to_ulonglong(m, c),
|
|
2599
|
+
r,
|
|
2501
2600
|
)
|
|
2502
2601
|
self._throw_if_error()
|
|
2503
2602
|
return result
|
|
@@ -2520,11 +2619,9 @@ class QrackSimulator:
|
|
|
2520
2619
|
Expectation value
|
|
2521
2620
|
"""
|
|
2522
2621
|
if (len(q) << 1) != len(c):
|
|
2523
|
-
raise RuntimeError(
|
|
2524
|
-
"factorized_expectation_rdm argument lengths do not match."
|
|
2525
|
-
)
|
|
2622
|
+
raise RuntimeError("factorized_expectation_rdm argument lengths do not match.")
|
|
2526
2623
|
result = Qrack.qrack_lib.FactorizedExpectationFp(
|
|
2527
|
-
self.sid, len(q),
|
|
2624
|
+
self.sid, len(q), QrackSimulator._ulonglong_byref(q), QrackSimulator._real1_byref(c)
|
|
2528
2625
|
)
|
|
2529
2626
|
self._throw_if_error()
|
|
2530
2627
|
return result
|
|
@@ -2549,11 +2646,9 @@ class QrackSimulator:
|
|
|
2549
2646
|
Expectation value
|
|
2550
2647
|
"""
|
|
2551
2648
|
if (len(q) << 1) != len(c):
|
|
2552
|
-
raise RuntimeError(
|
|
2553
|
-
"factorized_expectation_fp_rdm argument lengths do not match."
|
|
2554
|
-
)
|
|
2649
|
+
raise RuntimeError("factorized_expectation_fp_rdm argument lengths do not match.")
|
|
2555
2650
|
result = Qrack.qrack_lib.FactorizedExpectationFpRdm(
|
|
2556
|
-
self.sid, len(q),
|
|
2651
|
+
self.sid, len(q), QrackSimulator._ulonglong_byref(q), QrackSimulator._real1_byref(c), r
|
|
2557
2652
|
)
|
|
2558
2653
|
self._throw_if_error()
|
|
2559
2654
|
return result
|
|
@@ -2577,7 +2672,7 @@ class QrackSimulator:
|
|
|
2577
2672
|
if (3 * len(q)) != len(b):
|
|
2578
2673
|
raise RuntimeError("unitary_expectation argument lengths do not match.")
|
|
2579
2674
|
result = Qrack.qrack_lib.UnitaryExpectation(
|
|
2580
|
-
self.sid, len(q),
|
|
2675
|
+
self.sid, len(q), QrackSimulator._ulonglong_byref(q), QrackSimulator._real1_byref(b)
|
|
2581
2676
|
)
|
|
2582
2677
|
self._throw_if_error()
|
|
2583
2678
|
return result
|
|
@@ -2601,7 +2696,7 @@ class QrackSimulator:
|
|
|
2601
2696
|
if (len(q) << 2) != len(b):
|
|
2602
2697
|
raise RuntimeError("matrix_expectation argument lengths do not match.")
|
|
2603
2698
|
result = Qrack.qrack_lib.MatrixExpectation(
|
|
2604
|
-
self.sid, len(q),
|
|
2699
|
+
self.sid, len(q), QrackSimulator._ulonglong_byref(q), QrackSimulator._complex_byref(b)
|
|
2605
2700
|
)
|
|
2606
2701
|
self._throw_if_error()
|
|
2607
2702
|
return result
|
|
@@ -2633,9 +2728,9 @@ class QrackSimulator:
|
|
|
2633
2728
|
result = Qrack.qrack_lib.UnitaryExpectationEigenVal(
|
|
2634
2729
|
self.sid,
|
|
2635
2730
|
len(q),
|
|
2636
|
-
|
|
2637
|
-
|
|
2638
|
-
|
|
2731
|
+
QrackSimulator._ulonglong_byref(q),
|
|
2732
|
+
QrackSimulator._real1_byref(b),
|
|
2733
|
+
QrackSimulator._real1_byref(e),
|
|
2639
2734
|
)
|
|
2640
2735
|
self._throw_if_error()
|
|
2641
2736
|
return result
|
|
@@ -2667,9 +2762,9 @@ class QrackSimulator:
|
|
|
2667
2762
|
result = Qrack.qrack_lib.MatrixExpectationEigenVal(
|
|
2668
2763
|
self.sid,
|
|
2669
2764
|
len(q),
|
|
2670
|
-
|
|
2671
|
-
|
|
2672
|
-
|
|
2765
|
+
QrackSimulator._ulonglong_byref(q),
|
|
2766
|
+
QrackSimulator._complex_byref(b),
|
|
2767
|
+
QrackSimulator._real1_byref(e),
|
|
2673
2768
|
)
|
|
2674
2769
|
self._throw_if_error()
|
|
2675
2770
|
return result
|
|
@@ -2694,7 +2789,7 @@ class QrackSimulator:
|
|
|
2694
2789
|
if len(q) != len(b):
|
|
2695
2790
|
raise RuntimeError("pauli_expectation argument lengths do not match.")
|
|
2696
2791
|
result = Qrack.qrack_lib.PauliExpectation(
|
|
2697
|
-
self.sid, len(q),
|
|
2792
|
+
self.sid, len(q), QrackSimulator._ulonglong_byref(q), QrackSimulator._ulonglong_byref(b)
|
|
2698
2793
|
)
|
|
2699
2794
|
self._throw_if_error()
|
|
2700
2795
|
return result
|
|
@@ -2714,7 +2809,7 @@ class QrackSimulator:
|
|
|
2714
2809
|
Returns:
|
|
2715
2810
|
float variance
|
|
2716
2811
|
"""
|
|
2717
|
-
result = Qrack.qrack_lib.Variance(self.sid, len(q),
|
|
2812
|
+
result = Qrack.qrack_lib.Variance(self.sid, len(q), QrackSimulator._ulonglong_byref(q))
|
|
2718
2813
|
self._throw_if_error()
|
|
2719
2814
|
return result
|
|
2720
2815
|
|
|
@@ -2736,7 +2831,7 @@ class QrackSimulator:
|
|
|
2736
2831
|
variance
|
|
2737
2832
|
"""
|
|
2738
2833
|
result = Qrack.qrack_lib.VarianceRdm(
|
|
2739
|
-
self.sid, len(q),
|
|
2834
|
+
self.sid, len(q), QrackSimulator._ulonglong_byref(q), r
|
|
2740
2835
|
)
|
|
2741
2836
|
self._throw_if_error()
|
|
2742
2837
|
return result
|
|
@@ -2762,7 +2857,11 @@ class QrackSimulator:
|
|
|
2762
2857
|
raise RuntimeError("factorized_variance argument lengths do not match.")
|
|
2763
2858
|
m = max([(x.bit_length() + 63) // 64 for x in c])
|
|
2764
2859
|
result = Qrack.qrack_lib.FactorizedVariance(
|
|
2765
|
-
self.sid,
|
|
2860
|
+
self.sid,
|
|
2861
|
+
len(q),
|
|
2862
|
+
QrackSimulator._ulonglong_byref(q),
|
|
2863
|
+
m,
|
|
2864
|
+
QrackSimulator._to_ulonglong(m, c),
|
|
2766
2865
|
)
|
|
2767
2866
|
self._throw_if_error()
|
|
2768
2867
|
return result
|
|
@@ -2790,7 +2889,12 @@ class QrackSimulator:
|
|
|
2790
2889
|
raise RuntimeError("factorized_variance_rdm argument lengths do not match.")
|
|
2791
2890
|
m = max([(x.bit_length() + 63) // 64 for x in c])
|
|
2792
2891
|
result = Qrack.qrack_lib.FactorizedVarianceRdm(
|
|
2793
|
-
self.sid,
|
|
2892
|
+
self.sid,
|
|
2893
|
+
len(q),
|
|
2894
|
+
QrackSimulator._ulonglong_byref(q),
|
|
2895
|
+
m,
|
|
2896
|
+
QrackSimulator._to_ulonglong(m, c),
|
|
2897
|
+
r,
|
|
2794
2898
|
)
|
|
2795
2899
|
self._throw_if_error()
|
|
2796
2900
|
return result
|
|
@@ -2815,7 +2919,7 @@ class QrackSimulator:
|
|
|
2815
2919
|
if (len(q) << 1) != len(c):
|
|
2816
2920
|
raise RuntimeError("factorized_variance_rdm argument lengths do not match.")
|
|
2817
2921
|
result = Qrack.qrack_lib.FactorizedVarianceFp(
|
|
2818
|
-
self.sid, len(q),
|
|
2922
|
+
self.sid, len(q), QrackSimulator._ulonglong_byref(q), QrackSimulator._real1_byref(c)
|
|
2819
2923
|
)
|
|
2820
2924
|
self._throw_if_error()
|
|
2821
2925
|
return result
|
|
@@ -2840,11 +2944,9 @@ class QrackSimulator:
|
|
|
2840
2944
|
variance
|
|
2841
2945
|
"""
|
|
2842
2946
|
if (len(q) << 1) != len(c):
|
|
2843
|
-
raise RuntimeError(
|
|
2844
|
-
"factorized_variance_fp_rdm argument lengths do not match."
|
|
2845
|
-
)
|
|
2947
|
+
raise RuntimeError("factorized_variance_fp_rdm argument lengths do not match.")
|
|
2846
2948
|
result = Qrack.qrack_lib.FactorizedVarianceFpRdm(
|
|
2847
|
-
self.sid, len(q),
|
|
2949
|
+
self.sid, len(q), QrackSimulator._ulonglong_byref(q), QrackSimulator._real1_byref(c), r
|
|
2848
2950
|
)
|
|
2849
2951
|
self._throw_if_error()
|
|
2850
2952
|
return result
|
|
@@ -2868,7 +2970,7 @@ class QrackSimulator:
|
|
|
2868
2970
|
if (3 * len(q)) != len(b):
|
|
2869
2971
|
raise RuntimeError("unitary_variance argument lengths do not match.")
|
|
2870
2972
|
result = Qrack.qrack_lib.UnitaryVariance(
|
|
2871
|
-
self.sid, len(q),
|
|
2973
|
+
self.sid, len(q), QrackSimulator._ulonglong_byref(q), QrackSimulator._real1_byref(b)
|
|
2872
2974
|
)
|
|
2873
2975
|
self._throw_if_error()
|
|
2874
2976
|
return result
|
|
@@ -2892,7 +2994,7 @@ class QrackSimulator:
|
|
|
2892
2994
|
if (len(q) << 2) != len(b):
|
|
2893
2995
|
raise RuntimeError("matrix_variance argument lengths do not match.")
|
|
2894
2996
|
result = Qrack.qrack_lib.MatrixVariance(
|
|
2895
|
-
self.sid, len(q),
|
|
2997
|
+
self.sid, len(q), QrackSimulator._ulonglong_byref(q), QrackSimulator._complex_byref(b)
|
|
2896
2998
|
)
|
|
2897
2999
|
self._throw_if_error()
|
|
2898
3000
|
return result
|
|
@@ -2924,9 +3026,9 @@ class QrackSimulator:
|
|
|
2924
3026
|
result = Qrack.qrack_lib.UnitaryVarianceEigenVal(
|
|
2925
3027
|
self.sid,
|
|
2926
3028
|
len(q),
|
|
2927
|
-
|
|
2928
|
-
|
|
2929
|
-
|
|
3029
|
+
QrackSimulator._ulonglong_byref(q),
|
|
3030
|
+
QrackSimulator._real1_byref(b),
|
|
3031
|
+
QrackSimulator._real1_byref(e),
|
|
2930
3032
|
)
|
|
2931
3033
|
self._throw_if_error()
|
|
2932
3034
|
return result
|
|
@@ -2958,9 +3060,9 @@ class QrackSimulator:
|
|
|
2958
3060
|
result = Qrack.qrack_lib.MatrixVarianceEigenVal(
|
|
2959
3061
|
self.sid,
|
|
2960
3062
|
len(q),
|
|
2961
|
-
|
|
2962
|
-
|
|
2963
|
-
|
|
3063
|
+
QrackSimulator._ulonglong_byref(q),
|
|
3064
|
+
QrackSimulator._complex_byref(b),
|
|
3065
|
+
QrackSimulator._real1_byref(e),
|
|
2964
3066
|
)
|
|
2965
3067
|
self._throw_if_error()
|
|
2966
3068
|
return result
|
|
@@ -2985,7 +3087,7 @@ class QrackSimulator:
|
|
|
2985
3087
|
if len(q) != len(b):
|
|
2986
3088
|
raise RuntimeError("pauli_variance argument lengths do not match.")
|
|
2987
3089
|
result = Qrack.qrack_lib.PauliVariance(
|
|
2988
|
-
self.sid, len(q),
|
|
3090
|
+
self.sid, len(q), QrackSimulator._ulonglong_byref(q), QrackSimulator._ulonglong_byref(b)
|
|
2989
3091
|
)
|
|
2990
3092
|
self._throw_if_error()
|
|
2991
3093
|
return result
|
|
@@ -3009,7 +3111,7 @@ class QrackSimulator:
|
|
|
3009
3111
|
if len(b) != len(q):
|
|
3010
3112
|
raise RuntimeError("Lengths of list parameters are mismatched.")
|
|
3011
3113
|
result = Qrack.qrack_lib.JointEnsembleProbability(
|
|
3012
|
-
self.sid, len(b),
|
|
3114
|
+
self.sid, len(b), QrackSimulator._ulonglong_byref(b), q
|
|
3013
3115
|
)
|
|
3014
3116
|
self._throw_if_error()
|
|
3015
3117
|
return result
|
|
@@ -3038,7 +3140,7 @@ class QrackSimulator:
|
|
|
3038
3140
|
)
|
|
3039
3141
|
|
|
3040
3142
|
Qrack.qrack_lib.PhaseParity(
|
|
3041
|
-
self.sid, ctypes.c_double(la), len(q),
|
|
3143
|
+
self.sid, ctypes.c_double(la), len(q), QrackSimulator._ulonglong_byref(q)
|
|
3042
3144
|
)
|
|
3043
3145
|
self._throw_if_error()
|
|
3044
3146
|
|
|
@@ -3064,7 +3166,7 @@ class QrackSimulator:
|
|
|
3064
3166
|
"QrackStabilizer cannot phase_root_n()! (Create a QrackSimulator instead, also with isTensorNetwork=False.)"
|
|
3065
3167
|
)
|
|
3066
3168
|
|
|
3067
|
-
Qrack.qrack_lib.PhaseRootN(self.sid, n, len(q),
|
|
3169
|
+
Qrack.qrack_lib.PhaseRootN(self.sid, n, len(q), QrackSimulator._ulonglong_byref(q))
|
|
3068
3170
|
self._throw_if_error()
|
|
3069
3171
|
|
|
3070
3172
|
def try_separate_1qb(self, qi1):
|
|
@@ -3121,7 +3223,7 @@ class QrackSimulator:
|
|
|
3121
3223
|
State of all the qubits.
|
|
3122
3224
|
"""
|
|
3123
3225
|
result = Qrack.qrack_lib.TrySeparateTol(
|
|
3124
|
-
self.sid, len(qs),
|
|
3226
|
+
self.sid, len(qs), QrackSimulator._ulonglong_byref(qs), t
|
|
3125
3227
|
)
|
|
3126
3228
|
self._throw_if_error()
|
|
3127
3229
|
return result
|
|
@@ -3137,7 +3239,7 @@ class QrackSimulator:
|
|
|
3137
3239
|
Raises:
|
|
3138
3240
|
Runtimeerror: QrackSimulator raised an exception.
|
|
3139
3241
|
"""
|
|
3140
|
-
result = Qrack.qrack_lib.Separate(self.sid, len(qs),
|
|
3242
|
+
result = Qrack.qrack_lib.Separate(self.sid, len(qs), QrackSimulator._ulonglong_byref(qs))
|
|
3141
3243
|
self._throw_if_error()
|
|
3142
3244
|
|
|
3143
3245
|
def get_unitary_fidelity(self):
|
|
@@ -3261,6 +3363,41 @@ class QrackSimulator:
|
|
|
3261
3363
|
Qrack.qrack_lib.SetNoiseParameter(self.sid, np)
|
|
3262
3364
|
self._throw_if_error()
|
|
3263
3365
|
|
|
3366
|
+
def set_ace_max_qb(self, qb):
|
|
3367
|
+
"""Set "automatic circuit elision" (ACE) max qubits
|
|
3368
|
+
|
|
3369
|
+
If isSchmidtDecompose=True, maximum entangled subsytem size
|
|
3370
|
+
of this simulator will be capped to 'qb', and entangling
|
|
3371
|
+
gates that would exceed that size are replaced with gate
|
|
3372
|
+
shadows.
|
|
3373
|
+
|
|
3374
|
+
Args:
|
|
3375
|
+
qb: maximum subsystem qubits
|
|
3376
|
+
|
|
3377
|
+
Raises:
|
|
3378
|
+
RuntimeError: QrackSimulator raised an exception.
|
|
3379
|
+
"""
|
|
3380
|
+
Qrack.qrack_lib.SetAceMaxQb(self.sid, qb)
|
|
3381
|
+
self._throw_if_error()
|
|
3382
|
+
|
|
3383
|
+
def set_sparse_ace_max_mb(self, mb):
|
|
3384
|
+
"""Set sparse "automatic circuit elision" (ACE) max memory
|
|
3385
|
+
|
|
3386
|
+
If isSchmidtDecompose=True, isSparse=True, and
|
|
3387
|
+
isOpenCL=False, maximum subsytem size memory MB of this
|
|
3388
|
+
simulator will be capped to 'mb', and entangling gates
|
|
3389
|
+
that would exceed that size are replaced with gate
|
|
3390
|
+
shadows.
|
|
3391
|
+
|
|
3392
|
+
Args:
|
|
3393
|
+
mb: maximum subsystem memory in MB
|
|
3394
|
+
|
|
3395
|
+
Raises:
|
|
3396
|
+
RuntimeError: QrackSimulator raised an exception.
|
|
3397
|
+
"""
|
|
3398
|
+
Qrack.qrack_lib.SetSparseAceMaxMb(self.sid, mb)
|
|
3399
|
+
self._throw_if_error()
|
|
3400
|
+
|
|
3264
3401
|
def normalize(self):
|
|
3265
3402
|
"""Normalize the state
|
|
3266
3403
|
|
|
@@ -3442,9 +3579,7 @@ class QrackSimulator:
|
|
|
3442
3579
|
"swap",
|
|
3443
3580
|
]
|
|
3444
3581
|
try:
|
|
3445
|
-
circ = transpile(
|
|
3446
|
-
clifford_circ, basis_gates=basis_gates, optimization_level=2
|
|
3447
|
-
)
|
|
3582
|
+
circ = transpile(clifford_circ, basis_gates=basis_gates, optimization_level=2)
|
|
3448
3583
|
except:
|
|
3449
3584
|
circ = clifford_circ
|
|
3450
3585
|
|
|
@@ -3540,9 +3675,7 @@ class QrackSimulator:
|
|
|
3540
3675
|
)
|
|
3541
3676
|
elif op.name == "h":
|
|
3542
3677
|
non_clifford = np.matmul(
|
|
3543
|
-
np.array(
|
|
3544
|
-
[[sqrt1_2, sqrt1_2], [sqrt1_2, -sqrt1_2]], np.complex128
|
|
3545
|
-
),
|
|
3678
|
+
np.array([[sqrt1_2, sqrt1_2], [sqrt1_2, -sqrt1_2]], np.complex128),
|
|
3546
3679
|
non_clifford,
|
|
3547
3680
|
)
|
|
3548
3681
|
elif op.name == "x":
|
|
@@ -3650,9 +3783,7 @@ class QrackSimulator:
|
|
|
3650
3783
|
j += 1
|
|
3651
3784
|
continue
|
|
3652
3785
|
|
|
3653
|
-
if (q1 == i) and (
|
|
3654
|
-
(op.name == "cx") or (op.name == "cy") or (op.name == "cz")
|
|
3655
|
-
):
|
|
3786
|
+
if (q1 == i) and ((op.name == "cx") or (op.name == "cy") or (op.name == "cz")):
|
|
3656
3787
|
if np.isclose(np.abs(non_clifford[0][1]), 0) and np.isclose(
|
|
3657
3788
|
np.abs(non_clifford[1][0]), 0
|
|
3658
3789
|
):
|
|
@@ -3718,9 +3849,7 @@ class QrackSimulator:
|
|
|
3718
3849
|
elif op.name == "h":
|
|
3719
3850
|
non_clifford = np.matmul(
|
|
3720
3851
|
non_clifford,
|
|
3721
|
-
np.array(
|
|
3722
|
-
[[sqrt1_2, sqrt1_2], [sqrt1_2, -sqrt1_2]], np.complex128
|
|
3723
|
-
),
|
|
3852
|
+
np.array([[sqrt1_2, sqrt1_2], [sqrt1_2, -sqrt1_2]], np.complex128),
|
|
3724
3853
|
)
|
|
3725
3854
|
elif op.name == "x":
|
|
3726
3855
|
non_clifford = np.matmul(
|
|
@@ -3910,12 +4039,8 @@ class QrackSimulator:
|
|
|
3910
4039
|
qasm = qasm3.dumps(circ)
|
|
3911
4040
|
except:
|
|
3912
4041
|
qasm = circ.qasm()
|
|
3913
|
-
qasm = qasm.replace(
|
|
3914
|
-
|
|
3915
|
-
)
|
|
3916
|
-
highest_index = max(
|
|
3917
|
-
[int(x) for x in re.findall(r"\[(.*?)\]", qasm) if x.isdigit()]
|
|
3918
|
-
)
|
|
4042
|
+
qasm = qasm.replace("qreg q[" + str(circ.width()) + "];", "qreg q[" + str(width) + "];")
|
|
4043
|
+
highest_index = max([int(x) for x in re.findall(r"\[(.*?)\]", qasm) if x.isdigit()])
|
|
3919
4044
|
if highest_index != width:
|
|
3920
4045
|
qasm = qasm.replace(
|
|
3921
4046
|
"qreg q[" + str(width) + "];", "qreg q[" + str(highest_index) + "];"
|
|
@@ -4030,17 +4155,11 @@ class QrackSimulator:
|
|
|
4030
4155
|
(-1 * float(operation.params[1])) + math.pi / 2,
|
|
4031
4156
|
)
|
|
4032
4157
|
elif name == "rx":
|
|
4033
|
-
self._sim.r(
|
|
4034
|
-
Pauli.PauliX, float(operation.params[0]), operation.qubits[0]._index
|
|
4035
|
-
)
|
|
4158
|
+
self._sim.r(Pauli.PauliX, float(operation.params[0]), operation.qubits[0]._index)
|
|
4036
4159
|
elif name == "ry":
|
|
4037
|
-
self._sim.r(
|
|
4038
|
-
Pauli.PauliY, float(operation.params[0]), operation.qubits[0]._index
|
|
4039
|
-
)
|
|
4160
|
+
self._sim.r(Pauli.PauliY, float(operation.params[0]), operation.qubits[0]._index)
|
|
4040
4161
|
elif name == "rz":
|
|
4041
|
-
self._sim.r(
|
|
4042
|
-
Pauli.PauliZ, float(operation.params[0]), operation.qubits[0]._index
|
|
4043
|
-
)
|
|
4162
|
+
self._sim.r(Pauli.PauliZ, float(operation.params[0]), operation.qubits[0]._index)
|
|
4044
4163
|
elif name == "h":
|
|
4045
4164
|
self._sim.h(operation.qubits[0]._index)
|
|
4046
4165
|
elif name == "x":
|
|
@@ -4092,21 +4211,13 @@ class QrackSimulator:
|
|
|
4092
4211
|
float(operation.params[2]),
|
|
4093
4212
|
)
|
|
4094
4213
|
elif name == "cx":
|
|
4095
|
-
self._sim.mcx(
|
|
4096
|
-
[q._index for q in operation.qubits[0:1]], operation.qubits[1]._index
|
|
4097
|
-
)
|
|
4214
|
+
self._sim.mcx([q._index for q in operation.qubits[0:1]], operation.qubits[1]._index)
|
|
4098
4215
|
elif name == "cy":
|
|
4099
|
-
self._sim.mcy(
|
|
4100
|
-
[q._index for q in operation.qubits[0:1]], operation.qubits[1]._index
|
|
4101
|
-
)
|
|
4216
|
+
self._sim.mcy([q._index for q in operation.qubits[0:1]], operation.qubits[1]._index)
|
|
4102
4217
|
elif name == "cz":
|
|
4103
|
-
self._sim.mcz(
|
|
4104
|
-
[q._index for q in operation.qubits[0:1]], operation.qubits[1]._index
|
|
4105
|
-
)
|
|
4218
|
+
self._sim.mcz([q._index for q in operation.qubits[0:1]], operation.qubits[1]._index)
|
|
4106
4219
|
elif name == "ch":
|
|
4107
|
-
self._sim.mch(
|
|
4108
|
-
[q._index for q in operation.qubits[0:1]], operation.qubits[1]._index
|
|
4109
|
-
)
|
|
4220
|
+
self._sim.mch([q._index for q in operation.qubits[0:1]], operation.qubits[1]._index)
|
|
4110
4221
|
elif name == "cp":
|
|
4111
4222
|
self._sim.mcmtrx(
|
|
4112
4223
|
[q._index for q in operation.qubits[0:1]],
|
|
@@ -4132,34 +4243,20 @@ class QrackSimulator:
|
|
|
4132
4243
|
operation.qubits[1]._index,
|
|
4133
4244
|
)
|
|
4134
4245
|
elif name == "dcx":
|
|
4135
|
-
self._sim.mcx(
|
|
4136
|
-
[q._index for q in operation.qubits[0:1]], operation.qubits[1]._index
|
|
4137
|
-
)
|
|
4246
|
+
self._sim.mcx([q._index for q in operation.qubits[0:1]], operation.qubits[1]._index)
|
|
4138
4247
|
self._sim.mcx(operation.qubits[1:2]._index, operation.qubits[0]._index)
|
|
4139
4248
|
elif name == "ccx":
|
|
4140
|
-
self._sim.mcx(
|
|
4141
|
-
[q._index for q in operation.qubits[0:2]], operation.qubits[2]._index
|
|
4142
|
-
)
|
|
4249
|
+
self._sim.mcx([q._index for q in operation.qubits[0:2]], operation.qubits[2]._index)
|
|
4143
4250
|
elif name == "ccy":
|
|
4144
|
-
self._sim.mcy(
|
|
4145
|
-
[q._index for q in operation.qubits[0:2]], operation.qubits[2]._index
|
|
4146
|
-
)
|
|
4251
|
+
self._sim.mcy([q._index for q in operation.qubits[0:2]], operation.qubits[2]._index)
|
|
4147
4252
|
elif name == "ccz":
|
|
4148
|
-
self._sim.mcz(
|
|
4149
|
-
[q._index for q in operation.qubits[0:2]], operation.qubits[2]._index
|
|
4150
|
-
)
|
|
4253
|
+
self._sim.mcz([q._index for q in operation.qubits[0:2]], operation.qubits[2]._index)
|
|
4151
4254
|
elif name == "mcx":
|
|
4152
|
-
self._sim.mcx(
|
|
4153
|
-
[q._index for q in operation.qubits[0:-1]], operation.qubits[-1]._index
|
|
4154
|
-
)
|
|
4255
|
+
self._sim.mcx([q._index for q in operation.qubits[0:-1]], operation.qubits[-1]._index)
|
|
4155
4256
|
elif name == "mcy":
|
|
4156
|
-
self._sim.mcy(
|
|
4157
|
-
[q._index for q in operation.qubits[0:-1]], operation.qubits[-1]._index
|
|
4158
|
-
)
|
|
4257
|
+
self._sim.mcy([q._index for q in operation.qubits[0:-1]], operation.qubits[-1]._index)
|
|
4159
4258
|
elif name == "mcz":
|
|
4160
|
-
self._sim.mcz(
|
|
4161
|
-
[q._index for q in operation.qubits[0:-1]], operation.qubits[-1]._index
|
|
4162
|
-
)
|
|
4259
|
+
self._sim.mcz([q._index for q in operation.qubits[0:-1]], operation.qubits[-1]._index)
|
|
4163
4260
|
elif name == "swap":
|
|
4164
4261
|
self._sim.swap(operation.qubits[0]._index, operation.qubits[1]._index)
|
|
4165
4262
|
elif name == "iswap":
|
|
@@ -4211,9 +4308,9 @@ class QrackSimulator:
|
|
|
4211
4308
|
cregbit = clbit
|
|
4212
4309
|
|
|
4213
4310
|
regbit = 1 << cregbit
|
|
4214
|
-
self._classical_register = (
|
|
4215
|
-
|
|
4216
|
-
)
|
|
4311
|
+
self._classical_register = (self._classical_register & (~regbit)) | (
|
|
4312
|
+
qubit_outcome << cregbit
|
|
4313
|
+
)
|
|
4217
4314
|
|
|
4218
4315
|
elif name == "bfunc":
|
|
4219
4316
|
mask = int(operation.mask, 16)
|
|
@@ -4328,9 +4425,7 @@ class QrackSimulator:
|
|
|
4328
4425
|
if operation.name == "id" or operation.name == "barrier":
|
|
4329
4426
|
continue
|
|
4330
4427
|
|
|
4331
|
-
if is_initializing and (
|
|
4332
|
-
(operation.name == "measure") or (operation.name == "reset")
|
|
4333
|
-
):
|
|
4428
|
+
if is_initializing and ((operation.name == "measure") or (operation.name == "reset")):
|
|
4334
4429
|
continue
|
|
4335
4430
|
|
|
4336
4431
|
is_initializing = False
|
|
@@ -4388,14 +4483,13 @@ class QrackSimulator:
|
|
|
4388
4483
|
self._sample_cregbits = []
|
|
4389
4484
|
|
|
4390
4485
|
if self._sample_measure and (len(self._sample_qubits) > 0):
|
|
4391
|
-
_data = self._add_sample_measure(
|
|
4392
|
-
self._sample_qubits, self._sample_clbits, self._shots
|
|
4393
|
-
)
|
|
4486
|
+
_data = self._add_sample_measure(self._sample_qubits, self._sample_clbits, self._shots)
|
|
4394
4487
|
|
|
4395
4488
|
del self._sim
|
|
4396
4489
|
|
|
4397
4490
|
return _data
|
|
4398
4491
|
|
|
4492
|
+
@staticmethod
|
|
4399
4493
|
def get_qiskit_basis_gates():
|
|
4400
4494
|
return [
|
|
4401
4495
|
"id",
|