pyqrack-cpu 1.58.0__py3-none-win_amd64.whl → 1.58.5__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 might be problematic. Click here for more details.

@@ -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,88 @@ class QrackAceBackend:
404
443
 
405
444
  return qb, lhv
406
445
 
446
+ def get_lhv_bloch_angles(self, q):
447
+ z = (1 - q.bloch[2]) / 2
448
+ prob = z**2
449
+ x = (1 - q.bloch[0]) / 2
450
+ prob += x**2
451
+ y = (1 - q.bloch[1]) / 2
452
+ prob += y**2
453
+
454
+ prob = math.sqrt(prob)
455
+ inclination = math.atan2(math.sqrt(x**2 + y**2), z)
456
+ azimuth = math.atan2(y, x)
457
+
458
+ return prob, azimuth, inclination
459
+
460
+ def get_bloch_angles(self, hq):
461
+ sim = self.sim[hq[0]]
462
+ q = hq[1]
463
+
464
+ # Z axis
465
+ z = 1 - 2 * sim.prob(q)
466
+ prob = z**2
467
+
468
+ # X axis
469
+ sim.h(q)
470
+ x = 1 - 2 * sim.prob(q)
471
+ prob += x**2
472
+ sim.h(q)
473
+
474
+ # Y axis
475
+ sim.adjs(q)
476
+ sim.h(q)
477
+ y = 1 - 2 * sim.prob(q)
478
+ prob += y**2
479
+ sim.h(q)
480
+ sim.s(q)
481
+
482
+ prob = math.sqrt(prob)
483
+ inclination = math.atan2(math.sqrt(x**2 + y**2), z)
484
+ azimuth = math.atan2(y, x)
485
+
486
+ return prob, azimuth, inclination
487
+
488
+ def rotate_lhv_to_bloch(
489
+ self, q, azimuth_curr, inclination_curr, azimuth_target, inclination_target
490
+ ):
491
+ delta_azimuth = azimuth_target - azimuth_curr
492
+ delta_inclination = inclination_target - inclination_curr
493
+
494
+ cosA = math.cos(delta_azimuth)
495
+ sinA = math.sin(delta_azimuth)
496
+ cosI = math.cos(delta_inclination / 2)
497
+ sinI = math.sin(delta_inclination / 2)
498
+
499
+ m00 = complex(cosI, 0)
500
+ m01 = complex(-cosA, sinA) * sinI
501
+ m10 = complex(cosA, sinA) * sinI
502
+ m11 = complex(cosI, 0)
503
+
504
+ q.mtrx([m00, m01, m10, m11])
505
+
506
+ def rotate_to_bloch(
507
+ self, hq, azimuth_curr, inclination_curr, azimuth_target, inclination_target
508
+ ):
509
+ sim = self.sim[hq[0]]
510
+ q = hq[1]
511
+
512
+ delta_azimuth = azimuth_target - azimuth_curr
513
+ delta_inclination = inclination_target - inclination_curr
514
+
515
+ # Apply rotation as "Azimuth, Inclination" (AI)
516
+ cosA = math.cos(delta_azimuth)
517
+ sinA = math.sin(delta_azimuth)
518
+ cosI = math.cos(delta_inclination / 2)
519
+ sinI = math.sin(delta_inclination / 2)
520
+
521
+ m00 = complex(cosI, 0)
522
+ m01 = complex(-cosA, sinA) * sinI
523
+ m10 = complex(cosA, sinA) * sinI
524
+ m11 = complex(cosI, 0)
525
+
526
+ sim.mtrx([m00, m01, m10, m11], q)
527
+
407
528
  def _correct(self, lq, phase=False):
408
529
  hq = self._unpack(lq)
409
530
 
@@ -454,6 +575,28 @@ class QrackAceBackend:
454
575
  hq[q].x()
455
576
  else:
456
577
  self.sim[hq[q][0]].x(hq[q][1])
578
+
579
+ p, a, i = [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0]
580
+ p[0], a[0], i[0] = self.get_bloch_angles(hq[0])
581
+ p[1], a[1], i[1] = self.get_bloch_angles(hq[1])
582
+ p[3], a[2], i[2] = self.get_bloch_angles(hq[3])
583
+ p[4], a[3], i[3] = self.get_bloch_angles(hq[4])
584
+
585
+ indices = []
586
+ a_target = 0
587
+ i_target = 0
588
+ for x in range(4):
589
+ if p[x] < 0.5:
590
+ continue
591
+ indices.append(x)
592
+ a_target += a[x]
593
+ i_target += i[x]
594
+
595
+ if len(indices) > 1:
596
+ a_target /= len(indices)
597
+ i_target /= len(indices)
598
+ for x in indices:
599
+ self.rotate_to_bloch(hq[x], a[x], i[x], a_target, i_target)
457
600
  else:
458
601
  # RMS
459
602
  p = [
@@ -473,6 +616,26 @@ class QrackAceBackend:
473
616
  else:
474
617
  self.sim[hq[q][0]].x(hq[q][1])
475
618
 
619
+ p, a, i = [0, 0], [0, 0], [0, 0]
620
+ p[0], a[0], i[0] = self.get_bloch_angles(hq[0])
621
+ p[1], a[1], i[1] = self.get_bloch_angles(hq[1])
622
+
623
+ indices = []
624
+ a_target = 0
625
+ i_target = 0
626
+ for x in range(2):
627
+ if p[x] < 0.5:
628
+ continue
629
+ indices.append(x)
630
+ a_target += a[x]
631
+ i_target += i[x]
632
+
633
+ if len(indices) > 1:
634
+ a_target /= len(indices)
635
+ i_target /= len(indices)
636
+ for x in indices:
637
+ self.rotate_to_bloch(hq[x], a[x], i[x], a_target, i_target)
638
+
476
639
  if phase:
477
640
  for q in qb:
478
641
  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 = [c_ulonglong, c_ulonglong, POINTER(c_longlong)]
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,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: pyqrack-cpu
3
- Version: 1.58.0
3
+ Version: 1.58.5
4
4
  Summary: pyqrack - Pure Python vm6502q/qrack Wrapper
5
5
  Home-page: https://github.com/vm6502q/pyqrack
6
6
  Author: Daniel Strano
@@ -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=FN4Dqs0yMLy60nLpEhBh0L2LcWjtDRRGhQaVzthU5F0,44721
4
+ pyqrack/qrack_ace_backend.py,sha256=-lkX7LMTlicz8RobAdr28RCjegbSvtsv4MZIUPwMck8,50039
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=nCxCsmcVo-dk7LQfQ0F7SYwxbJTB8myIAgPqE078cAw,44230
13
- pyqrack/qrack_system/qrack_lib/qrack_pinvoke.dll,sha256=Bti1kWi6HKxmPz0hh21F6gbsN_DvBKc7t8ov3q5T6AE,1746432
12
+ pyqrack/qrack_system/qrack_system.py,sha256=73m6cDyaE-wY0w4uFqdpngDOMoYJWOnzjitF8mD0Vb4,44281
13
+ pyqrack/qrack_system/qrack_lib/qrack_pinvoke.dll,sha256=eshGbI2LfFHXgvDNGIDr1sjG4Zx7iFxS4DyuFNxDohQ,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-1.58.0.dist-info/LICENSE,sha256=IdAVedmFOPQtHi_XeEI9OhJwUuwlT6tCJwrT55zAn3w,1090
18
- pyqrack_cpu-1.58.0.dist-info/METADATA,sha256=2579tJLLndggYOekjUH82573kzDqMHZ1_uHyAFW-5yo,5994
19
- pyqrack_cpu-1.58.0.dist-info/WHEEL,sha256=JMWfR_Dj7ISokcwe0cBhCfK6JKnIi-ZX11L6d_ntt6o,98
20
- pyqrack_cpu-1.58.0.dist-info/top_level.txt,sha256=YE_3q9JTGRLMilNg2tGP1y7uU-Dx8PDao2OhwoIbv8E,8
21
- pyqrack_cpu-1.58.0.dist-info/RECORD,,
17
+ pyqrack_cpu-1.58.5.dist-info/LICENSE,sha256=IdAVedmFOPQtHi_XeEI9OhJwUuwlT6tCJwrT55zAn3w,1090
18
+ pyqrack_cpu-1.58.5.dist-info/METADATA,sha256=bpuPn5OHURZO5FtD9mH3i1VDna7yQ-0hgdPrv8R9nLA,5994
19
+ pyqrack_cpu-1.58.5.dist-info/WHEEL,sha256=JMWfR_Dj7ISokcwe0cBhCfK6JKnIi-ZX11L6d_ntt6o,98
20
+ pyqrack_cpu-1.58.5.dist-info/top_level.txt,sha256=YE_3q9JTGRLMilNg2tGP1y7uU-Dx8PDao2OhwoIbv8E,8
21
+ pyqrack_cpu-1.58.5.dist-info/RECORD,,