pyqrack-cpu-complex128 1.58.0__py3-none-macosx_13_0_x86_64.whl → 1.58.9__py3-none-macosx_13_0_x86_64.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of pyqrack-cpu-complex128 might be problematic. Click here for more details.
- pyqrack/qrack_ace_backend.py +140 -0
- pyqrack/qrack_system/qrack_system.py +5 -1
- {pyqrack_cpu_complex128-1.58.0.dist-info → pyqrack_cpu_complex128-1.58.9.dist-info}/METADATA +1 -1
- {pyqrack_cpu_complex128-1.58.0.dist-info → pyqrack_cpu_complex128-1.58.9.dist-info}/RECORD +7 -7
- {pyqrack_cpu_complex128-1.58.0.dist-info → pyqrack_cpu_complex128-1.58.9.dist-info}/LICENSE +0 -0
- {pyqrack_cpu_complex128-1.58.0.dist-info → pyqrack_cpu_complex128-1.58.9.dist-info}/WHEEL +0 -0
- {pyqrack_cpu_complex128-1.58.0.dist-info → pyqrack_cpu_complex128-1.58.9.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,6 +443,57 @@ class QrackAceBackend:
|
|
|
404
443
|
|
|
405
444
|
return qb, lhv
|
|
406
445
|
|
|
446
|
+
def _get_bloch_angles(self, hq):
|
|
447
|
+
sim = self.sim[hq[0]]
|
|
448
|
+
q = hq[1]
|
|
449
|
+
|
|
450
|
+
# Z axis
|
|
451
|
+
z = 1 - 2 * sim.prob(q)
|
|
452
|
+
prob = z**2
|
|
453
|
+
|
|
454
|
+
# X axis
|
|
455
|
+
sim.h(q)
|
|
456
|
+
x = 1 - 2 * sim.prob(q)
|
|
457
|
+
prob += x**2
|
|
458
|
+
sim.h(q)
|
|
459
|
+
|
|
460
|
+
# Y axis
|
|
461
|
+
sim.adjs(q)
|
|
462
|
+
sim.h(q)
|
|
463
|
+
y = 1 - 2 * sim.prob(q)
|
|
464
|
+
prob += y**2
|
|
465
|
+
sim.h(q)
|
|
466
|
+
sim.s(q)
|
|
467
|
+
|
|
468
|
+
prob = math.sqrt(prob)
|
|
469
|
+
inclination = math.atan2(math.sqrt(x**2 + y**2), z)
|
|
470
|
+
azimuth = math.atan2(y, x)
|
|
471
|
+
|
|
472
|
+
return prob, azimuth, inclination
|
|
473
|
+
|
|
474
|
+
def _rotate_to_bloch(
|
|
475
|
+
self, hq, azimuth_curr, inclination_curr, azimuth_target, inclination_target
|
|
476
|
+
):
|
|
477
|
+
sim = self.sim[hq[0]]
|
|
478
|
+
q = hq[1]
|
|
479
|
+
|
|
480
|
+
delta_azimuth = azimuth_target - azimuth_curr
|
|
481
|
+
delta_inclination = inclination_target - inclination_curr
|
|
482
|
+
|
|
483
|
+
# Apply rotation as "Azimuth, Inclination" (AI)
|
|
484
|
+
cosA = math.cos(delta_azimuth)
|
|
485
|
+
sinA = math.sin(delta_azimuth)
|
|
486
|
+
cosI = math.cos(delta_inclination / 2)
|
|
487
|
+
sinI = math.sin(delta_inclination / 2)
|
|
488
|
+
|
|
489
|
+
m00 = complex(cosI, 0)
|
|
490
|
+
m01 = complex(-cosA, sinA) * sinI
|
|
491
|
+
m10 = complex(cosA, sinA) * sinI
|
|
492
|
+
m11 = complex(cosI, 0)
|
|
493
|
+
|
|
494
|
+
sim.mtrx([m00, m01, m10, m11], q)
|
|
495
|
+
|
|
496
|
+
|
|
407
497
|
def _correct(self, lq, phase=False):
|
|
408
498
|
hq = self._unpack(lq)
|
|
409
499
|
|
|
@@ -454,6 +544,32 @@ class QrackAceBackend:
|
|
|
454
544
|
hq[q].x()
|
|
455
545
|
else:
|
|
456
546
|
self.sim[hq[q][0]].x(hq[q][1])
|
|
547
|
+
|
|
548
|
+
p, a, i = [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0]
|
|
549
|
+
p[0], a[0], i[0] = self._get_bloch_angles(hq[0])
|
|
550
|
+
p[1], a[1], i[1] = self._get_bloch_angles(hq[1])
|
|
551
|
+
p[3], a[3], i[3] = self._get_bloch_angles(hq[3])
|
|
552
|
+
p[4], a[4], i[4] = self._get_bloch_angles(hq[4])
|
|
553
|
+
|
|
554
|
+
indices = []
|
|
555
|
+
a_target = 0
|
|
556
|
+
i_target = 0
|
|
557
|
+
weight = 0
|
|
558
|
+
for x in range(5):
|
|
559
|
+
if p[x] < 0.5:
|
|
560
|
+
continue
|
|
561
|
+
indices.append(x)
|
|
562
|
+
w = (1.5 - p[x])
|
|
563
|
+
w *= w
|
|
564
|
+
a_target += w * a[x]
|
|
565
|
+
i_target += w * i[x]
|
|
566
|
+
weight += w
|
|
567
|
+
|
|
568
|
+
if len(indices) > 1:
|
|
569
|
+
a_target /= weight
|
|
570
|
+
i_target /= weight
|
|
571
|
+
for x in indices:
|
|
572
|
+
self._rotate_to_bloch(hq[x], a[x], i[x], a_target, i_target)
|
|
457
573
|
else:
|
|
458
574
|
# RMS
|
|
459
575
|
p = [
|
|
@@ -473,6 +589,30 @@ class QrackAceBackend:
|
|
|
473
589
|
else:
|
|
474
590
|
self.sim[hq[q][0]].x(hq[q][1])
|
|
475
591
|
|
|
592
|
+
p, a, i = [0, 0, 0], [0, 0, 0], [0, 0, 0]
|
|
593
|
+
p[0], a[0], i[0] = self._get_bloch_angles(hq[0])
|
|
594
|
+
p[1], a[1], i[1] = self._get_bloch_angles(hq[1])
|
|
595
|
+
|
|
596
|
+
indices = []
|
|
597
|
+
a_target = 0
|
|
598
|
+
i_target = 0
|
|
599
|
+
weight = 0
|
|
600
|
+
for x in range(3):
|
|
601
|
+
if p[x] < 0.5:
|
|
602
|
+
continue
|
|
603
|
+
indices.append(x)
|
|
604
|
+
w = (1.5 - p[x])
|
|
605
|
+
w *= w
|
|
606
|
+
a_target += w * a[x]
|
|
607
|
+
i_target += w * i[x]
|
|
608
|
+
weight += w
|
|
609
|
+
|
|
610
|
+
if len(indices) > 1:
|
|
611
|
+
a_target /= weight
|
|
612
|
+
i_target /= weight
|
|
613
|
+
for x in indices:
|
|
614
|
+
self._rotate_to_bloch(hq[x], a[x], i[x], a_target, i_target)
|
|
615
|
+
|
|
476
616
|
if phase:
|
|
477
617
|
for q in qb:
|
|
478
618
|
b = hq[q]
|
|
@@ -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=3tBwfCCD-zQjQ2g1EUZdggKdn-3b2uSFTbT7LS0YLaU,785
|
|
2
2
|
pyqrack/neuron_activation_fn.py,sha256=fQTTFfsvwcot_43Vopacot47IV2Rxk8pelUyuzwpXPs,593
|
|
3
3
|
pyqrack/pauli.py,sha256=wg500wDOwdIU4lEVJoMmjtbAdmtakZYzLPjdzC2rwUQ,654
|
|
4
|
-
pyqrack/qrack_ace_backend.py,sha256=
|
|
4
|
+
pyqrack/qrack_ace_backend.py,sha256=Q9XFDoe2miRqbqTm-ZrMdXBfZ8Bk2dkvJuaBc3RBcM8,47776
|
|
5
5
|
pyqrack/qrack_circuit.py,sha256=vDCKGbcEHJDFUKprjCpWgit8lXFnMrPimKHURD2_Hj4,19538
|
|
6
6
|
pyqrack/qrack_neuron.py,sha256=UiJdjAGB6usjAGHWSosSFCUUeIkhh3MtZbsaxfsIsNw,9043
|
|
7
7
|
pyqrack/qrack_neuron_torch_layer.py,sha256=Bs5BLC2GFevfSpo_jSJ2AZl-hfDRJmzlGN9pFw1CtoQ,6160
|
|
@@ -9,15 +9,15 @@ pyqrack/qrack_simulator.py,sha256=2z4zGNPvDvVz2ctjeJl3jxUnKu0CxkABHvW5zxdUHa8,14
|
|
|
9
9
|
pyqrack/qrack_stabilizer.py,sha256=O-7VJ9Vw4h25PK_kesSjIqHXGSo8lLrQLIyGgmzG7Co,2124
|
|
10
10
|
pyqrack/quimb_circuit_type.py,sha256=Sk-Tmn38kUYmAkJJ75btWuhYZyTXOOezmowFhfdiGDc,621
|
|
11
11
|
pyqrack/qrack_system/__init__.py,sha256=-oZ9dsb1hixsnrkUJRY_C5DzQ_l6MtifF_Z465BgqV4,334
|
|
12
|
-
pyqrack/qrack_system/qrack_system.py,sha256=
|
|
12
|
+
pyqrack/qrack_system/qrack_system.py,sha256=FWEMiBfDDoNIAo8jbqFR9MkvRGr6rOU_frvKGMgnTO8,42943
|
|
13
13
|
pyqrack/qrack_system/qrack_cl_precompile/qrack_cl_precompile,sha256=8xQYqoFTKIl-5v6ZkqmbWp14Eowkl8ty2vNF2shC5hU,35040
|
|
14
14
|
pyqrack/qrack_system/qrack_lib/libqrack_pinvoke.9.21.0.dylib,sha256=56UECwCa73rLbO65UvbPaTIqKrd4i56Gf4Jr6txNOJ0,3000968
|
|
15
15
|
pyqrack/qrack_system/qrack_lib/libqrack_pinvoke.dylib,sha256=56UECwCa73rLbO65UvbPaTIqKrd4i56Gf4Jr6txNOJ0,3000968
|
|
16
16
|
pyqrack/stats/__init__.py,sha256=Hla85my2fY_roR9lIjGBVpEG7ySOTMwjWa8D6-kgCnY,276
|
|
17
17
|
pyqrack/stats/load_quantized_data.py,sha256=z12u9F7Nt3P-i44nY1xxvso_klS6WIHS3iqq7R2_lqE,1184
|
|
18
18
|
pyqrack/stats/quantize_by_range.py,sha256=UM0_7jJDdQ7g30cR3UQAxkbzkqrmsy1oUfqg0h11FUY,2270
|
|
19
|
-
pyqrack_cpu_complex128-1.58.
|
|
20
|
-
pyqrack_cpu_complex128-1.58.
|
|
21
|
-
pyqrack_cpu_complex128-1.58.
|
|
22
|
-
pyqrack_cpu_complex128-1.58.
|
|
23
|
-
pyqrack_cpu_complex128-1.58.
|
|
19
|
+
pyqrack_cpu_complex128-1.58.9.dist-info/LICENSE,sha256=HxB-7SaWTuewAk1nz-3_3FUD6QhgX73kNT_taKVUTq8,1069
|
|
20
|
+
pyqrack_cpu_complex128-1.58.9.dist-info/METADATA,sha256=7cyxTMLZYoJ2dDvhZCaQ5zO4p_p9lmdXqScy4XqOuik,5921
|
|
21
|
+
pyqrack_cpu_complex128-1.58.9.dist-info/WHEEL,sha256=nZx8s83OrgdDmpcWX-8FgI0sEAjdQimt4SdYsdcCaC8,107
|
|
22
|
+
pyqrack_cpu_complex128-1.58.9.dist-info/top_level.txt,sha256=YE_3q9JTGRLMilNg2tGP1y7uU-Dx8PDao2OhwoIbv8E,8
|
|
23
|
+
pyqrack_cpu_complex128-1.58.9.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
{pyqrack_cpu_complex128-1.58.0.dist-info → pyqrack_cpu_complex128-1.58.9.dist-info}/top_level.txt
RENAMED
|
File without changes
|