PyQrackIsing 8.14.3__tar.gz → 8.14.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-8.14.3/pyqrackising.egg-info → pyqrackising-8.14.4}/PKG-INFO +1 -1
- {pyqrackising-8.14.3 → pyqrackising-8.14.4}/pyproject.toml +1 -1
- {pyqrackising-8.14.3 → pyqrackising-8.14.4}/pyqrackising/maxcut_tfim.py +13 -7
- {pyqrackising-8.14.3 → pyqrackising-8.14.4}/pyqrackising/maxcut_tfim_sparse.py +20 -11
- {pyqrackising-8.14.3 → pyqrackising-8.14.4}/pyqrackising/maxcut_tfim_streaming.py +20 -9
- {pyqrackising-8.14.3 → pyqrackising-8.14.4}/pyqrackising/spin_glass_solver.py +2 -1
- {pyqrackising-8.14.3 → pyqrackising-8.14.4}/pyqrackising/spin_glass_solver_sparse.py +5 -3
- {pyqrackising-8.14.3 → pyqrackising-8.14.4}/pyqrackising/spin_glass_solver_streaming.py +2 -1
- {pyqrackising-8.14.3 → pyqrackising-8.14.4/pyqrackising.egg-info}/PKG-INFO +1 -1
- {pyqrackising-8.14.3 → pyqrackising-8.14.4}/setup.py +1 -1
- {pyqrackising-8.14.3 → pyqrackising-8.14.4}/LICENSE.md +0 -0
- {pyqrackising-8.14.3 → pyqrackising-8.14.4}/MANIFEST.in +0 -0
- {pyqrackising-8.14.3 → pyqrackising-8.14.4}/README.md +0 -0
- {pyqrackising-8.14.3 → pyqrackising-8.14.4}/pyqrackising/__init__.py +0 -0
- {pyqrackising-8.14.3 → pyqrackising-8.14.4}/pyqrackising/convert_tensor_network_to_tsp.py +0 -0
- {pyqrackising-8.14.3 → pyqrackising-8.14.4}/pyqrackising/generate_tfim_samples.py +0 -0
- {pyqrackising-8.14.3 → pyqrackising-8.14.4}/pyqrackising/kernels.cl +0 -0
- {pyqrackising-8.14.3 → pyqrackising-8.14.4}/pyqrackising/maxcut_tfim_util.py +0 -0
- {pyqrackising-8.14.3 → pyqrackising-8.14.4}/pyqrackising/spin_glass_solver_util.py +0 -0
- {pyqrackising-8.14.3 → pyqrackising-8.14.4}/pyqrackising/tfim_magnetization.py +0 -0
- {pyqrackising-8.14.3 → pyqrackising-8.14.4}/pyqrackising/tfim_square_magnetization.py +0 -0
- {pyqrackising-8.14.3 → pyqrackising-8.14.4}/pyqrackising/tsp.py +0 -0
- {pyqrackising-8.14.3 → pyqrackising-8.14.4}/pyqrackising/tsp_maxcut.py +0 -0
- {pyqrackising-8.14.3 → pyqrackising-8.14.4}/pyqrackising.egg-info/SOURCES.txt +0 -0
- {pyqrackising-8.14.3 → pyqrackising-8.14.4}/pyqrackising.egg-info/dependency_links.txt +0 -0
- {pyqrackising-8.14.3 → pyqrackising-8.14.4}/pyqrackising.egg-info/not-zip-safe +0 -0
- {pyqrackising-8.14.3 → pyqrackising-8.14.4}/pyqrackising.egg-info/top_level.txt +0 -0
- {pyqrackising-8.14.3 → pyqrackising-8.14.4}/setup.cfg +0 -0
|
@@ -10,7 +10,7 @@ build-backend = "setuptools.build_meta"
|
|
|
10
10
|
|
|
11
11
|
[project]
|
|
12
12
|
name = "pyqrackising"
|
|
13
|
-
version = "8.14.
|
|
13
|
+
version = "8.14.4"
|
|
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"}
|
|
@@ -90,7 +90,7 @@ def compute_cut(sample, G_m, n_qubits):
|
|
|
90
90
|
|
|
91
91
|
@njit(parallel=True)
|
|
92
92
|
def sample_measurement(G_m, max_edge, shots, thresholds, weights, repulsion_base, is_spin_glass):
|
|
93
|
-
shots =
|
|
93
|
+
shots = max(1, shots >> 1)
|
|
94
94
|
n = len(G_m)
|
|
95
95
|
tot_init_weight = weights.sum()
|
|
96
96
|
|
|
@@ -107,16 +107,20 @@ def sample_measurement(G_m, max_edge, shots, thresholds, weights, repulsion_base
|
|
|
107
107
|
for s in prange(shots):
|
|
108
108
|
# First dimension: Hamming weight
|
|
109
109
|
m = sample_mag(thresholds)
|
|
110
|
+
|
|
110
111
|
# Second dimension: permutation within Hamming weight
|
|
111
|
-
|
|
112
|
-
|
|
112
|
+
sample = local_repulsion_choice(G_m, max_edge, weights, tot_init_weight, repulsion_base, n, m)
|
|
113
|
+
solutions[s] = sample
|
|
114
|
+
energies[s] = compute_energy(sample, G_m, n)
|
|
113
115
|
else:
|
|
114
116
|
for s in prange(shots):
|
|
115
117
|
# First dimension: Hamming weight
|
|
116
118
|
m = sample_mag(thresholds)
|
|
119
|
+
|
|
117
120
|
# Second dimension: permutation within Hamming weight
|
|
118
|
-
|
|
119
|
-
|
|
121
|
+
sample = local_repulsion_choice(G_m, max_edge, weights, tot_init_weight, repulsion_base, n, m)
|
|
122
|
+
solutions[s] = sample
|
|
123
|
+
energies[s] = compute_cut(sample, G_m, n)
|
|
120
124
|
|
|
121
125
|
best_index = np.argmax(energies)
|
|
122
126
|
energy = energies[best_index]
|
|
@@ -141,7 +145,7 @@ def shot_loop(G_m, max_edge, thresholds, weights, tot_init_weight, repulsion_bas
|
|
|
141
145
|
|
|
142
146
|
|
|
143
147
|
def sample_for_opencl(G_m, G_m_buf, max_edge, shots, thresholds, weights, repulsion_base, is_spin_glass, is_segmented, segment_size):
|
|
144
|
-
shots = max(1, shots >> 1)
|
|
148
|
+
shots = ((max(1, shots >> 1) + 3) >> 2) << 2
|
|
145
149
|
n = len(G_m)
|
|
146
150
|
tot_init_weight = weights.sum()
|
|
147
151
|
|
|
@@ -199,6 +203,7 @@ def init_J_and_z(G_m):
|
|
|
199
203
|
return J_eff, degrees, G_max
|
|
200
204
|
|
|
201
205
|
|
|
206
|
+
@njit
|
|
202
207
|
def cpu_footer(shots, quality, n_qubits, G_m, nodes, is_spin_glass, anneal_t, anneal_h, repulsion_base):
|
|
203
208
|
J_eff, degrees, max_edge = init_J_and_z(G_m)
|
|
204
209
|
hamming_prob = maxcut_hamming_cdf(n_qubits, J_eff, degrees, quality, anneal_t, anneal_h)
|
|
@@ -319,7 +324,8 @@ def maxcut_tfim(
|
|
|
319
324
|
if repulsion_base is None:
|
|
320
325
|
repulsion_base = 8.0
|
|
321
326
|
|
|
322
|
-
|
|
327
|
+
wgs = max(32, opencl_context.work_group_size)
|
|
328
|
+
is_opencl = is_maxcut_gpu and IS_OPENCL_AVAILABLE and (n_qubits >= wgs) and (shots >= wgs)
|
|
323
329
|
|
|
324
330
|
if not is_opencl:
|
|
325
331
|
bit_string, best_value, partition = cpu_footer(shots, quality, n_qubits, G_m, nodes, is_spin_glass, anneal_t, anneal_h, repulsion_base)
|
|
@@ -79,22 +79,25 @@ def local_repulsion_choice(G_data, G_rows, G_cols, max_edge, weights, tot_init_w
|
|
|
79
79
|
def compute_energy(sample, G_data, G_rows, G_cols, n_qubits):
|
|
80
80
|
energy = 0
|
|
81
81
|
for u in range(n_qubits):
|
|
82
|
+
u_bit = sample[u]
|
|
82
83
|
for col in range(G_rows[u], G_rows[u + 1]):
|
|
83
84
|
v = G_cols[col]
|
|
84
85
|
val = G_data[col]
|
|
85
|
-
energy += val if
|
|
86
|
+
energy += val if u_bit == sample[v] else -val
|
|
86
87
|
|
|
87
88
|
return -energy
|
|
88
89
|
|
|
89
90
|
|
|
90
91
|
@njit
|
|
91
92
|
def compute_cut(sample, G_data, G_rows, G_cols, n_qubits):
|
|
92
|
-
l,
|
|
93
|
+
l, r = get_cut_base(sample)
|
|
94
|
+
s = l if len(l) < len(r) else r
|
|
93
95
|
cut = 0
|
|
94
|
-
for u in
|
|
96
|
+
for u in s:
|
|
97
|
+
u_bit = sample[u]
|
|
95
98
|
for col in range(G_rows[u], G_rows[u + 1]):
|
|
96
99
|
v = G_cols[col]
|
|
97
|
-
if
|
|
100
|
+
if u_bit != sample[v]:
|
|
98
101
|
cut += G_data[col]
|
|
99
102
|
|
|
100
103
|
return cut
|
|
@@ -102,7 +105,7 @@ def compute_cut(sample, G_data, G_rows, G_cols, n_qubits):
|
|
|
102
105
|
|
|
103
106
|
@njit(parallel=True)
|
|
104
107
|
def sample_measurement(G_data, G_rows, G_cols, max_edge, shots, thresholds, weights, repulsion_base, is_spin_glass):
|
|
105
|
-
shots =
|
|
108
|
+
shots = max(1, shots >> 1)
|
|
106
109
|
n = G_rows.shape[0] - 1
|
|
107
110
|
tot_init_weight = weights.sum()
|
|
108
111
|
|
|
@@ -119,16 +122,20 @@ def sample_measurement(G_data, G_rows, G_cols, max_edge, shots, thresholds, weig
|
|
|
119
122
|
for s in prange(shots):
|
|
120
123
|
# First dimension: Hamming weight
|
|
121
124
|
m = sample_mag(thresholds)
|
|
125
|
+
|
|
122
126
|
# Second dimension: permutation within Hamming weight
|
|
123
|
-
|
|
124
|
-
|
|
127
|
+
sample = local_repulsion_choice(G_data, G_rows, G_cols, max_edge, weights, tot_init_weight, repulsion_base, n, m)
|
|
128
|
+
solutions[s] = sample
|
|
129
|
+
energies[s] = compute_energy(sample, G_data, G_rows, G_cols, n)
|
|
125
130
|
else:
|
|
126
131
|
for s in prange(shots):
|
|
127
132
|
# First dimension: Hamming weight
|
|
128
133
|
m = sample_mag(thresholds)
|
|
134
|
+
|
|
129
135
|
# Second dimension: permutation within Hamming weight
|
|
130
|
-
|
|
131
|
-
|
|
136
|
+
sample = local_repulsion_choice(G_data, G_rows, G_cols, max_edge, weights, tot_init_weight, repulsion_base, n, m)
|
|
137
|
+
solutions[s] = sample
|
|
138
|
+
energies[s] = compute_cut(sample, G_data, G_rows, G_cols, n)
|
|
132
139
|
|
|
133
140
|
best_index = np.argmax(energies)
|
|
134
141
|
energy = energies[best_index]
|
|
@@ -153,7 +160,7 @@ def shot_loop(G_data, G_rows, G_cols, max_edge, thresholds, weights, tot_init_we
|
|
|
153
160
|
|
|
154
161
|
|
|
155
162
|
def sample_for_opencl(G_data, G_rows, G_cols, G_data_buf, G_rows_buf, G_cols_buf, max_edge, shots, thresholds, weights, repulsion_base, is_spin_glass, is_segmented, segment_size):
|
|
156
|
-
shots = max(1, shots >> 1)
|
|
163
|
+
shots = ((max(1, shots >> 1) + 3) >> 2) << 2
|
|
157
164
|
n = G_rows.shape[0] - 1
|
|
158
165
|
tot_init_weight = weights.sum()
|
|
159
166
|
|
|
@@ -210,6 +217,7 @@ def init_J_and_z(G_m):
|
|
|
210
217
|
return J_eff, degrees, G_max
|
|
211
218
|
|
|
212
219
|
|
|
220
|
+
@njit
|
|
213
221
|
def cpu_footer(J_eff, degrees, shots, quality, n_qubits, G_max, G_data, G_rows, G_cols, nodes, is_spin_glass, anneal_t, anneal_h, repulsion_base):
|
|
214
222
|
hamming_prob = maxcut_hamming_cdf(n_qubits, J_eff, degrees, quality, anneal_t, anneal_h)
|
|
215
223
|
|
|
@@ -382,7 +390,8 @@ def maxcut_tfim_sparse(
|
|
|
382
390
|
|
|
383
391
|
n_qubits = G_m.shape[0]
|
|
384
392
|
|
|
385
|
-
|
|
393
|
+
wgs = max(32, opencl_context.work_group_size)
|
|
394
|
+
is_opencl = is_maxcut_gpu and IS_OPENCL_AVAILABLE and (n_qubits >= wgs) and (shots >= wgs)
|
|
386
395
|
|
|
387
396
|
if not is_opencl:
|
|
388
397
|
bit_string, best_value, partition = cpu_footer(J_eff, degrees, shots, quality, n_qubits, G_max, G_m.data, G_m.indptr, G_m.indices, nodes, is_spin_glass, anneal_t, anneal_h, repulsion_base)
|
|
@@ -64,9 +64,10 @@ def local_repulsion_choice(G_func, nodes, max_edge, weights, tot_init_weight, re
|
|
|
64
64
|
def compute_energy(sample, G_func, nodes, n_qubits):
|
|
65
65
|
energy = 0
|
|
66
66
|
for u in range(n_qubits):
|
|
67
|
+
u_bit = sample[u]
|
|
67
68
|
for v in range(u + 1, n_qubits):
|
|
68
69
|
val = G_func(nodes[u], nodes[v])
|
|
69
|
-
energy += val if
|
|
70
|
+
energy += val if u_bit == sample[v] else -val
|
|
70
71
|
|
|
71
72
|
return -energy
|
|
72
73
|
|
|
@@ -96,14 +97,24 @@ def sample_measurement(G_func, nodes, max_edge, shots, thresholds, degrees_sum,
|
|
|
96
97
|
improved = True
|
|
97
98
|
while improved:
|
|
98
99
|
improved = False
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
100
|
+
if is_spin_glass:
|
|
101
|
+
for s in prange(shots):
|
|
102
|
+
# First dimension: Hamming weight
|
|
103
|
+
m = sample_mag(thresholds)
|
|
104
|
+
|
|
105
|
+
# Second dimension: permutation within Hamming weight
|
|
106
|
+
sample = local_repulsion_choice(G_func, nodes, max_edge, weights, tot_init_weight, repulsion_base, n, m)
|
|
107
|
+
solutions[s] = sample
|
|
108
|
+
energies[s] = compute_energy(sample, G_func, nodes, n)
|
|
109
|
+
else:
|
|
110
|
+
for s in prange(shots):
|
|
111
|
+
# First dimension: Hamming weight
|
|
112
|
+
m = sample_mag(thresholds)
|
|
113
|
+
|
|
114
|
+
# Second dimension: permutation within Hamming weight
|
|
115
|
+
sample = local_repulsion_choice(G_func, nodes, max_edge, weights, tot_init_weight, repulsion_base, n, m)
|
|
116
|
+
solutions[s] = sample
|
|
117
|
+
energies[s] = compute_cut(sample, G_func, nodes, n)
|
|
107
118
|
|
|
108
119
|
best_index = np.argmax(energies)
|
|
109
120
|
energy = energies[best_index]
|
|
@@ -32,8 +32,9 @@ def compute_energy(theta_bits, G_m):
|
|
|
32
32
|
n_qubits = len(G_m)
|
|
33
33
|
energy = 0
|
|
34
34
|
for u in range(n_qubits):
|
|
35
|
+
u_bit = theta_bits[u]
|
|
35
36
|
for v in range(u + 1, n_qubits):
|
|
36
|
-
energy += G_m[u, v] if
|
|
37
|
+
energy += G_m[u, v] if u_bit == theta_bits[v] else -G_m[u, v]
|
|
37
38
|
|
|
38
39
|
return energy
|
|
39
40
|
|
|
@@ -19,12 +19,14 @@ except ImportError:
|
|
|
19
19
|
|
|
20
20
|
@njit
|
|
21
21
|
def evaluate_cut_edges(theta_bits, G_data, G_rows, G_cols):
|
|
22
|
-
l,
|
|
22
|
+
l, r = get_cut_base(theta_bits)
|
|
23
|
+
s = l if len(l) < len(r) else r
|
|
23
24
|
cut = 0
|
|
24
|
-
for u in
|
|
25
|
+
for u in s:
|
|
26
|
+
u_bit = theta_bits[u]
|
|
25
27
|
for col in range(G_rows[u], G_rows[u + 1]):
|
|
26
28
|
v = G_cols[col]
|
|
27
|
-
if
|
|
29
|
+
if u_bit != theta_bits[v]:
|
|
28
30
|
cut += G_data[col]
|
|
29
31
|
|
|
30
32
|
return cut
|
|
@@ -28,9 +28,10 @@ def compute_energy(theta_bits, G_func, nodes):
|
|
|
28
28
|
n_qubits = len(nodes)
|
|
29
29
|
energy = 0
|
|
30
30
|
for u in range(n_qubits):
|
|
31
|
+
u_bit = theta_bits[u]
|
|
31
32
|
for v in range(u + 1, n_qubits):
|
|
32
33
|
val = G_func(nodes[u], nodes[v])
|
|
33
|
-
energy += (val if
|
|
34
|
+
energy += (val if u_bit == theta_bits[v] else -val)
|
|
34
35
|
|
|
35
36
|
return energy
|
|
36
37
|
|
|
@@ -7,7 +7,7 @@ with open(README_PATH) as readme_file:
|
|
|
7
7
|
|
|
8
8
|
setup(
|
|
9
9
|
name='pyqrackising',
|
|
10
|
-
version='8.14.
|
|
10
|
+
version='8.14.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
|