PyQrackIsing 9.3.8__tar.gz → 9.3.10__tar.gz

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.
Files changed (28) hide show
  1. {pyqrackising-9.3.8/pyqrackising.egg-info → pyqrackising-9.3.10}/PKG-INFO +1 -1
  2. {pyqrackising-9.3.8 → pyqrackising-9.3.10}/pyproject.toml +1 -1
  3. {pyqrackising-9.3.8 → pyqrackising-9.3.10}/pyqrackising/generate_tfim_samples.py +12 -1
  4. {pyqrackising-9.3.8 → pyqrackising-9.3.10}/pyqrackising/otoc.py +81 -9
  5. {pyqrackising-9.3.8 → pyqrackising-9.3.10/pyqrackising.egg-info}/PKG-INFO +1 -1
  6. {pyqrackising-9.3.8 → pyqrackising-9.3.10}/setup.py +1 -1
  7. {pyqrackising-9.3.8 → pyqrackising-9.3.10}/LICENSE.md +0 -0
  8. {pyqrackising-9.3.8 → pyqrackising-9.3.10}/MANIFEST.in +0 -0
  9. {pyqrackising-9.3.8 → pyqrackising-9.3.10}/README.md +0 -0
  10. {pyqrackising-9.3.8 → pyqrackising-9.3.10}/pyqrackising/__init__.py +0 -0
  11. {pyqrackising-9.3.8 → pyqrackising-9.3.10}/pyqrackising/convert_tensor_network_to_tsp.py +0 -0
  12. {pyqrackising-9.3.8 → pyqrackising-9.3.10}/pyqrackising/kernels.cl +0 -0
  13. {pyqrackising-9.3.8 → pyqrackising-9.3.10}/pyqrackising/maxcut_tfim.py +0 -0
  14. {pyqrackising-9.3.8 → pyqrackising-9.3.10}/pyqrackising/maxcut_tfim_sparse.py +0 -0
  15. {pyqrackising-9.3.8 → pyqrackising-9.3.10}/pyqrackising/maxcut_tfim_streaming.py +0 -0
  16. {pyqrackising-9.3.8 → pyqrackising-9.3.10}/pyqrackising/maxcut_tfim_util.py +0 -0
  17. {pyqrackising-9.3.8 → pyqrackising-9.3.10}/pyqrackising/spin_glass_solver.py +0 -0
  18. {pyqrackising-9.3.8 → pyqrackising-9.3.10}/pyqrackising/spin_glass_solver_sparse.py +0 -0
  19. {pyqrackising-9.3.8 → pyqrackising-9.3.10}/pyqrackising/spin_glass_solver_streaming.py +0 -0
  20. {pyqrackising-9.3.8 → pyqrackising-9.3.10}/pyqrackising/tfim_magnetization.py +0 -0
  21. {pyqrackising-9.3.8 → pyqrackising-9.3.10}/pyqrackising/tfim_square_magnetization.py +0 -0
  22. {pyqrackising-9.3.8 → pyqrackising-9.3.10}/pyqrackising/tsp.py +0 -0
  23. {pyqrackising-9.3.8 → pyqrackising-9.3.10}/pyqrackising/tsp_maxcut.py +0 -0
  24. {pyqrackising-9.3.8 → pyqrackising-9.3.10}/pyqrackising.egg-info/SOURCES.txt +0 -0
  25. {pyqrackising-9.3.8 → pyqrackising-9.3.10}/pyqrackising.egg-info/dependency_links.txt +0 -0
  26. {pyqrackising-9.3.8 → pyqrackising-9.3.10}/pyqrackising.egg-info/not-zip-safe +0 -0
  27. {pyqrackising-9.3.8 → pyqrackising-9.3.10}/pyqrackising.egg-info/top_level.txt +0 -0
  28. {pyqrackising-9.3.8 → pyqrackising-9.3.10}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pyqrackising
3
- Version: 9.3.8
3
+ Version: 9.3.10
4
4
  Summary: Fast MAXCUT, TSP, and sampling heuristics from near-ideal transverse field Ising model (TFIM)
5
5
  Home-page: https://github.com/vm6502q/PyQrackIsing
6
6
  Author: Dan Strano
@@ -10,7 +10,7 @@ build-backend = "setuptools.build_meta"
10
10
 
11
11
  [project]
12
12
  name = "pyqrackising"
13
- version = "9.3.8"
13
+ version = "9.3.10"
14
14
  requires-python = ">=3.8"
15
15
  description = "Fast MAXCUT, TSP, and sampling heuristics from near-ideal transverse field Ising model (TFIM)"
16
16
  readme = {file = "README.txt", content-type = "text/markdown"}
@@ -1,10 +1,14 @@
1
- from .maxcut_tfim_util import probability_by_hamming_weight, sample_mag
1
+ from .maxcut_tfim_util import probability_by_hamming_weight, sample_mag, opencl_context
2
2
  import itertools
3
3
  import math
4
+ import sys
4
5
  import numpy as np
5
6
  from numba import njit
6
7
 
7
8
 
9
+ epsilon = opencl_context.epsilon
10
+
11
+
8
12
  @njit
9
13
  def factor_width(width, is_transpose=False):
10
14
  col_len = math.floor(math.sqrt(width))
@@ -104,6 +108,13 @@ def fix_cdf(hamming_prob):
104
108
 
105
109
  @njit
106
110
  def get_tfim_hamming_distribution(J=-1.0, h=2.0, z=4, theta=0.174532925199432957, t=5, n_qubits=56):
111
+ if h <= epsilon:
112
+ bias = np.empty(n_qubits + 1, dtype=np.float64)
113
+ if J > 0:
114
+ bias[-1] = 1.0
115
+ else:
116
+ bias[0] = 1.0
117
+ return bias
107
118
  bias = probability_by_hamming_weight(J, h, z, theta, t, n_qubits + 1)
108
119
  return bias / bias.sum()
109
120
 
@@ -1,7 +1,10 @@
1
- from .maxcut_tfim_util import probability_by_hamming_weight, sample_mag
1
+ from .maxcut_tfim_util import probability_by_hamming_weight, sample_mag, opencl_context
2
2
  from numba import njit
3
3
  import numpy as np
4
- import random
4
+ import sys
5
+
6
+
7
+ epsilon = opencl_context.epsilon
5
8
 
6
9
 
7
10
  def get_otoc_hamming_distribution(J=-1.0, h=2.0, z=4, theta=0.174532925199432957, t=5, n_qubits=56, cycles=1, pauli_string = 'X' + 'I' * 55):
@@ -9,6 +12,12 @@ def get_otoc_hamming_distribution(J=-1.0, h=2.0, z=4, theta=0.174532925199432957
9
12
  if len(pauli_string) != n_qubits:
10
13
  raise ValueError("OTOCS pauli_string must be same length as n_qubits! (Use 'I' for qubits that aren't changed.)")
11
14
 
15
+ n_bias = n_qubits + 1
16
+ if h <= epsilon:
17
+ bias = np.empty(n_bias, dtype=np.float64)
18
+ bias[0] = 1.0
19
+ return { 'X': bias, 'Y': bias, 'Z': bias }
20
+
12
21
  fwd = probability_by_hamming_weight(J, h, z, theta, t, n_qubits + 1)
13
22
  rev = probability_by_hamming_weight(-J, -h, z, theta + np.pi, t, n_qubits + 1)
14
23
  diff_theta = rev - fwd
@@ -25,7 +34,6 @@ def get_otoc_hamming_distribution(J=-1.0, h=2.0, z=4, theta=0.174532925199432957
25
34
  diff_phi *= cycles
26
35
  # diff_lam = diff_phi
27
36
 
28
- n_bias = n_qubits + 1
29
37
  diff_z = np.zeros(n_bias, dtype=np.float64)
30
38
  diff_x = np.zeros(n_bias, dtype=np.float64)
31
39
  diff_y = np.zeros(n_bias, dtype=np.float64)
@@ -73,18 +81,70 @@ def take_all(b, basis, sample):
73
81
  return sample
74
82
 
75
83
 
76
- def take_sample(b, basis, sample, m):
84
+ def take_sample(b, basis, sample, m, inv_dist):
77
85
  indices = []
86
+ tot_inv_dist = 0.0
78
87
  for i in range(len(basis)):
79
88
  if basis[i] == b:
80
89
  indices.append(i)
81
- indices = random.sample(indices, m)
82
- for i in indices:
90
+ tot_inv_dist += inv_dist[i]
91
+ selected = []
92
+ for i in range(m):
93
+ r = tot_inv_dist * np.random.random()
94
+ p = 0.0
95
+ idx = 0
96
+ while p < r:
97
+ p += inv_dist[indices[idx]]
98
+ idx += 1
99
+ i = indices[idx]
100
+ del indices[idx]
101
+ selected.append(i)
102
+ tot_inv_dist -= inv_dist[i]
103
+ for i in selected:
83
104
  sample |= 1 << i
84
105
 
85
106
  return sample
86
107
 
87
108
 
109
+ @njit
110
+ def factor_width(width):
111
+ col_len = np.floor(np.sqrt(width))
112
+ while ((width // col_len) * col_len) != width:
113
+ col_len -= 1
114
+ row_len = width // col_len
115
+
116
+ return row_len, col_len
117
+
118
+
119
+ # Provided by Google search AI
120
+ def find_all_str_occurrences(main_string, sub_string):
121
+ indices = []
122
+ start_index = 0
123
+ while True:
124
+ index = main_string.find(sub_string, start_index)
125
+ if index == -1:
126
+ break
127
+ indices.append(index)
128
+ start_index = index + 1 # Start searching after the found occurrence
129
+
130
+ return indices
131
+
132
+
133
+ def get_inv_dist(butterfly_idx, n_qubits, row_len):
134
+ inv_dist = np.zeros(n_qubits, dtype=np.float64)
135
+ for idx in butterfly_idx:
136
+ for q in range(n_qubits):
137
+ b_row = idx // row_len
138
+ b_col = idx % row_len
139
+ q_row = q // row_len
140
+ q_col = q % row_len
141
+ dist = (q_row - b_row) ** 2 + (q_col - b_col) ** 2
142
+ if dist > 0:
143
+ inv_dist[q] += 1.0 / dist
144
+
145
+ return inv_dist
146
+
147
+
88
148
  def generate_otoc_samples(J=-1.0, h=2.0, z=4, theta=0.174532925199432957, t=5, n_qubits=56, cycles=1, pauli_string = 'X' + 'I' * 55, shots=100, measurement_basis='Z' * 56):
89
149
  pauli_string = list(pauli_string)
90
150
  if len(pauli_string) != n_qubits:
@@ -116,6 +176,18 @@ def generate_otoc_samples(J=-1.0, h=2.0, z=4, theta=0.174532925199432957, t=5, n
116
176
  bases = { 'X': basis_x, 'Y': basis_y, 'Z': basis_z }
117
177
  thresholds = { key: fix_cdf(value) for key, value in get_otoc_hamming_distribution(J, h, z, theta, t, n_qubits, cycles, pauli_string).items() }
118
178
 
179
+ row_len, col_len = factor_width(n_qubits)
180
+ p_string = "".join(pauli_string)
181
+ butterfly_idx_x = find_all_str_occurrences(p_string, 'X')
182
+ butterfly_idx_y = find_all_str_occurrences(p_string, 'Y')
183
+ butterfly_idx_z = find_all_str_occurrences(p_string, 'Z')
184
+
185
+ inv_dist_x = get_inv_dist(butterfly_idx_x, n_qubits, row_len)
186
+ inv_dist_y = get_inv_dist(butterfly_idx_y, n_qubits, row_len)
187
+ inv_dist_z = get_inv_dist(butterfly_idx_z, n_qubits, row_len)
188
+
189
+ inv_dist = { 'X': inv_dist_x, 'Y': inv_dist_y, 'Z': inv_dist_z }
190
+
119
191
  samples = []
120
192
  for _ in range(shots):
121
193
  sample_3_axis = { 'X': 0, 'Y': 0, 'Z': 0 }
@@ -133,7 +205,7 @@ def generate_otoc_samples(J=-1.0, h=2.0, z=4, theta=0.174532925199432957, t=5, n
133
205
  # Second dimension: permutation within Hamming weight
134
206
  z_count = basis.count('Z')
135
207
  if z_count > m:
136
- sample_3_axis[key] = take_sample('Z', basis, sample_3_axis[key], m)
208
+ sample_3_axis[key] = take_sample('Z', basis, sample_3_axis[key], m, inv_dist[key])
137
209
  continue
138
210
  m -= z_count
139
211
  sample_3_axis[key] = take_all('Z', basis, sample_3_axis[key])
@@ -142,14 +214,14 @@ def generate_otoc_samples(J=-1.0, h=2.0, z=4, theta=0.174532925199432957, t=5, n
142
214
 
143
215
  i_count = basis.count('I')
144
216
  if i_count > m:
145
- sample_3_axis[key] = take_sample('I', basis, sample_3_axis[key], m)
217
+ sample_3_axis[key] = take_sample('I', basis, sample_3_axis[key], m, inv_dist[key])
146
218
  continue
147
219
  m -= i_count
148
220
  sample_3_axis[key] = take_all('I', basis, sample_3_axis[key])
149
221
  if m == 0:
150
222
  continue
151
223
 
152
- sample_3_axis[key] = take_sample('X', basis, sample_3_axis[key], m)
224
+ sample_3_axis[key] = take_sample('X', basis, sample_3_axis[key], m, inv_dist[key])
153
225
 
154
226
  sample = 0
155
227
  j = 0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pyqrackising
3
- Version: 9.3.8
3
+ Version: 9.3.10
4
4
  Summary: Fast MAXCUT, TSP, and sampling heuristics from near-ideal transverse field Ising model (TFIM)
5
5
  Home-page: https://github.com/vm6502q/PyQrackIsing
6
6
  Author: Dan Strano
@@ -7,7 +7,7 @@ with open(README_PATH) as readme_file:
7
7
 
8
8
  setup(
9
9
  name='pyqrackising',
10
- version='9.3.8',
10
+ version='9.3.10',
11
11
  author='Dan Strano',
12
12
  author_email='stranoj@gmail.com',
13
13
  description='Fast MAXCUT, TSP, and sampling heuristics from near-ideal transverse field Ising model (TFIM)',
File without changes
File without changes
File without changes
File without changes