PyQrackIsing 5.7.3__tar.gz → 5.7.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-5.7.3/pyqrackising.egg-info → pyqrackising-5.7.4}/PKG-INFO +1 -1
- {pyqrackising-5.7.3 → pyqrackising-5.7.4}/pyproject.toml +1 -1
- {pyqrackising-5.7.3 → pyqrackising-5.7.4}/pyqrackising/kernels.cl +60 -51
- {pyqrackising-5.7.3 → pyqrackising-5.7.4}/pyqrackising/maxcut_tfim.py +10 -14
- {pyqrackising-5.7.3 → pyqrackising-5.7.4}/pyqrackising/maxcut_tfim_sparse.py +11 -15
- {pyqrackising-5.7.3 → pyqrackising-5.7.4}/pyqrackising/maxcut_tfim_streaming.py +9 -13
- {pyqrackising-5.7.3 → pyqrackising-5.7.4}/pyqrackising/spin_glass_solver.py +1 -1
- {pyqrackising-5.7.3 → pyqrackising-5.7.4}/pyqrackising/spin_glass_solver_sparse.py +1 -1
- {pyqrackising-5.7.3 → pyqrackising-5.7.4}/pyqrackising/spin_glass_solver_streaming.py +1 -1
- {pyqrackising-5.7.3 → pyqrackising-5.7.4/pyqrackising.egg-info}/PKG-INFO +1 -1
- {pyqrackising-5.7.3 → pyqrackising-5.7.4}/setup.py +1 -1
- {pyqrackising-5.7.3 → pyqrackising-5.7.4}/CMakeLists.txt +0 -0
- {pyqrackising-5.7.3 → pyqrackising-5.7.4}/LICENSE.md +0 -0
- {pyqrackising-5.7.3 → pyqrackising-5.7.4}/MANIFEST.in +0 -0
- {pyqrackising-5.7.3 → pyqrackising-5.7.4}/README.md +0 -0
- {pyqrackising-5.7.3 → pyqrackising-5.7.4}/pyqrackising/__init__.py +0 -0
- {pyqrackising-5.7.3 → pyqrackising-5.7.4}/pyqrackising/_pyqrack_ising.cpp +0 -0
- {pyqrackising-5.7.3 → pyqrackising-5.7.4}/pyqrackising/generate_tfim_samples.py +0 -0
- {pyqrackising-5.7.3 → pyqrackising-5.7.4}/pyqrackising/maxcut_tfim_util.py +0 -0
- {pyqrackising-5.7.3 → pyqrackising-5.7.4}/pyqrackising/spin_glass_solver_util.py +0 -0
- {pyqrackising-5.7.3 → pyqrackising-5.7.4}/pyqrackising/tfim_magnetization.py +0 -0
- {pyqrackising-5.7.3 → pyqrackising-5.7.4}/pyqrackising/tfim_square_magnetization.py +0 -0
- {pyqrackising-5.7.3 → pyqrackising-5.7.4}/pyqrackising/tsp.py +0 -0
- {pyqrackising-5.7.3 → pyqrackising-5.7.4}/pyqrackising.egg-info/SOURCES.txt +0 -0
- {pyqrackising-5.7.3 → pyqrackising-5.7.4}/pyqrackising.egg-info/dependency_links.txt +0 -0
- {pyqrackising-5.7.3 → pyqrackising-5.7.4}/pyqrackising.egg-info/not-zip-safe +0 -0
- {pyqrackising-5.7.3 → pyqrackising-5.7.4}/pyqrackising.egg-info/top_level.txt +0 -0
- {pyqrackising-5.7.3 → pyqrackising-5.7.4}/setup.cfg +0 -0
|
@@ -12,7 +12,7 @@ build-backend = "setuptools.build_meta"
|
|
|
12
12
|
|
|
13
13
|
[project]
|
|
14
14
|
name = "pyqrackising"
|
|
15
|
-
version = "5.7.
|
|
15
|
+
version = "5.7.4"
|
|
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"}
|
|
@@ -1,94 +1,103 @@
|
|
|
1
1
|
__kernel void init_theta(
|
|
2
|
-
__constant
|
|
2
|
+
__constant double* fargs,
|
|
3
3
|
const int n_qubits,
|
|
4
|
-
__constant
|
|
5
|
-
__constant
|
|
6
|
-
__global
|
|
4
|
+
__constant double* J_eff,
|
|
5
|
+
__constant unsigned* degrees,
|
|
6
|
+
__global double* theta
|
|
7
7
|
) {
|
|
8
8
|
const int q = get_global_id(0);
|
|
9
9
|
if (q >= n_qubits) {
|
|
10
10
|
return;
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
-
const
|
|
13
|
+
const double h_mult = fabs(fargs[2]);
|
|
14
14
|
|
|
15
|
-
const
|
|
16
|
-
const
|
|
17
|
-
const
|
|
15
|
+
const double J = J_eff[q];
|
|
16
|
+
const unsigned z = degrees[q];
|
|
17
|
+
const double abs_zJ = fabs(z * J);
|
|
18
18
|
|
|
19
19
|
float val;
|
|
20
|
-
if (abs_zJ < 2e-
|
|
21
|
-
val = (J > 0.
|
|
20
|
+
if (abs_zJ < 2e-52) {
|
|
21
|
+
val = (J > 0.0) ? M_PI_F : -M_PI_F;
|
|
22
22
|
} else {
|
|
23
|
-
val = asin(fmax(-1.
|
|
23
|
+
val = asin(fmax(-1.0, fmin(1.0, h_mult / (z * J))));
|
|
24
24
|
}
|
|
25
25
|
|
|
26
26
|
theta[q] = val;
|
|
27
27
|
}
|
|
28
28
|
|
|
29
29
|
// By Google Search AI
|
|
30
|
-
inline void AtomicAdd_g_f(volatile __global
|
|
30
|
+
inline void AtomicAdd_g_f(volatile __global double *source, const double operand) {
|
|
31
31
|
union {
|
|
32
|
-
|
|
33
|
-
|
|
32
|
+
ulong intVal;
|
|
33
|
+
double floatVal;
|
|
34
34
|
} oldVal, newVal;
|
|
35
35
|
|
|
36
36
|
do {
|
|
37
37
|
oldVal.floatVal = *source;
|
|
38
38
|
newVal.floatVal = oldVal.floatVal + operand;
|
|
39
39
|
// Use atomic_cmpxchg to atomically update the value
|
|
40
|
-
} while (atomic_cmpxchg((volatile __global
|
|
40
|
+
} while (atomic_cmpxchg((volatile __global ulong*)source, oldVal.intVal, newVal.intVal) != oldVal.intVal);
|
|
41
41
|
}
|
|
42
42
|
|
|
43
43
|
// By Elara (custom OpenAI GPT)
|
|
44
|
-
inline
|
|
45
|
-
int q,
|
|
44
|
+
inline double probability_by_hamming_weight(
|
|
45
|
+
int q, double J, double h, unsigned z, double theta, double t, int n_qubits
|
|
46
46
|
) {
|
|
47
|
-
|
|
48
|
-
if (ratio > 1.
|
|
49
|
-
|
|
47
|
+
double ratio = fabs(h) / (z * J);
|
|
48
|
+
if (ratio > 1.0) {
|
|
49
|
+
ratio = 1.0;
|
|
50
|
+
}
|
|
51
|
+
double theta_c = asin(ratio);
|
|
52
|
+
|
|
53
|
+
double p = pow(2.0, fabs(J / h) - 1.0)
|
|
54
|
+
* (1.0 + sin(theta - theta_c) * cos(1.5 * M_PI_F * J * t + theta) / (1.0 + sqrt(t)))
|
|
55
|
+
- 0.5;
|
|
50
56
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
57
|
+
if ((p * (n_qubits + 2.0)) >= 1024.0) {
|
|
58
|
+
return 0.0;
|
|
59
|
+
}
|
|
54
60
|
|
|
55
|
-
|
|
61
|
+
double numerator = pow(2.0, (n_qubits + 2.0) * p) - 1.0;
|
|
62
|
+
double denominator = pow(2.0, p) - 1.0;
|
|
63
|
+
double result = numerator * pow(2.0, -((n_qubits + 1.0) * p) - p * q) / denominator;
|
|
56
64
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
65
|
+
if (isnan(result) || isinf(result)) {
|
|
66
|
+
return 0.0;
|
|
67
|
+
}
|
|
60
68
|
|
|
61
|
-
if (isnan(result) || isinf(result)) return 0.0f;
|
|
62
69
|
return result;
|
|
63
70
|
}
|
|
64
71
|
|
|
65
72
|
__kernel void maxcut_hamming_cdf(
|
|
66
73
|
int n_qubits,
|
|
67
|
-
__constant
|
|
68
|
-
__constant
|
|
69
|
-
__constant
|
|
70
|
-
__constant
|
|
71
|
-
__global
|
|
74
|
+
__constant unsigned* degrees,
|
|
75
|
+
__constant double* args,
|
|
76
|
+
__constant double* J_func,
|
|
77
|
+
__constant double* theta,
|
|
78
|
+
__global double* hamming_prob
|
|
72
79
|
) {
|
|
73
|
-
const
|
|
74
|
-
const
|
|
75
|
-
const
|
|
80
|
+
const double delta_t = args[0U];
|
|
81
|
+
const double tot_t = args[1U];
|
|
82
|
+
const double h_mult = args[2U];
|
|
76
83
|
const int step = get_group_id(0) / n_qubits;
|
|
77
84
|
const int qi = get_group_id(0) % n_qubits;
|
|
78
|
-
const
|
|
79
|
-
const
|
|
80
|
-
if (fabs(z * J_eff) <=
|
|
85
|
+
const double J_eff = J_func[qi];
|
|
86
|
+
const unsigned z = degrees[qi];
|
|
87
|
+
if (fabs(z * J_eff) <= 2e-52) {
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
81
90
|
|
|
82
|
-
const
|
|
83
|
-
const
|
|
84
|
-
const
|
|
85
|
-
const
|
|
91
|
+
const double theta_eff = theta[qi];
|
|
92
|
+
const double t = step * delta_t;
|
|
93
|
+
const double tm1 = (step - 1) * delta_t;
|
|
94
|
+
const double h_t = h_mult * (tot_t - t);
|
|
86
95
|
|
|
87
96
|
const int n_threads = get_local_size(0);
|
|
88
97
|
|
|
89
98
|
for (int qo = get_local_id(0); qo < n_qubits; qo += n_threads) {
|
|
90
|
-
int _qo = (J_eff > 0.
|
|
91
|
-
|
|
99
|
+
int _qo = (J_eff > 0.0) ? (n_qubits - (1 + qo)) : qo;
|
|
100
|
+
double diff = probability_by_hamming_weight(_qo, J_eff, h_t, z, theta_eff, t, n_qubits);
|
|
92
101
|
diff -= probability_by_hamming_weight(_qo, J_eff, h_t, z, theta_eff, tm1, n_qubits);
|
|
93
102
|
AtomicAdd_g_f(&(hamming_prob[_qo]), diff);
|
|
94
103
|
}
|
|
@@ -131,7 +140,7 @@ float bootstrap_worker(__constant char* theta, __global double* G_m, __constant
|
|
|
131
140
|
return (float)energy;
|
|
132
141
|
}
|
|
133
142
|
|
|
134
|
-
#define
|
|
143
|
+
#define EPSILON 1.1920928955078125e-7
|
|
135
144
|
|
|
136
145
|
__kernel void bootstrap(
|
|
137
146
|
uint prng_seed,
|
|
@@ -176,7 +185,7 @@ __kernel void bootstrap(
|
|
|
176
185
|
if (hid_energy < lid_energy) {
|
|
177
186
|
loc_energy[lt_id] = hid_energy;
|
|
178
187
|
loc_index[lt_id] = loc_index[lt_id + offset];
|
|
179
|
-
} else if (((hid_energy - lid_energy) <=
|
|
188
|
+
} else if (((hid_energy - lid_energy) <= EPSILON) && ((xorshift32(&prng_seed) >> 31) & 1)) {
|
|
180
189
|
loc_index[lt_id] = loc_index[lt_id + offset];
|
|
181
190
|
}
|
|
182
191
|
}
|
|
@@ -261,7 +270,7 @@ __kernel void bootstrap_sparse(
|
|
|
261
270
|
if (hid_energy < lid_energy) {
|
|
262
271
|
loc_energy[lt_id] = hid_energy;
|
|
263
272
|
loc_index[lt_id] = loc_index[lt_id + offset];
|
|
264
|
-
} else if (((hid_energy - lid_energy) <=
|
|
273
|
+
} else if (((hid_energy - lid_energy) <= EPSILON) && ((xorshift32(&prng_seed) >> 31) & 1)) {
|
|
265
274
|
loc_index[lt_id] = loc_index[lt_id + offset];
|
|
266
275
|
}
|
|
267
276
|
}
|
|
@@ -370,7 +379,7 @@ __kernel void sample_for_solution_best_bitset(
|
|
|
370
379
|
break;
|
|
371
380
|
}
|
|
372
381
|
if ((temp_sol[k >> 5] >> l) & 1) {
|
|
373
|
-
weight *= max(
|
|
382
|
+
weight *= max(EPSILON, 1.0 - G_m[u_offset + v] / max_weight);
|
|
374
383
|
}
|
|
375
384
|
}
|
|
376
385
|
}
|
|
@@ -574,7 +583,7 @@ __kernel void sample_for_solution_best_bitset_sparse(
|
|
|
574
583
|
const int v = G_cols[col];
|
|
575
584
|
|
|
576
585
|
if ((temp_sol[v >> 5] >> (v & 31)) & 1) {
|
|
577
|
-
weight *= max(
|
|
586
|
+
weight *= max(EPSILON, 1.0 - G_data[col] / max_weight);
|
|
578
587
|
}
|
|
579
588
|
}
|
|
580
589
|
|
|
@@ -586,7 +595,7 @@ __kernel void sample_for_solution_best_bitset_sparse(
|
|
|
586
595
|
int end = G_rows[v + 1];
|
|
587
596
|
int j = binary_search(&(G_cols[start]), u, end - start) + start;
|
|
588
597
|
if (j < end) {
|
|
589
|
-
weight *= max(
|
|
598
|
+
weight *= max(EPSILON, 1.0 - G_data[j] / max_weight);
|
|
590
599
|
}
|
|
591
600
|
}
|
|
592
601
|
|
|
@@ -22,7 +22,7 @@ def update_repulsion_choice(G_m, max_weight, weights, n, used, node):
|
|
|
22
22
|
for nbr in range(n):
|
|
23
23
|
if used[nbr]:
|
|
24
24
|
continue
|
|
25
|
-
weights[nbr] *= max(
|
|
25
|
+
weights[nbr] *= max(1.1920928955078125e-7, 1 - G_m[node, nbr] / max_weight)
|
|
26
26
|
|
|
27
27
|
|
|
28
28
|
# Written by Elara (OpenAI custom GPT) and improved by Dan Strano
|
|
@@ -120,7 +120,7 @@ def sample_for_solution(G_m, shots, thresholds, weights):
|
|
|
120
120
|
def init_J_and_z(G_m):
|
|
121
121
|
n_qubits = len(G_m)
|
|
122
122
|
degrees = np.empty(n_qubits, dtype=np.uint32)
|
|
123
|
-
J_eff = np.empty(n_qubits, dtype=np.
|
|
123
|
+
J_eff = np.empty(n_qubits, dtype=np.float64)
|
|
124
124
|
J_max = -float("inf")
|
|
125
125
|
for n in prange(n_qubits):
|
|
126
126
|
degree = sum(G_m[n] != 0.0)
|
|
@@ -218,11 +218,9 @@ def cpu_footer(shots, quality, n_qubits, G_m, nodes):
|
|
|
218
218
|
maxcut_hamming_cdf(n_qubits, J_eff, degrees, quality, hamming_prob)
|
|
219
219
|
|
|
220
220
|
degrees = None
|
|
221
|
-
J_eff = 1.0 / (1.0 + (
|
|
222
|
-
weights = J_eff.astype(np.float64)
|
|
223
|
-
J_eff = None
|
|
221
|
+
J_eff = 1.0 / (1.0 + (2 ** -52) - J_eff)
|
|
224
222
|
|
|
225
|
-
best_solution, best_value = sample_for_solution(G_m, shots, hamming_prob,
|
|
223
|
+
best_solution, best_value = sample_for_solution(G_m, shots, hamming_prob, J_eff)
|
|
226
224
|
|
|
227
225
|
bit_string, l, r = get_cut(best_solution, nodes)
|
|
228
226
|
|
|
@@ -275,13 +273,13 @@ def maxcut_tfim(
|
|
|
275
273
|
return "01", weight, ([nodes[0]], [nodes[1]])
|
|
276
274
|
|
|
277
275
|
if quality is None:
|
|
278
|
-
quality =
|
|
276
|
+
quality = 3
|
|
279
277
|
|
|
280
278
|
if shots is None:
|
|
281
279
|
# Number of measurement shots
|
|
282
280
|
shots = n_qubits << quality
|
|
283
281
|
|
|
284
|
-
n_steps =
|
|
282
|
+
n_steps = n_qubits << quality
|
|
285
283
|
grid_size = n_steps * n_qubits
|
|
286
284
|
|
|
287
285
|
if (not is_base_maxcut_gpu) or not (IS_OPENCL_AVAILABLE and grid_size >= 128):
|
|
@@ -293,7 +291,7 @@ def maxcut_tfim(
|
|
|
293
291
|
tot_t = 2.0 * n_steps * delta_t
|
|
294
292
|
h_mult = 2.0 / tot_t
|
|
295
293
|
|
|
296
|
-
args = np.empty(3, dtype=np.
|
|
294
|
+
args = np.empty(3, dtype=np.float64)
|
|
297
295
|
args[0] = delta_t
|
|
298
296
|
args[1] = tot_t
|
|
299
297
|
args[2] = h_mult
|
|
@@ -303,7 +301,7 @@ def maxcut_tfim(
|
|
|
303
301
|
args_buf = cl.Buffer(opencl_context.ctx, mf.READ_ONLY | mf.COPY_HOST_PTR, hostbuf=args)
|
|
304
302
|
J_buf = cl.Buffer(opencl_context.ctx, mf.READ_ONLY | mf.COPY_HOST_PTR, hostbuf=J_eff)
|
|
305
303
|
deg_buf = cl.Buffer(opencl_context.ctx, mf.READ_ONLY | mf.COPY_HOST_PTR, hostbuf=degrees)
|
|
306
|
-
theta_buf = cl.Buffer(opencl_context.ctx, mf.READ_WRITE, size=(n_qubits * np.
|
|
304
|
+
theta_buf = cl.Buffer(opencl_context.ctx, mf.READ_WRITE, size=(n_qubits * np.float64().nbytes))
|
|
307
305
|
|
|
308
306
|
# Warp size is 32:
|
|
309
307
|
group_size = min(n_qubits, 64)
|
|
@@ -347,11 +345,9 @@ def maxcut_tfim(
|
|
|
347
345
|
|
|
348
346
|
if not is_alt_gpu_sampling:
|
|
349
347
|
degrees = None
|
|
350
|
-
J_eff = 1.0 / (1.0 + (
|
|
351
|
-
weights = J_eff.astype(np.float64)
|
|
352
|
-
J_eff = None
|
|
348
|
+
J_eff = 1.0 / (1.0 + (2 ** -52) - J_eff)
|
|
353
349
|
|
|
354
|
-
return gpu_footer(shots, n_qubits, G_m,
|
|
350
|
+
return gpu_footer(shots, n_qubits, G_m, J_eff, hamming_prob, nodes)
|
|
355
351
|
|
|
356
352
|
fix_cdf(hamming_prob)
|
|
357
353
|
best_solution, best_value = run_sampling_opencl(G_m, hamming_prob, shots, n_qubits, is_g_buf_reused)
|
|
@@ -43,7 +43,7 @@ def update_repulsion_choice(G_cols, G_data, G_rows, max_weight, weights, n, used
|
|
|
43
43
|
nbr = G_cols[j]
|
|
44
44
|
if used[nbr]:
|
|
45
45
|
continue
|
|
46
|
-
weights[nbr] *= max(
|
|
46
|
+
weights[nbr] *= max(1.1920928955078125e-7, 1 - G_data[j] / max_weight)
|
|
47
47
|
|
|
48
48
|
for nbr in range(node):
|
|
49
49
|
if used[nbr]:
|
|
@@ -52,7 +52,7 @@ def update_repulsion_choice(G_cols, G_data, G_rows, max_weight, weights, n, used
|
|
|
52
52
|
end = G_rows[nbr + 1]
|
|
53
53
|
j = binary_search(G_cols[start:end], node) + start
|
|
54
54
|
if j < end:
|
|
55
|
-
weights[nbr] *= max(
|
|
55
|
+
weights[nbr] *= max(1.1920928955078125e-7, 1 - G_data[j] / max_weight)
|
|
56
56
|
|
|
57
57
|
|
|
58
58
|
# Written by Elara (OpenAI custom GPT) and improved by Dan Strano
|
|
@@ -152,7 +152,7 @@ def sample_for_solution(G_data, G_rows, G_cols, shots, thresholds, weights):
|
|
|
152
152
|
def init_J_and_z(G_data, G_rows, G_cols):
|
|
153
153
|
n_qubits = G_rows.shape[0] - 1
|
|
154
154
|
degrees = np.empty(n_qubits, dtype=np.uint32)
|
|
155
|
-
J_eff = np.empty(n_qubits, dtype=np.
|
|
155
|
+
J_eff = np.empty(n_qubits, dtype=np.float64)
|
|
156
156
|
for r in prange(n_qubits):
|
|
157
157
|
# Row sum
|
|
158
158
|
start = G_rows[r]
|
|
@@ -271,11 +271,9 @@ def cpu_footer(shots, quality, n_qubits, G_data, G_rows, G_cols, nodes):
|
|
|
271
271
|
maxcut_hamming_cdf(n_qubits, J_eff, degrees, quality, hamming_prob)
|
|
272
272
|
|
|
273
273
|
degrees = None
|
|
274
|
-
J_eff = 1.0 / (1.0 + (
|
|
275
|
-
weights = J_eff.astype(np.float64)
|
|
276
|
-
J_eff = None
|
|
274
|
+
J_eff = 1.0 / (1.0 + (2 ** -52) - J_eff)
|
|
277
275
|
|
|
278
|
-
best_solution, best_value = sample_for_solution(G_data, G_rows, G_cols, shots, hamming_prob,
|
|
276
|
+
best_solution, best_value = sample_for_solution(G_data, G_rows, G_cols, shots, hamming_prob, J_eff)
|
|
279
277
|
|
|
280
278
|
bit_string, l, r = get_cut(best_solution, nodes)
|
|
281
279
|
|
|
@@ -294,7 +292,7 @@ def gpu_footer(shots, n_qubits, G_data, G_rows, G_cols, weights, hamming_prob, n
|
|
|
294
292
|
|
|
295
293
|
|
|
296
294
|
def to_scipy_sparse_upper_triangular(G, nodes, n_nodes):
|
|
297
|
-
lil = lil_matrix((n_nodes, n_nodes), dtype=np.
|
|
295
|
+
lil = lil_matrix((n_nodes, n_nodes), dtype=np.float64)
|
|
298
296
|
for u in range(n_nodes):
|
|
299
297
|
u_node = nodes[u]
|
|
300
298
|
for v in range(u + 1, n_nodes):
|
|
@@ -340,13 +338,13 @@ def maxcut_tfim_sparse(
|
|
|
340
338
|
return "01", weight, ([nodes[0]], [nodes[1]])
|
|
341
339
|
|
|
342
340
|
if quality is None:
|
|
343
|
-
quality =
|
|
341
|
+
quality = 3
|
|
344
342
|
|
|
345
343
|
if shots is None:
|
|
346
344
|
# Number of measurement shots
|
|
347
345
|
shots = n_qubits << quality
|
|
348
346
|
|
|
349
|
-
n_steps =
|
|
347
|
+
n_steps = n_qubits << quality
|
|
350
348
|
grid_size = n_steps * n_qubits
|
|
351
349
|
|
|
352
350
|
if (not is_base_maxcut_gpu) or not (IS_OPENCL_AVAILABLE and grid_size >= 128):
|
|
@@ -358,7 +356,7 @@ def maxcut_tfim_sparse(
|
|
|
358
356
|
tot_t = 2.0 * n_steps * delta_t
|
|
359
357
|
h_mult = 2.0 / tot_t
|
|
360
358
|
|
|
361
|
-
args = np.empty(3, dtype=np.
|
|
359
|
+
args = np.empty(3, dtype=np.float64)
|
|
362
360
|
args[0] = delta_t
|
|
363
361
|
args[1] = tot_t
|
|
364
362
|
args[2] = h_mult
|
|
@@ -412,11 +410,9 @@ def maxcut_tfim_sparse(
|
|
|
412
410
|
|
|
413
411
|
if not is_alt_gpu_sampling:
|
|
414
412
|
degrees = None
|
|
415
|
-
J_eff = 1.0 / (1.0 + (
|
|
416
|
-
weights = J_eff.astype(np.float64)
|
|
417
|
-
J_eff = None
|
|
413
|
+
J_eff = 1.0 / (1.0 + (2 ** -52) - J_eff)
|
|
418
414
|
|
|
419
|
-
return gpu_footer(shots, n_qubits, G_m.data, G_m.indptr, G_m.indices,
|
|
415
|
+
return gpu_footer(shots, n_qubits, G_m.data, G_m.indptr, G_m.indices, J_eff, hamming_prob, nodes)
|
|
420
416
|
|
|
421
417
|
fix_cdf(hamming_prob)
|
|
422
418
|
best_solution, best_value = run_sampling_opencl(G_m, hamming_prob, shots, n_qubits, is_g_buf_reused)
|
|
@@ -22,7 +22,7 @@ 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(
|
|
25
|
+
weights[nbr] *= max(1.1920928955078125e-7, 1 - G_func((nodes[node], nodes[nbr]), G_func_args_tuple) / max_weight)
|
|
26
26
|
|
|
27
27
|
|
|
28
28
|
# Written by Elara (OpenAI custom GPT) and improved by Dan Strano
|
|
@@ -120,7 +120,7 @@ def sample_for_solution(G_func, G_func_args_tuple, nodes, max_weight, shots, thr
|
|
|
120
120
|
def init_J_and_z(G_func, G_func_args_tuple, nodes):
|
|
121
121
|
n_qubits = len(nodes)
|
|
122
122
|
degrees = np.empty(n_qubits, dtype=np.uint32)
|
|
123
|
-
J_eff = np.empty(n_qubits, dtype=np.
|
|
123
|
+
J_eff = np.empty(n_qubits, dtype=np.float64)
|
|
124
124
|
J_max = -float("inf")
|
|
125
125
|
G_max = -float("inf")
|
|
126
126
|
for n in prange(n_qubits):
|
|
@@ -151,11 +151,9 @@ def cpu_footer(shots, quality, n_qubits, G_func, G_func_args_tuple, nodes):
|
|
|
151
151
|
|
|
152
152
|
max_weight = degrees.sum()
|
|
153
153
|
degrees = None
|
|
154
|
-
J_eff = 1.0 / (1.0 + (
|
|
155
|
-
weights = J_eff.astype(np.float64)
|
|
156
|
-
J_eff = None
|
|
154
|
+
J_eff = 1.0 / (1.0 + (2 ** -52) - J_eff)
|
|
157
155
|
|
|
158
|
-
best_solution, best_value = sample_for_solution(G_func, G_func_args_tuple, nodes, G_max, shots, hamming_prob, max_weight,
|
|
156
|
+
best_solution, best_value = sample_for_solution(G_func, G_func_args_tuple, nodes, G_max, shots, hamming_prob, max_weight, J_eff, n_qubits)
|
|
159
157
|
|
|
160
158
|
bit_string, l, r = get_cut(best_solution, nodes)
|
|
161
159
|
|
|
@@ -198,13 +196,13 @@ def maxcut_tfim_streaming(
|
|
|
198
196
|
return "01", weight, ([nodes[0]], [nodes[1]])
|
|
199
197
|
|
|
200
198
|
if quality is None:
|
|
201
|
-
quality =
|
|
199
|
+
quality = 3
|
|
202
200
|
|
|
203
201
|
if shots is None:
|
|
204
202
|
# Number of measurement shots
|
|
205
203
|
shots = n_qubits << quality
|
|
206
204
|
|
|
207
|
-
n_steps =
|
|
205
|
+
n_steps = n_qubits << quality
|
|
208
206
|
grid_size = n_steps * n_qubits
|
|
209
207
|
|
|
210
208
|
if (not is_base_maxcut_gpu) or not (IS_OPENCL_AVAILABLE and grid_size >= 128):
|
|
@@ -216,7 +214,7 @@ def maxcut_tfim_streaming(
|
|
|
216
214
|
tot_t = 2.0 * n_steps * delta_t
|
|
217
215
|
h_mult = 2.0 / tot_t
|
|
218
216
|
|
|
219
|
-
args = np.empty(3, dtype=np.
|
|
217
|
+
args = np.empty(3, dtype=np.float64)
|
|
220
218
|
args[0] = delta_t
|
|
221
219
|
args[1] = tot_t
|
|
222
220
|
args[2] = h_mult
|
|
@@ -270,8 +268,6 @@ def maxcut_tfim_streaming(
|
|
|
270
268
|
|
|
271
269
|
max_weight = degrees.sum()
|
|
272
270
|
degrees = None
|
|
273
|
-
J_eff = 1.0 / (1.0 + (
|
|
274
|
-
weights = J_eff.astype(np.float64)
|
|
275
|
-
J_eff = None
|
|
271
|
+
J_eff = 1.0 / (1.0 + (2 ** -52) - J_eff)
|
|
276
272
|
|
|
277
|
-
return gpu_footer(shots, n_qubits, G_func, G_func_args_tuple, nodes, G_max,
|
|
273
|
+
return gpu_footer(shots, n_qubits, G_func, G_func_args_tuple, nodes, G_max, J_eff, degrees, hamming_prob, max_weight)
|
|
@@ -51,7 +51,7 @@ ext_modules = [CMakeExtension('tfim_sampler')]
|
|
|
51
51
|
|
|
52
52
|
setup(
|
|
53
53
|
name='pyqrackising',
|
|
54
|
-
version='5.7.
|
|
54
|
+
version='5.7.4',
|
|
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
|