PyQrackIsing 9.0.0__tar.gz → 9.1.0__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.0.0/pyqrackising.egg-info → pyqrackising-9.1.0}/PKG-INFO +1 -1
- {pyqrackising-9.0.0 → pyqrackising-9.1.0}/README.md +2 -2
- {pyqrackising-9.0.0 → pyqrackising-9.1.0}/pyproject.toml +1 -1
- {pyqrackising-9.0.0 → pyqrackising-9.1.0}/pyqrackising/maxcut_tfim.py +39 -23
- {pyqrackising-9.0.0 → pyqrackising-9.1.0}/pyqrackising/maxcut_tfim_sparse.py +40 -24
- {pyqrackising-9.0.0 → pyqrackising-9.1.0}/pyqrackising/maxcut_tfim_streaming.py +39 -23
- {pyqrackising-9.0.0 → pyqrackising-9.1.0}/pyqrackising/maxcut_tfim_util.py +2 -7
- {pyqrackising-9.0.0 → pyqrackising-9.1.0}/pyqrackising/spin_glass_solver.py +57 -16
- {pyqrackising-9.0.0 → pyqrackising-9.1.0}/pyqrackising/spin_glass_solver_sparse.py +57 -16
- {pyqrackising-9.0.0 → pyqrackising-9.1.0}/pyqrackising/spin_glass_solver_streaming.py +58 -16
- {pyqrackising-9.0.0 → pyqrackising-9.1.0/pyqrackising.egg-info}/PKG-INFO +1 -1
- {pyqrackising-9.0.0 → pyqrackising-9.1.0}/setup.py +1 -1
- {pyqrackising-9.0.0 → pyqrackising-9.1.0}/LICENSE.md +0 -0
- {pyqrackising-9.0.0 → pyqrackising-9.1.0}/MANIFEST.in +0 -0
- {pyqrackising-9.0.0 → pyqrackising-9.1.0}/pyqrackising/__init__.py +0 -0
- {pyqrackising-9.0.0 → pyqrackising-9.1.0}/pyqrackising/convert_tensor_network_to_tsp.py +0 -0
- {pyqrackising-9.0.0 → pyqrackising-9.1.0}/pyqrackising/generate_tfim_samples.py +0 -0
- {pyqrackising-9.0.0 → pyqrackising-9.1.0}/pyqrackising/kernels.cl +0 -0
- {pyqrackising-9.0.0 → pyqrackising-9.1.0}/pyqrackising/tfim_magnetization.py +0 -0
- {pyqrackising-9.0.0 → pyqrackising-9.1.0}/pyqrackising/tfim_square_magnetization.py +0 -0
- {pyqrackising-9.0.0 → pyqrackising-9.1.0}/pyqrackising/tsp.py +0 -0
- {pyqrackising-9.0.0 → pyqrackising-9.1.0}/pyqrackising/tsp_maxcut.py +0 -0
- {pyqrackising-9.0.0 → pyqrackising-9.1.0}/pyqrackising.egg-info/SOURCES.txt +0 -0
- {pyqrackising-9.0.0 → pyqrackising-9.1.0}/pyqrackising.egg-info/dependency_links.txt +0 -0
- {pyqrackising-9.0.0 → pyqrackising-9.1.0}/pyqrackising.egg-info/not-zip-safe +0 -0
- {pyqrackising-9.0.0 → pyqrackising-9.1.0}/pyqrackising.egg-info/top_level.txt +0 -0
- {pyqrackising-9.0.0 → pyqrackising-9.1.0}/setup.cfg +0 -0
|
@@ -73,10 +73,10 @@ def generate_spin_glass_graph(n_nodes=16, degree=3, seed=None):
|
|
|
73
73
|
|
|
74
74
|
|
|
75
75
|
G = generate_spin_glass_graph(n_nodes=64, seed=42)
|
|
76
|
-
solution_bit_string, cut_value, node_groups, energy = spin_glass_solver(G, quality=6, shots=None, anneal_t=8.0, anneal_h=8.0, is_spin_glass=True, best_guess=None, is_maxcut_gpu=True)
|
|
76
|
+
solution_bit_string, cut_value, node_groups, energy = spin_glass_solver(G, quality=6, shots=None, anneal_t=8.0, anneal_h=8.0, is_spin_glass=True, best_guess=None, is_maxcut_gpu=True, gray_iterations=None, gray_seed_multiple=None)
|
|
77
77
|
# solution_bit_string, cut_value, node_groups, energy = spin_glass_solver(G, best_guess=maxcut_tfim(G, quality=6)[0])
|
|
78
78
|
```
|
|
79
|
-
We also provide `spin_glass_solver_sparse(G)` and `spin_glass_solver_streaming(G_func, nodes)`. `best_guess` gives the option to seed the algorithm with a best guess as to the maximal cut (as an integer, binary string, or list of booleans). By default, `spin_glass_solver()` uses `maxcut_tfim(G)` with passed-through `quality` as `best_guess`, which typically works well, but it could be seeded with higher `maxcut_tfim()` `quality` or Goemans-Williamson, for example. `is_spin_glass` controls whether the solver optimizes for cut value or spin-glass energy. This function is designed with a sign convention for weights such that it can immediately be used as a MAXCUT solver itself: you might need to reverse the sign convention on your weights for spin glass graphs, but this is only convention.
|
|
79
|
+
We also provide `spin_glass_solver_sparse(G)` and `spin_glass_solver_streaming(G_func, nodes)`. `best_guess` gives the option to seed the algorithm with a best guess as to the maximal cut (as an integer, binary string, or list of booleans). By default, `spin_glass_solver()` uses `maxcut_tfim(G)` with passed-through `quality` as `best_guess`, which typically works well, but it could be seeded with higher `maxcut_tfim()` `quality` or Goemans-Williamson, for example. `is_spin_glass` controls whether the solver optimizes for cut value or spin-glass energy. This function is designed with a sign convention for weights such that it can immediately be used as a MAXCUT solver itself: you might need to reverse the sign convention on your weights for spin glass graphs, but this is only convention. `gray_iterations` gives manual control over how many iterations are carried out of a parallel Gray-code search on `best_guess`. `gray_seed_multiple` controls how many parallel search seeds (as a multiple of your CPU thread count) are tested for the best parallel seeds, and a value of `1` will perfectly cover the search space without collision if your node count is a power of 2.
|
|
80
80
|
|
|
81
81
|
From the MAXCUT solvers, we provide a (recursive) Traveling Salesman Problem (TSP) solver:
|
|
82
82
|
```py
|
|
@@ -10,7 +10,7 @@ build-backend = "setuptools.build_meta"
|
|
|
10
10
|
|
|
11
11
|
[project]
|
|
12
12
|
name = "pyqrackising"
|
|
13
|
-
version = "9.
|
|
13
|
+
version = "9.1.0"
|
|
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,6 +1,7 @@
|
|
|
1
1
|
import networkx as nx
|
|
2
2
|
import numpy as np
|
|
3
3
|
from numba import njit, prange
|
|
4
|
+
import os
|
|
4
5
|
|
|
5
6
|
from .maxcut_tfim_util import compute_cut, compute_energy, convert_bool_to_uint, get_cut, get_cut_base, make_G_m_buf, make_theta_buf, maxcut_hamming_cdf, opencl_context, sample_mag, setup_opencl, bit_pick
|
|
6
7
|
|
|
@@ -59,13 +60,14 @@ def local_repulsion_choice(G_m, repulsion_base, n, m, s):
|
|
|
59
60
|
|
|
60
61
|
|
|
61
62
|
@njit(parallel=True)
|
|
62
|
-
def sample_measurement(G_m, shots, thresholds, repulsion_base, is_spin_glass):
|
|
63
|
-
|
|
63
|
+
def sample_measurement(G_m, shots, thread_count, thresholds, repulsion_base, is_spin_glass):
|
|
64
|
+
shot_segment = (max(1, shots >> 1) + thread_count - 1) // thread_count
|
|
65
|
+
shots = shot_segment * thread_count
|
|
64
66
|
n = len(G_m)
|
|
65
67
|
|
|
66
|
-
solutions = np.empty((
|
|
67
|
-
energies = np.
|
|
68
|
-
|
|
68
|
+
solutions = np.empty((thread_count, n), dtype=np.bool_)
|
|
69
|
+
energies = np.full(thread_count, np.finfo(dtype).min, dtype=dtype)
|
|
70
|
+
|
|
69
71
|
best_solution = solutions[0]
|
|
70
72
|
best_energy = -float("inf")
|
|
71
73
|
|
|
@@ -73,23 +75,35 @@ def sample_measurement(G_m, shots, thresholds, repulsion_base, is_spin_glass):
|
|
|
73
75
|
while improved:
|
|
74
76
|
improved = False
|
|
75
77
|
if is_spin_glass:
|
|
76
|
-
for
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
78
|
+
for i in prange(thread_count):
|
|
79
|
+
s_offset = i * shot_segment
|
|
80
|
+
for j in range(shot_segment):
|
|
81
|
+
s = s_offset + j
|
|
82
|
+
|
|
83
|
+
# First dimension: Hamming weight
|
|
84
|
+
m = sample_mag(thresholds)
|
|
85
|
+
|
|
86
|
+
# Second dimension: permutation within Hamming weight
|
|
87
|
+
sample = local_repulsion_choice(G_m, repulsion_base, n, m, s)
|
|
88
|
+
energy = compute_energy(sample, G_m, n)
|
|
89
|
+
|
|
90
|
+
if energy > energies[i]:
|
|
91
|
+
solutions[i], energies[i] = sample, energy
|
|
84
92
|
else:
|
|
85
|
-
for
|
|
86
|
-
|
|
87
|
-
|
|
93
|
+
for i in prange(thread_count):
|
|
94
|
+
s_offset = i * shot_segment
|
|
95
|
+
for j in range(shot_segment):
|
|
96
|
+
s = s_offset + j
|
|
97
|
+
|
|
98
|
+
# First dimension: Hamming weight
|
|
99
|
+
m = sample_mag(thresholds)
|
|
88
100
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
101
|
+
# Second dimension: permutation within Hamming weight
|
|
102
|
+
sample = local_repulsion_choice(G_m, repulsion_base, n, m, s)
|
|
103
|
+
energy = compute_cut(sample, G_m, n)
|
|
104
|
+
|
|
105
|
+
if energy > energies[i]:
|
|
106
|
+
solutions[i], energies[i] = sample, energy
|
|
93
107
|
|
|
94
108
|
best_index = np.argmax(energies)
|
|
95
109
|
energy = energies[best_index]
|
|
@@ -164,14 +178,14 @@ def init_J_and_z(G_m, repulsion_base):
|
|
|
164
178
|
|
|
165
179
|
|
|
166
180
|
@njit
|
|
167
|
-
def cpu_footer(shots, quality, n_qubits, G_m, nodes, is_spin_glass, anneal_t, anneal_h, repulsion_base):
|
|
181
|
+
def cpu_footer(shots, thread_count, quality, n_qubits, G_m, nodes, is_spin_glass, anneal_t, anneal_h, repulsion_base):
|
|
168
182
|
J_eff, degrees = init_J_and_z(G_m, repulsion_base)
|
|
169
183
|
hamming_prob = maxcut_hamming_cdf(n_qubits, J_eff, degrees, quality, anneal_t, anneal_h)
|
|
170
184
|
|
|
171
185
|
degrees = None
|
|
172
186
|
J_eff = None
|
|
173
187
|
|
|
174
|
-
best_solution, best_value = sample_measurement(G_m, shots, hamming_prob, repulsion_base, is_spin_glass)
|
|
188
|
+
best_solution, best_value = sample_measurement(G_m, shots, thread_count, hamming_prob, repulsion_base, is_spin_glass)
|
|
175
189
|
|
|
176
190
|
bit_string, l, r = get_cut(best_solution, nodes, n_qubits)
|
|
177
191
|
|
|
@@ -297,7 +311,9 @@ def maxcut_tfim(
|
|
|
297
311
|
is_opencl = is_maxcut_gpu and IS_OPENCL_AVAILABLE
|
|
298
312
|
|
|
299
313
|
if not is_opencl:
|
|
300
|
-
|
|
314
|
+
thread_count = os.cpu_count() ** 2
|
|
315
|
+
|
|
316
|
+
bit_string, best_value, partition = cpu_footer(shots, thread_count, quality, n_qubits, G_m, nodes, is_spin_glass, anneal_t, anneal_h, repulsion_base)
|
|
301
317
|
|
|
302
318
|
if best_value < 0.0:
|
|
303
319
|
# Best cut is trivial partition, all/empty
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import networkx as nx
|
|
2
2
|
import numpy as np
|
|
3
3
|
from numba import njit, prange
|
|
4
|
+
import os
|
|
4
5
|
|
|
5
6
|
from .maxcut_tfim_util import binary_search, compute_cut_sparse, compute_energy_sparse, convert_bool_to_uint, get_cut, get_cut_base, make_G_m_csr_buf, make_theta_buf, maxcut_hamming_cdf, opencl_context, sample_mag, setup_opencl, bit_pick, to_scipy_sparse_upper_triangular
|
|
6
7
|
|
|
@@ -69,13 +70,14 @@ def local_repulsion_choice(G_data, G_rows, G_cols, repulsion_base, n, m, s):
|
|
|
69
70
|
|
|
70
71
|
|
|
71
72
|
@njit(parallel=True)
|
|
72
|
-
def sample_measurement(G_data, G_rows, G_cols, shots, thresholds, repulsion_base, is_spin_glass):
|
|
73
|
-
|
|
73
|
+
def sample_measurement(G_data, G_rows, G_cols, shots, thread_count, thresholds, repulsion_base, is_spin_glass):
|
|
74
|
+
shot_segment = (max(1, shots >> 1) + thread_count - 1) // thread_count
|
|
75
|
+
shots = shot_segment * thread_count
|
|
74
76
|
n = G_rows.shape[0] - 1
|
|
75
77
|
|
|
76
|
-
solutions = np.empty((
|
|
77
|
-
energies = np.
|
|
78
|
-
|
|
78
|
+
solutions = np.empty((thread_count, n), dtype=np.bool_)
|
|
79
|
+
energies = np.full(thread_count, np.finfo(dtype).min, dtype=dtype)
|
|
80
|
+
|
|
79
81
|
best_solution = solutions[0]
|
|
80
82
|
best_energy = -float("inf")
|
|
81
83
|
|
|
@@ -83,23 +85,35 @@ def sample_measurement(G_data, G_rows, G_cols, shots, thresholds, repulsion_base
|
|
|
83
85
|
while improved:
|
|
84
86
|
improved = False
|
|
85
87
|
if is_spin_glass:
|
|
86
|
-
for
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
88
|
+
for i in prange(thread_count):
|
|
89
|
+
s_offset = i * shot_segment
|
|
90
|
+
for j in range(shot_segment):
|
|
91
|
+
s = s_offset + j
|
|
92
|
+
|
|
93
|
+
# First dimension: Hamming weight
|
|
94
|
+
m = sample_mag(thresholds)
|
|
95
|
+
|
|
96
|
+
# Second dimension: permutation within Hamming weight
|
|
97
|
+
sample = local_repulsion_choice(G_data, G_rows, G_cols, repulsion_base, n, m, s)
|
|
98
|
+
energy = compute_energy_sparse(sample, G_data, G_rows, G_cols, n)
|
|
99
|
+
|
|
100
|
+
if energy > energies[i]:
|
|
101
|
+
solutions[i], energies[i] = sample, energy
|
|
94
102
|
else:
|
|
95
|
-
for
|
|
96
|
-
|
|
97
|
-
|
|
103
|
+
for i in prange(thread_count):
|
|
104
|
+
s_offset = i * shot_segment
|
|
105
|
+
for j in range(shot_segment):
|
|
106
|
+
s = s_offset + j
|
|
107
|
+
|
|
108
|
+
# First dimension: Hamming weight
|
|
109
|
+
m = sample_mag(thresholds)
|
|
98
110
|
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
111
|
+
# Second dimension: permutation within Hamming weight
|
|
112
|
+
sample = local_repulsion_choice(G_data, G_rows, G_cols, repulsion_base, n, m, s)
|
|
113
|
+
energy = compute_cut_sparse(sample, G_data, G_rows, G_cols, n)
|
|
114
|
+
|
|
115
|
+
if energy > energies[i]:
|
|
116
|
+
solutions[i], energies[i] = sample, energy
|
|
103
117
|
|
|
104
118
|
best_index = np.argmax(energies)
|
|
105
119
|
energy = energies[best_index]
|
|
@@ -109,7 +123,7 @@ def sample_measurement(G_data, G_rows, G_cols, shots, thresholds, repulsion_base
|
|
|
109
123
|
improved = True
|
|
110
124
|
|
|
111
125
|
if is_spin_glass:
|
|
112
|
-
best_energy = compute_cut_sparse(
|
|
126
|
+
best_energy = compute_cut_sparse(sample, G_data, G_rows, G_cols, n)
|
|
113
127
|
|
|
114
128
|
return best_solution, best_energy
|
|
115
129
|
|
|
@@ -174,10 +188,10 @@ def init_J_and_z(G_m, repulsion_base):
|
|
|
174
188
|
|
|
175
189
|
|
|
176
190
|
@njit
|
|
177
|
-
def cpu_footer(J_eff, degrees, shots, quality, n_qubits, G_data, G_rows, G_cols, nodes, is_spin_glass, anneal_t, anneal_h, repulsion_base):
|
|
191
|
+
def cpu_footer(J_eff, degrees, shots, thread_count, quality, n_qubits, G_data, G_rows, G_cols, nodes, is_spin_glass, anneal_t, anneal_h, repulsion_base):
|
|
178
192
|
hamming_prob = maxcut_hamming_cdf(n_qubits, J_eff, degrees, quality, anneal_t, anneal_h)
|
|
179
193
|
|
|
180
|
-
best_solution, best_value = sample_measurement(G_data, G_rows, G_cols, shots, hamming_prob, repulsion_base, is_spin_glass)
|
|
194
|
+
best_solution, best_value = sample_measurement(G_data, G_rows, G_cols, shots, thread_count, hamming_prob, repulsion_base, is_spin_glass)
|
|
181
195
|
|
|
182
196
|
bit_string, l, r = get_cut(best_solution, nodes, n_qubits)
|
|
183
197
|
|
|
@@ -312,7 +326,9 @@ def maxcut_tfim_sparse(
|
|
|
312
326
|
is_opencl = is_maxcut_gpu and IS_OPENCL_AVAILABLE
|
|
313
327
|
|
|
314
328
|
if not is_opencl:
|
|
315
|
-
|
|
329
|
+
thread_count = os.cpu_count() ** 2
|
|
330
|
+
|
|
331
|
+
bit_string, best_value, partition = cpu_footer(J_eff, degrees, shots, thread_count, quality, n_qubits, G_m.data, G_m.indptr, G_m.indices, nodes, is_spin_glass, anneal_t, anneal_h, repulsion_base)
|
|
316
332
|
|
|
317
333
|
if best_value < 0.0:
|
|
318
334
|
# Best cut is trivial partition, all/empty
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import networkx as nx
|
|
2
2
|
import numpy as np
|
|
3
3
|
from numba import njit, prange
|
|
4
|
+
import os
|
|
4
5
|
|
|
5
6
|
from .maxcut_tfim_util import compute_cut_streaming, compute_energy_streaming, get_cut, get_cut_base, maxcut_hamming_cdf, opencl_context, sample_mag, bit_pick
|
|
6
7
|
|
|
@@ -52,11 +53,12 @@ def local_repulsion_choice(G_func, nodes, repulsion_base, n, m, s):
|
|
|
52
53
|
|
|
53
54
|
|
|
54
55
|
@njit(parallel=True)
|
|
55
|
-
def sample_measurement(G_func, nodes, shots, thresholds, n, repulsion_base, is_spin_glass):
|
|
56
|
-
|
|
56
|
+
def sample_measurement(G_func, nodes, shots, thread_count, thresholds, n, repulsion_base, is_spin_glass):
|
|
57
|
+
shot_segment = (max(1, shots >> 1) + thread_count - 1) // thread_count
|
|
58
|
+
shots = shot_segment * thread_count
|
|
57
59
|
|
|
58
|
-
solutions = np.empty((
|
|
59
|
-
energies = np.
|
|
60
|
+
solutions = np.empty((thread_count, n), dtype=np.bool_)
|
|
61
|
+
energies = np.full(thread_count, np.finfo(dtype).min, dtype=dtype)
|
|
60
62
|
|
|
61
63
|
best_solution = solutions[0]
|
|
62
64
|
best_energy = -float("inf")
|
|
@@ -65,23 +67,35 @@ def sample_measurement(G_func, nodes, shots, thresholds, n, repulsion_base, is_s
|
|
|
65
67
|
while improved:
|
|
66
68
|
improved = False
|
|
67
69
|
if is_spin_glass:
|
|
68
|
-
for
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
70
|
+
for i in prange(thread_count):
|
|
71
|
+
s_offset = i * shot_segment
|
|
72
|
+
for j in range(shot_segment):
|
|
73
|
+
s = s_offset + j
|
|
74
|
+
|
|
75
|
+
# First dimension: Hamming weight
|
|
76
|
+
m = sample_mag(thresholds)
|
|
77
|
+
|
|
78
|
+
# Second dimension: permutation within Hamming weight
|
|
79
|
+
sample = local_repulsion_choice(G_func, nodes, repulsion_base, n, m, s)
|
|
80
|
+
energy = compute_energy_streaming(sample, G_func, nodes, n)
|
|
81
|
+
|
|
82
|
+
if energy > energies[i]:
|
|
83
|
+
solutions[i], energies[i] = sample, energy
|
|
76
84
|
else:
|
|
77
|
-
for
|
|
78
|
-
|
|
79
|
-
|
|
85
|
+
for i in prange(thread_count):
|
|
86
|
+
s_offset = i * shot_segment
|
|
87
|
+
for j in range(shot_segment):
|
|
88
|
+
s = s_offset + j
|
|
80
89
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
90
|
+
# First dimension: Hamming weight
|
|
91
|
+
m = sample_mag(thresholds)
|
|
92
|
+
|
|
93
|
+
# Second dimension: permutation within Hamming weight
|
|
94
|
+
sample = local_repulsion_choice(G_func, nodes, repulsion_base, n, m, s)
|
|
95
|
+
energy = compute_cut_streaming(sample, G_func, nodes, n)
|
|
96
|
+
|
|
97
|
+
if energy > energies[i]:
|
|
98
|
+
solutions[i], energies[i] = sample, energy
|
|
85
99
|
|
|
86
100
|
best_index = np.argmax(energies)
|
|
87
101
|
energy = energies[best_index]
|
|
@@ -91,7 +105,7 @@ def sample_measurement(G_func, nodes, shots, thresholds, n, repulsion_base, is_s
|
|
|
91
105
|
improved = True
|
|
92
106
|
|
|
93
107
|
if is_spin_glass:
|
|
94
|
-
best_energy = compute_cut_streaming(
|
|
108
|
+
best_energy = compute_cut_streaming(sample, G_func, nodes, n)
|
|
95
109
|
|
|
96
110
|
return best_solution, best_energy
|
|
97
111
|
|
|
@@ -132,14 +146,14 @@ def find_G_min(G_func, nodes, n_nodes):
|
|
|
132
146
|
|
|
133
147
|
|
|
134
148
|
@njit
|
|
135
|
-
def cpu_footer(shots, quality, n_qubits, G_min, G_func, nodes, is_spin_glass, anneal_t, anneal_h, repulsion_base):
|
|
149
|
+
def cpu_footer(shots, thread_count, quality, n_qubits, G_min, G_func, nodes, is_spin_glass, anneal_t, anneal_h, repulsion_base):
|
|
136
150
|
J_eff, degrees = init_J_and_z(G_func, nodes, G_min, repulsion_base)
|
|
137
151
|
hamming_prob = maxcut_hamming_cdf(n_qubits, J_eff, degrees, quality, anneal_t, anneal_h)
|
|
138
152
|
|
|
139
153
|
degrees = None
|
|
140
154
|
J_eff = None
|
|
141
155
|
|
|
142
|
-
best_solution, best_value = sample_measurement(G_func, nodes, shots, hamming_prob, n_qubits, repulsion_base, is_spin_glass)
|
|
156
|
+
best_solution, best_value = sample_measurement(G_func, nodes, shots, thread_count, hamming_prob, n_qubits, repulsion_base, is_spin_glass)
|
|
143
157
|
|
|
144
158
|
bit_string, l, r = get_cut(best_solution, nodes, n_qubits)
|
|
145
159
|
|
|
@@ -191,7 +205,9 @@ def maxcut_tfim_streaming(
|
|
|
191
205
|
|
|
192
206
|
G_min = find_G_min(G_func, nodes, n_qubits)
|
|
193
207
|
|
|
194
|
-
|
|
208
|
+
thread_count = os.cpu_count() ** 2
|
|
209
|
+
|
|
210
|
+
bit_string, best_value, partition = cpu_footer(shots, thread_count, quality, n_qubits, G_min, G_func, nodes, is_spin_glass, anneal_t, anneal_h, repulsion_base)
|
|
195
211
|
|
|
196
212
|
if best_value < 0.0:
|
|
197
213
|
# Best cut is trivial partition, all/empty
|
|
@@ -484,19 +484,14 @@ def bit_pick(weights, used, n):
|
|
|
484
484
|
|
|
485
485
|
@njit
|
|
486
486
|
def gray_code_next(state, curr_idx):
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
prev = curr_idx - 1
|
|
491
|
-
curr = curr_idx
|
|
487
|
+
prev = curr_idx
|
|
488
|
+
curr = curr_idx + 1
|
|
492
489
|
prev = prev ^ (prev >> 1)
|
|
493
490
|
curr = curr ^ (curr >> 1)
|
|
494
491
|
diff = prev ^ curr
|
|
495
492
|
flip_bit = int(np.log2(diff))
|
|
496
493
|
state[flip_bit] = not state[flip_bit]
|
|
497
494
|
|
|
498
|
-
return state.copy()
|
|
499
|
-
|
|
500
495
|
|
|
501
496
|
@njit
|
|
502
497
|
def gray_mutation(index, seed_bits):
|
|
@@ -48,7 +48,7 @@ def run_double_bit_flips(best_theta, is_spin_glass, G_m):
|
|
|
48
48
|
n = len(best_theta)
|
|
49
49
|
|
|
50
50
|
states = np.empty((n, n), dtype=np.bool_)
|
|
51
|
-
energies = np.
|
|
51
|
+
energies = np.full(n, np.finfo(dtype).min, dtype=dtype)
|
|
52
52
|
|
|
53
53
|
if is_spin_glass:
|
|
54
54
|
for i in prange(n):
|
|
@@ -60,7 +60,8 @@ def run_double_bit_flips(best_theta, is_spin_glass, G_m):
|
|
|
60
60
|
state[j] = not state[j]
|
|
61
61
|
energy = compute_energy(state, G_m, n)
|
|
62
62
|
if energy > energies[i]:
|
|
63
|
-
states[i], energies[i] = state, energy
|
|
63
|
+
states[i], energies[i] = state.copy(), energy
|
|
64
|
+
state[j] = not state[j]
|
|
64
65
|
else:
|
|
65
66
|
for i in prange(n):
|
|
66
67
|
state = best_theta.copy()
|
|
@@ -71,7 +72,8 @@ def run_double_bit_flips(best_theta, is_spin_glass, G_m):
|
|
|
71
72
|
state[j] = not state[j]
|
|
72
73
|
energy = compute_cut(state, G_m, n)
|
|
73
74
|
if energy > energies[i]:
|
|
74
|
-
states[i], energies[i] = state, energy
|
|
75
|
+
states[i], energies[i] = state.copy(), energy
|
|
76
|
+
state[j] = not state[j]
|
|
75
77
|
|
|
76
78
|
best_index = np.argmax(energies)
|
|
77
79
|
best_energy = energies[best_index]
|
|
@@ -80,33 +82,60 @@ def run_double_bit_flips(best_theta, is_spin_glass, G_m):
|
|
|
80
82
|
return best_energy, best_state
|
|
81
83
|
|
|
82
84
|
|
|
85
|
+
@njit(parallel=True)
|
|
86
|
+
def pick_gray_seeds(best_theta, thread_count, gray_seed_multiple, G_m, n, is_spin_glass):
|
|
87
|
+
seed_count = thread_count * gray_seed_multiple
|
|
88
|
+
|
|
89
|
+
seeds = np.empty((seed_count, n), dtype=np.bool_)
|
|
90
|
+
energies = np.empty(seed_count, dtype=dtype)
|
|
91
|
+
|
|
92
|
+
if is_spin_glass:
|
|
93
|
+
for i in prange(seed_count):
|
|
94
|
+
seed = gray_mutation(i, best_theta)
|
|
95
|
+
energies[i] = compute_energy(seed, G_m, n)
|
|
96
|
+
seeds[i] = seed
|
|
97
|
+
else:
|
|
98
|
+
for i in prange(seed_count):
|
|
99
|
+
seed = gray_mutation(i, best_theta)
|
|
100
|
+
energies[i] = compute_cut(seed, G_m, n)
|
|
101
|
+
seeds[i] = seed
|
|
102
|
+
|
|
103
|
+
indices = np.argsort(energies)[::-1]
|
|
104
|
+
|
|
105
|
+
best_seeds = np.empty((thread_count, n), dtype=np.bool_)
|
|
106
|
+
best_energies = np.empty(thread_count, dtype=dtype)
|
|
107
|
+
|
|
108
|
+
for i in prange(thread_count):
|
|
109
|
+
idx = indices[i]
|
|
110
|
+
best_seeds[i] = seeds[idx]
|
|
111
|
+
best_energies[i] = energies[idx]
|
|
112
|
+
|
|
113
|
+
return best_seeds, best_energies
|
|
114
|
+
|
|
83
115
|
@njit(parallel=True)
|
|
84
116
|
def run_gray_optimization(best_theta, iterators, gray_iterations, thread_count, is_spin_glass, G_m):
|
|
85
117
|
n = len(best_theta)
|
|
86
|
-
thread_iterations = gray_iterations // thread_count
|
|
87
|
-
gray_iterations = (gray_iterations + thread_count - 1) // thread_count
|
|
118
|
+
thread_iterations = (gray_iterations + thread_count - 1) // thread_count
|
|
88
119
|
|
|
89
120
|
states = np.empty((thread_count, n), dtype=np.bool_)
|
|
90
|
-
energies = np.
|
|
121
|
+
energies = np.full(thread_count, np.finfo(dtype).min, dtype=dtype)
|
|
91
122
|
|
|
92
123
|
if is_spin_glass:
|
|
93
124
|
for i in prange(thread_count):
|
|
94
|
-
i_offset = i * thread_iterations
|
|
95
125
|
iterator = iterators[i]
|
|
96
126
|
for curr_idx in range(thread_iterations):
|
|
97
|
-
|
|
98
|
-
energy = compute_energy(
|
|
127
|
+
gray_code_next(iterator, curr_idx)
|
|
128
|
+
energy = compute_energy(iterator, G_m, n)
|
|
99
129
|
if energy > energies[i]:
|
|
100
|
-
states[i], energies[i] =
|
|
130
|
+
states[i], energies[i] = iterator.copy(), energy
|
|
101
131
|
else:
|
|
102
132
|
for i in prange(thread_count):
|
|
103
|
-
i_offset = i * thread_iterations
|
|
104
133
|
iterator = iterators[i]
|
|
105
134
|
for curr_idx in range(thread_iterations):
|
|
106
|
-
|
|
107
|
-
energy = compute_cut(
|
|
135
|
+
gray_code_next(iterator, curr_idx)
|
|
136
|
+
energy = compute_cut(iterator, G_m, n)
|
|
108
137
|
if energy > energies[i]:
|
|
109
|
-
states[i], energies[i] =
|
|
138
|
+
states[i], energies[i] = iterator.copy(), energy
|
|
110
139
|
|
|
111
140
|
best_index = np.argmax(energies)
|
|
112
141
|
best_energy = energies[best_index]
|
|
@@ -126,7 +155,8 @@ def spin_glass_solver(
|
|
|
126
155
|
anneal_h=None,
|
|
127
156
|
repulsion_base=None,
|
|
128
157
|
is_log=False,
|
|
129
|
-
gray_iterations=None
|
|
158
|
+
gray_iterations=None,
|
|
159
|
+
gray_seed_multiple=None
|
|
130
160
|
):
|
|
131
161
|
dtype = opencl_context.dtype
|
|
132
162
|
nodes = None
|
|
@@ -169,6 +199,9 @@ def spin_glass_solver(
|
|
|
169
199
|
if gray_iterations is None:
|
|
170
200
|
gray_iterations = n_qubits * os.cpu_count()
|
|
171
201
|
|
|
202
|
+
if gray_seed_multiple is None:
|
|
203
|
+
gray_seed_multiple = os.cpu_count()
|
|
204
|
+
|
|
172
205
|
max_energy = compute_energy(best_theta, G_m, n_qubits) if is_spin_glass else cut_value
|
|
173
206
|
|
|
174
207
|
thread_count = os.cpu_count() ** 2
|
|
@@ -193,7 +226,15 @@ def spin_glass_solver(
|
|
|
193
226
|
continue
|
|
194
227
|
|
|
195
228
|
# Gray code with default O(n^3)
|
|
196
|
-
iterators =
|
|
229
|
+
iterators, energies = pick_gray_seeds(best_theta, thread_count, gray_seed_multiple, G_m, n_qubits, is_spin_glass)
|
|
230
|
+
best_i = np.argmax(energies)
|
|
231
|
+
energy, state = energies[best_i], iterators[best_i]
|
|
232
|
+
if energy > max_energy:
|
|
233
|
+
max_energy = energy
|
|
234
|
+
best_theta = state
|
|
235
|
+
improved = True
|
|
236
|
+
continue
|
|
237
|
+
|
|
197
238
|
energy, state = run_gray_optimization(best_theta, iterators, gray_iterations, thread_count, is_spin_glass, G_m)
|
|
198
239
|
if energy > max_energy:
|
|
199
240
|
max_energy = energy
|
|
@@ -49,7 +49,7 @@ def run_double_bit_flips(best_theta, is_spin_glass, G_data, G_rows, G_cols):
|
|
|
49
49
|
n = len(best_theta)
|
|
50
50
|
|
|
51
51
|
states = np.empty((n, n), dtype=np.bool_)
|
|
52
|
-
energies = np.
|
|
52
|
+
energies = np.full(n, np.finfo(dtype).min, dtype=dtype)
|
|
53
53
|
|
|
54
54
|
if is_spin_glass:
|
|
55
55
|
for i in prange(n):
|
|
@@ -61,7 +61,8 @@ def run_double_bit_flips(best_theta, is_spin_glass, G_data, G_rows, G_cols):
|
|
|
61
61
|
state[j] = not state[j]
|
|
62
62
|
energy = compute_energy_sparse(state, G_data, G_rows, G_cols, n)
|
|
63
63
|
if energy > energies[i]:
|
|
64
|
-
states[i], energies[i] = state, energy
|
|
64
|
+
states[i], energies[i] = state.copy(), energy
|
|
65
|
+
state[j] = not state[j]
|
|
65
66
|
else:
|
|
66
67
|
for i in prange(n):
|
|
67
68
|
state = best_theta.copy()
|
|
@@ -72,7 +73,8 @@ def run_double_bit_flips(best_theta, is_spin_glass, G_data, G_rows, G_cols):
|
|
|
72
73
|
state[j] = not state[j]
|
|
73
74
|
energy = compute_cut_sparse(state, G_data, G_rows, G_cols, n)
|
|
74
75
|
if energy > energies[i]:
|
|
75
|
-
states[i], energies[i] = state, energy
|
|
76
|
+
states[i], energies[i] = state.copy(), energy
|
|
77
|
+
state[j] = not state[j]
|
|
76
78
|
|
|
77
79
|
best_index = np.argmax(energies)
|
|
78
80
|
best_energy = energies[best_index]
|
|
@@ -81,33 +83,60 @@ def run_double_bit_flips(best_theta, is_spin_glass, G_data, G_rows, G_cols):
|
|
|
81
83
|
return best_energy, best_state
|
|
82
84
|
|
|
83
85
|
|
|
86
|
+
@njit(parallel=True)
|
|
87
|
+
def pick_gray_seeds(best_theta, thread_count, gray_seed_multiple, G_data, G_rows, G_cols, n, is_spin_glass):
|
|
88
|
+
seed_count = thread_count * gray_seed_multiple
|
|
89
|
+
|
|
90
|
+
seeds = np.empty((seed_count, n), dtype=np.bool_)
|
|
91
|
+
energies = np.empty(seed_count, dtype=dtype)
|
|
92
|
+
|
|
93
|
+
if is_spin_glass:
|
|
94
|
+
for i in prange(seed_count):
|
|
95
|
+
seed = gray_mutation(i, best_theta)
|
|
96
|
+
energies[i] = compute_energy_sparse(seed, G_data, G_rows, G_cols, n)
|
|
97
|
+
seeds[i] = seed
|
|
98
|
+
else:
|
|
99
|
+
for i in prange(seed_count):
|
|
100
|
+
seed = gray_mutation(i, best_theta)
|
|
101
|
+
energies[i] = compute_cut_sparse(seed, G_data, G_rows, G_cols, n)
|
|
102
|
+
seeds[i] = seed
|
|
103
|
+
|
|
104
|
+
indices = np.argsort(energies)[::-1]
|
|
105
|
+
|
|
106
|
+
best_seeds = np.empty((thread_count, n), dtype=np.bool_)
|
|
107
|
+
best_energies = np.empty(thread_count, dtype=dtype)
|
|
108
|
+
|
|
109
|
+
for i in prange(thread_count):
|
|
110
|
+
idx = indices[i]
|
|
111
|
+
best_seeds[i] = seeds[idx]
|
|
112
|
+
best_energies[i] = energies[idx]
|
|
113
|
+
|
|
114
|
+
return best_seeds, best_energies
|
|
115
|
+
|
|
84
116
|
@njit(parallel=True)
|
|
85
117
|
def run_gray_optimization(best_theta, iterators, gray_iterations, thread_count, is_spin_glass, G_data, G_rows, G_cols):
|
|
86
118
|
n = len(best_theta)
|
|
87
|
-
thread_iterations = gray_iterations // thread_count
|
|
88
|
-
gray_iterations = (gray_iterations + thread_count - 1) // thread_count
|
|
119
|
+
thread_iterations = (gray_iterations + thread_count - 1) // thread_count
|
|
89
120
|
|
|
90
121
|
states = np.empty((thread_count, n), dtype=np.bool_)
|
|
91
|
-
energies = np.
|
|
122
|
+
energies = np.full(thread_count, np.finfo(dtype).min, dtype=dtype)
|
|
92
123
|
|
|
93
124
|
if is_spin_glass:
|
|
94
125
|
for i in prange(thread_count):
|
|
95
|
-
i_offset = i * thread_iterations
|
|
96
126
|
iterator = iterators[i]
|
|
97
127
|
for curr_idx in range(thread_iterations):
|
|
98
|
-
|
|
99
|
-
energy = compute_energy_sparse(
|
|
128
|
+
gray_code_next(iterator, curr_idx)
|
|
129
|
+
energy = compute_energy_sparse(iterator, G_data, G_rows, G_cols, n)
|
|
100
130
|
if energy > energies[i]:
|
|
101
|
-
states[i], energies[i] =
|
|
131
|
+
states[i], energies[i] = iterator.copy(), energy
|
|
102
132
|
else:
|
|
103
133
|
for i in prange(thread_count):
|
|
104
|
-
i_offset = i * thread_iterations
|
|
105
134
|
iterator = iterators[i]
|
|
106
135
|
for curr_idx in range(thread_iterations):
|
|
107
|
-
|
|
108
|
-
energy = compute_cut_sparse(
|
|
136
|
+
gray_code_next(iterator, curr_idx)
|
|
137
|
+
energy = compute_cut_sparse(iterator, G_data, G_rows, G_cols, n)
|
|
109
138
|
if energy > energies[i]:
|
|
110
|
-
states[i], energies[i] =
|
|
139
|
+
states[i], energies[i] = iterator.copy(), energy
|
|
111
140
|
|
|
112
141
|
best_index = np.argmax(energies)
|
|
113
142
|
best_energy = energies[best_index]
|
|
@@ -127,7 +156,8 @@ def spin_glass_solver_sparse(
|
|
|
127
156
|
anneal_h=None,
|
|
128
157
|
repulsion_base=None,
|
|
129
158
|
is_log=False,
|
|
130
|
-
gray_iterations=None
|
|
159
|
+
gray_iterations=None,
|
|
160
|
+
gray_seed_multiple=None
|
|
131
161
|
):
|
|
132
162
|
dtype = opencl_context.dtype
|
|
133
163
|
nodes = None
|
|
@@ -170,6 +200,9 @@ def spin_glass_solver_sparse(
|
|
|
170
200
|
if gray_iterations is None:
|
|
171
201
|
gray_iterations = n_qubits * os.cpu_count()
|
|
172
202
|
|
|
203
|
+
if gray_seed_multiple is None:
|
|
204
|
+
gray_seed_multiple = os.cpu_count()
|
|
205
|
+
|
|
173
206
|
max_energy = compute_energy_sparse(best_theta, G_m.data, G_m.indptr, G_m.indices, n_qubits) if is_spin_glass else cut_value
|
|
174
207
|
|
|
175
208
|
thread_count = os.cpu_count() ** 2
|
|
@@ -194,7 +227,15 @@ def spin_glass_solver_sparse(
|
|
|
194
227
|
continue
|
|
195
228
|
|
|
196
229
|
# Gray code with default O(n^3)
|
|
197
|
-
iterators =
|
|
230
|
+
iterators, energies = pick_gray_seeds(best_theta, thread_count, gray_seed_multiple, G_m.data, G_m.indptr, G_m.indices, n_qubits, is_spin_glass)
|
|
231
|
+
best_i = np.argmax(energies)
|
|
232
|
+
energy, state = energies[best_i], iterators[best_i]
|
|
233
|
+
if energy > max_energy:
|
|
234
|
+
max_energy = energy
|
|
235
|
+
best_theta = state
|
|
236
|
+
improved = True
|
|
237
|
+
continue
|
|
238
|
+
|
|
198
239
|
energy, state = run_gray_optimization(best_theta, iterators, gray_iterations, thread_count, is_spin_glass, G_m.data, G_m.indptr, G_m.indices)
|
|
199
240
|
if energy > max_energy:
|
|
200
241
|
max_energy = energy
|
|
@@ -41,7 +41,7 @@ def run_double_bit_flips(best_theta, is_spin_glass, G_func, nodes):
|
|
|
41
41
|
n = len(best_theta)
|
|
42
42
|
|
|
43
43
|
states = np.empty((n, n), dtype=np.bool_)
|
|
44
|
-
energies = np.
|
|
44
|
+
energies = np.full(n, np.finfo(dtype).min, dtype=dtype)
|
|
45
45
|
|
|
46
46
|
if is_spin_glass:
|
|
47
47
|
for i in prange(n):
|
|
@@ -53,7 +53,8 @@ def run_double_bit_flips(best_theta, is_spin_glass, G_func, nodes):
|
|
|
53
53
|
state[j] = not state[j]
|
|
54
54
|
energy = compute_energy_streaming(state, G_func, nodes, n)
|
|
55
55
|
if energy > energies[i]:
|
|
56
|
-
states[i], energies[i] = state, energy
|
|
56
|
+
states[i], energies[i] = state.copy(), energy
|
|
57
|
+
state[j] = not state[j]
|
|
57
58
|
else:
|
|
58
59
|
for i in prange(n):
|
|
59
60
|
state = best_theta.copy()
|
|
@@ -64,7 +65,8 @@ def run_double_bit_flips(best_theta, is_spin_glass, G_func, nodes):
|
|
|
64
65
|
state[j] = not state[j]
|
|
65
66
|
energy = compute_cut_streaming(state, G_func, nodes, n)
|
|
66
67
|
if energy > energies[i]:
|
|
67
|
-
states[i], energies[i] = state, energy
|
|
68
|
+
states[i], energies[i] = state.copy(), energy
|
|
69
|
+
state[j] = not state[j]
|
|
68
70
|
|
|
69
71
|
best_index = np.argmax(energies)
|
|
70
72
|
best_energy = energies[best_index]
|
|
@@ -73,33 +75,61 @@ def run_double_bit_flips(best_theta, is_spin_glass, G_func, nodes):
|
|
|
73
75
|
return best_energy, best_state
|
|
74
76
|
|
|
75
77
|
|
|
78
|
+
@njit(parallel=True)
|
|
79
|
+
def pick_gray_seeds(best_theta, thread_count, gray_seed_multiple, G_func, nodes, n, is_spin_glass):
|
|
80
|
+
seed_count = thread_count * gray_seed_multiple
|
|
81
|
+
|
|
82
|
+
seeds = np.empty((seed_count, n), dtype=np.bool_)
|
|
83
|
+
energies = np.empty(seed_count, dtype=dtype)
|
|
84
|
+
|
|
85
|
+
if is_spin_glass:
|
|
86
|
+
for i in prange(seed_count):
|
|
87
|
+
seed = gray_mutation(i, best_theta)
|
|
88
|
+
energies[i] = compute_energy_streaming(seed, G_func, nodes, n)
|
|
89
|
+
seeds[i] = seed
|
|
90
|
+
else:
|
|
91
|
+
for i in prange(seed_count):
|
|
92
|
+
seed = gray_mutation(i, best_theta)
|
|
93
|
+
energies[i] = compute_cut_streaming(seed, G_func, nodes, n)
|
|
94
|
+
seeds[i] = seed
|
|
95
|
+
|
|
96
|
+
indices = np.argsort(energies)[::-1]
|
|
97
|
+
|
|
98
|
+
best_seeds = np.empty((thread_count, n), dtype=np.bool_)
|
|
99
|
+
best_energies = np.empty(thread_count, dtype=dtype)
|
|
100
|
+
|
|
101
|
+
for i in prange(thread_count):
|
|
102
|
+
idx = indices[i]
|
|
103
|
+
best_seeds[i] = seeds[idx]
|
|
104
|
+
best_energies[i] = energies[idx]
|
|
105
|
+
|
|
106
|
+
return best_seeds, best_energies
|
|
107
|
+
|
|
76
108
|
@njit(parallel=True)
|
|
77
109
|
def run_gray_optimization(best_theta, iterators, gray_iterations, thread_count, is_spin_glass, G_func, nodes):
|
|
78
110
|
n = len(best_theta)
|
|
79
|
-
thread_iterations = gray_iterations // thread_count
|
|
80
|
-
gray_iterations = (gray_iterations + thread_count - 1) // thread_count
|
|
111
|
+
thread_iterations = (gray_iterations + thread_count - 1) // thread_count
|
|
81
112
|
|
|
82
113
|
states = np.empty((thread_count, n), dtype=np.bool_)
|
|
83
|
-
energies = np.
|
|
114
|
+
energies = np.full(thread_count, np.finfo(dtype).min, dtype=dtype)
|
|
84
115
|
|
|
85
116
|
if is_spin_glass:
|
|
86
117
|
for i in prange(thread_count):
|
|
87
|
-
i_offset = i * thread_iterations
|
|
88
118
|
iterator = iterators[i]
|
|
89
119
|
for curr_idx in range(thread_iterations):
|
|
90
|
-
|
|
91
|
-
energy = compute_energy_streaming(
|
|
120
|
+
gray_code_next(iterator, curr_idx)
|
|
121
|
+
energy = compute_energy_streaming(iterator, G_func, nodes, n)
|
|
92
122
|
if energy > energies[i]:
|
|
93
|
-
states[i], energies[i] =
|
|
123
|
+
states[i], energies[i] = iterator.copy(), energy
|
|
94
124
|
else:
|
|
95
125
|
for i in prange(thread_count):
|
|
96
|
-
i_offset = i * thread_iterations
|
|
97
126
|
iterator = iterators[i]
|
|
127
|
+
r_iterator = iterator.copy()
|
|
98
128
|
for curr_idx in range(thread_iterations):
|
|
99
|
-
|
|
100
|
-
energy = compute_cut_streaming(
|
|
129
|
+
gray_code_next(iterator, curr_idx)
|
|
130
|
+
energy = compute_cut_streaming(iterator, G_func, nodes, n)
|
|
101
131
|
if energy > energies[i]:
|
|
102
|
-
states[i], energies[i] =
|
|
132
|
+
states[i], energies[i] = iterator.copy(), energy
|
|
103
133
|
|
|
104
134
|
best_index = np.argmax(energies)
|
|
105
135
|
best_energy = energies[best_index]
|
|
@@ -120,7 +150,8 @@ def spin_glass_solver_streaming(
|
|
|
120
150
|
anneal_h=None,
|
|
121
151
|
repulsion_base=None,
|
|
122
152
|
is_log=False,
|
|
123
|
-
gray_iterations=None
|
|
153
|
+
gray_iterations=None,
|
|
154
|
+
gray_seed_multiple=None
|
|
124
155
|
):
|
|
125
156
|
dtype = opencl_context.dtype
|
|
126
157
|
n_qubits = len(nodes)
|
|
@@ -153,6 +184,9 @@ def spin_glass_solver_streaming(
|
|
|
153
184
|
if gray_iterations is None:
|
|
154
185
|
gray_iterations = n_qubits * os.cpu_count()
|
|
155
186
|
|
|
187
|
+
if gray_seed_multiple is None:
|
|
188
|
+
gray_seed_multiple = os.cpu_count()
|
|
189
|
+
|
|
156
190
|
max_energy = compute_energy_streaming(best_theta, G_func, nodes, n_qubits) if is_spin_glass else cut_value
|
|
157
191
|
|
|
158
192
|
thread_count = os.cpu_count() ** 2
|
|
@@ -177,7 +211,15 @@ def spin_glass_solver_streaming(
|
|
|
177
211
|
continue
|
|
178
212
|
|
|
179
213
|
# Gray code with default O(n^3)
|
|
180
|
-
iterators =
|
|
214
|
+
iterators, energies = pick_gray_seeds(best_theta, thread_count, gray_seed_multiple, G_func, nodes, n_qubits, is_spin_glass)
|
|
215
|
+
best_i = np.argmax(energies)
|
|
216
|
+
energy, state = energies[best_i], iterators[best_i]
|
|
217
|
+
if energy > max_energy:
|
|
218
|
+
max_energy = energy
|
|
219
|
+
best_theta = state
|
|
220
|
+
improved = True
|
|
221
|
+
continue
|
|
222
|
+
|
|
181
223
|
energy, state = run_gray_optimization(best_theta, iterators, gray_iterations, thread_count, is_spin_glass, G_func, nodes)
|
|
182
224
|
if energy > max_energy:
|
|
183
225
|
max_energy = energy
|
|
@@ -7,7 +7,7 @@ with open(README_PATH) as readme_file:
|
|
|
7
7
|
|
|
8
8
|
setup(
|
|
9
9
|
name='pyqrackising',
|
|
10
|
-
version='9.
|
|
10
|
+
version='9.1.0',
|
|
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
|