PyQrackIsing 9.15.3__tar.gz → 9.15.4__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.
- {pyqrackising-9.15.3/pyqrackising.egg-info → pyqrackising-9.15.4}/PKG-INFO +1 -1
- {pyqrackising-9.15.3 → pyqrackising-9.15.4}/pyproject.toml +1 -1
- {pyqrackising-9.15.3 → pyqrackising-9.15.4}/pyqrackising/maxcut_tfim_util.py +49 -0
- {pyqrackising-9.15.3 → pyqrackising-9.15.4}/pyqrackising/spin_glass_solver_sparse.py +49 -102
- {pyqrackising-9.15.3 → pyqrackising-9.15.4/pyqrackising.egg-info}/PKG-INFO +1 -1
- {pyqrackising-9.15.3 → pyqrackising-9.15.4}/setup.py +1 -1
- {pyqrackising-9.15.3 → pyqrackising-9.15.4}/LICENSE.md +0 -0
- {pyqrackising-9.15.3 → pyqrackising-9.15.4}/MANIFEST.in +0 -0
- {pyqrackising-9.15.3 → pyqrackising-9.15.4}/README.md +0 -0
- {pyqrackising-9.15.3 → pyqrackising-9.15.4}/pyqrackising/__init__.py +0 -0
- {pyqrackising-9.15.3 → pyqrackising-9.15.4}/pyqrackising/convert_tensor_network_to_tsp.py +0 -0
- {pyqrackising-9.15.3 → pyqrackising-9.15.4}/pyqrackising/generate_tfim_samples.py +0 -0
- {pyqrackising-9.15.3 → pyqrackising-9.15.4}/pyqrackising/kernels.cl +0 -0
- {pyqrackising-9.15.3 → pyqrackising-9.15.4}/pyqrackising/maxcut_tfim.py +0 -0
- {pyqrackising-9.15.3 → pyqrackising-9.15.4}/pyqrackising/maxcut_tfim_sparse.py +0 -0
- {pyqrackising-9.15.3 → pyqrackising-9.15.4}/pyqrackising/maxcut_tfim_streaming.py +0 -0
- {pyqrackising-9.15.3 → pyqrackising-9.15.4}/pyqrackising/otoc.py +0 -0
- {pyqrackising-9.15.3 → pyqrackising-9.15.4}/pyqrackising/solve_maxcut_bnb.py +0 -0
- {pyqrackising-9.15.3 → pyqrackising-9.15.4}/pyqrackising/solve_maxcut_bnb_sparse.py +0 -0
- {pyqrackising-9.15.3 → pyqrackising-9.15.4}/pyqrackising/solve_maxcut_bnb_streaming.py +0 -0
- {pyqrackising-9.15.3 → pyqrackising-9.15.4}/pyqrackising/solve_maxcut_exact.py +0 -0
- {pyqrackising-9.15.3 → pyqrackising-9.15.4}/pyqrackising/solve_maxcut_exact_sparse.py +0 -0
- {pyqrackising-9.15.3 → pyqrackising-9.15.4}/pyqrackising/solve_maxcut_exact_streaming.py +0 -0
- {pyqrackising-9.15.3 → pyqrackising-9.15.4}/pyqrackising/spin_glass_solver.py +0 -0
- {pyqrackising-9.15.3 → pyqrackising-9.15.4}/pyqrackising/spin_glass_solver_streaming.py +0 -0
- {pyqrackising-9.15.3 → pyqrackising-9.15.4}/pyqrackising/tfim_magnetization.py +0 -0
- {pyqrackising-9.15.3 → pyqrackising-9.15.4}/pyqrackising/tfim_square_magnetization.py +0 -0
- {pyqrackising-9.15.3 → pyqrackising-9.15.4}/pyqrackising/tsp.py +0 -0
- {pyqrackising-9.15.3 → pyqrackising-9.15.4}/pyqrackising/tsp_maxcut.py +0 -0
- {pyqrackising-9.15.3 → pyqrackising-9.15.4}/pyqrackising.egg-info/SOURCES.txt +0 -0
- {pyqrackising-9.15.3 → pyqrackising-9.15.4}/pyqrackising.egg-info/dependency_links.txt +0 -0
- {pyqrackising-9.15.3 → pyqrackising-9.15.4}/pyqrackising.egg-info/not-zip-safe +0 -0
- {pyqrackising-9.15.3 → pyqrackising-9.15.4}/pyqrackising.egg-info/requires.txt +0 -0
- {pyqrackising-9.15.3 → pyqrackising-9.15.4}/pyqrackising.egg-info/top_level.txt +0 -0
- {pyqrackising-9.15.3 → pyqrackising-9.15.4}/setup.cfg +0 -0
|
@@ -7,7 +7,7 @@ build-backend = "setuptools.build_meta"
|
|
|
7
7
|
|
|
8
8
|
[project]
|
|
9
9
|
name = "pyqrackising"
|
|
10
|
-
version = "9.15.
|
|
10
|
+
version = "9.15.4"
|
|
11
11
|
requires-python = ">=3.8"
|
|
12
12
|
description = "Fast MAXCUT, TSP, and sampling heuristics from near-ideal transverse field Ising model (TFIM)"
|
|
13
13
|
readme = {file = "README.txt", content-type = "text/markdown"}
|
|
@@ -416,6 +416,55 @@ def compute_cut_sparse(sample, G_data, G_rows, G_cols, n_qubits):
|
|
|
416
416
|
return cut
|
|
417
417
|
|
|
418
418
|
|
|
419
|
+
@njit(cache=True)
|
|
420
|
+
def compute_cut_diff_sparse(u, sample, G_data, G_rows, G_cols, n_qubits):
|
|
421
|
+
energy = 0.0
|
|
422
|
+
u_bit = sample[u]
|
|
423
|
+
for col in range(G_rows[u], G_rows[u + 1]):
|
|
424
|
+
v = G_cols[col]
|
|
425
|
+
val = G_data[col]
|
|
426
|
+
energy += -val if u_bit == sample[v] else val
|
|
427
|
+
|
|
428
|
+
return energy
|
|
429
|
+
|
|
430
|
+
|
|
431
|
+
@njit(cache=True)
|
|
432
|
+
def compute_energy_diff_sparse(u, sample, G_data, G_rows, G_cols, n_qubits):
|
|
433
|
+
energy = 0.0
|
|
434
|
+
u_bit = sample[u]
|
|
435
|
+
for col in range(G_rows[u], G_rows[u + 1]):
|
|
436
|
+
v = G_cols[col]
|
|
437
|
+
val = G_data[col]
|
|
438
|
+
energy += -val if u_bit == sample[v] else val
|
|
439
|
+
|
|
440
|
+
return energy
|
|
441
|
+
|
|
442
|
+
|
|
443
|
+
@njit(cache=True)
|
|
444
|
+
def compute_cut_diff_2_sparse(k, l, sample, G_data, G_rows, G_cols, n_qubits):
|
|
445
|
+
if l < k:
|
|
446
|
+
t = k
|
|
447
|
+
k = l
|
|
448
|
+
l = t
|
|
449
|
+
energy = 0.0
|
|
450
|
+
k_bit = sample[k]
|
|
451
|
+
l_bit = sample[l]
|
|
452
|
+
for col in range(G_rows[k], G_rows[k + 1]):
|
|
453
|
+
v = G_cols[col]
|
|
454
|
+
if v == l:
|
|
455
|
+
continue
|
|
456
|
+
val = G_data[col]
|
|
457
|
+
energy += -val if k_bit == sample[v] else val
|
|
458
|
+
for col in range(G_rows[l], G_rows[l + 1]):
|
|
459
|
+
v = G_cols[col]
|
|
460
|
+
if v == k:
|
|
461
|
+
continue
|
|
462
|
+
val = G_data[col]
|
|
463
|
+
energy += -val if l_bit == sample[v] else val
|
|
464
|
+
|
|
465
|
+
return energy
|
|
466
|
+
|
|
467
|
+
|
|
419
468
|
@njit(cache=True)
|
|
420
469
|
def compute_energy_streaming(sample, G_func, nodes, n_qubits):
|
|
421
470
|
energy = 0.0
|
|
@@ -2,6 +2,8 @@ from .maxcut_tfim_sparse import maxcut_tfim_sparse
|
|
|
2
2
|
from .maxcut_tfim_util import (
|
|
3
3
|
compute_cut_sparse,
|
|
4
4
|
compute_energy_sparse,
|
|
5
|
+
compute_cut_diff_sparse,
|
|
6
|
+
compute_cut_diff_2_sparse,
|
|
5
7
|
get_cut,
|
|
6
8
|
gray_code_next,
|
|
7
9
|
gray_mutation,
|
|
@@ -35,31 +37,19 @@ gnl = opencl_context.GRAY_NODE_LIMIT
|
|
|
35
37
|
@njit(parallel=True, cache=True)
|
|
36
38
|
def run_single_bit_flips(best_theta, is_spin_glass, G_data, G_rows, G_cols):
|
|
37
39
|
n = len(best_theta)
|
|
38
|
-
|
|
39
|
-
|
|
40
|
+
energies = np.empty(n, dtype=dtype)
|
|
40
41
|
for i in prange(n):
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
v_bit = best_theta[v]
|
|
49
|
-
old_cut = old_bit != v_bit
|
|
50
|
-
new_cut = new_bit != v_bit
|
|
51
|
-
if old_cut != new_cut:
|
|
52
|
-
delta += val if new_cut else -val
|
|
53
|
-
if is_spin_glass:
|
|
54
|
-
delta *= dtype(2)
|
|
55
|
-
deltas[i] = delta
|
|
56
|
-
|
|
57
|
-
best_index = np.argmax(deltas)
|
|
58
|
-
best_delta = deltas[best_index]
|
|
42
|
+
state = best_theta.copy()
|
|
43
|
+
state[i] = not state[i]
|
|
44
|
+
energies[i] = compute_cut_diff_sparse(i, state, G_data, G_rows, G_cols, n)
|
|
45
|
+
best_index = np.argmax(energies)
|
|
46
|
+
best_energy = energies[best_index]
|
|
47
|
+
if is_spin_glass:
|
|
48
|
+
best_energy *= 2.0
|
|
59
49
|
best_state = best_theta.copy()
|
|
60
50
|
best_state[best_index] = not best_state[best_index]
|
|
61
51
|
|
|
62
|
-
return
|
|
52
|
+
return best_energy, best_state
|
|
63
53
|
|
|
64
54
|
|
|
65
55
|
@njit(parallel=True, cache=True)
|
|
@@ -69,7 +59,7 @@ def run_double_bit_flips(best_theta, is_spin_glass, G_data, G_rows, G_cols, thre
|
|
|
69
59
|
thread_batch = (combo_count + thread_count - 1) // thread_count
|
|
70
60
|
|
|
71
61
|
states = np.empty((thread_count, n), dtype=np.bool_)
|
|
72
|
-
|
|
62
|
+
energies = np.empty(thread_count, dtype=dtype)
|
|
73
63
|
|
|
74
64
|
for t in prange(thread_count):
|
|
75
65
|
s = int(t)
|
|
@@ -85,49 +75,21 @@ def run_double_bit_flips(best_theta, is_spin_glass, G_data, G_rows, G_cols, thre
|
|
|
85
75
|
break
|
|
86
76
|
j = int(c + i + 1)
|
|
87
77
|
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
delta = dtype(0)
|
|
94
|
-
|
|
95
|
-
for col in range(G_rows[i], G_rows[i + 1]):
|
|
96
|
-
v = G_cols[col]
|
|
97
|
-
if v == j:
|
|
98
|
-
continue # k-l edge: both flip, XOR unchanged, zero delta
|
|
99
|
-
val = G_data[col]
|
|
100
|
-
v_bit = best_theta[v]
|
|
101
|
-
if (old_i != v_bit) != (new_i != v_bit):
|
|
102
|
-
delta += val if (new_i != v_bit) else -val
|
|
103
|
-
|
|
104
|
-
for col in range(G_rows[j], G_rows[j + 1]):
|
|
105
|
-
v = G_cols[col]
|
|
106
|
-
if v == i:
|
|
107
|
-
continue
|
|
108
|
-
val = G_data[col]
|
|
109
|
-
v_bit = best_theta[v]
|
|
110
|
-
if (old_j != v_bit) != (new_j != v_bit):
|
|
111
|
-
delta += val if (new_j != v_bit) else -val
|
|
112
|
-
|
|
113
|
-
if is_spin_glass:
|
|
114
|
-
delta *= dtype(2)
|
|
115
|
-
|
|
116
|
-
states[t, i] = new_i
|
|
117
|
-
states[t, j] = new_j
|
|
118
|
-
# copy other bits (only need to track i,j changes)
|
|
119
|
-
for k in range(n):
|
|
120
|
-
if k != i and k != j:
|
|
121
|
-
states[t, k] = best_theta[k]
|
|
122
|
-
deltas[t] = delta
|
|
78
|
+
state = best_theta.copy()
|
|
79
|
+
state[i] = not state[i]
|
|
80
|
+
state[j] = not state[j]
|
|
81
|
+
|
|
82
|
+
states[t], energies[t] = state, compute_cut_diff_2_sparse(i, j, state, G_data, G_rows, G_cols, n)
|
|
123
83
|
|
|
124
84
|
s += thread_batch
|
|
125
85
|
|
|
126
|
-
best_index = np.argmax(
|
|
127
|
-
|
|
86
|
+
best_index = np.argmax(energies)
|
|
87
|
+
best_energy = energies[best_index]
|
|
88
|
+
if is_spin_glass:
|
|
89
|
+
best_energy *= 2.0
|
|
128
90
|
best_state = states[best_index]
|
|
129
91
|
|
|
130
|
-
return
|
|
92
|
+
return best_energy, best_state
|
|
131
93
|
|
|
132
94
|
|
|
133
95
|
@njit(parallel=True, cache=True)
|
|
@@ -167,50 +129,30 @@ def pick_gray_seeds(best_theta, thread_count, gray_seed_multiple, G_data, G_rows
|
|
|
167
129
|
|
|
168
130
|
|
|
169
131
|
@njit(parallel=True, cache=True)
|
|
170
|
-
def run_gray_optimization(
|
|
171
|
-
best_theta,
|
|
172
|
-
iterators,
|
|
173
|
-
energies,
|
|
174
|
-
gray_iterations,
|
|
175
|
-
thread_count,
|
|
176
|
-
is_spin_glass,
|
|
177
|
-
G_data,
|
|
178
|
-
G_rows,
|
|
179
|
-
G_cols,
|
|
180
|
-
):
|
|
132
|
+
def run_gray_optimization(best_theta, iterators, gray_iterations, thread_count, is_spin_glass, G_data, G_rows, G_cols):
|
|
181
133
|
n = len(best_theta)
|
|
182
134
|
thread_iterations = (gray_iterations + thread_count - 1) // thread_count
|
|
183
135
|
blocks = (n + 63) >> 6
|
|
136
|
+
energies = np.empty(thread_count, dtype=dtype)
|
|
184
137
|
|
|
185
138
|
for i in prange(thread_count):
|
|
186
139
|
iterator = iterators[i]
|
|
187
|
-
best_energy = energies[i]
|
|
188
140
|
for curr_idx in range(thread_iterations):
|
|
141
|
+
best_energy = 0.0
|
|
189
142
|
for block in range(blocks):
|
|
190
143
|
flip_bit = gray_code_next(iterator, curr_idx, block << 6)
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
delta = dtype(0)
|
|
195
|
-
for col in range(G_rows[flip_bit], G_rows[flip_bit + 1]):
|
|
196
|
-
v = G_cols[col]
|
|
197
|
-
val = G_data[col]
|
|
198
|
-
v_bit = iterator[v]
|
|
199
|
-
old_cut = old_bit != v_bit
|
|
200
|
-
new_cut = new_bit != v_bit
|
|
201
|
-
if old_cut != new_cut:
|
|
202
|
-
delta += val if new_cut else -val
|
|
203
|
-
if is_spin_glass:
|
|
204
|
-
delta *= dtype(2)
|
|
205
|
-
if delta > dtype(0):
|
|
206
|
-
best_energy += delta
|
|
144
|
+
energy = compute_cut_diff(flip_bit, iterator, G_data, G_rows, G_cols, n)
|
|
145
|
+
if energy > 0.0:
|
|
146
|
+
best_energy += energy
|
|
207
147
|
else:
|
|
148
|
+
# Revert iterator
|
|
208
149
|
iterator[flip_bit] = not iterator[flip_bit]
|
|
209
|
-
|
|
210
|
-
energies[i] = best_energy
|
|
150
|
+
energies[i] += best_energy
|
|
211
151
|
|
|
212
152
|
best_index = np.argmax(energies)
|
|
213
153
|
best_energy = energies[best_index]
|
|
154
|
+
if is_spin_glass:
|
|
155
|
+
best_energy *= 2.0
|
|
214
156
|
best_state = iterators[best_index]
|
|
215
157
|
|
|
216
158
|
return best_energy, best_state
|
|
@@ -220,6 +162,7 @@ def run_bit_flips_opencl(
|
|
|
220
162
|
is_double,
|
|
221
163
|
n,
|
|
222
164
|
kernel,
|
|
165
|
+
best_energy,
|
|
223
166
|
theta,
|
|
224
167
|
theta_buf,
|
|
225
168
|
G_data_buf,
|
|
@@ -276,12 +219,12 @@ def run_bit_flips_opencl(
|
|
|
276
219
|
# Queue read for results we might not need
|
|
277
220
|
cl.enqueue_copy(queue, max_index_host, max_index_buf)
|
|
278
221
|
|
|
279
|
-
# Find global
|
|
222
|
+
# Find global minimum
|
|
280
223
|
best_x = np.argmax(max_energy_host)
|
|
281
224
|
energy = max_energy_host[best_x]
|
|
282
225
|
|
|
283
226
|
if energy <= 0.0:
|
|
284
|
-
# No improvement:
|
|
227
|
+
# No improvement: we can exit early
|
|
285
228
|
return 0.0, theta
|
|
286
229
|
|
|
287
230
|
# We need the best index
|
|
@@ -360,9 +303,9 @@ def run_gray_search_opencl(
|
|
|
360
303
|
best_x = np.argmax(max_energy_host)
|
|
361
304
|
energy = max_energy_host[best_x]
|
|
362
305
|
|
|
363
|
-
if energy <=
|
|
306
|
+
if energy <= 0.0:
|
|
364
307
|
# No improvement: we can exit early
|
|
365
|
-
return
|
|
308
|
+
return 0.0, theta
|
|
366
309
|
|
|
367
310
|
# We need the best index
|
|
368
311
|
queue.finish()
|
|
@@ -715,6 +658,7 @@ def spin_glass_solver_sparse(
|
|
|
715
658
|
False,
|
|
716
659
|
n_qubits,
|
|
717
660
|
single_bit_flips_kernel,
|
|
661
|
+
max_energy,
|
|
718
662
|
best_theta,
|
|
719
663
|
theta_buf,
|
|
720
664
|
G_data_buf,
|
|
@@ -725,8 +669,8 @@ def spin_glass_solver_sparse(
|
|
|
725
669
|
)
|
|
726
670
|
else:
|
|
727
671
|
energy, state = run_single_bit_flips(best_theta, is_spin_glass, G_m.data, G_m.indptr, G_m.indices)
|
|
728
|
-
if energy >
|
|
729
|
-
max_energy
|
|
672
|
+
if energy > max_energy:
|
|
673
|
+
max_energy = energy
|
|
730
674
|
best_theta = state
|
|
731
675
|
improved = True
|
|
732
676
|
continue
|
|
@@ -738,6 +682,7 @@ def spin_glass_solver_sparse(
|
|
|
738
682
|
True,
|
|
739
683
|
n_qubits,
|
|
740
684
|
double_bit_flips_kernel,
|
|
685
|
+
max_energy,
|
|
741
686
|
best_theta,
|
|
742
687
|
theta_buf,
|
|
743
688
|
G_data_buf,
|
|
@@ -748,8 +693,8 @@ def spin_glass_solver_sparse(
|
|
|
748
693
|
)
|
|
749
694
|
else:
|
|
750
695
|
energy, state = run_double_bit_flips(best_theta, is_spin_glass, G_m.data, G_m.indptr, G_m.indices, thread_count)
|
|
751
|
-
if energy >
|
|
752
|
-
max_energy
|
|
696
|
+
if energy > max_energy:
|
|
697
|
+
max_energy = energy
|
|
753
698
|
best_theta = state
|
|
754
699
|
improved = True
|
|
755
700
|
continue
|
|
@@ -815,6 +760,7 @@ def spin_glass_solver_sparse(
|
|
|
815
760
|
False,
|
|
816
761
|
n_qubits,
|
|
817
762
|
single_bit_flips_kernel,
|
|
763
|
+
max_energy,
|
|
818
764
|
reheat_theta,
|
|
819
765
|
theta_buf,
|
|
820
766
|
G_data_buf,
|
|
@@ -825,8 +771,8 @@ def spin_glass_solver_sparse(
|
|
|
825
771
|
)
|
|
826
772
|
else:
|
|
827
773
|
energy, state = run_single_bit_flips(reheat_theta, is_spin_glass, G_m.data, G_m.indptr, G_m.indices)
|
|
828
|
-
if energy >
|
|
829
|
-
max_energy
|
|
774
|
+
if energy > max_energy:
|
|
775
|
+
max_energy = energy
|
|
830
776
|
best_theta = state
|
|
831
777
|
improved = True
|
|
832
778
|
continue
|
|
@@ -841,6 +787,7 @@ def spin_glass_solver_sparse(
|
|
|
841
787
|
True,
|
|
842
788
|
n_qubits,
|
|
843
789
|
double_bit_flips_kernel,
|
|
790
|
+
max_energy,
|
|
844
791
|
reheat_theta,
|
|
845
792
|
theta_buf,
|
|
846
793
|
G_data_buf,
|
|
@@ -851,8 +798,8 @@ def spin_glass_solver_sparse(
|
|
|
851
798
|
)
|
|
852
799
|
else:
|
|
853
800
|
energy, state = run_double_bit_flips(reheat_theta, is_spin_glass, G_m.data, G_m.indptr, G_m.indices, thread_count)
|
|
854
|
-
if energy >
|
|
855
|
-
max_energy
|
|
801
|
+
if energy > max_energy:
|
|
802
|
+
max_energy = energy
|
|
856
803
|
best_theta = state
|
|
857
804
|
improved = True
|
|
858
805
|
|
|
@@ -7,7 +7,7 @@ with open(README_PATH) as readme_file:
|
|
|
7
7
|
|
|
8
8
|
setup(
|
|
9
9
|
name="pyqrackising",
|
|
10
|
-
version="9.15.
|
|
10
|
+
version="9.15.4",
|
|
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
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|