PyQrackIsing 1.14.9__tar.gz → 1.14.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 (21) hide show
  1. {pyqrackising-1.14.9/PyQrackIsing.egg-info → pyqrackising-1.14.10}/PKG-INFO +1 -1
  2. {pyqrackising-1.14.9 → pyqrackising-1.14.10}/PyQrackIsing/maxcut_tfim.py +81 -39
  3. {pyqrackising-1.14.9 → pyqrackising-1.14.10/PyQrackIsing.egg-info}/PKG-INFO +1 -1
  4. {pyqrackising-1.14.9 → pyqrackising-1.14.10}/pyproject.toml +1 -1
  5. {pyqrackising-1.14.9 → pyqrackising-1.14.10}/setup.py +1 -1
  6. {pyqrackising-1.14.9 → pyqrackising-1.14.10}/CMakeLists.txt +0 -0
  7. {pyqrackising-1.14.9 → pyqrackising-1.14.10}/LICENSE.md +0 -0
  8. {pyqrackising-1.14.9 → pyqrackising-1.14.10}/MANIFEST.in +0 -0
  9. {pyqrackising-1.14.9 → pyqrackising-1.14.10}/PyQrackIsing/__init__.py +0 -0
  10. {pyqrackising-1.14.9 → pyqrackising-1.14.10}/PyQrackIsing/_pyqrack_ising.cpp +0 -0
  11. {pyqrackising-1.14.9 → pyqrackising-1.14.10}/PyQrackIsing/generate_tfim_samples.py +0 -0
  12. {pyqrackising-1.14.9 → pyqrackising-1.14.10}/PyQrackIsing/spin_glass_solver.py +0 -0
  13. {pyqrackising-1.14.9 → pyqrackising-1.14.10}/PyQrackIsing/tfim_magnetization.py +0 -0
  14. {pyqrackising-1.14.9 → pyqrackising-1.14.10}/PyQrackIsing/tfim_square_magnetization.py +0 -0
  15. {pyqrackising-1.14.9 → pyqrackising-1.14.10}/PyQrackIsing/tsp_symmetric.py +0 -0
  16. {pyqrackising-1.14.9 → pyqrackising-1.14.10}/PyQrackIsing.egg-info/SOURCES.txt +0 -0
  17. {pyqrackising-1.14.9 → pyqrackising-1.14.10}/PyQrackIsing.egg-info/dependency_links.txt +0 -0
  18. {pyqrackising-1.14.9 → pyqrackising-1.14.10}/PyQrackIsing.egg-info/not-zip-safe +0 -0
  19. {pyqrackising-1.14.9 → pyqrackising-1.14.10}/PyQrackIsing.egg-info/top_level.txt +0 -0
  20. {pyqrackising-1.14.9 → pyqrackising-1.14.10}/README.md +0 -0
  21. {pyqrackising-1.14.9 → pyqrackising-1.14.10}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: PyQrackIsing
3
- Version: 1.14.9
3
+ Version: 1.14.10
4
4
  Summary: Near-ideal closed-form solutions for transverse field Ising model (TFIM)
5
5
  Home-page: https://github.com/vm6502q/PyQrackIsing
6
6
  Author: Dan Strano
@@ -147,52 +147,95 @@ def maxcut_hamming_cdf(n_qubits, J_func, degrees, quality, hamming_prob):
147
147
 
148
148
 
149
149
  # Written by Elara (OpenAI custom GPT)
150
- def local_repulsion_choice(nodes, adjacency, degrees, weights, n, m):
150
+ @njit
151
+ def local_repulsion_choice(adjacency, degrees, weights, n, m):
151
152
  """
152
- Pick m nodes (bit positions) out of n with repulsion bias:
153
+
154
+ Pick m nodes out of n with repulsion bias:
153
155
  - High-degree nodes are already less likely
154
156
  - After choosing a node, its neighbors' probabilities are further reduced
157
+ adjacency: 2D int array (n x max_deg), padded with -1
158
+
159
+ degrees: int array of shape (n,)
160
+ weights: float64 array of shape (n,)
155
161
  """
156
162
 
157
- # Base weights: inverse degree
158
- # degrees = np.array([len(adjacency.get(i, [])) for i in range(n)], dtype=np.float64)
159
- # weights = 1.0 / (degrees + 1.0)
160
163
  weights = weights.copy()
161
-
162
- chosen = []
163
- available = set(range(len(nodes)))
164
+ chosen = np.zeros(m, dtype=np.int32) # store chosen indices
165
+ available = np.ones(n, dtype=np.int32) # 1 = available, 0 = not
166
+ mask = np.zeros(n, dtype=np.bool_)
167
+ chosen_count = 0
164
168
 
165
169
  for _ in range(m):
166
- if not available:
170
+ # Count available
171
+ total_w = 0.0
172
+ for i in range(n):
173
+ if available[i] == 1:
174
+ total_w += weights[i]
175
+ if total_w <= 0:
167
176
  break
168
177
 
169
- # Normalize weights over remaining nodes
170
- sub_weights = np.array([weights[i] for i in available], dtype=np.float64)
171
- sub_weights /= sub_weights.sum()
172
- sub_nodes = list(available)
173
-
174
- # Sample one node
175
- idx = np.random.choice(len(sub_nodes), p=sub_weights)
176
- node = sub_nodes[idx]
177
- chosen.append(node)
178
+ # Normalize & sample
179
+ r = np.random.rand()
180
+ cum = 0.0
181
+ node = -1
182
+ for i in range(n):
183
+ if available[i] == 1:
184
+ cum += weights[i] / total_w
185
+ if r < cum:
186
+ node = i
187
+ break
188
+
189
+ if node == -1:
190
+ continue
178
191
 
179
- # Remove node from available
180
- available.remove(node)
192
+ # Select node
193
+ chosen[chosen_count] = node
194
+ chosen_count += 1
195
+ available[node] = 0
196
+ mask[node] = 1
181
197
 
182
198
  # Repulsion: penalize neighbors
183
- for nbr in adjacency.get(nodes[node], []):
184
- idx = nodes.index(nbr)
185
- if idx in available:
186
- weights[idx] *= 0.5 # halve neighbor's weight (tunable!)
187
-
188
- # Build integer mask
189
- mask = 0
190
- for pos in chosen:
191
- mask |= 1 << pos
199
+ deg = degrees[node]
200
+ for j in range(deg):
201
+ nbr = adjacency[node, j]
202
+ if nbr >= 0 and available[nbr] == 1:
203
+ weights[nbr] *= 0.5 # tunable penalty factor
192
204
 
193
205
  return mask
194
206
 
195
207
 
208
+ @njit(parallel=True)
209
+ def local_repulsion_choice_sample(shots, thresholds, adjacency, degrees, weights, n):
210
+ samples = np.zeros((shots, n), dtype=np.bool_) # (shots × n) boolean mask array
211
+
212
+ for s in prange(shots):
213
+ # First dimension: Hamming weight
214
+ mag_prob = np.random.random()
215
+ m = 0
216
+ while thresholds[m] < mag_prob:
217
+ m += 1
218
+ m += 1
219
+
220
+ # Second dimension: permutation within Hamming weight
221
+ samples[s, :] = local_repulsion_choice(adjacency, degrees, weights, n, m)
222
+
223
+ return samples
224
+
225
+
226
+ def mask_array_to_python_ints(masks):
227
+ samples = []
228
+ for mask in masks:
229
+ sample = 0
230
+ for b in reversed(mask):
231
+ sample <<= 1
232
+ if b:
233
+ sample |= 1
234
+ samples.append(sample)
235
+
236
+ return samples
237
+
238
+
196
239
  def evaluate_cut_edges(samples, edge_keys, edge_values):
197
240
  best_value = float("-inf")
198
241
  best_solution = None
@@ -324,18 +367,17 @@ def maxcut_tfim(
324
367
  maxcut_hamming_cdf(n_qubits, J_eff, degrees, quality, thresholds)
325
368
 
326
369
  G_dict = nx.to_dict_of_lists(G)
370
+ max_degree = max(len(x) for x in G_dict.values())
371
+ adjacency = np.full((len(nodes), max_degree), -1, dtype=np.int32)
372
+ for i in range(len(nodes)):
373
+ adj = G_dict.get(nodes[i], [])
374
+ for j in range(len(adj)):
375
+ adjacency[i, j] = nodes.index(adj[j])
376
+
327
377
  J_max = max(J_eff)
328
378
  weights = 1.0 / (1.0 + (J_max - J_eff))
329
- samples = []
330
- for s in range(shots):
331
- # First dimension: Hamming weight
332
- mag_prob = np.random.random()
333
- m = 0
334
- while thresholds[m] < mag_prob:
335
- m += 1
336
- m += 1
337
- # Second dimension: permutation within Hamming weight
338
- samples.append(local_repulsion_choice(nodes, G_dict, degrees, weights, n_qubits, m))
379
+ # We only need unique instances
380
+ samples = list(set(mask_array_to_python_ints(local_repulsion_choice_sample(shots, thresholds, adjacency, degrees, weights, n_qubits))))
339
381
 
340
382
  edge_keys = []
341
383
  edge_values = []
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: PyQrackIsing
3
- Version: 1.14.9
3
+ Version: 1.14.10
4
4
  Summary: Near-ideal closed-form solutions for transverse field Ising model (TFIM)
5
5
  Home-page: https://github.com/vm6502q/PyQrackIsing
6
6
  Author: Dan Strano
@@ -12,7 +12,7 @@ build-backend = "setuptools.build_meta"
12
12
 
13
13
  [project]
14
14
  name = "PyQrackIsing"
15
- version = "1.14.9"
15
+ version = "1.14.10"
16
16
  requires-python = ">=3.8"
17
17
  description = "Near-ideal closed-form solutions for transverse field Ising model (TFIM)"
18
18
  readme = {file = "README.txt", content-type = "text/markdown"}
@@ -51,7 +51,7 @@ ext_modules = [CMakeExtension('tfim_sampler')]
51
51
 
52
52
  setup(
53
53
  name='PyQrackIsing',
54
- version='1.14.9',
54
+ version='1.14.10',
55
55
  author='Dan Strano',
56
56
  author_email='stranoj@gmail.com',
57
57
  description='Near-ideal closed-form solutions for transverse field Ising model (TFIM)',
File without changes
File without changes
File without changes