pyqrack-cpu-complex128 1.58.0__py3-none-win_amd64.whl → 1.58.10__py3-none-win_amd64.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of pyqrack-cpu-complex128 might be problematic. Click here for more details.
- pyqrack/qrack_ace_backend.py +181 -5
- pyqrack/qrack_system/qrack_lib/qrack_pinvoke.dll +0 -0
- pyqrack/qrack_system/qrack_system.py +5 -1
- {pyqrack_cpu_complex128-1.58.0.dist-info → pyqrack_cpu_complex128-1.58.10.dist-info}/METADATA +1 -1
- {pyqrack_cpu_complex128-1.58.0.dist-info → pyqrack_cpu_complex128-1.58.10.dist-info}/RECORD +8 -8
- {pyqrack_cpu_complex128-1.58.0.dist-info → pyqrack_cpu_complex128-1.58.10.dist-info}/LICENSE +0 -0
- {pyqrack_cpu_complex128-1.58.0.dist-info → pyqrack_cpu_complex128-1.58.10.dist-info}/WHEEL +0 -0
- {pyqrack_cpu_complex128-1.58.0.dist-info → pyqrack_cpu_complex128-1.58.10.dist-info}/top_level.txt +0 -0
pyqrack/qrack_ace_backend.py
CHANGED
|
@@ -102,6 +102,45 @@ class LHVQubit:
|
|
|
102
102
|
self.ry(theta)
|
|
103
103
|
self.rz(phi)
|
|
104
104
|
|
|
105
|
+
# Provided verbatim by Elara (the custom OpenAI GPT):
|
|
106
|
+
def mtrx(self, matrix):
|
|
107
|
+
"""
|
|
108
|
+
Apply a 2x2 unitary matrix to the LHV Bloch vector using only standard math/cmath.
|
|
109
|
+
Matrix format: [a, b, c, d] for [[a, b], [c, d]]
|
|
110
|
+
"""
|
|
111
|
+
a, b, c, d = matrix
|
|
112
|
+
|
|
113
|
+
# Current Bloch vector
|
|
114
|
+
x, y, z = self.bloch
|
|
115
|
+
|
|
116
|
+
# Convert to density matrix ρ = ½ (I + xσx + yσy + zσz)
|
|
117
|
+
rho = [[(1 + z) / 2, (x - 1j * y) / 2], [(x + 1j * y) / 2, (1 - z) / 2]]
|
|
118
|
+
|
|
119
|
+
# Compute U * ρ
|
|
120
|
+
u_rho = [
|
|
121
|
+
[a * rho[0][0] + b * rho[1][0], a * rho[0][1] + b * rho[1][1]],
|
|
122
|
+
[c * rho[0][0] + d * rho[1][0], c * rho[0][1] + d * rho[1][1]],
|
|
123
|
+
]
|
|
124
|
+
|
|
125
|
+
# Compute (U * ρ) * U†
|
|
126
|
+
rho_prime = [
|
|
127
|
+
[
|
|
128
|
+
u_rho[0][0] * a.conjugate() + u_rho[0][1] * b.conjugate(),
|
|
129
|
+
u_rho[0][0] * c.conjugate() + u_rho[0][1] * d.conjugate(),
|
|
130
|
+
],
|
|
131
|
+
[
|
|
132
|
+
u_rho[1][0] * a.conjugate() + u_rho[1][1] * b.conjugate(),
|
|
133
|
+
u_rho[1][0] * c.conjugate() + u_rho[1][1] * d.conjugate(),
|
|
134
|
+
],
|
|
135
|
+
]
|
|
136
|
+
|
|
137
|
+
# Extract Bloch components: Tr(ρ'σi) = 2 * Re[...]
|
|
138
|
+
new_x = 2 * rho_prime[0][1].real + 2 * rho_prime[1][0].real
|
|
139
|
+
new_y = 2 * (rho_prime[0][1].imag - rho_prime[1][0].imag)
|
|
140
|
+
new_z = 2 * rho_prime[0][0].real - 1 # since Tr(ρ') = 1
|
|
141
|
+
|
|
142
|
+
self.bloch = [new_x, new_y, new_z]
|
|
143
|
+
|
|
105
144
|
def prob(self, basis=Pauli.PauliZ):
|
|
106
145
|
"""Sample a classical outcome from the current 'quantum' state"""
|
|
107
146
|
if basis == Pauli.PauliZ:
|
|
@@ -404,7 +443,91 @@ class QrackAceBackend:
|
|
|
404
443
|
|
|
405
444
|
return qb, lhv
|
|
406
445
|
|
|
407
|
-
def
|
|
446
|
+
def _get_lhv_bloch_angles(self, sim):
|
|
447
|
+
# Z axis
|
|
448
|
+
z = 1 - 2 * sim.prob(Pauli.PauliZ)
|
|
449
|
+
prob = z**2
|
|
450
|
+
|
|
451
|
+
# X axis
|
|
452
|
+
x = 1 - 2 * sim.prob(Pauli.PauliX)
|
|
453
|
+
prob += x**2
|
|
454
|
+
|
|
455
|
+
# Y axis
|
|
456
|
+
y = 1 - 2 * sim.prob(Pauli.PauliY)
|
|
457
|
+
prob += y**2
|
|
458
|
+
|
|
459
|
+
prob = math.sqrt(prob)
|
|
460
|
+
inclination = math.atan2(math.sqrt(x**2 + y**2), z)
|
|
461
|
+
azimuth = math.atan2(y, x)
|
|
462
|
+
|
|
463
|
+
return prob, azimuth, inclination
|
|
464
|
+
|
|
465
|
+
def _get_bloch_angles(self, hq):
|
|
466
|
+
sim = self.sim[hq[0]]
|
|
467
|
+
q = hq[1]
|
|
468
|
+
|
|
469
|
+
# Z axis
|
|
470
|
+
z = 1 - 2 * sim.prob(q)
|
|
471
|
+
prob = z**2
|
|
472
|
+
|
|
473
|
+
# X axis
|
|
474
|
+
sim.h(q)
|
|
475
|
+
x = 1 - 2 * sim.prob(q)
|
|
476
|
+
prob += x**2
|
|
477
|
+
sim.h(q)
|
|
478
|
+
|
|
479
|
+
# Y axis
|
|
480
|
+
sim.adjs(q)
|
|
481
|
+
sim.h(q)
|
|
482
|
+
y = 1 - 2 * sim.prob(q)
|
|
483
|
+
prob += y**2
|
|
484
|
+
sim.h(q)
|
|
485
|
+
sim.s(q)
|
|
486
|
+
|
|
487
|
+
prob = math.sqrt(prob)
|
|
488
|
+
inclination = math.atan2(math.sqrt(x**2 + y**2), z)
|
|
489
|
+
azimuth = math.atan2(y, x)
|
|
490
|
+
|
|
491
|
+
return prob, azimuth, inclination
|
|
492
|
+
|
|
493
|
+
def _rotate_to_bloch(
|
|
494
|
+
self, hq, delta_azimuth, delta_inclination
|
|
495
|
+
):
|
|
496
|
+
sim = self.sim[hq[0]]
|
|
497
|
+
q = hq[1]
|
|
498
|
+
|
|
499
|
+
# Apply rotation as "Azimuth, Inclination" (AI)
|
|
500
|
+
cosA = math.cos(delta_azimuth)
|
|
501
|
+
sinA = math.sin(delta_azimuth)
|
|
502
|
+
cosI = math.cos(delta_inclination / 2)
|
|
503
|
+
sinI = math.sin(delta_inclination / 2)
|
|
504
|
+
|
|
505
|
+
m00 = complex(cosI, 0)
|
|
506
|
+
m01 = complex(-cosA, sinA) * sinI
|
|
507
|
+
m10 = complex(cosA, sinA) * sinI
|
|
508
|
+
m11 = complex(cosI, 0)
|
|
509
|
+
|
|
510
|
+
sim.mtrx([m00, m01, m10, m11], q)
|
|
511
|
+
|
|
512
|
+
|
|
513
|
+
def _rotate_lhv_to_bloch(
|
|
514
|
+
self, sim, delta_azimuth, delta_inclination
|
|
515
|
+
):
|
|
516
|
+
# Apply rotation as "Azimuth, Inclination" (AI)
|
|
517
|
+
cosA = math.cos(delta_azimuth)
|
|
518
|
+
sinA = math.sin(delta_azimuth)
|
|
519
|
+
cosI = math.cos(delta_inclination / 2)
|
|
520
|
+
sinI = math.sin(delta_inclination / 2)
|
|
521
|
+
|
|
522
|
+
m00 = complex(cosI, 0)
|
|
523
|
+
m01 = complex(-cosA, sinA) * sinI
|
|
524
|
+
m10 = complex(cosA, sinA) * sinI
|
|
525
|
+
m11 = complex(cosI, 0)
|
|
526
|
+
|
|
527
|
+
sim.mtrx([m00, m01, m10, m11])
|
|
528
|
+
|
|
529
|
+
|
|
530
|
+
def _correct(self, lq, phase=False, skip_rotation=False):
|
|
408
531
|
hq = self._unpack(lq)
|
|
409
532
|
|
|
410
533
|
if len(hq) == 1:
|
|
@@ -454,6 +577,34 @@ class QrackAceBackend:
|
|
|
454
577
|
hq[q].x()
|
|
455
578
|
else:
|
|
456
579
|
self.sim[hq[q][0]].x(hq[q][1])
|
|
580
|
+
|
|
581
|
+
if not skip_rotation:
|
|
582
|
+
p, a, i = [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0]
|
|
583
|
+
p[0], a[0], i[0] = self._get_bloch_angles(hq[0])
|
|
584
|
+
p[1], a[1], i[1] = self._get_bloch_angles(hq[1])
|
|
585
|
+
p[3], a[3], i[3] = self._get_bloch_angles(hq[3])
|
|
586
|
+
p[4], a[4], i[4] = self._get_bloch_angles(hq[4])
|
|
587
|
+
|
|
588
|
+
indices = []
|
|
589
|
+
a_target = 0
|
|
590
|
+
i_target = 0
|
|
591
|
+
weight = 0
|
|
592
|
+
for x in range(5):
|
|
593
|
+
if p[x] < 0.5:
|
|
594
|
+
continue
|
|
595
|
+
indices.append(x)
|
|
596
|
+
w = (1.5 - p[x])
|
|
597
|
+
w *= w
|
|
598
|
+
a_target += w * a[x]
|
|
599
|
+
i_target += w * i[x]
|
|
600
|
+
weight += w
|
|
601
|
+
|
|
602
|
+
if len(indices) > 1:
|
|
603
|
+
a_target /= weight
|
|
604
|
+
i_target /= weight
|
|
605
|
+
for x in indices:
|
|
606
|
+
self._rotate_to_bloch(hq[x], a_target - a[x], i_target - i[x])
|
|
607
|
+
|
|
457
608
|
else:
|
|
458
609
|
# RMS
|
|
459
610
|
p = [
|
|
@@ -473,6 +624,31 @@ class QrackAceBackend:
|
|
|
473
624
|
else:
|
|
474
625
|
self.sim[hq[q][0]].x(hq[q][1])
|
|
475
626
|
|
|
627
|
+
if not skip_rotation:
|
|
628
|
+
p, a, i = [0, 0, 0], [0, 0, 0], [0, 0, 0]
|
|
629
|
+
p[0], a[0], i[0] = self._get_bloch_angles(hq[0])
|
|
630
|
+
p[1], a[1], i[1] = self._get_bloch_angles(hq[1])
|
|
631
|
+
|
|
632
|
+
indices = []
|
|
633
|
+
a_target = 0
|
|
634
|
+
i_target = 0
|
|
635
|
+
weight = 0
|
|
636
|
+
for x in range(3):
|
|
637
|
+
if p[x] < 0.5:
|
|
638
|
+
continue
|
|
639
|
+
indices.append(x)
|
|
640
|
+
w = (1.5 - p[x])
|
|
641
|
+
w *= w
|
|
642
|
+
a_target += w * a[x]
|
|
643
|
+
i_target += w * i[x]
|
|
644
|
+
weight += w
|
|
645
|
+
|
|
646
|
+
if len(indices) > 1:
|
|
647
|
+
a_target /= weight
|
|
648
|
+
i_target /= weight
|
|
649
|
+
for x in indices:
|
|
650
|
+
self._rotate_to_bloch(hq[x], a_target - a[x], i_target - i[x])
|
|
651
|
+
|
|
476
652
|
if phase:
|
|
477
653
|
for q in qb:
|
|
478
654
|
b = hq[q]
|
|
@@ -496,8 +672,8 @@ class QrackAceBackend:
|
|
|
496
672
|
b = hq[lhv]
|
|
497
673
|
b.u(th, ph, lm)
|
|
498
674
|
|
|
499
|
-
self._correct(lq, False)
|
|
500
|
-
self._correct(lq, True)
|
|
675
|
+
self._correct(lq, False, True)
|
|
676
|
+
self._correct(lq, True, False)
|
|
501
677
|
|
|
502
678
|
def r(self, p, th, lq):
|
|
503
679
|
hq = self._unpack(lq)
|
|
@@ -521,7 +697,7 @@ class QrackAceBackend:
|
|
|
521
697
|
b.rz(th)
|
|
522
698
|
|
|
523
699
|
if p != Pauli.PauliZ:
|
|
524
|
-
self._correct(lq, False)
|
|
700
|
+
self._correct(lq, False, p != Pauli.PauliX)
|
|
525
701
|
if p != Pauli.PauliX:
|
|
526
702
|
self._correct(lq, True)
|
|
527
703
|
|
|
@@ -745,7 +921,7 @@ class QrackAceBackend:
|
|
|
745
921
|
|
|
746
922
|
self._correct(lq1, True)
|
|
747
923
|
if pauli != Pauli.PauliZ:
|
|
748
|
-
self._correct(lq2, False)
|
|
924
|
+
self._correct(lq2, False, pauli != Pauli.PauliX)
|
|
749
925
|
if pauli != Pauli.PauliX:
|
|
750
926
|
self._correct(lq2, True)
|
|
751
927
|
|
|
Binary file
|
|
@@ -147,7 +147,11 @@ class QrackSystem:
|
|
|
147
147
|
self.qrack_lib.set_device.argtypes = [c_ulonglong, c_longlong]
|
|
148
148
|
|
|
149
149
|
self.qrack_lib.set_device_list.restype = None
|
|
150
|
-
self.qrack_lib.set_device_list.argtypes = [
|
|
150
|
+
self.qrack_lib.set_device_list.argtypes = [
|
|
151
|
+
c_ulonglong,
|
|
152
|
+
c_ulonglong,
|
|
153
|
+
POINTER(c_longlong),
|
|
154
|
+
]
|
|
151
155
|
|
|
152
156
|
# pseudo-quantum
|
|
153
157
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
pyqrack/__init__.py,sha256=9fGCYdEUg_AsENCDRylbrZvUMVbUajRTn3CyuFGuFyM,805
|
|
2
2
|
pyqrack/neuron_activation_fn.py,sha256=GOqcCkiEB60jCojTrcuHuZMDP5aTOy0adtR8SY_2EZc,614
|
|
3
3
|
pyqrack/pauli.py,sha256=TUm1SN_HLz3eMW9gD_eg-IYXcMCyr36mYSytq_ExZIU,673
|
|
4
|
-
pyqrack/qrack_ace_backend.py,sha256=
|
|
4
|
+
pyqrack/qrack_ace_backend.py,sha256=NH8O8i-3_TI73-d2WAz6KzWN1GFlu9iZcCmXtpfJjcQ,50441
|
|
5
5
|
pyqrack/qrack_circuit.py,sha256=QK2dtPYurdXuw-efVq7lYz40_480NxCejXhOVwBGkXs,20122
|
|
6
6
|
pyqrack/qrack_neuron.py,sha256=a3F0hduVvXZi9aXsY0du5hBFXpMq_R5UHHDOv2-YtFM,9305
|
|
7
7
|
pyqrack/qrack_neuron_torch_layer.py,sha256=OhNSldzaqLaMoNBkin68j8QWOOiuZCQJDZPgSDRI2Fk,6330
|
|
@@ -9,13 +9,13 @@ pyqrack/qrack_simulator.py,sha256=uETnc4eNOg7w0f9aO_BbRMnQHr-XrA2Doy1kkD7cW9Q,14
|
|
|
9
9
|
pyqrack/qrack_stabilizer.py,sha256=AJe7dfFcxFKyig3tjWXw0UKhXer5Wl9QNvjNNqlOL5M,2182
|
|
10
10
|
pyqrack/quimb_circuit_type.py,sha256=iC0CCpZBGhziFC8-uBCH43Mi29uvVUrtBG6W9YBlyps,638
|
|
11
11
|
pyqrack/qrack_system/__init__.py,sha256=PUterej-xpA4BqFmiBrQCMeTQlsRf-K8Dxnwp-iVvUQ,343
|
|
12
|
-
pyqrack/qrack_system/qrack_system.py,sha256=
|
|
13
|
-
pyqrack/qrack_system/qrack_lib/qrack_pinvoke.dll,sha256=
|
|
12
|
+
pyqrack/qrack_system/qrack_system.py,sha256=WY4gLHfkHrNKoYOkHMqBE4wUxwGgCmAk_GgujGRZms0,44281
|
|
13
|
+
pyqrack/qrack_system/qrack_lib/qrack_pinvoke.dll,sha256=9llAt7eJzXW4F3qsBufp-ZQVl0MbagCKCVP9lG-120c,1746432
|
|
14
14
|
pyqrack/stats/__init__.py,sha256=hI715MGW7D4mDYhUFpRI4ZLsynYDO4tN-rjsuuYbG6Q,282
|
|
15
15
|
pyqrack/stats/load_quantized_data.py,sha256=_1w9BPrZNreP0wOAyaAZHdEGKoGiI7tMeFD9P3eyJC0,1219
|
|
16
16
|
pyqrack/stats/quantize_by_range.py,sha256=0eBIqByIxa4vfm4fQGZLAMGR9y8raxde3e5rvUWJ_dQ,2326
|
|
17
|
-
pyqrack_cpu_complex128-1.58.
|
|
18
|
-
pyqrack_cpu_complex128-1.58.
|
|
19
|
-
pyqrack_cpu_complex128-1.58.
|
|
20
|
-
pyqrack_cpu_complex128-1.58.
|
|
21
|
-
pyqrack_cpu_complex128-1.58.
|
|
17
|
+
pyqrack_cpu_complex128-1.58.10.dist-info/LICENSE,sha256=IdAVedmFOPQtHi_XeEI9OhJwUuwlT6tCJwrT55zAn3w,1090
|
|
18
|
+
pyqrack_cpu_complex128-1.58.10.dist-info/METADATA,sha256=psjp_ya6xhbcGMUkX2IdN_PyajF1boAbW268lRlsqvM,6006
|
|
19
|
+
pyqrack_cpu_complex128-1.58.10.dist-info/WHEEL,sha256=JMWfR_Dj7ISokcwe0cBhCfK6JKnIi-ZX11L6d_ntt6o,98
|
|
20
|
+
pyqrack_cpu_complex128-1.58.10.dist-info/top_level.txt,sha256=YE_3q9JTGRLMilNg2tGP1y7uU-Dx8PDao2OhwoIbv8E,8
|
|
21
|
+
pyqrack_cpu_complex128-1.58.10.dist-info/RECORD,,
|
{pyqrack_cpu_complex128-1.58.0.dist-info → pyqrack_cpu_complex128-1.58.10.dist-info}/LICENSE
RENAMED
|
File without changes
|
|
File without changes
|
{pyqrack_cpu_complex128-1.58.0.dist-info → pyqrack_cpu_complex128-1.58.10.dist-info}/top_level.txt
RENAMED
|
File without changes
|