PyQrackIsing 6.3.1__tar.gz → 7.0.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-6.3.1/pyqrackising.egg-info → pyqrackising-7.0.0}/PKG-INFO +1 -1
- {pyqrackising-6.3.1 → pyqrackising-7.0.0}/pyproject.toml +1 -1
- {pyqrackising-6.3.1 → pyqrackising-7.0.0}/pyqrackising/maxcut_tfim_streaming.py +23 -24
- {pyqrackising-6.3.1 → pyqrackising-7.0.0}/pyqrackising/spin_glass_solver_streaming.py +13 -14
- {pyqrackising-6.3.1 → pyqrackising-7.0.0/pyqrackising.egg-info}/PKG-INFO +1 -1
- {pyqrackising-6.3.1 → pyqrackising-7.0.0}/setup.py +1 -1
- {pyqrackising-6.3.1 → pyqrackising-7.0.0}/CMakeLists.txt +0 -0
- {pyqrackising-6.3.1 → pyqrackising-7.0.0}/LICENSE.md +0 -0
- {pyqrackising-6.3.1 → pyqrackising-7.0.0}/MANIFEST.in +0 -0
- {pyqrackising-6.3.1 → pyqrackising-7.0.0}/README.md +0 -0
- {pyqrackising-6.3.1 → pyqrackising-7.0.0}/pyqrackising/__init__.py +0 -0
- {pyqrackising-6.3.1 → pyqrackising-7.0.0}/pyqrackising/_pyqrack_ising.cpp +0 -0
- {pyqrackising-6.3.1 → pyqrackising-7.0.0}/pyqrackising/convert_tensor_network_to_tsp.py +0 -0
- {pyqrackising-6.3.1 → pyqrackising-7.0.0}/pyqrackising/generate_tfim_samples.py +0 -0
- {pyqrackising-6.3.1 → pyqrackising-7.0.0}/pyqrackising/kernels.cl +0 -0
- {pyqrackising-6.3.1 → pyqrackising-7.0.0}/pyqrackising/maxcut_tfim.py +0 -0
- {pyqrackising-6.3.1 → pyqrackising-7.0.0}/pyqrackising/maxcut_tfim_sparse.py +0 -0
- {pyqrackising-6.3.1 → pyqrackising-7.0.0}/pyqrackising/maxcut_tfim_util.py +0 -0
- {pyqrackising-6.3.1 → pyqrackising-7.0.0}/pyqrackising/spin_glass_solver.py +0 -0
- {pyqrackising-6.3.1 → pyqrackising-7.0.0}/pyqrackising/spin_glass_solver_sparse.py +0 -0
- {pyqrackising-6.3.1 → pyqrackising-7.0.0}/pyqrackising/spin_glass_solver_util.py +0 -0
- {pyqrackising-6.3.1 → pyqrackising-7.0.0}/pyqrackising/tfim_magnetization.py +0 -0
- {pyqrackising-6.3.1 → pyqrackising-7.0.0}/pyqrackising/tfim_square_magnetization.py +0 -0
- {pyqrackising-6.3.1 → pyqrackising-7.0.0}/pyqrackising/tsp.py +0 -0
- {pyqrackising-6.3.1 → pyqrackising-7.0.0}/pyqrackising.egg-info/SOURCES.txt +0 -0
- {pyqrackising-6.3.1 → pyqrackising-7.0.0}/pyqrackising.egg-info/dependency_links.txt +0 -0
- {pyqrackising-6.3.1 → pyqrackising-7.0.0}/pyqrackising.egg-info/not-zip-safe +0 -0
- {pyqrackising-6.3.1 → pyqrackising-7.0.0}/pyqrackising.egg-info/top_level.txt +0 -0
- {pyqrackising-6.3.1 → pyqrackising-7.0.0}/setup.cfg +0 -0
|
@@ -12,7 +12,7 @@ build-backend = "setuptools.build_meta"
|
|
|
12
12
|
|
|
13
13
|
[project]
|
|
14
14
|
name = "pyqrackising"
|
|
15
|
-
version = "
|
|
15
|
+
version = "7.0.0"
|
|
16
16
|
requires-python = ">=3.8"
|
|
17
17
|
description = "Fast MAXCUT, TSP, and sampling heuristics from near-ideal transverse field Ising model (TFIM)"
|
|
18
18
|
readme = {file = "README.txt", content-type = "text/markdown"}
|
|
@@ -14,7 +14,7 @@ except ImportError:
|
|
|
14
14
|
|
|
15
15
|
|
|
16
16
|
@njit
|
|
17
|
-
def update_repulsion_choice(G_func,
|
|
17
|
+
def update_repulsion_choice(G_func, nodes, max_weight, weights, n, used, node):
|
|
18
18
|
# Select node
|
|
19
19
|
used[node] = True
|
|
20
20
|
|
|
@@ -22,12 +22,12 @@ def update_repulsion_choice(G_func, G_func_args_tuple, nodes, max_weight, weight
|
|
|
22
22
|
for nbr in range(n):
|
|
23
23
|
if used[nbr]:
|
|
24
24
|
continue
|
|
25
|
-
weights[nbr] *= max(1.1920928955078125e-7, 1 - G_func(
|
|
25
|
+
weights[nbr] *= max(1.1920928955078125e-7, 1 - G_func(nodes[node], nodes[nbr]) / max_weight)
|
|
26
26
|
|
|
27
27
|
|
|
28
28
|
# Written by Elara (OpenAI custom GPT) and improved by Dan Strano
|
|
29
29
|
@njit
|
|
30
|
-
def local_repulsion_choice(G_func,
|
|
30
|
+
def local_repulsion_choice(G_func, nodes, max_weight, weights, n, m, shot):
|
|
31
31
|
"""
|
|
32
32
|
Pick m nodes out of n with repulsion bias:
|
|
33
33
|
- High-degree nodes are already less likely
|
|
@@ -40,7 +40,7 @@ def local_repulsion_choice(G_func, G_func_args_tuple, nodes, max_weight, weights
|
|
|
40
40
|
used = np.zeros(n, dtype=np.bool_) # False = available, True = used
|
|
41
41
|
|
|
42
42
|
# Update answer and weights
|
|
43
|
-
update_repulsion_choice(G_func,
|
|
43
|
+
update_repulsion_choice(G_func, nodes, max_weight, weights, n, used, shot % n)
|
|
44
44
|
|
|
45
45
|
for _ in range(1, m):
|
|
46
46
|
# Count available
|
|
@@ -71,24 +71,24 @@ def local_repulsion_choice(G_func, G_func_args_tuple, nodes, max_weight, weights
|
|
|
71
71
|
used[node] = True
|
|
72
72
|
|
|
73
73
|
# Update answer and weights
|
|
74
|
-
update_repulsion_choice(G_func,
|
|
74
|
+
update_repulsion_choice(G_func, nodes, max_weight, weights, n, used, node)
|
|
75
75
|
|
|
76
76
|
return used
|
|
77
77
|
|
|
78
78
|
|
|
79
79
|
@njit
|
|
80
|
-
def compute_energy(sample, G_func,
|
|
80
|
+
def compute_energy(sample, G_func, nodes, n_qubits):
|
|
81
81
|
energy = 0
|
|
82
82
|
for u in range(n_qubits):
|
|
83
83
|
for v in range(u + 1, n_qubits):
|
|
84
|
-
val = G_func(
|
|
84
|
+
val = G_func(nodes[u], nodes[v])
|
|
85
85
|
energy += val if sample[u] == sample[v] else -val
|
|
86
86
|
|
|
87
87
|
return energy
|
|
88
88
|
|
|
89
89
|
|
|
90
90
|
@njit(parallel=True)
|
|
91
|
-
def sample_for_solution(G_func,
|
|
91
|
+
def sample_for_solution(G_func, nodes, max_weight, shots, thresholds, degrees_sum, weights, n, dtype):
|
|
92
92
|
solutions = np.empty((shots, n), dtype=np.bool_)
|
|
93
93
|
energies = np.empty(shots, dtype=dtype)
|
|
94
94
|
|
|
@@ -101,10 +101,10 @@ def sample_for_solution(G_func, G_func_args_tuple, nodes, max_weight, shots, thr
|
|
|
101
101
|
m += 1
|
|
102
102
|
|
|
103
103
|
# Second dimension: permutation within Hamming weight
|
|
104
|
-
sample = local_repulsion_choice(G_func,
|
|
104
|
+
sample = local_repulsion_choice(G_func, nodes, max_weight, weights, n, m, s)
|
|
105
105
|
|
|
106
106
|
solutions[s] = sample
|
|
107
|
-
energies[s] = compute_energy(sample, G_func,
|
|
107
|
+
energies[s] = compute_energy(sample, G_func, nodes, n)
|
|
108
108
|
|
|
109
109
|
best_solution = solutions[np.argmin(energies)]
|
|
110
110
|
|
|
@@ -112,13 +112,13 @@ def sample_for_solution(G_func, G_func_args_tuple, nodes, max_weight, shots, thr
|
|
|
112
112
|
for u in range(n):
|
|
113
113
|
for v in range(u + 1, n):
|
|
114
114
|
if best_solution[u] != best_solution[v]:
|
|
115
|
-
best_value += G_func(
|
|
115
|
+
best_value += G_func(nodes[u], nodes[v])
|
|
116
116
|
|
|
117
117
|
return best_solution, best_value
|
|
118
118
|
|
|
119
119
|
|
|
120
120
|
@njit(parallel=True)
|
|
121
|
-
def init_J_and_z(G_func,
|
|
121
|
+
def init_J_and_z(G_func, nodes, dtype):
|
|
122
122
|
n_qubits = len(nodes)
|
|
123
123
|
degrees = np.empty(n_qubits, dtype=np.uint32)
|
|
124
124
|
J_eff = np.empty(n_qubits, dtype=dtype)
|
|
@@ -128,7 +128,7 @@ def init_J_and_z(G_func, G_func_args_tuple, nodes, dtype):
|
|
|
128
128
|
degree = 0
|
|
129
129
|
J = 0.0
|
|
130
130
|
for m in range(n_qubits):
|
|
131
|
-
val = G_func(
|
|
131
|
+
val = G_func(nodes[n], nodes[m])
|
|
132
132
|
if val != 0.0:
|
|
133
133
|
degree += 1
|
|
134
134
|
J += val
|
|
@@ -144,8 +144,8 @@ def init_J_and_z(G_func, G_func_args_tuple, nodes, dtype):
|
|
|
144
144
|
|
|
145
145
|
|
|
146
146
|
@njit
|
|
147
|
-
def cpu_footer(shots, quality, n_qubits, G_func,
|
|
148
|
-
J_eff, degrees, G_max = init_J_and_z(G_func,
|
|
147
|
+
def cpu_footer(shots, quality, n_qubits, G_func, nodes, dtype):
|
|
148
|
+
J_eff, degrees, G_max = init_J_and_z(G_func, nodes, dtype)
|
|
149
149
|
hamming_prob = init_thresholds(n_qubits, dtype)
|
|
150
150
|
|
|
151
151
|
maxcut_hamming_cdf(n_qubits, J_eff, degrees, quality, hamming_prob, dtype)
|
|
@@ -154,7 +154,7 @@ def cpu_footer(shots, quality, n_qubits, G_func, G_func_args_tuple, nodes, dtype
|
|
|
154
154
|
degrees = None
|
|
155
155
|
J_eff = 1.0 / (1.0 + (2 ** -52) - J_eff)
|
|
156
156
|
|
|
157
|
-
best_solution, best_value = sample_for_solution(G_func,
|
|
157
|
+
best_solution, best_value = sample_for_solution(G_func, nodes, G_max, shots, hamming_prob, max_weight, J_eff, n_qubits, dtype)
|
|
158
158
|
|
|
159
159
|
bit_string, l, r = get_cut(best_solution, nodes)
|
|
160
160
|
|
|
@@ -162,10 +162,10 @@ def cpu_footer(shots, quality, n_qubits, G_func, G_func_args_tuple, nodes, dtype
|
|
|
162
162
|
|
|
163
163
|
|
|
164
164
|
@njit
|
|
165
|
-
def gpu_footer(shots, n_qubits, G_func,
|
|
165
|
+
def gpu_footer(shots, n_qubits, G_func, nodes, G_max, weights, degrees, hamming_prob, max_weight, dtype):
|
|
166
166
|
fix_cdf(hamming_prob)
|
|
167
167
|
|
|
168
|
-
best_solution, best_value = sample_for_solution(G_func,
|
|
168
|
+
best_solution, best_value = sample_for_solution(G_func, nodes, G_max, shots, hamming_prob, max_weight, weights, n_qubits, dtype)
|
|
169
169
|
|
|
170
170
|
bit_string, l, r = get_cut(best_solution, nodes)
|
|
171
171
|
|
|
@@ -175,7 +175,6 @@ def gpu_footer(shots, n_qubits, G_func, G_func_args_tuple, nodes, G_max, weights
|
|
|
175
175
|
def maxcut_tfim_streaming(
|
|
176
176
|
G_func,
|
|
177
177
|
nodes,
|
|
178
|
-
G_func_args_tuple=None,
|
|
179
178
|
quality=None,
|
|
180
179
|
shots=None,
|
|
181
180
|
is_base_maxcut_gpu=True
|
|
@@ -192,7 +191,7 @@ def maxcut_tfim_streaming(
|
|
|
192
191
|
return "0", 0, (nodes, [])
|
|
193
192
|
|
|
194
193
|
if n_qubits == 2:
|
|
195
|
-
weight = G_func(
|
|
194
|
+
weight = G_func(nodes[0], nodes[1])
|
|
196
195
|
if weight < 0.0:
|
|
197
196
|
return "00", 0, (nodes, [])
|
|
198
197
|
|
|
@@ -208,10 +207,10 @@ def maxcut_tfim_streaming(
|
|
|
208
207
|
n_steps = n_qubits << quality
|
|
209
208
|
grid_size = n_steps * n_qubits
|
|
210
209
|
|
|
211
|
-
if (not is_base_maxcut_gpu) or not
|
|
212
|
-
return cpu_footer(shots, quality, n_qubits, G_func,
|
|
210
|
+
if (not is_base_maxcut_gpu) or (not IS_OPENCL_AVAILABLE):
|
|
211
|
+
return cpu_footer(shots, quality, n_qubits, G_func, nodes, dtype)
|
|
213
212
|
|
|
214
|
-
J_eff, degrees, G_max = init_J_and_z(G_func,
|
|
213
|
+
J_eff, degrees, G_max = init_J_and_z(G_func, nodes, dtype)
|
|
215
214
|
|
|
216
215
|
delta_t = 1.0 / n_steps
|
|
217
216
|
tot_t = 2.0 * n_steps * delta_t
|
|
@@ -271,4 +270,4 @@ def maxcut_tfim_streaming(
|
|
|
271
270
|
degrees = None
|
|
272
271
|
J_eff = 1.0 / (1.0 + (2 ** -52) - J_eff)
|
|
273
272
|
|
|
274
|
-
return gpu_footer(shots, n_qubits, G_func,
|
|
273
|
+
return gpu_footer(shots, n_qubits, G_func, nodes, G_max, J_eff, degrees, hamming_prob, max_weight, dtype)
|
|
@@ -9,46 +9,46 @@ import os
|
|
|
9
9
|
|
|
10
10
|
|
|
11
11
|
@njit
|
|
12
|
-
def evaluate_cut_edges(theta_bits, G_func,
|
|
12
|
+
def evaluate_cut_edges(theta_bits, G_func, nodes):
|
|
13
13
|
n_qubits = len(nodes)
|
|
14
14
|
cut = 0
|
|
15
15
|
for u in range(n_qubits):
|
|
16
16
|
for v in range(u + 1, n_qubits):
|
|
17
17
|
if theta_bits[u] != theta_bits[v]:
|
|
18
|
-
cut += G_func(
|
|
18
|
+
cut += G_func(nodes[u], nodes[v])
|
|
19
19
|
|
|
20
20
|
return cut
|
|
21
21
|
|
|
22
22
|
|
|
23
23
|
@njit
|
|
24
|
-
def compute_energy(theta_bits, G_func,
|
|
24
|
+
def compute_energy(theta_bits, G_func, nodes):
|
|
25
25
|
n_qubits = len(nodes)
|
|
26
26
|
energy = 0
|
|
27
27
|
for u in range(n_qubits):
|
|
28
28
|
for v in range(u + 1, n_qubits):
|
|
29
|
-
val = G_func(
|
|
29
|
+
val = G_func(nodes[u], nodes[v])
|
|
30
30
|
energy += (val if theta_bits[u] == theta_bits[v] else -val)
|
|
31
31
|
|
|
32
32
|
return energy
|
|
33
33
|
|
|
34
34
|
|
|
35
35
|
@njit
|
|
36
|
-
def bootstrap_worker(theta, G_func,
|
|
36
|
+
def bootstrap_worker(theta, G_func, nodes, indices):
|
|
37
37
|
local_theta = theta.copy()
|
|
38
38
|
for i in indices:
|
|
39
39
|
local_theta[i] = not local_theta[i]
|
|
40
|
-
energy = compute_energy(local_theta, G_func,
|
|
40
|
+
energy = compute_energy(local_theta, G_func, nodes)
|
|
41
41
|
|
|
42
42
|
return energy
|
|
43
43
|
|
|
44
44
|
|
|
45
45
|
@njit(parallel=True)
|
|
46
|
-
def bootstrap(best_theta, G_func,
|
|
46
|
+
def bootstrap(best_theta, G_func, nodes, indices_array, k, min_energy, dtype):
|
|
47
47
|
n = len(indices_array) // k
|
|
48
48
|
energies = np.empty(n, dtype=dtype)
|
|
49
49
|
for i in prange(n):
|
|
50
50
|
j = i * k
|
|
51
|
-
energies[i] = bootstrap_worker(best_theta, G_func,
|
|
51
|
+
energies[i] = bootstrap_worker(best_theta, G_func, nodes, indices_array[j : j + k])
|
|
52
52
|
|
|
53
53
|
energy = energies.min()
|
|
54
54
|
if energy < min_energy:
|
|
@@ -66,7 +66,6 @@ def bootstrap(best_theta, G_func, G_func_args_tuple, nodes, indices_array, k, mi
|
|
|
66
66
|
def spin_glass_solver_streaming(
|
|
67
67
|
G_func,
|
|
68
68
|
nodes,
|
|
69
|
-
G_func_args_tuple=None,
|
|
70
69
|
quality=None,
|
|
71
70
|
shots=None,
|
|
72
71
|
best_guess=None,
|
|
@@ -83,7 +82,7 @@ def spin_glass_solver_streaming(
|
|
|
83
82
|
return "0", 0, (nodes, []), 0
|
|
84
83
|
|
|
85
84
|
if n_qubits == 2:
|
|
86
|
-
weight = G_func(
|
|
85
|
+
weight = G_func(nodes[0], nodes[1])
|
|
87
86
|
if weight < 0.0:
|
|
88
87
|
return "00", 0, (nodes, []), weight
|
|
89
88
|
|
|
@@ -100,10 +99,10 @@ def spin_glass_solver_streaming(
|
|
|
100
99
|
elif isinstance(best_guess, list):
|
|
101
100
|
bitstring = "".join(["1" if b else "0" for b in best_guess])
|
|
102
101
|
else:
|
|
103
|
-
bitstring, _, _ = maxcut_tfim_streaming(G_func, nodes,
|
|
102
|
+
bitstring, _, _ = maxcut_tfim_streaming(G_func, nodes, quality=quality, shots=shots, is_base_maxcut_gpu=is_base_maxcut_gpu)
|
|
104
103
|
best_theta = np.array([b == "1" for b in list(bitstring)], dtype=np.bool_)
|
|
105
104
|
|
|
106
|
-
min_energy = compute_energy(best_theta, G_func,
|
|
105
|
+
min_energy = compute_energy(best_theta, G_func, nodes)
|
|
107
106
|
improved = True
|
|
108
107
|
correction_quality = 1
|
|
109
108
|
combos_list = []
|
|
@@ -123,7 +122,7 @@ def spin_glass_solver_streaming(
|
|
|
123
122
|
else:
|
|
124
123
|
combos = combos_list[k - 1]
|
|
125
124
|
|
|
126
|
-
energy = bootstrap(best_theta, G_func,
|
|
125
|
+
energy = bootstrap(best_theta, G_func, nodes, combos, k, min_energy, dtype)
|
|
127
126
|
|
|
128
127
|
if energy < min_energy:
|
|
129
128
|
min_energy = energy
|
|
@@ -135,6 +134,6 @@ def spin_glass_solver_streaming(
|
|
|
135
134
|
k = k + 1
|
|
136
135
|
|
|
137
136
|
bitstring, l, r = get_cut_from_bit_array(best_theta, nodes)
|
|
138
|
-
cut_value = evaluate_cut_edges(best_theta, G_func,
|
|
137
|
+
cut_value = evaluate_cut_edges(best_theta, G_func, nodes)
|
|
139
138
|
|
|
140
139
|
return bitstring, float(cut_value), (l, r), float(min_energy)
|
|
@@ -51,7 +51,7 @@ ext_modules = [CMakeExtension('tfim_sampler')]
|
|
|
51
51
|
|
|
52
52
|
setup(
|
|
53
53
|
name='pyqrackising',
|
|
54
|
-
version='
|
|
54
|
+
version='7.0.0',
|
|
55
55
|
author='Dan Strano',
|
|
56
56
|
author_email='stranoj@gmail.com',
|
|
57
57
|
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
|