PyQrackIsing 1.26.1__tar.gz → 1.26.3__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.26.1/PyQrackIsing.egg-info → pyqrackising-1.26.3}/PKG-INFO +1 -1
  2. {pyqrackising-1.26.1 → pyqrackising-1.26.3}/PyQrackIsing/maxcut_tfim.py +42 -58
  3. {pyqrackising-1.26.1 → pyqrackising-1.26.3}/PyQrackIsing/spin_glass_solver.py +2 -3
  4. {pyqrackising-1.26.1 → pyqrackising-1.26.3/PyQrackIsing.egg-info}/PKG-INFO +1 -1
  5. {pyqrackising-1.26.1 → pyqrackising-1.26.3}/pyproject.toml +1 -1
  6. {pyqrackising-1.26.1 → pyqrackising-1.26.3}/setup.py +1 -1
  7. {pyqrackising-1.26.1 → pyqrackising-1.26.3}/CMakeLists.txt +0 -0
  8. {pyqrackising-1.26.1 → pyqrackising-1.26.3}/LICENSE.md +0 -0
  9. {pyqrackising-1.26.1 → pyqrackising-1.26.3}/MANIFEST.in +0 -0
  10. {pyqrackising-1.26.1 → pyqrackising-1.26.3}/PyQrackIsing/__init__.py +0 -0
  11. {pyqrackising-1.26.1 → pyqrackising-1.26.3}/PyQrackIsing/_pyqrack_ising.cpp +0 -0
  12. {pyqrackising-1.26.1 → pyqrackising-1.26.3}/PyQrackIsing/generate_tfim_samples.py +0 -0
  13. {pyqrackising-1.26.1 → pyqrackising-1.26.3}/PyQrackIsing/tfim_magnetization.py +0 -0
  14. {pyqrackising-1.26.1 → pyqrackising-1.26.3}/PyQrackIsing/tfim_square_magnetization.py +0 -0
  15. {pyqrackising-1.26.1 → pyqrackising-1.26.3}/PyQrackIsing/tsp_symmetric.py +0 -0
  16. {pyqrackising-1.26.1 → pyqrackising-1.26.3}/PyQrackIsing.egg-info/SOURCES.txt +0 -0
  17. {pyqrackising-1.26.1 → pyqrackising-1.26.3}/PyQrackIsing.egg-info/dependency_links.txt +0 -0
  18. {pyqrackising-1.26.1 → pyqrackising-1.26.3}/PyQrackIsing.egg-info/not-zip-safe +0 -0
  19. {pyqrackising-1.26.1 → pyqrackising-1.26.3}/PyQrackIsing.egg-info/top_level.txt +0 -0
  20. {pyqrackising-1.26.1 → pyqrackising-1.26.3}/README.md +0 -0
  21. {pyqrackising-1.26.1 → pyqrackising-1.26.3}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: PyQrackIsing
3
- Version: 1.26.1
3
+ Version: 1.26.3
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
@@ -162,7 +162,7 @@ def local_repulsion_choice(adjacency, degrees, weights, n, m):
162
162
 
163
163
  weights = weights.copy()
164
164
  chosen = np.zeros(m, dtype=np.int32) # store chosen indices
165
- available = np.ones(n, dtype=np.int32) # 1 = available, 0 = not
165
+ available = np.ones(n, dtype=np.bool_) # True = available, False = not
166
166
  mask = np.zeros(n, dtype=np.bool_)
167
167
  chosen_count = 0
168
168
 
@@ -170,7 +170,7 @@ def local_repulsion_choice(adjacency, degrees, weights, n, m):
170
170
  # Count available
171
171
  total_w = 0.0
172
172
  for i in range(n):
173
- if available[i] == 1:
173
+ if available[i]:
174
174
  total_w += weights[i]
175
175
  if total_w <= 0:
176
176
  break
@@ -180,7 +180,7 @@ def local_repulsion_choice(adjacency, degrees, weights, n, m):
180
180
  cum = 0.0
181
181
  node = -1
182
182
  for i in range(n):
183
- if available[i] == 1:
183
+ if available[i]:
184
184
  cum += weights[i] / total_w
185
185
  if r < cum:
186
186
  node = i
@@ -192,22 +192,38 @@ def local_repulsion_choice(adjacency, degrees, weights, n, m):
192
192
  # Select node
193
193
  chosen[chosen_count] = node
194
194
  chosen_count += 1
195
- available[node] = 0
196
- mask[node] = 1
195
+ available[node] = False
196
+ mask[node] = True
197
197
 
198
198
  # Repulsion: penalize neighbors
199
- deg = degrees[node]
200
- for j in range(deg):
199
+ for j in range(degrees[node]):
201
200
  nbr = adjacency[node, j]
202
- if nbr >= 0 and available[nbr] == 1:
201
+ if nbr < 0:
202
+ break
203
+ if available[nbr]:
203
204
  weights[nbr] *= 0.5 # tunable penalty factor
204
205
 
205
206
  return mask
206
207
 
207
208
 
209
+ @njit
210
+ def compute_energy(sample, G_m, n_qubits):
211
+ energy = 0
212
+ for u in range(n_qubits):
213
+ for v in range(u + 1, n_qubits):
214
+ eigen = 1 if sample[u] == sample[v] else -1
215
+ energy += G_m[u, v] * eigen
216
+
217
+ return energy
218
+
219
+
208
220
  @njit(parallel=True)
209
- def local_repulsion_choice_sample(shots, thresholds, adjacency, degrees, weights, n):
210
- samples = np.empty((shots, n), dtype=np.bool_) # (shots × n) boolean mask array
221
+ def sample_for_solution(G_m, shots, thresholds, degrees, J_eff, n):
222
+ adjacency = compute_adjacency(G_m, degrees.max())
223
+ weights = 1.0 / (1.0 + (2 ** -52) - J_eff)
224
+
225
+ best_solution = np.zeros(n, dtype=np.bool_)
226
+ best_energy = compute_energy(best_solution, G_m, n)
211
227
 
212
228
  for s in prange(shots):
213
229
  # First dimension: Hamming weight
@@ -218,40 +234,18 @@ def local_repulsion_choice_sample(shots, thresholds, adjacency, degrees, weights
218
234
  m += 1
219
235
 
220
236
  # 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)
237
+ sample = local_repulsion_choice(adjacency, degrees, weights, n, m)
235
238
 
236
- return samples
239
+ energy = compute_energy(sample, G_m, n)
240
+ if energy < best_energy:
241
+ best_energy = energy
242
+ best_solution = sample
237
243
 
238
-
239
- def evaluate_cut_edges(G_m, samples):
240
- n_qubits = len(G_m)
241
- best_value = float("-inf")
242
- best_solution = None
243
- best_cut_edges = None
244
-
245
- for state in samples:
246
- cut_edges = []
247
- cut_value = 0
248
- for u in range(n_qubits):
249
- for v in range(u + 1, n_qubits):
250
- if ((state >> u) & 1) != ((state >> v) & 1):
251
- cut_value += G_m[u, v]
252
- if cut_value > best_value:
253
- best_value = cut_value
254
- best_solution = state
244
+ best_value = 0
245
+ for u in range(n):
246
+ for v in range(u + 1, n):
247
+ if best_solution[u] != best_solution[v]:
248
+ best_value += G_m[u, v]
255
249
 
256
250
  return best_solution, float(best_value)
257
251
 
@@ -313,11 +307,11 @@ def init_theta(delta_t, tot_t, h_mult, n_qubits, J_eff, degrees):
313
307
 
314
308
  return theta
315
309
 
316
- @njit
317
- def compute_adjacency(G_m):
310
+ @njit(parallel=True)
311
+ def compute_adjacency(G_m, max_degree):
318
312
  n_qubits = len(G_m)
319
- adjacency = np.full((n_qubits, n_qubits), -1, dtype=np.int32)
320
- for i in range(n_qubits):
313
+ adjacency = np.full((n_qubits, max_degree), -1, dtype=np.int32)
314
+ for i in prange(n_qubits):
321
315
  k = 0
322
316
  for j in range(n_qubits):
323
317
  if i == j:
@@ -329,11 +323,6 @@ def compute_adjacency(G_m):
329
323
  return adjacency
330
324
 
331
325
 
332
- # By Gemini (Google Search AI)
333
- def int_to_bitstring(integer, length):
334
- return (bin(integer)[2:].zfill(length))[::-1]
335
-
336
-
337
326
  def maxcut_tfim(
338
327
  G,
339
328
  quality=None,
@@ -398,14 +387,9 @@ def maxcut_tfim(
398
387
  else:
399
388
  maxcut_hamming_cdf(n_qubits, J_eff, degrees, quality, thresholds)
400
389
 
401
- adjacency = compute_adjacency(G_m)
402
- weights = 1.0 / (1.0 + (2 ** -53) - J_eff)
403
- # We only need unique instances
404
- samples = list(set(mask_array_to_python_ints(local_repulsion_choice_sample(shots, thresholds, adjacency, degrees, weights, n_qubits))))
405
-
406
- best_solution, best_value = evaluate_cut_edges(G_m, samples)
390
+ best_solution, best_value = sample_for_solution(G_m, shots, thresholds, degrees, J_eff, n_qubits)
407
391
 
408
- bit_string = int_to_bitstring(best_solution, n_qubits)
392
+ bit_string = "".join(["1" if b else "0" for b in best_solution])
409
393
  bit_list = list(bit_string)
410
394
  l, r = [], []
411
395
  for i in range(len(bit_list)):
@@ -23,9 +23,8 @@ def compute_energy(theta_bits, G_m):
23
23
  energy = 0
24
24
  for u in range(n_qubits):
25
25
  for v in range(u + 1, n_qubits):
26
- spin_u = 1 if theta_bits[u] else -1
27
- spin_v = 1 if theta_bits[v] else -1
28
- energy += G_m[u, v] * spin_u * spin_v
26
+ eigen = 1 if theta_bits[u] == theta_bits[v] else -1
27
+ energy += G_m[u, v] * eigen
29
28
 
30
29
  return energy
31
30
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: PyQrackIsing
3
- Version: 1.26.1
3
+ Version: 1.26.3
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.26.1"
15
+ version = "1.26.3"
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.26.1',
54
+ version='1.26.3',
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
File without changes