PyQrackIsing 9.3.9__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.9/pyqrackising.egg-info → pyqrackising-9.3.10}/PKG-INFO +1 -1
  2. {pyqrackising-9.3.9 → pyqrackising-9.3.10}/pyproject.toml +1 -1
  3. {pyqrackising-9.3.9 → pyqrackising-9.3.10}/pyqrackising/otoc.py +70 -7
  4. {pyqrackising-9.3.9 → pyqrackising-9.3.10/pyqrackising.egg-info}/PKG-INFO +1 -1
  5. {pyqrackising-9.3.9 → pyqrackising-9.3.10}/setup.py +1 -1
  6. {pyqrackising-9.3.9 → pyqrackising-9.3.10}/LICENSE.md +0 -0
  7. {pyqrackising-9.3.9 → pyqrackising-9.3.10}/MANIFEST.in +0 -0
  8. {pyqrackising-9.3.9 → pyqrackising-9.3.10}/README.md +0 -0
  9. {pyqrackising-9.3.9 → pyqrackising-9.3.10}/pyqrackising/__init__.py +0 -0
  10. {pyqrackising-9.3.9 → pyqrackising-9.3.10}/pyqrackising/convert_tensor_network_to_tsp.py +0 -0
  11. {pyqrackising-9.3.9 → pyqrackising-9.3.10}/pyqrackising/generate_tfim_samples.py +0 -0
  12. {pyqrackising-9.3.9 → pyqrackising-9.3.10}/pyqrackising/kernels.cl +0 -0
  13. {pyqrackising-9.3.9 → pyqrackising-9.3.10}/pyqrackising/maxcut_tfim.py +0 -0
  14. {pyqrackising-9.3.9 → pyqrackising-9.3.10}/pyqrackising/maxcut_tfim_sparse.py +0 -0
  15. {pyqrackising-9.3.9 → pyqrackising-9.3.10}/pyqrackising/maxcut_tfim_streaming.py +0 -0
  16. {pyqrackising-9.3.9 → pyqrackising-9.3.10}/pyqrackising/maxcut_tfim_util.py +0 -0
  17. {pyqrackising-9.3.9 → pyqrackising-9.3.10}/pyqrackising/spin_glass_solver.py +0 -0
  18. {pyqrackising-9.3.9 → pyqrackising-9.3.10}/pyqrackising/spin_glass_solver_sparse.py +0 -0
  19. {pyqrackising-9.3.9 → pyqrackising-9.3.10}/pyqrackising/spin_glass_solver_streaming.py +0 -0
  20. {pyqrackising-9.3.9 → pyqrackising-9.3.10}/pyqrackising/tfim_magnetization.py +0 -0
  21. {pyqrackising-9.3.9 → pyqrackising-9.3.10}/pyqrackising/tfim_square_magnetization.py +0 -0
  22. {pyqrackising-9.3.9 → pyqrackising-9.3.10}/pyqrackising/tsp.py +0 -0
  23. {pyqrackising-9.3.9 → pyqrackising-9.3.10}/pyqrackising/tsp_maxcut.py +0 -0
  24. {pyqrackising-9.3.9 → pyqrackising-9.3.10}/pyqrackising.egg-info/SOURCES.txt +0 -0
  25. {pyqrackising-9.3.9 → pyqrackising-9.3.10}/pyqrackising.egg-info/dependency_links.txt +0 -0
  26. {pyqrackising-9.3.9 → pyqrackising-9.3.10}/pyqrackising.egg-info/not-zip-safe +0 -0
  27. {pyqrackising-9.3.9 → pyqrackising-9.3.10}/pyqrackising.egg-info/top_level.txt +0 -0
  28. {pyqrackising-9.3.9 → 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.9
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.9"
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,7 +1,6 @@
1
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
5
4
  import sys
6
5
 
7
6
 
@@ -82,18 +81,70 @@ def take_all(b, basis, sample):
82
81
  return sample
83
82
 
84
83
 
85
- def take_sample(b, basis, sample, m):
84
+ def take_sample(b, basis, sample, m, inv_dist):
86
85
  indices = []
86
+ tot_inv_dist = 0.0
87
87
  for i in range(len(basis)):
88
88
  if basis[i] == b:
89
89
  indices.append(i)
90
- indices = random.sample(indices, m)
91
- 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:
92
104
  sample |= 1 << i
93
105
 
94
106
  return sample
95
107
 
96
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
+
97
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):
98
149
  pauli_string = list(pauli_string)
99
150
  if len(pauli_string) != n_qubits:
@@ -125,6 +176,18 @@ def generate_otoc_samples(J=-1.0, h=2.0, z=4, theta=0.174532925199432957, t=5, n
125
176
  bases = { 'X': basis_x, 'Y': basis_y, 'Z': basis_z }
126
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() }
127
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
+
128
191
  samples = []
129
192
  for _ in range(shots):
130
193
  sample_3_axis = { 'X': 0, 'Y': 0, 'Z': 0 }
@@ -142,7 +205,7 @@ def generate_otoc_samples(J=-1.0, h=2.0, z=4, theta=0.174532925199432957, t=5, n
142
205
  # Second dimension: permutation within Hamming weight
143
206
  z_count = basis.count('Z')
144
207
  if z_count > m:
145
- 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])
146
209
  continue
147
210
  m -= z_count
148
211
  sample_3_axis[key] = take_all('Z', basis, sample_3_axis[key])
@@ -151,14 +214,14 @@ def generate_otoc_samples(J=-1.0, h=2.0, z=4, theta=0.174532925199432957, t=5, n
151
214
 
152
215
  i_count = basis.count('I')
153
216
  if i_count > m:
154
- 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])
155
218
  continue
156
219
  m -= i_count
157
220
  sample_3_axis[key] = take_all('I', basis, sample_3_axis[key])
158
221
  if m == 0:
159
222
  continue
160
223
 
161
- 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])
162
225
 
163
226
  sample = 0
164
227
  j = 0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pyqrackising
3
- Version: 9.3.9
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.9',
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