pyqrack-cpu 1.76.0__py3-none-macosx_14_0_arm64.whl → 1.80.3__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.
- pyqrack/__init__.py +2 -2
- pyqrack/qrack_ace_backend.py +44 -70
- pyqrack/qrack_circuit.py +51 -40
- pyqrack/qrack_neuron.py +35 -10
- pyqrack/qrack_neuron_torch_layer.py +182 -106
- pyqrack/qrack_simulator.py +269 -271
- pyqrack/qrack_system/qrack_lib/{libqrack_pinvoke.9.34.5.dylib → libqrack_pinvoke.9.35.2.dylib} +0 -0
- pyqrack/qrack_system/qrack_lib/libqrack_pinvoke.dylib +0 -0
- pyqrack/qrack_system/qrack_system.py +19 -12
- pyqrack/stats/load_quantized_data.py +1 -3
- pyqrack/stats/quantize_by_range.py +2 -6
- {pyqrack_cpu-1.76.0.dist-info → pyqrack_cpu-1.80.3.dist-info}/METADATA +3 -3
- pyqrack_cpu-1.80.3.dist-info/RECORD +23 -0
- pyqrack_cpu-1.76.0.dist-info/RECORD +0 -23
- {pyqrack_cpu-1.76.0.dist-info → pyqrack_cpu-1.80.3.dist-info}/LICENSE +0 -0
- {pyqrack_cpu-1.76.0.dist-info → pyqrack_cpu-1.80.3.dist-info}/WHEEL +0 -0
- {pyqrack_cpu-1.76.0.dist-info → pyqrack_cpu-1.80.3.dist-info}/top_level.txt +0 -0
pyqrack/qrack_simulator.py
CHANGED
|
@@ -57,9 +57,7 @@ class QrackSimulator:
|
|
|
57
57
|
isPaged=True,
|
|
58
58
|
isCpuGpuHybrid=True,
|
|
59
59
|
isOpenCL=True,
|
|
60
|
-
isHostPointer=(
|
|
61
|
-
True if os.environ.get("PYQRACK_HOST_POINTER_DEFAULT_ON") else False
|
|
62
|
-
),
|
|
60
|
+
isHostPointer=(True if os.environ.get("PYQRACK_HOST_POINTER_DEFAULT_ON") else False),
|
|
63
61
|
isSparse=False,
|
|
64
62
|
noise=0,
|
|
65
63
|
pyzxCircuit=None,
|
|
@@ -100,7 +98,7 @@ class QrackSimulator:
|
|
|
100
98
|
isCpuGpuHybrid,
|
|
101
99
|
isOpenCL,
|
|
102
100
|
isHostPointer,
|
|
103
|
-
isSparse
|
|
101
|
+
isSparse,
|
|
104
102
|
)
|
|
105
103
|
|
|
106
104
|
self._throw_if_error()
|
|
@@ -118,36 +116,45 @@ class QrackSimulator:
|
|
|
118
116
|
Qrack.qrack_lib.destroy(self.sid)
|
|
119
117
|
self.sid = None
|
|
120
118
|
|
|
121
|
-
|
|
119
|
+
@staticmethod
|
|
120
|
+
def _int_byref(a):
|
|
122
121
|
return (ctypes.c_int * len(a))(*a)
|
|
123
122
|
|
|
124
|
-
|
|
123
|
+
@staticmethod
|
|
124
|
+
def _ulonglong_byref(a):
|
|
125
125
|
return (ctypes.c_ulonglong * len(a))(*a)
|
|
126
126
|
|
|
127
|
-
|
|
127
|
+
@staticmethod
|
|
128
|
+
def _longlong_byref(a):
|
|
128
129
|
return (ctypes.c_longlong * len(a))(*a)
|
|
129
130
|
|
|
130
|
-
|
|
131
|
+
@staticmethod
|
|
132
|
+
def _double_byref(a):
|
|
131
133
|
return (ctypes.c_double * len(a))(*a)
|
|
132
134
|
|
|
133
|
-
|
|
135
|
+
@staticmethod
|
|
136
|
+
def _complex_byref(a):
|
|
134
137
|
t = [(c.real, c.imag) for c in a]
|
|
135
|
-
return
|
|
138
|
+
return QrackSimulator._double_byref([float(item) for sublist in t for item in sublist])
|
|
136
139
|
|
|
137
|
-
|
|
140
|
+
@staticmethod
|
|
141
|
+
def _real1_byref(a):
|
|
138
142
|
# This needs to be c_double, if PyQrack is built with fp64.
|
|
139
143
|
if Qrack.fppow < 6:
|
|
140
144
|
return (ctypes.c_float * len(a))(*a)
|
|
141
145
|
return (ctypes.c_double * len(a))(*a)
|
|
142
146
|
|
|
143
|
-
|
|
147
|
+
@staticmethod
|
|
148
|
+
def _bool_byref(a):
|
|
144
149
|
return (ctypes.c_bool * len(a))(*a)
|
|
145
150
|
|
|
146
|
-
|
|
151
|
+
@staticmethod
|
|
152
|
+
def _qrack_complex_byref(a):
|
|
147
153
|
t = [(c.real, c.imag) for c in a]
|
|
148
|
-
return
|
|
154
|
+
return QrackSimulator._real1_byref([float(item) for sublist in t for item in sublist])
|
|
149
155
|
|
|
150
|
-
|
|
156
|
+
@staticmethod
|
|
157
|
+
def _to_ubyte(nv, v):
|
|
151
158
|
c = math.floor((nv - 1) / 8) + 1
|
|
152
159
|
b = (ctypes.c_ubyte * (c * (1 << nv)))()
|
|
153
160
|
n = 0
|
|
@@ -159,7 +166,8 @@ class QrackSimulator:
|
|
|
159
166
|
|
|
160
167
|
return b
|
|
161
168
|
|
|
162
|
-
|
|
169
|
+
@staticmethod
|
|
170
|
+
def _to_ulonglong(m, v):
|
|
163
171
|
b = (ctypes.c_ulonglong * (m * len(v)))()
|
|
164
172
|
n = 0
|
|
165
173
|
for u in v:
|
|
@@ -171,7 +179,8 @@ class QrackSimulator:
|
|
|
171
179
|
return b
|
|
172
180
|
|
|
173
181
|
# See https://stackoverflow.com/questions/5389507/iterating-over-every-two-elements-in-a-list#answer-30426000
|
|
174
|
-
|
|
182
|
+
@staticmethod
|
|
183
|
+
def _pairwise(it):
|
|
175
184
|
it = iter(it)
|
|
176
185
|
while True:
|
|
177
186
|
try:
|
|
@@ -197,7 +206,7 @@ class QrackSimulator:
|
|
|
197
206
|
|
|
198
207
|
def set_device_list(self, d):
|
|
199
208
|
"""Set the GPU device ID"""
|
|
200
|
-
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))
|
|
201
210
|
self._throw_if_error()
|
|
202
211
|
|
|
203
212
|
def clone(self):
|
|
@@ -361,7 +370,7 @@ class QrackSimulator:
|
|
|
361
370
|
raise ValueError(
|
|
362
371
|
"2x2 matrix 'm' in QrackSimulator.mtrx() must contain at least 4 elements."
|
|
363
372
|
)
|
|
364
|
-
Qrack.qrack_lib.Mtrx(self.sid,
|
|
373
|
+
Qrack.qrack_lib.Mtrx(self.sid, QrackSimulator._complex_byref(m), q)
|
|
365
374
|
self._throw_if_error()
|
|
366
375
|
|
|
367
376
|
def r(self, b, ph, q):
|
|
@@ -401,9 +410,9 @@ class QrackSimulator:
|
|
|
401
410
|
Qrack.qrack_lib.Exp(
|
|
402
411
|
self.sid,
|
|
403
412
|
len(b),
|
|
404
|
-
|
|
413
|
+
QrackSimulator._ulonglong_byref(b),
|
|
405
414
|
ctypes.c_double(ph),
|
|
406
|
-
|
|
415
|
+
QrackSimulator._ulonglong_byref(q),
|
|
407
416
|
)
|
|
408
417
|
self._throw_if_error()
|
|
409
418
|
|
|
@@ -420,7 +429,7 @@ class QrackSimulator:
|
|
|
420
429
|
Raises:
|
|
421
430
|
RuntimeError: QrackSimulator raised an exception.
|
|
422
431
|
"""
|
|
423
|
-
Qrack.qrack_lib.MCX(self.sid, len(c),
|
|
432
|
+
Qrack.qrack_lib.MCX(self.sid, len(c), QrackSimulator._ulonglong_byref(c), q)
|
|
424
433
|
self._throw_if_error()
|
|
425
434
|
|
|
426
435
|
def mcy(self, c, q):
|
|
@@ -436,7 +445,7 @@ class QrackSimulator:
|
|
|
436
445
|
Raises:
|
|
437
446
|
RuntimeError: QrackSimulator raised an exception.
|
|
438
447
|
"""
|
|
439
|
-
Qrack.qrack_lib.MCY(self.sid, len(c),
|
|
448
|
+
Qrack.qrack_lib.MCY(self.sid, len(c), QrackSimulator._ulonglong_byref(c), q)
|
|
440
449
|
self._throw_if_error()
|
|
441
450
|
|
|
442
451
|
def mcz(self, c, q):
|
|
@@ -452,7 +461,7 @@ class QrackSimulator:
|
|
|
452
461
|
Raises:
|
|
453
462
|
RuntimeError: QrackSimulator raised an exception.
|
|
454
463
|
"""
|
|
455
|
-
Qrack.qrack_lib.MCZ(self.sid, len(c),
|
|
464
|
+
Qrack.qrack_lib.MCZ(self.sid, len(c), QrackSimulator._ulonglong_byref(c), q)
|
|
456
465
|
self._throw_if_error()
|
|
457
466
|
|
|
458
467
|
def mch(self, c, q):
|
|
@@ -468,7 +477,7 @@ class QrackSimulator:
|
|
|
468
477
|
Raises:
|
|
469
478
|
RuntimeError: QrackSimulator raised an exception.
|
|
470
479
|
"""
|
|
471
|
-
Qrack.qrack_lib.MCH(self.sid, len(c),
|
|
480
|
+
Qrack.qrack_lib.MCH(self.sid, len(c), QrackSimulator._ulonglong_byref(c), q)
|
|
472
481
|
self._throw_if_error()
|
|
473
482
|
|
|
474
483
|
def mcs(self, c, q):
|
|
@@ -484,7 +493,7 @@ class QrackSimulator:
|
|
|
484
493
|
Raises:
|
|
485
494
|
RuntimeError: QrackSimulator raised an exception.
|
|
486
495
|
"""
|
|
487
|
-
Qrack.qrack_lib.MCS(self.sid, len(c),
|
|
496
|
+
Qrack.qrack_lib.MCS(self.sid, len(c), QrackSimulator._ulonglong_byref(c), q)
|
|
488
497
|
self._throw_if_error()
|
|
489
498
|
|
|
490
499
|
def mct(self, c, q):
|
|
@@ -500,7 +509,7 @@ class QrackSimulator:
|
|
|
500
509
|
Raises:
|
|
501
510
|
RuntimeError: QrackSimulator raised an exception.
|
|
502
511
|
"""
|
|
503
|
-
Qrack.qrack_lib.MCT(self.sid, len(c),
|
|
512
|
+
Qrack.qrack_lib.MCT(self.sid, len(c), QrackSimulator._ulonglong_byref(c), q)
|
|
504
513
|
self._throw_if_error()
|
|
505
514
|
|
|
506
515
|
def mcadjs(self, c, q):
|
|
@@ -516,7 +525,7 @@ class QrackSimulator:
|
|
|
516
525
|
Raises:
|
|
517
526
|
RuntimeError: QrackSimulator raised an exception.
|
|
518
527
|
"""
|
|
519
|
-
Qrack.qrack_lib.MCAdjS(self.sid, len(c),
|
|
528
|
+
Qrack.qrack_lib.MCAdjS(self.sid, len(c), QrackSimulator._ulonglong_byref(c), q)
|
|
520
529
|
self._throw_if_error()
|
|
521
530
|
|
|
522
531
|
def mcadjt(self, c, q):
|
|
@@ -532,7 +541,7 @@ class QrackSimulator:
|
|
|
532
541
|
Raises:
|
|
533
542
|
RuntimeError: QrackSimulator raised an exception.
|
|
534
543
|
"""
|
|
535
|
-
Qrack.qrack_lib.MCAdjT(self.sid, len(c),
|
|
544
|
+
Qrack.qrack_lib.MCAdjT(self.sid, len(c), QrackSimulator._ulonglong_byref(c), q)
|
|
536
545
|
self._throw_if_error()
|
|
537
546
|
|
|
538
547
|
def mcu(self, c, q, th, ph, la):
|
|
@@ -554,7 +563,7 @@ class QrackSimulator:
|
|
|
554
563
|
Qrack.qrack_lib.MCU(
|
|
555
564
|
self.sid,
|
|
556
565
|
len(c),
|
|
557
|
-
|
|
566
|
+
QrackSimulator._ulonglong_byref(c),
|
|
558
567
|
q,
|
|
559
568
|
ctypes.c_double(th),
|
|
560
569
|
ctypes.c_double(ph),
|
|
@@ -582,7 +591,11 @@ class QrackSimulator:
|
|
|
582
591
|
"2x2 matrix 'm' in QrackSimulator.mcmtrx() must contain at least 4 elements."
|
|
583
592
|
)
|
|
584
593
|
Qrack.qrack_lib.MCMtrx(
|
|
585
|
-
self.sid,
|
|
594
|
+
self.sid,
|
|
595
|
+
len(c),
|
|
596
|
+
QrackSimulator._ulonglong_byref(c),
|
|
597
|
+
QrackSimulator._complex_byref(m),
|
|
598
|
+
q,
|
|
586
599
|
)
|
|
587
600
|
self._throw_if_error()
|
|
588
601
|
|
|
@@ -598,7 +611,7 @@ class QrackSimulator:
|
|
|
598
611
|
Raises:
|
|
599
612
|
RuntimeError: QrackSimulator raised an exception.
|
|
600
613
|
"""
|
|
601
|
-
Qrack.qrack_lib.MACX(self.sid, len(c),
|
|
614
|
+
Qrack.qrack_lib.MACX(self.sid, len(c), QrackSimulator._ulonglong_byref(c), q)
|
|
602
615
|
self._throw_if_error()
|
|
603
616
|
|
|
604
617
|
def macy(self, c, q):
|
|
@@ -614,7 +627,7 @@ class QrackSimulator:
|
|
|
614
627
|
Raises:
|
|
615
628
|
RuntimeError: QrackSimulator raised an exception.
|
|
616
629
|
"""
|
|
617
|
-
Qrack.qrack_lib.MACY(self.sid, len(c),
|
|
630
|
+
Qrack.qrack_lib.MACY(self.sid, len(c), QrackSimulator._ulonglong_byref(c), q)
|
|
618
631
|
self._throw_if_error()
|
|
619
632
|
|
|
620
633
|
def macz(self, c, q):
|
|
@@ -630,7 +643,7 @@ class QrackSimulator:
|
|
|
630
643
|
Raises:
|
|
631
644
|
RuntimeError: QrackSimulator raised an exception.
|
|
632
645
|
"""
|
|
633
|
-
Qrack.qrack_lib.MACZ(self.sid, len(c),
|
|
646
|
+
Qrack.qrack_lib.MACZ(self.sid, len(c), QrackSimulator._ulonglong_byref(c), q)
|
|
634
647
|
self._throw_if_error()
|
|
635
648
|
|
|
636
649
|
def mach(self, c, q):
|
|
@@ -646,7 +659,7 @@ class QrackSimulator:
|
|
|
646
659
|
Raises:
|
|
647
660
|
RuntimeError: QrackSimulator raised an exception.
|
|
648
661
|
"""
|
|
649
|
-
Qrack.qrack_lib.MACH(self.sid, len(c),
|
|
662
|
+
Qrack.qrack_lib.MACH(self.sid, len(c), QrackSimulator._ulonglong_byref(c), q)
|
|
650
663
|
self._throw_if_error()
|
|
651
664
|
|
|
652
665
|
def macs(self, c, q):
|
|
@@ -662,7 +675,7 @@ class QrackSimulator:
|
|
|
662
675
|
Raises:
|
|
663
676
|
RuntimeError: QrackSimulator raised an exception.
|
|
664
677
|
"""
|
|
665
|
-
Qrack.qrack_lib.MACS(self.sid, len(c),
|
|
678
|
+
Qrack.qrack_lib.MACS(self.sid, len(c), QrackSimulator._ulonglong_byref(c), q)
|
|
666
679
|
self._throw_if_error()
|
|
667
680
|
|
|
668
681
|
def mact(self, c, q):
|
|
@@ -678,7 +691,7 @@ class QrackSimulator:
|
|
|
678
691
|
Raises:
|
|
679
692
|
RuntimeError: QrackSimulator raised an exception.
|
|
680
693
|
"""
|
|
681
|
-
Qrack.qrack_lib.MACT(self.sid, len(c),
|
|
694
|
+
Qrack.qrack_lib.MACT(self.sid, len(c), QrackSimulator._ulonglong_byref(c), q)
|
|
682
695
|
self._throw_if_error()
|
|
683
696
|
|
|
684
697
|
def macadjs(self, c, q):
|
|
@@ -694,7 +707,7 @@ class QrackSimulator:
|
|
|
694
707
|
Raises:
|
|
695
708
|
RuntimeError: QrackSimulator raised an exception.
|
|
696
709
|
"""
|
|
697
|
-
Qrack.qrack_lib.MACAdjS(self.sid, len(c),
|
|
710
|
+
Qrack.qrack_lib.MACAdjS(self.sid, len(c), QrackSimulator._ulonglong_byref(c), q)
|
|
698
711
|
self._throw_if_error()
|
|
699
712
|
|
|
700
713
|
def macadjt(self, c, q):
|
|
@@ -710,7 +723,7 @@ class QrackSimulator:
|
|
|
710
723
|
Raises:
|
|
711
724
|
RuntimeError: QrackSimulator raised an exception.
|
|
712
725
|
"""
|
|
713
|
-
Qrack.qrack_lib.MACAdjT(self.sid, len(c),
|
|
726
|
+
Qrack.qrack_lib.MACAdjT(self.sid, len(c), QrackSimulator._ulonglong_byref(c), q)
|
|
714
727
|
self._throw_if_error()
|
|
715
728
|
|
|
716
729
|
def macu(self, c, q, th, ph, la):
|
|
@@ -732,7 +745,7 @@ class QrackSimulator:
|
|
|
732
745
|
Qrack.qrack_lib.MACU(
|
|
733
746
|
self.sid,
|
|
734
747
|
len(c),
|
|
735
|
-
|
|
748
|
+
QrackSimulator._ulonglong_byref(c),
|
|
736
749
|
q,
|
|
737
750
|
ctypes.c_double(th),
|
|
738
751
|
ctypes.c_double(ph),
|
|
@@ -760,7 +773,11 @@ class QrackSimulator:
|
|
|
760
773
|
"2x2 matrix 'm' in QrackSimulator.macmtrx() must contain at least 4 elements."
|
|
761
774
|
)
|
|
762
775
|
Qrack.qrack_lib.MACMtrx(
|
|
763
|
-
self.sid,
|
|
776
|
+
self.sid,
|
|
777
|
+
len(c),
|
|
778
|
+
QrackSimulator._ulonglong_byref(c),
|
|
779
|
+
QrackSimulator._complex_byref(m),
|
|
780
|
+
q,
|
|
764
781
|
)
|
|
765
782
|
self._throw_if_error()
|
|
766
783
|
|
|
@@ -785,7 +802,12 @@ class QrackSimulator:
|
|
|
785
802
|
"2x2 matrix 'm' in QrackSimulator.ucmtrx() must contain at least 4 elements."
|
|
786
803
|
)
|
|
787
804
|
Qrack.qrack_lib.UCMtrx(
|
|
788
|
-
self.sid,
|
|
805
|
+
self.sid,
|
|
806
|
+
len(c),
|
|
807
|
+
QrackSimulator._ulonglong_byref(c),
|
|
808
|
+
QrackSimulator._complex_byref(m),
|
|
809
|
+
q,
|
|
810
|
+
p,
|
|
789
811
|
)
|
|
790
812
|
self._throw_if_error()
|
|
791
813
|
|
|
@@ -809,7 +831,11 @@ class QrackSimulator:
|
|
|
809
831
|
"Multiplex matrix 'm' in QrackSimulator.multiplex1_mtrx() must contain at least (4 * 2 ** len(c)) elements."
|
|
810
832
|
)
|
|
811
833
|
Qrack.qrack_lib.Multiplex1Mtrx(
|
|
812
|
-
self.sid,
|
|
834
|
+
self.sid,
|
|
835
|
+
len(c),
|
|
836
|
+
QrackSimulator._ulonglong_byref(c),
|
|
837
|
+
q,
|
|
838
|
+
QrackSimulator._complex_byref(m),
|
|
813
839
|
)
|
|
814
840
|
self._throw_if_error()
|
|
815
841
|
|
|
@@ -824,7 +850,7 @@ class QrackSimulator:
|
|
|
824
850
|
Raises:
|
|
825
851
|
RuntimeError: QrackSimulator raised an exception.
|
|
826
852
|
"""
|
|
827
|
-
Qrack.qrack_lib.MX(self.sid, len(q),
|
|
853
|
+
Qrack.qrack_lib.MX(self.sid, len(q), QrackSimulator._ulonglong_byref(q))
|
|
828
854
|
self._throw_if_error()
|
|
829
855
|
|
|
830
856
|
def my(self, q):
|
|
@@ -838,7 +864,7 @@ class QrackSimulator:
|
|
|
838
864
|
Raises:
|
|
839
865
|
RuntimeError: QrackSimulator raised an exception.
|
|
840
866
|
"""
|
|
841
|
-
Qrack.qrack_lib.MY(self.sid, len(q),
|
|
867
|
+
Qrack.qrack_lib.MY(self.sid, len(q), QrackSimulator._ulonglong_byref(q))
|
|
842
868
|
self._throw_if_error()
|
|
843
869
|
|
|
844
870
|
def mz(self, q):
|
|
@@ -852,7 +878,7 @@ class QrackSimulator:
|
|
|
852
878
|
Raises:
|
|
853
879
|
RuntimeError: QrackSimulator raised an exception.
|
|
854
880
|
"""
|
|
855
|
-
Qrack.qrack_lib.MZ(self.sid, len(q),
|
|
881
|
+
Qrack.qrack_lib.MZ(self.sid, len(q), QrackSimulator._ulonglong_byref(q))
|
|
856
882
|
self._throw_if_error()
|
|
857
883
|
|
|
858
884
|
def mcr(self, b, ph, c, q):
|
|
@@ -875,7 +901,7 @@ class QrackSimulator:
|
|
|
875
901
|
ctypes.c_ulonglong(b),
|
|
876
902
|
ctypes.c_double(ph),
|
|
877
903
|
len(c),
|
|
878
|
-
|
|
904
|
+
QrackSimulator._ulonglong_byref(c),
|
|
879
905
|
q,
|
|
880
906
|
)
|
|
881
907
|
self._throw_if_error()
|
|
@@ -899,11 +925,11 @@ class QrackSimulator:
|
|
|
899
925
|
Qrack.qrack_lib.MCExp(
|
|
900
926
|
self.sid,
|
|
901
927
|
len(b),
|
|
902
|
-
|
|
928
|
+
QrackSimulator._ulonglong_byref(b),
|
|
903
929
|
ctypes.c_double(ph),
|
|
904
930
|
len(cs),
|
|
905
|
-
|
|
906
|
-
|
|
931
|
+
QrackSimulator._ulonglong_byref(cs),
|
|
932
|
+
QrackSimulator._ulonglong_byref(q),
|
|
907
933
|
)
|
|
908
934
|
self._throw_if_error()
|
|
909
935
|
|
|
@@ -967,9 +993,7 @@ class QrackSimulator:
|
|
|
967
993
|
Raises:
|
|
968
994
|
RuntimeError: QrackSimulator raised an exception.
|
|
969
995
|
"""
|
|
970
|
-
Qrack.qrack_lib.FSim(
|
|
971
|
-
self.sid, ctypes.c_double(th), ctypes.c_double(ph), qi1, qi2
|
|
972
|
-
)
|
|
996
|
+
Qrack.qrack_lib.FSim(self.sid, ctypes.c_double(th), ctypes.c_double(ph), qi1, qi2)
|
|
973
997
|
self._throw_if_error()
|
|
974
998
|
|
|
975
999
|
def cswap(self, c, qi1, qi2):
|
|
@@ -985,7 +1009,7 @@ class QrackSimulator:
|
|
|
985
1009
|
Raises:
|
|
986
1010
|
RuntimeError: QrackSimulator raised an exception.
|
|
987
1011
|
"""
|
|
988
|
-
Qrack.qrack_lib.CSWAP(self.sid, len(c),
|
|
1012
|
+
Qrack.qrack_lib.CSWAP(self.sid, len(c), QrackSimulator._ulonglong_byref(c), qi1, qi2)
|
|
989
1013
|
self._throw_if_error()
|
|
990
1014
|
|
|
991
1015
|
def acswap(self, c, qi1, qi2):
|
|
@@ -1001,7 +1025,7 @@ class QrackSimulator:
|
|
|
1001
1025
|
Raises:
|
|
1002
1026
|
RuntimeError: QrackSimulator raised an exception.
|
|
1003
1027
|
"""
|
|
1004
|
-
Qrack.qrack_lib.ACSWAP(self.sid, len(c),
|
|
1028
|
+
Qrack.qrack_lib.ACSWAP(self.sid, len(c), QrackSimulator._ulonglong_byref(c), qi1, qi2)
|
|
1005
1029
|
self._throw_if_error()
|
|
1006
1030
|
|
|
1007
1031
|
# standard operations
|
|
@@ -1085,7 +1109,7 @@ class QrackSimulator:
|
|
|
1085
1109
|
if len(b) != len(q):
|
|
1086
1110
|
raise RuntimeError("Lengths of list parameters are mismatched.")
|
|
1087
1111
|
result = Qrack.qrack_lib.Measure(
|
|
1088
|
-
self.sid, len(b),
|
|
1112
|
+
self.sid, len(b), QrackSimulator._int_byref(b), QrackSimulator._ulonglong_byref(q)
|
|
1089
1113
|
)
|
|
1090
1114
|
self._throw_if_error()
|
|
1091
1115
|
return result
|
|
@@ -1106,8 +1130,8 @@ class QrackSimulator:
|
|
|
1106
1130
|
Returns:
|
|
1107
1131
|
list of measurement result.
|
|
1108
1132
|
"""
|
|
1109
|
-
m =
|
|
1110
|
-
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)
|
|
1111
1135
|
self._throw_if_error()
|
|
1112
1136
|
return [m[i] for i in range(s)]
|
|
1113
1137
|
|
|
@@ -1123,7 +1147,8 @@ class QrackSimulator:
|
|
|
1123
1147
|
self._throw_if_error()
|
|
1124
1148
|
|
|
1125
1149
|
# arithmetic-logic-unit (ALU)
|
|
1126
|
-
|
|
1150
|
+
@staticmethod
|
|
1151
|
+
def _split_longs(a):
|
|
1127
1152
|
"""Split operation
|
|
1128
1153
|
|
|
1129
1154
|
Splits the given integer into 64 bit numbers.
|
|
@@ -1146,7 +1171,8 @@ class QrackSimulator:
|
|
|
1146
1171
|
a = a >> 64
|
|
1147
1172
|
return aParts
|
|
1148
1173
|
|
|
1149
|
-
|
|
1174
|
+
@staticmethod
|
|
1175
|
+
def _split_longs_2(a, m):
|
|
1150
1176
|
"""Split simultanoues operation
|
|
1151
1177
|
|
|
1152
1178
|
Splits 2 integers into same number of 64 bit numbers.
|
|
@@ -1185,13 +1211,13 @@ class QrackSimulator:
|
|
|
1185
1211
|
Raises:
|
|
1186
1212
|
RuntimeError: QrackSimulator raised an exception.
|
|
1187
1213
|
"""
|
|
1188
|
-
aParts =
|
|
1214
|
+
aParts = QrackSimulator._split_longs(a)
|
|
1189
1215
|
Qrack.qrack_lib.ADD(
|
|
1190
1216
|
self.sid,
|
|
1191
1217
|
len(aParts),
|
|
1192
|
-
|
|
1218
|
+
QrackSimulator._ulonglong_byref(aParts),
|
|
1193
1219
|
len(q),
|
|
1194
|
-
|
|
1220
|
+
QrackSimulator._ulonglong_byref(q),
|
|
1195
1221
|
)
|
|
1196
1222
|
self._throw_if_error()
|
|
1197
1223
|
|
|
@@ -1207,13 +1233,13 @@ class QrackSimulator:
|
|
|
1207
1233
|
Raises:
|
|
1208
1234
|
RuntimeError: QrackSimulator raised an exception.
|
|
1209
1235
|
"""
|
|
1210
|
-
aParts =
|
|
1236
|
+
aParts = QrackSimulator._split_longs(a)
|
|
1211
1237
|
Qrack.qrack_lib.SUB(
|
|
1212
1238
|
self.sid,
|
|
1213
1239
|
len(aParts),
|
|
1214
|
-
|
|
1240
|
+
QrackSimulator._ulonglong_byref(aParts),
|
|
1215
1241
|
len(q),
|
|
1216
|
-
|
|
1242
|
+
QrackSimulator._ulonglong_byref(q),
|
|
1217
1243
|
)
|
|
1218
1244
|
self._throw_if_error()
|
|
1219
1245
|
|
|
@@ -1231,14 +1257,14 @@ class QrackSimulator:
|
|
|
1231
1257
|
Raises:
|
|
1232
1258
|
RuntimeError: QrackSimulator raised an exception.
|
|
1233
1259
|
"""
|
|
1234
|
-
aParts =
|
|
1260
|
+
aParts = QrackSimulator._split_longs(a)
|
|
1235
1261
|
Qrack.qrack_lib.ADDS(
|
|
1236
1262
|
self.sid,
|
|
1237
1263
|
len(aParts),
|
|
1238
|
-
|
|
1264
|
+
QrackSimulator._ulonglong_byref(aParts),
|
|
1239
1265
|
s,
|
|
1240
1266
|
len(q),
|
|
1241
|
-
|
|
1267
|
+
QrackSimulator._ulonglong_byref(q),
|
|
1242
1268
|
)
|
|
1243
1269
|
self._throw_if_error()
|
|
1244
1270
|
|
|
@@ -1256,14 +1282,14 @@ class QrackSimulator:
|
|
|
1256
1282
|
Raises:
|
|
1257
1283
|
RuntimeError: QrackSimulator raised an exception.
|
|
1258
1284
|
"""
|
|
1259
|
-
aParts =
|
|
1285
|
+
aParts = QrackSimulator._split_longs(a)
|
|
1260
1286
|
Qrack.qrack_lib.SUBS(
|
|
1261
1287
|
self.sid,
|
|
1262
1288
|
len(aParts),
|
|
1263
|
-
|
|
1289
|
+
QrackSimulator._ulonglong_byref(aParts),
|
|
1264
1290
|
s,
|
|
1265
1291
|
len(q),
|
|
1266
|
-
|
|
1292
|
+
QrackSimulator._ulonglong_byref(q),
|
|
1267
1293
|
)
|
|
1268
1294
|
self._throw_if_error()
|
|
1269
1295
|
|
|
@@ -1294,14 +1320,14 @@ class QrackSimulator:
|
|
|
1294
1320
|
|
|
1295
1321
|
if len(q) != len(o):
|
|
1296
1322
|
raise RuntimeError("Lengths of list parameters are mismatched.")
|
|
1297
|
-
aParts =
|
|
1323
|
+
aParts = QrackSimulator._split_longs(a)
|
|
1298
1324
|
Qrack.qrack_lib.MUL(
|
|
1299
1325
|
self.sid,
|
|
1300
1326
|
len(aParts),
|
|
1301
|
-
|
|
1327
|
+
QrackSimulator._ulonglong_byref(aParts),
|
|
1302
1328
|
len(q),
|
|
1303
|
-
|
|
1304
|
-
|
|
1329
|
+
QrackSimulator._ulonglong_byref(q),
|
|
1330
|
+
QrackSimulator._ulonglong_byref(o),
|
|
1305
1331
|
)
|
|
1306
1332
|
self._throw_if_error()
|
|
1307
1333
|
|
|
@@ -1333,14 +1359,14 @@ class QrackSimulator:
|
|
|
1333
1359
|
|
|
1334
1360
|
if len(q) != len(o):
|
|
1335
1361
|
raise RuntimeError("Lengths of list parameters are mismatched.")
|
|
1336
|
-
aParts =
|
|
1362
|
+
aParts = QrackSimulator._split_longs(a)
|
|
1337
1363
|
Qrack.qrack_lib.DIV(
|
|
1338
1364
|
self.sid,
|
|
1339
1365
|
len(aParts),
|
|
1340
|
-
|
|
1366
|
+
QrackSimulator._ulonglong_byref(aParts),
|
|
1341
1367
|
len(q),
|
|
1342
|
-
|
|
1343
|
-
|
|
1368
|
+
QrackSimulator._ulonglong_byref(q),
|
|
1369
|
+
QrackSimulator._ulonglong_byref(o),
|
|
1344
1370
|
)
|
|
1345
1371
|
self._throw_if_error()
|
|
1346
1372
|
|
|
@@ -1361,15 +1387,15 @@ class QrackSimulator:
|
|
|
1361
1387
|
"""
|
|
1362
1388
|
if len(q) != len(o):
|
|
1363
1389
|
raise RuntimeError("Lengths of list parameters are mismatched.")
|
|
1364
|
-
aParts, mParts =
|
|
1390
|
+
aParts, mParts = QrackSimulator._split_longs_2(a, m)
|
|
1365
1391
|
Qrack.qrack_lib.MULN(
|
|
1366
1392
|
self.sid,
|
|
1367
1393
|
len(aParts),
|
|
1368
|
-
|
|
1369
|
-
|
|
1394
|
+
QrackSimulator._ulonglong_byref(aParts),
|
|
1395
|
+
QrackSimulator._ulonglong_byref(mParts),
|
|
1370
1396
|
len(q),
|
|
1371
|
-
|
|
1372
|
-
|
|
1397
|
+
QrackSimulator._ulonglong_byref(q),
|
|
1398
|
+
QrackSimulator._ulonglong_byref(o),
|
|
1373
1399
|
)
|
|
1374
1400
|
self._throw_if_error()
|
|
1375
1401
|
|
|
@@ -1391,15 +1417,15 @@ class QrackSimulator:
|
|
|
1391
1417
|
"""
|
|
1392
1418
|
if len(q) != len(o):
|
|
1393
1419
|
raise RuntimeError("Lengths of list parameters are mismatched.")
|
|
1394
|
-
aParts, mParts =
|
|
1420
|
+
aParts, mParts = QrackSimulator._split_longs_2(a, m)
|
|
1395
1421
|
Qrack.qrack_lib.DIVN(
|
|
1396
1422
|
self.sid,
|
|
1397
1423
|
len(aParts),
|
|
1398
|
-
|
|
1399
|
-
|
|
1424
|
+
QrackSimulator._ulonglong_byref(aParts),
|
|
1425
|
+
QrackSimulator._ulonglong_byref(mParts),
|
|
1400
1426
|
len(q),
|
|
1401
|
-
|
|
1402
|
-
|
|
1427
|
+
QrackSimulator._ulonglong_byref(q),
|
|
1428
|
+
QrackSimulator._ulonglong_byref(o),
|
|
1403
1429
|
)
|
|
1404
1430
|
self._throw_if_error()
|
|
1405
1431
|
|
|
@@ -1430,15 +1456,15 @@ class QrackSimulator:
|
|
|
1430
1456
|
|
|
1431
1457
|
if len(q) != len(o):
|
|
1432
1458
|
raise RuntimeError("Lengths of list parameters are mismatched.")
|
|
1433
|
-
aParts, mParts =
|
|
1459
|
+
aParts, mParts = QrackSimulator._split_longs_2(a, m)
|
|
1434
1460
|
Qrack.qrack_lib.POWN(
|
|
1435
1461
|
self.sid,
|
|
1436
1462
|
len(aParts),
|
|
1437
|
-
|
|
1438
|
-
|
|
1463
|
+
QrackSimulator._ulonglong_byref(aParts),
|
|
1464
|
+
QrackSimulator._ulonglong_byref(mParts),
|
|
1439
1465
|
len(q),
|
|
1440
|
-
|
|
1441
|
-
|
|
1466
|
+
QrackSimulator._ulonglong_byref(q),
|
|
1467
|
+
QrackSimulator._ulonglong_byref(o),
|
|
1442
1468
|
)
|
|
1443
1469
|
self._throw_if_error()
|
|
1444
1470
|
|
|
@@ -1456,15 +1482,15 @@ class QrackSimulator:
|
|
|
1456
1482
|
Raises:
|
|
1457
1483
|
RuntimeError: QrackSimulator raised an exception.
|
|
1458
1484
|
"""
|
|
1459
|
-
aParts =
|
|
1485
|
+
aParts = QrackSimulator._split_longs(a)
|
|
1460
1486
|
Qrack.qrack_lib.MCADD(
|
|
1461
1487
|
self.sid,
|
|
1462
1488
|
len(aParts),
|
|
1463
|
-
|
|
1489
|
+
QrackSimulator._ulonglong_byref(aParts),
|
|
1464
1490
|
len(c),
|
|
1465
|
-
|
|
1491
|
+
QrackSimulator._ulonglong_byref(c),
|
|
1466
1492
|
len(q),
|
|
1467
|
-
|
|
1493
|
+
QrackSimulator._ulonglong_byref(q),
|
|
1468
1494
|
)
|
|
1469
1495
|
self._throw_if_error()
|
|
1470
1496
|
|
|
@@ -1482,15 +1508,15 @@ class QrackSimulator:
|
|
|
1482
1508
|
Raises:
|
|
1483
1509
|
RuntimeError: QrackSimulator raised an exception.
|
|
1484
1510
|
"""
|
|
1485
|
-
aParts =
|
|
1511
|
+
aParts = QrackSimulator._split_longs(a)
|
|
1486
1512
|
Qrack.qrack_lib.MCSUB(
|
|
1487
1513
|
self.sid,
|
|
1488
1514
|
len(aParts),
|
|
1489
|
-
|
|
1515
|
+
QrackSimulator._ulonglong_byref(aParts),
|
|
1490
1516
|
len(c),
|
|
1491
|
-
|
|
1517
|
+
QrackSimulator._ulonglong_byref(c),
|
|
1492
1518
|
len(q),
|
|
1493
|
-
|
|
1519
|
+
QrackSimulator._ulonglong_byref(q),
|
|
1494
1520
|
)
|
|
1495
1521
|
self._throw_if_error()
|
|
1496
1522
|
|
|
@@ -1523,15 +1549,15 @@ class QrackSimulator:
|
|
|
1523
1549
|
|
|
1524
1550
|
if len(q) != len(o):
|
|
1525
1551
|
raise RuntimeError("Lengths of list parameters are mismatched.")
|
|
1526
|
-
aParts =
|
|
1552
|
+
aParts = QrackSimulator._split_longs(a)
|
|
1527
1553
|
Qrack.qrack_lib.MCMUL(
|
|
1528
1554
|
self.sid,
|
|
1529
1555
|
len(aParts),
|
|
1530
|
-
|
|
1556
|
+
QrackSimulator._ulonglong_byref(aParts),
|
|
1531
1557
|
len(c),
|
|
1532
|
-
|
|
1558
|
+
QrackSimulator._ulonglong_byref(c),
|
|
1533
1559
|
len(q),
|
|
1534
|
-
|
|
1560
|
+
QrackSimulator._ulonglong_byref(q),
|
|
1535
1561
|
)
|
|
1536
1562
|
self._throw_if_error()
|
|
1537
1563
|
|
|
@@ -1565,15 +1591,15 @@ class QrackSimulator:
|
|
|
1565
1591
|
|
|
1566
1592
|
if len(q) != len(o):
|
|
1567
1593
|
raise RuntimeError("Lengths of list parameters are mismatched.")
|
|
1568
|
-
aParts =
|
|
1594
|
+
aParts = QrackSimulator._split_longs(a)
|
|
1569
1595
|
Qrack.qrack_lib.MCDIV(
|
|
1570
1596
|
self.sid,
|
|
1571
1597
|
len(aParts),
|
|
1572
|
-
|
|
1598
|
+
QrackSimulator._ulonglong_byref(aParts),
|
|
1573
1599
|
len(c),
|
|
1574
|
-
|
|
1600
|
+
QrackSimulator._ulonglong_byref(c),
|
|
1575
1601
|
len(q),
|
|
1576
|
-
|
|
1602
|
+
QrackSimulator._ulonglong_byref(q),
|
|
1577
1603
|
)
|
|
1578
1604
|
self._throw_if_error()
|
|
1579
1605
|
|
|
@@ -1596,17 +1622,17 @@ class QrackSimulator:
|
|
|
1596
1622
|
"""
|
|
1597
1623
|
if len(q) != len(o):
|
|
1598
1624
|
raise RuntimeError("Lengths of list parameters are mismatched.")
|
|
1599
|
-
aParts, mParts =
|
|
1625
|
+
aParts, mParts = QrackSimulator._split_longs_2(a, m)
|
|
1600
1626
|
Qrack.qrack_lib.MCMULN(
|
|
1601
1627
|
self.sid,
|
|
1602
1628
|
len(aParts),
|
|
1603
|
-
|
|
1629
|
+
QrackSimulator._ulonglong_byref(aParts),
|
|
1604
1630
|
len(c),
|
|
1605
|
-
|
|
1606
|
-
|
|
1631
|
+
QrackSimulator._ulonglong_byref(c),
|
|
1632
|
+
QrackSimulator._ulonglong_byref(mParts),
|
|
1607
1633
|
len(q),
|
|
1608
|
-
|
|
1609
|
-
|
|
1634
|
+
QrackSimulator._ulonglong_byref(q),
|
|
1635
|
+
QrackSimulator._ulonglong_byref(o),
|
|
1610
1636
|
)
|
|
1611
1637
|
self._throw_if_error()
|
|
1612
1638
|
|
|
@@ -1630,17 +1656,17 @@ class QrackSimulator:
|
|
|
1630
1656
|
"""
|
|
1631
1657
|
if len(q) != len(o):
|
|
1632
1658
|
raise RuntimeError("Lengths of list parameters are mismatched.")
|
|
1633
|
-
aParts, mParts =
|
|
1659
|
+
aParts, mParts = QrackSimulator._split_longs_2(a, m)
|
|
1634
1660
|
Qrack.qrack_lib.MCDIVN(
|
|
1635
1661
|
self.sid,
|
|
1636
1662
|
len(aParts),
|
|
1637
|
-
|
|
1663
|
+
QrackSimulator._ulonglong_byref(aParts),
|
|
1638
1664
|
len(c),
|
|
1639
|
-
|
|
1640
|
-
|
|
1665
|
+
QrackSimulator._ulonglong_byref(c),
|
|
1666
|
+
QrackSimulator._ulonglong_byref(mParts),
|
|
1641
1667
|
len(q),
|
|
1642
|
-
|
|
1643
|
-
|
|
1668
|
+
QrackSimulator._ulonglong_byref(q),
|
|
1669
|
+
QrackSimulator._ulonglong_byref(o),
|
|
1644
1670
|
)
|
|
1645
1671
|
self._throw_if_error()
|
|
1646
1672
|
|
|
@@ -1673,17 +1699,17 @@ class QrackSimulator:
|
|
|
1673
1699
|
|
|
1674
1700
|
if len(q) != len(o):
|
|
1675
1701
|
raise RuntimeError("Lengths of list parameters are mismatched.")
|
|
1676
|
-
aParts, mParts =
|
|
1702
|
+
aParts, mParts = QrackSimulator._split_longs_2(a, m)
|
|
1677
1703
|
Qrack.qrack_lib.MCPOWN(
|
|
1678
1704
|
self.sid,
|
|
1679
1705
|
len(aParts),
|
|
1680
|
-
|
|
1706
|
+
QrackSimulator._ulonglong_byref(aParts),
|
|
1681
1707
|
len(c),
|
|
1682
|
-
|
|
1683
|
-
|
|
1708
|
+
QrackSimulator._ulonglong_byref(c),
|
|
1709
|
+
QrackSimulator._ulonglong_byref(mParts),
|
|
1684
1710
|
len(q),
|
|
1685
|
-
|
|
1686
|
-
|
|
1711
|
+
QrackSimulator._ulonglong_byref(q),
|
|
1712
|
+
QrackSimulator._ulonglong_byref(o),
|
|
1687
1713
|
)
|
|
1688
1714
|
self._throw_if_error()
|
|
1689
1715
|
|
|
@@ -1715,10 +1741,10 @@ class QrackSimulator:
|
|
|
1715
1741
|
Qrack.qrack_lib.LDA(
|
|
1716
1742
|
self.sid,
|
|
1717
1743
|
len(qi),
|
|
1718
|
-
|
|
1744
|
+
QrackSimulator._ulonglong_byref(qi),
|
|
1719
1745
|
len(qv),
|
|
1720
|
-
|
|
1721
|
-
|
|
1746
|
+
QrackSimulator._ulonglong_byref(qv),
|
|
1747
|
+
QrackSimulator._to_ubyte(len(qv), t),
|
|
1722
1748
|
)
|
|
1723
1749
|
self._throw_if_error()
|
|
1724
1750
|
|
|
@@ -1750,10 +1776,10 @@ class QrackSimulator:
|
|
|
1750
1776
|
self.sid,
|
|
1751
1777
|
s,
|
|
1752
1778
|
len(qi),
|
|
1753
|
-
|
|
1779
|
+
QrackSimulator._ulonglong_byref(qi),
|
|
1754
1780
|
len(qv),
|
|
1755
|
-
|
|
1756
|
-
|
|
1781
|
+
QrackSimulator._ulonglong_byref(qv),
|
|
1782
|
+
QrackSimulator._to_ubyte(len(qv), t),
|
|
1757
1783
|
)
|
|
1758
1784
|
self._throw_if_error()
|
|
1759
1785
|
|
|
@@ -1785,10 +1811,10 @@ class QrackSimulator:
|
|
|
1785
1811
|
self.sid,
|
|
1786
1812
|
s,
|
|
1787
1813
|
len(qi),
|
|
1788
|
-
|
|
1814
|
+
QrackSimulator._ulonglong_byref(qi),
|
|
1789
1815
|
len(qv),
|
|
1790
|
-
|
|
1791
|
-
|
|
1816
|
+
QrackSimulator._ulonglong_byref(qv),
|
|
1817
|
+
QrackSimulator._to_ubyte(len(qv), t),
|
|
1792
1818
|
)
|
|
1793
1819
|
self._throw_if_error()
|
|
1794
1820
|
|
|
@@ -1818,7 +1844,10 @@ class QrackSimulator:
|
|
|
1818
1844
|
)
|
|
1819
1845
|
|
|
1820
1846
|
Qrack.qrack_lib.Hash(
|
|
1821
|
-
self.sid,
|
|
1847
|
+
self.sid,
|
|
1848
|
+
len(q),
|
|
1849
|
+
QrackSimulator._ulonglong_byref(q),
|
|
1850
|
+
QrackSimulator._to_ubyte(len(q), t),
|
|
1822
1851
|
)
|
|
1823
1852
|
self._throw_if_error()
|
|
1824
1853
|
|
|
@@ -2039,7 +2068,7 @@ class QrackSimulator:
|
|
|
2039
2068
|
Raises:
|
|
2040
2069
|
RuntimeError: QrackSimulator raised an exception.
|
|
2041
2070
|
"""
|
|
2042
|
-
Qrack.qrack_lib.QFT(self.sid, len(qs),
|
|
2071
|
+
Qrack.qrack_lib.QFT(self.sid, len(qs), QrackSimulator._ulonglong_byref(qs))
|
|
2043
2072
|
self._throw_if_error()
|
|
2044
2073
|
|
|
2045
2074
|
def iqft(self, qs):
|
|
@@ -2054,7 +2083,7 @@ class QrackSimulator:
|
|
|
2054
2083
|
Raises:
|
|
2055
2084
|
RuntimeError: QrackSimulator raised an exception.
|
|
2056
2085
|
"""
|
|
2057
|
-
Qrack.qrack_lib.IQFT(self.sid, len(qs),
|
|
2086
|
+
Qrack.qrack_lib.IQFT(self.sid, len(qs), QrackSimulator._ulonglong_byref(qs))
|
|
2058
2087
|
self._throw_if_error()
|
|
2059
2088
|
|
|
2060
2089
|
# pseudo-quantum
|
|
@@ -2128,7 +2157,7 @@ class QrackSimulator:
|
|
|
2128
2157
|
"QrackSimulator with isTensorNetwork=True option cannot compose()! (Turn off just this option, in the constructor.)"
|
|
2129
2158
|
)
|
|
2130
2159
|
|
|
2131
|
-
Qrack.qrack_lib.Compose(self.sid, other.sid,
|
|
2160
|
+
Qrack.qrack_lib.Compose(self.sid, other.sid, QrackSimulator._ulonglong_byref(q))
|
|
2132
2161
|
self._throw_if_error()
|
|
2133
2162
|
|
|
2134
2163
|
def decompose(self, q):
|
|
@@ -2154,7 +2183,7 @@ 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
|
|
|
@@ -2177,7 +2206,7 @@ class QrackSimulator:
|
|
|
2177
2206
|
)
|
|
2178
2207
|
|
|
2179
2208
|
l = len(q)
|
|
2180
|
-
Qrack.qrack_lib.Dispose(self.sid, l,
|
|
2209
|
+
Qrack.qrack_lib.Dispose(self.sid, l, QrackSimulator._ulonglong_byref(q))
|
|
2181
2210
|
self._throw_if_error()
|
|
2182
2211
|
|
|
2183
2212
|
## miscellaneous
|
|
@@ -2247,7 +2276,7 @@ class QrackSimulator:
|
|
|
2247
2276
|
Raises:
|
|
2248
2277
|
RuntimeError: QrackSimulator raised an exception.
|
|
2249
2278
|
"""
|
|
2250
|
-
Qrack.qrack_lib.InKet(self.sid,
|
|
2279
|
+
Qrack.qrack_lib.InKet(self.sid, QrackSimulator._qrack_complex_byref(ket))
|
|
2251
2280
|
self._throw_if_error()
|
|
2252
2281
|
|
|
2253
2282
|
def out_ket(self):
|
|
@@ -2264,10 +2293,10 @@ class QrackSimulator:
|
|
|
2264
2293
|
list representing the state vector.
|
|
2265
2294
|
"""
|
|
2266
2295
|
amp_count = 1 << self.num_qubits()
|
|
2267
|
-
ket =
|
|
2296
|
+
ket = QrackSimulator._qrack_complex_byref([complex(0, 0)] * amp_count)
|
|
2268
2297
|
Qrack.qrack_lib.OutKet(self.sid, ket)
|
|
2269
2298
|
self._throw_if_error()
|
|
2270
|
-
return [complex(r, i) for r, i in
|
|
2299
|
+
return [complex(r, i) for r, i in QrackSimulator._pairwise(ket)]
|
|
2271
2300
|
|
|
2272
2301
|
def out_probs(self):
|
|
2273
2302
|
"""Get basis dimension probabilities
|
|
@@ -2282,7 +2311,7 @@ class QrackSimulator:
|
|
|
2282
2311
|
list representing the basis dimension probabilities.
|
|
2283
2312
|
"""
|
|
2284
2313
|
prob_count = 1 << self.num_qubits()
|
|
2285
|
-
probs =
|
|
2314
|
+
probs = QrackSimulator._real1_byref([0.0] * prob_count)
|
|
2286
2315
|
Qrack.qrack_lib.OutProbs(self.sid, probs)
|
|
2287
2316
|
self._throw_if_error()
|
|
2288
2317
|
return list(probs)
|
|
@@ -2302,10 +2331,12 @@ class QrackSimulator:
|
|
|
2302
2331
|
"""
|
|
2303
2332
|
amp_count = 1 << len(q)
|
|
2304
2333
|
sqr_amp_count = amp_count * amp_count
|
|
2305
|
-
flat_rdm =
|
|
2306
|
-
Qrack.qrack_lib.OutReducedDensityMatrix(
|
|
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
|
+
)
|
|
2307
2338
|
self._throw_if_error()
|
|
2308
|
-
return [complex(r, i) for r, i in
|
|
2339
|
+
return [complex(r, i) for r, i in QrackSimulator._pairwise(flat_rdm)]
|
|
2309
2340
|
|
|
2310
2341
|
def highest_prob_perm(self):
|
|
2311
2342
|
"""Get the permutation (bit string) with the highest probability
|
|
@@ -2367,8 +2398,8 @@ class QrackSimulator:
|
|
|
2367
2398
|
Returns:
|
|
2368
2399
|
list representing the state vector.
|
|
2369
2400
|
"""
|
|
2370
|
-
probs =
|
|
2371
|
-
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)
|
|
2372
2403
|
self._throw_if_error()
|
|
2373
2404
|
return list(probs)
|
|
2374
2405
|
|
|
@@ -2430,7 +2461,7 @@ class QrackSimulator:
|
|
|
2430
2461
|
if len(q) != len(c):
|
|
2431
2462
|
raise RuntimeError("prob_perm argument lengths do not match.")
|
|
2432
2463
|
result = Qrack.qrack_lib.PermutationProb(
|
|
2433
|
-
self.sid, len(q),
|
|
2464
|
+
self.sid, len(q), QrackSimulator._ulonglong_byref(q), QrackSimulator._bool_byref(c)
|
|
2434
2465
|
)
|
|
2435
2466
|
self._throw_if_error()
|
|
2436
2467
|
return result
|
|
@@ -2458,7 +2489,7 @@ class QrackSimulator:
|
|
|
2458
2489
|
if len(q) != len(c):
|
|
2459
2490
|
raise RuntimeError("prob_perm argument lengths do not match.")
|
|
2460
2491
|
result = Qrack.qrack_lib.PermutationProbRdm(
|
|
2461
|
-
self.sid, len(q),
|
|
2492
|
+
self.sid, len(q), QrackSimulator._ulonglong_byref(q), QrackSimulator._bool_byref(c), r
|
|
2462
2493
|
)
|
|
2463
2494
|
self._throw_if_error()
|
|
2464
2495
|
return result
|
|
@@ -2479,7 +2510,7 @@ class QrackSimulator:
|
|
|
2479
2510
|
Expectation value
|
|
2480
2511
|
"""
|
|
2481
2512
|
result = Qrack.qrack_lib.PermutationExpectation(
|
|
2482
|
-
self.sid, len(q),
|
|
2513
|
+
self.sid, len(q), QrackSimulator._ulonglong_byref(q)
|
|
2483
2514
|
)
|
|
2484
2515
|
self._throw_if_error()
|
|
2485
2516
|
return result
|
|
@@ -2502,7 +2533,7 @@ class QrackSimulator:
|
|
|
2502
2533
|
Expectation value
|
|
2503
2534
|
"""
|
|
2504
2535
|
result = Qrack.qrack_lib.PermutationExpectationRdm(
|
|
2505
|
-
self.sid, len(q),
|
|
2536
|
+
self.sid, len(q), QrackSimulator._ulonglong_byref(q), r
|
|
2506
2537
|
)
|
|
2507
2538
|
self._throw_if_error()
|
|
2508
2539
|
return result
|
|
@@ -2528,7 +2559,11 @@ class QrackSimulator:
|
|
|
2528
2559
|
raise RuntimeError("factorized_expectation argument lengths do not match.")
|
|
2529
2560
|
m = max([(x.bit_length() + 63) // 64 for x in c])
|
|
2530
2561
|
result = Qrack.qrack_lib.FactorizedExpectation(
|
|
2531
|
-
self.sid,
|
|
2562
|
+
self.sid,
|
|
2563
|
+
len(q),
|
|
2564
|
+
QrackSimulator._ulonglong_byref(q),
|
|
2565
|
+
m,
|
|
2566
|
+
QrackSimulator._to_ulonglong(m, c),
|
|
2532
2567
|
)
|
|
2533
2568
|
self._throw_if_error()
|
|
2534
2569
|
return result
|
|
@@ -2553,12 +2588,15 @@ class QrackSimulator:
|
|
|
2553
2588
|
Expectation value
|
|
2554
2589
|
"""
|
|
2555
2590
|
if (len(q) << 1) != len(c):
|
|
2556
|
-
raise RuntimeError(
|
|
2557
|
-
"factorized_expectation_rdm argument lengths do not match."
|
|
2558
|
-
)
|
|
2591
|
+
raise RuntimeError("factorized_expectation_rdm argument lengths do not match.")
|
|
2559
2592
|
m = max([(x.bit_length() + 63) // 64 for x in c])
|
|
2560
2593
|
result = Qrack.qrack_lib.FactorizedExpectationRdm(
|
|
2561
|
-
self.sid,
|
|
2594
|
+
self.sid,
|
|
2595
|
+
len(q),
|
|
2596
|
+
QrackSimulator._ulonglong_byref(q),
|
|
2597
|
+
m,
|
|
2598
|
+
QrackSimulator._to_ulonglong(m, c),
|
|
2599
|
+
r,
|
|
2562
2600
|
)
|
|
2563
2601
|
self._throw_if_error()
|
|
2564
2602
|
return result
|
|
@@ -2581,11 +2619,9 @@ class QrackSimulator:
|
|
|
2581
2619
|
Expectation value
|
|
2582
2620
|
"""
|
|
2583
2621
|
if (len(q) << 1) != len(c):
|
|
2584
|
-
raise RuntimeError(
|
|
2585
|
-
"factorized_expectation_rdm argument lengths do not match."
|
|
2586
|
-
)
|
|
2622
|
+
raise RuntimeError("factorized_expectation_rdm argument lengths do not match.")
|
|
2587
2623
|
result = Qrack.qrack_lib.FactorizedExpectationFp(
|
|
2588
|
-
self.sid, len(q),
|
|
2624
|
+
self.sid, len(q), QrackSimulator._ulonglong_byref(q), QrackSimulator._real1_byref(c)
|
|
2589
2625
|
)
|
|
2590
2626
|
self._throw_if_error()
|
|
2591
2627
|
return result
|
|
@@ -2610,11 +2646,9 @@ class QrackSimulator:
|
|
|
2610
2646
|
Expectation value
|
|
2611
2647
|
"""
|
|
2612
2648
|
if (len(q) << 1) != len(c):
|
|
2613
|
-
raise RuntimeError(
|
|
2614
|
-
"factorized_expectation_fp_rdm argument lengths do not match."
|
|
2615
|
-
)
|
|
2649
|
+
raise RuntimeError("factorized_expectation_fp_rdm argument lengths do not match.")
|
|
2616
2650
|
result = Qrack.qrack_lib.FactorizedExpectationFpRdm(
|
|
2617
|
-
self.sid, len(q),
|
|
2651
|
+
self.sid, len(q), QrackSimulator._ulonglong_byref(q), QrackSimulator._real1_byref(c), r
|
|
2618
2652
|
)
|
|
2619
2653
|
self._throw_if_error()
|
|
2620
2654
|
return result
|
|
@@ -2638,7 +2672,7 @@ class QrackSimulator:
|
|
|
2638
2672
|
if (3 * len(q)) != len(b):
|
|
2639
2673
|
raise RuntimeError("unitary_expectation argument lengths do not match.")
|
|
2640
2674
|
result = Qrack.qrack_lib.UnitaryExpectation(
|
|
2641
|
-
self.sid, len(q),
|
|
2675
|
+
self.sid, len(q), QrackSimulator._ulonglong_byref(q), QrackSimulator._real1_byref(b)
|
|
2642
2676
|
)
|
|
2643
2677
|
self._throw_if_error()
|
|
2644
2678
|
return result
|
|
@@ -2662,7 +2696,7 @@ class QrackSimulator:
|
|
|
2662
2696
|
if (len(q) << 2) != len(b):
|
|
2663
2697
|
raise RuntimeError("matrix_expectation argument lengths do not match.")
|
|
2664
2698
|
result = Qrack.qrack_lib.MatrixExpectation(
|
|
2665
|
-
self.sid, len(q),
|
|
2699
|
+
self.sid, len(q), QrackSimulator._ulonglong_byref(q), QrackSimulator._complex_byref(b)
|
|
2666
2700
|
)
|
|
2667
2701
|
self._throw_if_error()
|
|
2668
2702
|
return result
|
|
@@ -2694,9 +2728,9 @@ class QrackSimulator:
|
|
|
2694
2728
|
result = Qrack.qrack_lib.UnitaryExpectationEigenVal(
|
|
2695
2729
|
self.sid,
|
|
2696
2730
|
len(q),
|
|
2697
|
-
|
|
2698
|
-
|
|
2699
|
-
|
|
2731
|
+
QrackSimulator._ulonglong_byref(q),
|
|
2732
|
+
QrackSimulator._real1_byref(b),
|
|
2733
|
+
QrackSimulator._real1_byref(e),
|
|
2700
2734
|
)
|
|
2701
2735
|
self._throw_if_error()
|
|
2702
2736
|
return result
|
|
@@ -2728,9 +2762,9 @@ class QrackSimulator:
|
|
|
2728
2762
|
result = Qrack.qrack_lib.MatrixExpectationEigenVal(
|
|
2729
2763
|
self.sid,
|
|
2730
2764
|
len(q),
|
|
2731
|
-
|
|
2732
|
-
|
|
2733
|
-
|
|
2765
|
+
QrackSimulator._ulonglong_byref(q),
|
|
2766
|
+
QrackSimulator._complex_byref(b),
|
|
2767
|
+
QrackSimulator._real1_byref(e),
|
|
2734
2768
|
)
|
|
2735
2769
|
self._throw_if_error()
|
|
2736
2770
|
return result
|
|
@@ -2755,7 +2789,7 @@ class QrackSimulator:
|
|
|
2755
2789
|
if len(q) != len(b):
|
|
2756
2790
|
raise RuntimeError("pauli_expectation argument lengths do not match.")
|
|
2757
2791
|
result = Qrack.qrack_lib.PauliExpectation(
|
|
2758
|
-
self.sid, len(q),
|
|
2792
|
+
self.sid, len(q), QrackSimulator._ulonglong_byref(q), QrackSimulator._ulonglong_byref(b)
|
|
2759
2793
|
)
|
|
2760
2794
|
self._throw_if_error()
|
|
2761
2795
|
return result
|
|
@@ -2775,7 +2809,7 @@ class QrackSimulator:
|
|
|
2775
2809
|
Returns:
|
|
2776
2810
|
float variance
|
|
2777
2811
|
"""
|
|
2778
|
-
result = Qrack.qrack_lib.Variance(self.sid, len(q),
|
|
2812
|
+
result = Qrack.qrack_lib.Variance(self.sid, len(q), QrackSimulator._ulonglong_byref(q))
|
|
2779
2813
|
self._throw_if_error()
|
|
2780
2814
|
return result
|
|
2781
2815
|
|
|
@@ -2797,7 +2831,7 @@ class QrackSimulator:
|
|
|
2797
2831
|
variance
|
|
2798
2832
|
"""
|
|
2799
2833
|
result = Qrack.qrack_lib.VarianceRdm(
|
|
2800
|
-
self.sid, len(q),
|
|
2834
|
+
self.sid, len(q), QrackSimulator._ulonglong_byref(q), r
|
|
2801
2835
|
)
|
|
2802
2836
|
self._throw_if_error()
|
|
2803
2837
|
return result
|
|
@@ -2823,7 +2857,11 @@ class QrackSimulator:
|
|
|
2823
2857
|
raise RuntimeError("factorized_variance argument lengths do not match.")
|
|
2824
2858
|
m = max([(x.bit_length() + 63) // 64 for x in c])
|
|
2825
2859
|
result = Qrack.qrack_lib.FactorizedVariance(
|
|
2826
|
-
self.sid,
|
|
2860
|
+
self.sid,
|
|
2861
|
+
len(q),
|
|
2862
|
+
QrackSimulator._ulonglong_byref(q),
|
|
2863
|
+
m,
|
|
2864
|
+
QrackSimulator._to_ulonglong(m, c),
|
|
2827
2865
|
)
|
|
2828
2866
|
self._throw_if_error()
|
|
2829
2867
|
return result
|
|
@@ -2851,7 +2889,12 @@ class QrackSimulator:
|
|
|
2851
2889
|
raise RuntimeError("factorized_variance_rdm argument lengths do not match.")
|
|
2852
2890
|
m = max([(x.bit_length() + 63) // 64 for x in c])
|
|
2853
2891
|
result = Qrack.qrack_lib.FactorizedVarianceRdm(
|
|
2854
|
-
self.sid,
|
|
2892
|
+
self.sid,
|
|
2893
|
+
len(q),
|
|
2894
|
+
QrackSimulator._ulonglong_byref(q),
|
|
2895
|
+
m,
|
|
2896
|
+
QrackSimulator._to_ulonglong(m, c),
|
|
2897
|
+
r,
|
|
2855
2898
|
)
|
|
2856
2899
|
self._throw_if_error()
|
|
2857
2900
|
return result
|
|
@@ -2876,7 +2919,7 @@ class QrackSimulator:
|
|
|
2876
2919
|
if (len(q) << 1) != len(c):
|
|
2877
2920
|
raise RuntimeError("factorized_variance_rdm argument lengths do not match.")
|
|
2878
2921
|
result = Qrack.qrack_lib.FactorizedVarianceFp(
|
|
2879
|
-
self.sid, len(q),
|
|
2922
|
+
self.sid, len(q), QrackSimulator._ulonglong_byref(q), QrackSimulator._real1_byref(c)
|
|
2880
2923
|
)
|
|
2881
2924
|
self._throw_if_error()
|
|
2882
2925
|
return result
|
|
@@ -2901,11 +2944,9 @@ class QrackSimulator:
|
|
|
2901
2944
|
variance
|
|
2902
2945
|
"""
|
|
2903
2946
|
if (len(q) << 1) != len(c):
|
|
2904
|
-
raise RuntimeError(
|
|
2905
|
-
"factorized_variance_fp_rdm argument lengths do not match."
|
|
2906
|
-
)
|
|
2947
|
+
raise RuntimeError("factorized_variance_fp_rdm argument lengths do not match.")
|
|
2907
2948
|
result = Qrack.qrack_lib.FactorizedVarianceFpRdm(
|
|
2908
|
-
self.sid, len(q),
|
|
2949
|
+
self.sid, len(q), QrackSimulator._ulonglong_byref(q), QrackSimulator._real1_byref(c), r
|
|
2909
2950
|
)
|
|
2910
2951
|
self._throw_if_error()
|
|
2911
2952
|
return result
|
|
@@ -2929,7 +2970,7 @@ class QrackSimulator:
|
|
|
2929
2970
|
if (3 * len(q)) != len(b):
|
|
2930
2971
|
raise RuntimeError("unitary_variance argument lengths do not match.")
|
|
2931
2972
|
result = Qrack.qrack_lib.UnitaryVariance(
|
|
2932
|
-
self.sid, len(q),
|
|
2973
|
+
self.sid, len(q), QrackSimulator._ulonglong_byref(q), QrackSimulator._real1_byref(b)
|
|
2933
2974
|
)
|
|
2934
2975
|
self._throw_if_error()
|
|
2935
2976
|
return result
|
|
@@ -2953,7 +2994,7 @@ class QrackSimulator:
|
|
|
2953
2994
|
if (len(q) << 2) != len(b):
|
|
2954
2995
|
raise RuntimeError("matrix_variance argument lengths do not match.")
|
|
2955
2996
|
result = Qrack.qrack_lib.MatrixVariance(
|
|
2956
|
-
self.sid, len(q),
|
|
2997
|
+
self.sid, len(q), QrackSimulator._ulonglong_byref(q), QrackSimulator._complex_byref(b)
|
|
2957
2998
|
)
|
|
2958
2999
|
self._throw_if_error()
|
|
2959
3000
|
return result
|
|
@@ -2985,9 +3026,9 @@ class QrackSimulator:
|
|
|
2985
3026
|
result = Qrack.qrack_lib.UnitaryVarianceEigenVal(
|
|
2986
3027
|
self.sid,
|
|
2987
3028
|
len(q),
|
|
2988
|
-
|
|
2989
|
-
|
|
2990
|
-
|
|
3029
|
+
QrackSimulator._ulonglong_byref(q),
|
|
3030
|
+
QrackSimulator._real1_byref(b),
|
|
3031
|
+
QrackSimulator._real1_byref(e),
|
|
2991
3032
|
)
|
|
2992
3033
|
self._throw_if_error()
|
|
2993
3034
|
return result
|
|
@@ -3019,9 +3060,9 @@ class QrackSimulator:
|
|
|
3019
3060
|
result = Qrack.qrack_lib.MatrixVarianceEigenVal(
|
|
3020
3061
|
self.sid,
|
|
3021
3062
|
len(q),
|
|
3022
|
-
|
|
3023
|
-
|
|
3024
|
-
|
|
3063
|
+
QrackSimulator._ulonglong_byref(q),
|
|
3064
|
+
QrackSimulator._complex_byref(b),
|
|
3065
|
+
QrackSimulator._real1_byref(e),
|
|
3025
3066
|
)
|
|
3026
3067
|
self._throw_if_error()
|
|
3027
3068
|
return result
|
|
@@ -3046,7 +3087,7 @@ class QrackSimulator:
|
|
|
3046
3087
|
if len(q) != len(b):
|
|
3047
3088
|
raise RuntimeError("pauli_variance argument lengths do not match.")
|
|
3048
3089
|
result = Qrack.qrack_lib.PauliVariance(
|
|
3049
|
-
self.sid, len(q),
|
|
3090
|
+
self.sid, len(q), QrackSimulator._ulonglong_byref(q), QrackSimulator._ulonglong_byref(b)
|
|
3050
3091
|
)
|
|
3051
3092
|
self._throw_if_error()
|
|
3052
3093
|
return result
|
|
@@ -3070,7 +3111,7 @@ class QrackSimulator:
|
|
|
3070
3111
|
if len(b) != len(q):
|
|
3071
3112
|
raise RuntimeError("Lengths of list parameters are mismatched.")
|
|
3072
3113
|
result = Qrack.qrack_lib.JointEnsembleProbability(
|
|
3073
|
-
self.sid, len(b),
|
|
3114
|
+
self.sid, len(b), QrackSimulator._ulonglong_byref(b), q
|
|
3074
3115
|
)
|
|
3075
3116
|
self._throw_if_error()
|
|
3076
3117
|
return result
|
|
@@ -3099,7 +3140,7 @@ class QrackSimulator:
|
|
|
3099
3140
|
)
|
|
3100
3141
|
|
|
3101
3142
|
Qrack.qrack_lib.PhaseParity(
|
|
3102
|
-
self.sid, ctypes.c_double(la), len(q),
|
|
3143
|
+
self.sid, ctypes.c_double(la), len(q), QrackSimulator._ulonglong_byref(q)
|
|
3103
3144
|
)
|
|
3104
3145
|
self._throw_if_error()
|
|
3105
3146
|
|
|
@@ -3125,7 +3166,7 @@ class QrackSimulator:
|
|
|
3125
3166
|
"QrackStabilizer cannot phase_root_n()! (Create a QrackSimulator instead, also with isTensorNetwork=False.)"
|
|
3126
3167
|
)
|
|
3127
3168
|
|
|
3128
|
-
Qrack.qrack_lib.PhaseRootN(self.sid, n, len(q),
|
|
3169
|
+
Qrack.qrack_lib.PhaseRootN(self.sid, n, len(q), QrackSimulator._ulonglong_byref(q))
|
|
3129
3170
|
self._throw_if_error()
|
|
3130
3171
|
|
|
3131
3172
|
def try_separate_1qb(self, qi1):
|
|
@@ -3182,7 +3223,7 @@ class QrackSimulator:
|
|
|
3182
3223
|
State of all the qubits.
|
|
3183
3224
|
"""
|
|
3184
3225
|
result = Qrack.qrack_lib.TrySeparateTol(
|
|
3185
|
-
self.sid, len(qs),
|
|
3226
|
+
self.sid, len(qs), QrackSimulator._ulonglong_byref(qs), t
|
|
3186
3227
|
)
|
|
3187
3228
|
self._throw_if_error()
|
|
3188
3229
|
return result
|
|
@@ -3198,7 +3239,7 @@ class QrackSimulator:
|
|
|
3198
3239
|
Raises:
|
|
3199
3240
|
Runtimeerror: QrackSimulator raised an exception.
|
|
3200
3241
|
"""
|
|
3201
|
-
result = Qrack.qrack_lib.Separate(self.sid, len(qs),
|
|
3242
|
+
result = Qrack.qrack_lib.Separate(self.sid, len(qs), QrackSimulator._ulonglong_byref(qs))
|
|
3202
3243
|
self._throw_if_error()
|
|
3203
3244
|
|
|
3204
3245
|
def get_unitary_fidelity(self):
|
|
@@ -3538,9 +3579,7 @@ class QrackSimulator:
|
|
|
3538
3579
|
"swap",
|
|
3539
3580
|
]
|
|
3540
3581
|
try:
|
|
3541
|
-
circ = transpile(
|
|
3542
|
-
clifford_circ, basis_gates=basis_gates, optimization_level=2
|
|
3543
|
-
)
|
|
3582
|
+
circ = transpile(clifford_circ, basis_gates=basis_gates, optimization_level=2)
|
|
3544
3583
|
except:
|
|
3545
3584
|
circ = clifford_circ
|
|
3546
3585
|
|
|
@@ -3636,9 +3675,7 @@ class QrackSimulator:
|
|
|
3636
3675
|
)
|
|
3637
3676
|
elif op.name == "h":
|
|
3638
3677
|
non_clifford = np.matmul(
|
|
3639
|
-
np.array(
|
|
3640
|
-
[[sqrt1_2, sqrt1_2], [sqrt1_2, -sqrt1_2]], np.complex128
|
|
3641
|
-
),
|
|
3678
|
+
np.array([[sqrt1_2, sqrt1_2], [sqrt1_2, -sqrt1_2]], np.complex128),
|
|
3642
3679
|
non_clifford,
|
|
3643
3680
|
)
|
|
3644
3681
|
elif op.name == "x":
|
|
@@ -3746,9 +3783,7 @@ class QrackSimulator:
|
|
|
3746
3783
|
j += 1
|
|
3747
3784
|
continue
|
|
3748
3785
|
|
|
3749
|
-
if (q1 == i) and (
|
|
3750
|
-
(op.name == "cx") or (op.name == "cy") or (op.name == "cz")
|
|
3751
|
-
):
|
|
3786
|
+
if (q1 == i) and ((op.name == "cx") or (op.name == "cy") or (op.name == "cz")):
|
|
3752
3787
|
if np.isclose(np.abs(non_clifford[0][1]), 0) and np.isclose(
|
|
3753
3788
|
np.abs(non_clifford[1][0]), 0
|
|
3754
3789
|
):
|
|
@@ -3814,9 +3849,7 @@ class QrackSimulator:
|
|
|
3814
3849
|
elif op.name == "h":
|
|
3815
3850
|
non_clifford = np.matmul(
|
|
3816
3851
|
non_clifford,
|
|
3817
|
-
np.array(
|
|
3818
|
-
[[sqrt1_2, sqrt1_2], [sqrt1_2, -sqrt1_2]], np.complex128
|
|
3819
|
-
),
|
|
3852
|
+
np.array([[sqrt1_2, sqrt1_2], [sqrt1_2, -sqrt1_2]], np.complex128),
|
|
3820
3853
|
)
|
|
3821
3854
|
elif op.name == "x":
|
|
3822
3855
|
non_clifford = np.matmul(
|
|
@@ -4006,12 +4039,8 @@ class QrackSimulator:
|
|
|
4006
4039
|
qasm = qasm3.dumps(circ)
|
|
4007
4040
|
except:
|
|
4008
4041
|
qasm = circ.qasm()
|
|
4009
|
-
qasm = qasm.replace(
|
|
4010
|
-
|
|
4011
|
-
)
|
|
4012
|
-
highest_index = max(
|
|
4013
|
-
[int(x) for x in re.findall(r"\[(.*?)\]", qasm) if x.isdigit()]
|
|
4014
|
-
)
|
|
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()])
|
|
4015
4044
|
if highest_index != width:
|
|
4016
4045
|
qasm = qasm.replace(
|
|
4017
4046
|
"qreg q[" + str(width) + "];", "qreg q[" + str(highest_index) + "];"
|
|
@@ -4126,17 +4155,11 @@ class QrackSimulator:
|
|
|
4126
4155
|
(-1 * float(operation.params[1])) + math.pi / 2,
|
|
4127
4156
|
)
|
|
4128
4157
|
elif name == "rx":
|
|
4129
|
-
self._sim.r(
|
|
4130
|
-
Pauli.PauliX, float(operation.params[0]), operation.qubits[0]._index
|
|
4131
|
-
)
|
|
4158
|
+
self._sim.r(Pauli.PauliX, float(operation.params[0]), operation.qubits[0]._index)
|
|
4132
4159
|
elif name == "ry":
|
|
4133
|
-
self._sim.r(
|
|
4134
|
-
Pauli.PauliY, float(operation.params[0]), operation.qubits[0]._index
|
|
4135
|
-
)
|
|
4160
|
+
self._sim.r(Pauli.PauliY, float(operation.params[0]), operation.qubits[0]._index)
|
|
4136
4161
|
elif name == "rz":
|
|
4137
|
-
self._sim.r(
|
|
4138
|
-
Pauli.PauliZ, float(operation.params[0]), operation.qubits[0]._index
|
|
4139
|
-
)
|
|
4162
|
+
self._sim.r(Pauli.PauliZ, float(operation.params[0]), operation.qubits[0]._index)
|
|
4140
4163
|
elif name == "h":
|
|
4141
4164
|
self._sim.h(operation.qubits[0]._index)
|
|
4142
4165
|
elif name == "x":
|
|
@@ -4188,21 +4211,13 @@ class QrackSimulator:
|
|
|
4188
4211
|
float(operation.params[2]),
|
|
4189
4212
|
)
|
|
4190
4213
|
elif name == "cx":
|
|
4191
|
-
self._sim.mcx(
|
|
4192
|
-
[q._index for q in operation.qubits[0:1]], operation.qubits[1]._index
|
|
4193
|
-
)
|
|
4214
|
+
self._sim.mcx([q._index for q in operation.qubits[0:1]], operation.qubits[1]._index)
|
|
4194
4215
|
elif name == "cy":
|
|
4195
|
-
self._sim.mcy(
|
|
4196
|
-
[q._index for q in operation.qubits[0:1]], operation.qubits[1]._index
|
|
4197
|
-
)
|
|
4216
|
+
self._sim.mcy([q._index for q in operation.qubits[0:1]], operation.qubits[1]._index)
|
|
4198
4217
|
elif name == "cz":
|
|
4199
|
-
self._sim.mcz(
|
|
4200
|
-
[q._index for q in operation.qubits[0:1]], operation.qubits[1]._index
|
|
4201
|
-
)
|
|
4218
|
+
self._sim.mcz([q._index for q in operation.qubits[0:1]], operation.qubits[1]._index)
|
|
4202
4219
|
elif name == "ch":
|
|
4203
|
-
self._sim.mch(
|
|
4204
|
-
[q._index for q in operation.qubits[0:1]], operation.qubits[1]._index
|
|
4205
|
-
)
|
|
4220
|
+
self._sim.mch([q._index for q in operation.qubits[0:1]], operation.qubits[1]._index)
|
|
4206
4221
|
elif name == "cp":
|
|
4207
4222
|
self._sim.mcmtrx(
|
|
4208
4223
|
[q._index for q in operation.qubits[0:1]],
|
|
@@ -4228,34 +4243,20 @@ class QrackSimulator:
|
|
|
4228
4243
|
operation.qubits[1]._index,
|
|
4229
4244
|
)
|
|
4230
4245
|
elif name == "dcx":
|
|
4231
|
-
self._sim.mcx(
|
|
4232
|
-
[q._index for q in operation.qubits[0:1]], operation.qubits[1]._index
|
|
4233
|
-
)
|
|
4246
|
+
self._sim.mcx([q._index for q in operation.qubits[0:1]], operation.qubits[1]._index)
|
|
4234
4247
|
self._sim.mcx(operation.qubits[1:2]._index, operation.qubits[0]._index)
|
|
4235
4248
|
elif name == "ccx":
|
|
4236
|
-
self._sim.mcx(
|
|
4237
|
-
[q._index for q in operation.qubits[0:2]], operation.qubits[2]._index
|
|
4238
|
-
)
|
|
4249
|
+
self._sim.mcx([q._index for q in operation.qubits[0:2]], operation.qubits[2]._index)
|
|
4239
4250
|
elif name == "ccy":
|
|
4240
|
-
self._sim.mcy(
|
|
4241
|
-
[q._index for q in operation.qubits[0:2]], operation.qubits[2]._index
|
|
4242
|
-
)
|
|
4251
|
+
self._sim.mcy([q._index for q in operation.qubits[0:2]], operation.qubits[2]._index)
|
|
4243
4252
|
elif name == "ccz":
|
|
4244
|
-
self._sim.mcz(
|
|
4245
|
-
[q._index for q in operation.qubits[0:2]], operation.qubits[2]._index
|
|
4246
|
-
)
|
|
4253
|
+
self._sim.mcz([q._index for q in operation.qubits[0:2]], operation.qubits[2]._index)
|
|
4247
4254
|
elif name == "mcx":
|
|
4248
|
-
self._sim.mcx(
|
|
4249
|
-
[q._index for q in operation.qubits[0:-1]], operation.qubits[-1]._index
|
|
4250
|
-
)
|
|
4255
|
+
self._sim.mcx([q._index for q in operation.qubits[0:-1]], operation.qubits[-1]._index)
|
|
4251
4256
|
elif name == "mcy":
|
|
4252
|
-
self._sim.mcy(
|
|
4253
|
-
[q._index for q in operation.qubits[0:-1]], operation.qubits[-1]._index
|
|
4254
|
-
)
|
|
4257
|
+
self._sim.mcy([q._index for q in operation.qubits[0:-1]], operation.qubits[-1]._index)
|
|
4255
4258
|
elif name == "mcz":
|
|
4256
|
-
self._sim.mcz(
|
|
4257
|
-
[q._index for q in operation.qubits[0:-1]], operation.qubits[-1]._index
|
|
4258
|
-
)
|
|
4259
|
+
self._sim.mcz([q._index for q in operation.qubits[0:-1]], operation.qubits[-1]._index)
|
|
4259
4260
|
elif name == "swap":
|
|
4260
4261
|
self._sim.swap(operation.qubits[0]._index, operation.qubits[1]._index)
|
|
4261
4262
|
elif name == "iswap":
|
|
@@ -4307,9 +4308,9 @@ class QrackSimulator:
|
|
|
4307
4308
|
cregbit = clbit
|
|
4308
4309
|
|
|
4309
4310
|
regbit = 1 << cregbit
|
|
4310
|
-
self._classical_register = (
|
|
4311
|
-
|
|
4312
|
-
)
|
|
4311
|
+
self._classical_register = (self._classical_register & (~regbit)) | (
|
|
4312
|
+
qubit_outcome << cregbit
|
|
4313
|
+
)
|
|
4313
4314
|
|
|
4314
4315
|
elif name == "bfunc":
|
|
4315
4316
|
mask = int(operation.mask, 16)
|
|
@@ -4424,9 +4425,7 @@ class QrackSimulator:
|
|
|
4424
4425
|
if operation.name == "id" or operation.name == "barrier":
|
|
4425
4426
|
continue
|
|
4426
4427
|
|
|
4427
|
-
if is_initializing and (
|
|
4428
|
-
(operation.name == "measure") or (operation.name == "reset")
|
|
4429
|
-
):
|
|
4428
|
+
if is_initializing and ((operation.name == "measure") or (operation.name == "reset")):
|
|
4430
4429
|
continue
|
|
4431
4430
|
|
|
4432
4431
|
is_initializing = False
|
|
@@ -4484,14 +4483,13 @@ class QrackSimulator:
|
|
|
4484
4483
|
self._sample_cregbits = []
|
|
4485
4484
|
|
|
4486
4485
|
if self._sample_measure and (len(self._sample_qubits) > 0):
|
|
4487
|
-
_data = self._add_sample_measure(
|
|
4488
|
-
self._sample_qubits, self._sample_clbits, self._shots
|
|
4489
|
-
)
|
|
4486
|
+
_data = self._add_sample_measure(self._sample_qubits, self._sample_clbits, self._shots)
|
|
4490
4487
|
|
|
4491
4488
|
del self._sim
|
|
4492
4489
|
|
|
4493
4490
|
return _data
|
|
4494
4491
|
|
|
4492
|
+
@staticmethod
|
|
4495
4493
|
def get_qiskit_basis_gates():
|
|
4496
4494
|
return [
|
|
4497
4495
|
"id",
|