Skip to content

Commit 9657759

Browse files
(Anthropic) Claude caught a bug, suggested an optimization
1 parent bfb8298 commit 9657759

4 files changed

Lines changed: 9 additions & 6 deletions

File tree

pyqrackising/spin_glass_solver.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,8 @@ def pick_gray_seeds(best_theta, thread_count, gray_seed_multiple, G_m, n, is_spi
108108
energies[s] = compute_cut_diff_between(best_theta, seed, G_m, n)
109109
seeds[s] = seed
110110

111-
indices = np.argsort(energies)[::-1]
111+
indices = np.argpartition(energies, -thread_count)[-thread_count:]
112+
indices = indices[np.argsort(energies[indices])[::-1]]
112113
best_seeds = np.empty((thread_count, n), dtype=np.bool_)
113114
best_energies = np.empty(thread_count, dtype=dtype)
114115
for i in prange(thread_count):
@@ -295,7 +296,7 @@ def run_gray_search_opencl(
295296
blocks = (n + 63) // 64
296297
offset = best_x * blocks
297298
for b in range(blocks):
298-
s = max_theta_host[best_x]
299+
s = max_theta_host[offset + b]
299300
b_offset = b << 6
300301
for i in range(64):
301302
j = b_offset + i

pyqrackising/spin_glass_solver_sparse.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,8 @@ def pick_gray_seeds(best_theta, thread_count, gray_seed_multiple, G_data, G_rows
142142
energies[s] = compute_cut_sparse(seed, G_data, G_rows, G_cols, n)
143143
seeds[s] = seed
144144

145-
indices = np.argsort(energies)[::-1]
145+
indices = np.argpartition(energies, -thread_count)[-thread_count:]
146+
indices = indices[np.argsort(energies[indices])[::-1]]
146147
best_seeds = np.empty((thread_count, n), dtype=np.bool_)
147148
best_energies = np.empty(thread_count, dtype=dtype)
148149
for i in prange(thread_count):
@@ -362,7 +363,7 @@ def run_gray_search_opencl(
362363
blocks = (n + 63) // 64
363364
offset = best_x * blocks
364365
for b in range(blocks):
365-
s = max_theta_host[best_x]
366+
s = max_theta_host[offset + b]
366367
b_offset = b << 6
367368
for i in range(64):
368369
j = b_offset + i

pyqrackising/spin_glass_solver_streaming.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,8 @@ def pick_gray_seeds(best_theta, thread_count, gray_seed_multiple, G_func, nodes,
9999
energies[s] = compute_cut_diff_between_streaming(best_theta, seed, G_func, nodes, n)
100100
seeds[s] = seed
101101

102-
indices = np.argsort(energies)[::-1]
102+
indices = np.argpartition(energies, -thread_count)[-thread_count:]
103+
indices = indices[np.argsort(energies[indices])[::-1]]
103104
best_seeds = np.empty((thread_count, n), dtype=np.bool_)
104105
best_energies = np.empty(thread_count, dtype=dtype)
105106
for i in prange(thread_count):

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
setup(
99
name="pyqrackising",
10-
version="9.11.2",
10+
version="9.11.3",
1111
author="Dan Strano",
1212
author_email="stranoj@gmail.com",
1313
description="Fast MAXCUT, TSP, and sampling heuristics from near-ideal transverse field Ising model (TFIM)",

0 commit comments

Comments
 (0)