PyQrackIsing 7.5.1__tar.gz → 7.5.3__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-7.5.1/pyqrackising.egg-info → pyqrackising-7.5.3}/PKG-INFO +1 -1
- {pyqrackising-7.5.1 → pyqrackising-7.5.3}/pyproject.toml +1 -1
- {pyqrackising-7.5.1 → pyqrackising-7.5.3}/pyqrackising/maxcut_tfim.py +48 -9
- {pyqrackising-7.5.1 → pyqrackising-7.5.3}/pyqrackising/maxcut_tfim_sparse.py +49 -10
- {pyqrackising-7.5.1 → pyqrackising-7.5.3}/pyqrackising/maxcut_tfim_streaming.py +53 -16
- {pyqrackising-7.5.1 → pyqrackising-7.5.3}/pyqrackising/tsp_maxcut.py +12 -15
- {pyqrackising-7.5.1 → pyqrackising-7.5.3/pyqrackising.egg-info}/PKG-INFO +1 -1
- {pyqrackising-7.5.1 → pyqrackising-7.5.3}/setup.py +1 -1
- {pyqrackising-7.5.1 → pyqrackising-7.5.3}/CMakeLists.txt +0 -0
- {pyqrackising-7.5.1 → pyqrackising-7.5.3}/LICENSE.md +0 -0
- {pyqrackising-7.5.1 → pyqrackising-7.5.3}/MANIFEST.in +0 -0
- {pyqrackising-7.5.1 → pyqrackising-7.5.3}/README.md +0 -0
- {pyqrackising-7.5.1 → pyqrackising-7.5.3}/pyqrackising/__init__.py +0 -0
- {pyqrackising-7.5.1 → pyqrackising-7.5.3}/pyqrackising/_pyqrack_ising.cpp +0 -0
- {pyqrackising-7.5.1 → pyqrackising-7.5.3}/pyqrackising/convert_tensor_network_to_tsp.py +0 -0
- {pyqrackising-7.5.1 → pyqrackising-7.5.3}/pyqrackising/generate_tfim_samples.py +0 -0
- {pyqrackising-7.5.1 → pyqrackising-7.5.3}/pyqrackising/kernels.cl +0 -0
- {pyqrackising-7.5.1 → pyqrackising-7.5.3}/pyqrackising/maxcut_tfim_util.py +0 -0
- {pyqrackising-7.5.1 → pyqrackising-7.5.3}/pyqrackising/spin_glass_solver.py +0 -0
- {pyqrackising-7.5.1 → pyqrackising-7.5.3}/pyqrackising/spin_glass_solver_sparse.py +0 -0
- {pyqrackising-7.5.1 → pyqrackising-7.5.3}/pyqrackising/spin_glass_solver_streaming.py +0 -0
- {pyqrackising-7.5.1 → pyqrackising-7.5.3}/pyqrackising/spin_glass_solver_util.py +0 -0
- {pyqrackising-7.5.1 → pyqrackising-7.5.3}/pyqrackising/tfim_magnetization.py +0 -0
- {pyqrackising-7.5.1 → pyqrackising-7.5.3}/pyqrackising/tfim_square_magnetization.py +0 -0
- {pyqrackising-7.5.1 → pyqrackising-7.5.3}/pyqrackising/tsp.py +0 -0
- {pyqrackising-7.5.1 → pyqrackising-7.5.3}/pyqrackising.egg-info/SOURCES.txt +0 -0
- {pyqrackising-7.5.1 → pyqrackising-7.5.3}/pyqrackising.egg-info/dependency_links.txt +0 -0
- {pyqrackising-7.5.1 → pyqrackising-7.5.3}/pyqrackising.egg-info/not-zip-safe +0 -0
- {pyqrackising-7.5.1 → pyqrackising-7.5.3}/pyqrackising.egg-info/top_level.txt +0 -0
- {pyqrackising-7.5.1 → pyqrackising-7.5.3}/setup.cfg +0 -0
|
@@ -12,7 +12,7 @@ build-backend = "setuptools.build_meta"
|
|
|
12
12
|
|
|
13
13
|
[project]
|
|
14
14
|
name = "pyqrackising"
|
|
15
|
-
version = "7.5.
|
|
15
|
+
version = "7.5.3"
|
|
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_m,
|
|
17
|
+
def update_repulsion_choice(G_m, max_edge, weights, n, used, node):
|
|
18
18
|
# Select node
|
|
19
19
|
used[node] = True
|
|
20
20
|
|
|
@@ -22,12 +22,12 @@ 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(1.1920928955078125e-7, 1 - G_m[node, nbr] /
|
|
25
|
+
weights[nbr] *= max(1.1920928955078125e-7, 1 - G_m[node, nbr] / max_edge)
|
|
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_m,
|
|
30
|
+
def local_repulsion_choice(G_m, max_edge, weights, tot_init_weight, n, m):
|
|
31
31
|
"""
|
|
32
32
|
Pick m nodes out of n with repulsion bias:
|
|
33
33
|
- High-degree nodes are already less likely
|
|
@@ -39,10 +39,22 @@ def local_repulsion_choice(G_m, max_weight, weights, n, m, shot):
|
|
|
39
39
|
weights = weights.copy()
|
|
40
40
|
used = np.zeros(n, dtype=np.bool_) # False = available, True = used
|
|
41
41
|
|
|
42
|
-
#
|
|
43
|
-
|
|
42
|
+
# First bit:
|
|
43
|
+
r = np.random.rand()
|
|
44
|
+
cum = 0.0
|
|
45
|
+
node = 0
|
|
46
|
+
for i in range(n):
|
|
47
|
+
cum += weights[i]
|
|
48
|
+
if (tot_init_weight * r) < cum:
|
|
49
|
+
node = i
|
|
50
|
+
break
|
|
44
51
|
|
|
45
|
-
|
|
52
|
+
update_repulsion_choice(G_m, max_edge, weights, n, used, node)
|
|
53
|
+
|
|
54
|
+
if m == 1:
|
|
55
|
+
return used
|
|
56
|
+
|
|
57
|
+
for _ in range(1, m - 1):
|
|
46
58
|
# Count available
|
|
47
59
|
total_w = 0.0
|
|
48
60
|
for i in range(n):
|
|
@@ -68,7 +80,33 @@ def local_repulsion_choice(G_m, max_weight, weights, n, m, shot):
|
|
|
68
80
|
node += 1
|
|
69
81
|
|
|
70
82
|
# Update answer and weights
|
|
71
|
-
update_repulsion_choice(G_m,
|
|
83
|
+
update_repulsion_choice(G_m, max_edge, weights, n, used, node)
|
|
84
|
+
|
|
85
|
+
# Count available
|
|
86
|
+
total_w = 0.0
|
|
87
|
+
for i in range(n):
|
|
88
|
+
if used[i]:
|
|
89
|
+
continue
|
|
90
|
+
total_w += weights[i]
|
|
91
|
+
|
|
92
|
+
# Normalize & sample
|
|
93
|
+
r = np.random.rand()
|
|
94
|
+
cum = 0.0
|
|
95
|
+
node = -1
|
|
96
|
+
for i in range(n):
|
|
97
|
+
if used[i]:
|
|
98
|
+
continue
|
|
99
|
+
cum += weights[i]
|
|
100
|
+
if (total_w * r) < cum:
|
|
101
|
+
node = i
|
|
102
|
+
break
|
|
103
|
+
|
|
104
|
+
if node == -1:
|
|
105
|
+
node = 0
|
|
106
|
+
while used[node]:
|
|
107
|
+
node += 1
|
|
108
|
+
|
|
109
|
+
used[node] = True
|
|
72
110
|
|
|
73
111
|
return used
|
|
74
112
|
|
|
@@ -87,7 +125,8 @@ def compute_energy(sample, G_m, n_qubits):
|
|
|
87
125
|
def sample_for_solution(G_m, shots, thresholds, weights, dtype):
|
|
88
126
|
shots = max(1, shots >> 1)
|
|
89
127
|
n = len(G_m)
|
|
90
|
-
|
|
128
|
+
max_edge = G_m.max()
|
|
129
|
+
tot_init_weight = weights.sum()
|
|
91
130
|
|
|
92
131
|
solutions = np.empty((shots, n), dtype=np.bool_)
|
|
93
132
|
energies = np.empty(shots, dtype=dtype)
|
|
@@ -107,7 +146,7 @@ def sample_for_solution(G_m, shots, thresholds, weights, dtype):
|
|
|
107
146
|
m += 1
|
|
108
147
|
|
|
109
148
|
# Second dimension: permutation within Hamming weight
|
|
110
|
-
sample = local_repulsion_choice(G_m,
|
|
149
|
+
sample = local_repulsion_choice(G_m, max_edge, weights, tot_init_weight, n, m)
|
|
111
150
|
solutions[s] = sample
|
|
112
151
|
energies[s] = compute_energy(sample, G_m, n)
|
|
113
152
|
|
|
@@ -14,7 +14,7 @@ except ImportError:
|
|
|
14
14
|
|
|
15
15
|
|
|
16
16
|
@njit
|
|
17
|
-
def update_repulsion_choice(G_cols, G_data, G_rows,
|
|
17
|
+
def update_repulsion_choice(G_cols, G_data, G_rows, max_edge, weights, n, used, node):
|
|
18
18
|
# Select node
|
|
19
19
|
used[node] = True
|
|
20
20
|
|
|
@@ -23,7 +23,7 @@ def update_repulsion_choice(G_cols, G_data, G_rows, max_weight, weights, n, used
|
|
|
23
23
|
nbr = G_cols[j]
|
|
24
24
|
if used[nbr]:
|
|
25
25
|
continue
|
|
26
|
-
weights[nbr] *= max(1.1920928955078125e-7, 1 - G_data[j] /
|
|
26
|
+
weights[nbr] *= max(1.1920928955078125e-7, 1 - G_data[j] / max_edge)
|
|
27
27
|
|
|
28
28
|
for nbr in range(node):
|
|
29
29
|
if used[nbr]:
|
|
@@ -32,12 +32,12 @@ def update_repulsion_choice(G_cols, G_data, G_rows, max_weight, weights, n, used
|
|
|
32
32
|
end = G_rows[nbr + 1]
|
|
33
33
|
j = binary_search(G_cols[start:end], node) + start
|
|
34
34
|
if j < end:
|
|
35
|
-
weights[nbr] *= max(1.1920928955078125e-7, 1 - G_data[j] /
|
|
35
|
+
weights[nbr] *= max(1.1920928955078125e-7, 1 - G_data[j] / max_edge)
|
|
36
36
|
|
|
37
37
|
|
|
38
38
|
# Written by Elara (OpenAI custom GPT) and improved by Dan Strano
|
|
39
39
|
@njit
|
|
40
|
-
def local_repulsion_choice(G_cols, G_data, G_rows,
|
|
40
|
+
def local_repulsion_choice(G_cols, G_data, G_rows, max_edge, weights, tot_init_weight, n, m):
|
|
41
41
|
"""
|
|
42
42
|
Pick m nodes out of n with repulsion bias:
|
|
43
43
|
- High-degree nodes are already less likely
|
|
@@ -49,10 +49,22 @@ def local_repulsion_choice(G_cols, G_data, G_rows, max_weight, weights, n, m, sh
|
|
|
49
49
|
weights = weights.copy()
|
|
50
50
|
used = np.zeros(n, dtype=np.bool_) # False = available, True = used
|
|
51
51
|
|
|
52
|
-
#
|
|
53
|
-
|
|
52
|
+
# First bit:
|
|
53
|
+
r = np.random.rand()
|
|
54
|
+
cum = 0.0
|
|
55
|
+
node = 0
|
|
56
|
+
for i in range(n):
|
|
57
|
+
cum += weights[i]
|
|
58
|
+
if (tot_init_weight * r) < cum:
|
|
59
|
+
node = i
|
|
60
|
+
break
|
|
54
61
|
|
|
55
|
-
|
|
62
|
+
update_repulsion_choice(G_cols, G_data, G_rows, max_edge, weights, n, used, node)
|
|
63
|
+
|
|
64
|
+
if m == 1:
|
|
65
|
+
return used
|
|
66
|
+
|
|
67
|
+
for _ in range(1, m - 1):
|
|
56
68
|
# Count available
|
|
57
69
|
total_w = 0.0
|
|
58
70
|
for i in range(n):
|
|
@@ -78,7 +90,33 @@ def local_repulsion_choice(G_cols, G_data, G_rows, max_weight, weights, n, m, sh
|
|
|
78
90
|
node += 1
|
|
79
91
|
|
|
80
92
|
# Update answer and weights
|
|
81
|
-
update_repulsion_choice(G_cols, G_data, G_rows,
|
|
93
|
+
update_repulsion_choice(G_cols, G_data, G_rows, max_edge, weights, n, used, node)
|
|
94
|
+
|
|
95
|
+
# Count available
|
|
96
|
+
total_w = 0.0
|
|
97
|
+
for i in range(n):
|
|
98
|
+
if used[i]:
|
|
99
|
+
continue
|
|
100
|
+
total_w += weights[i]
|
|
101
|
+
|
|
102
|
+
# Normalize & sample
|
|
103
|
+
r = np.random.rand()
|
|
104
|
+
cum = 0.0
|
|
105
|
+
node = -1
|
|
106
|
+
for i in range(n):
|
|
107
|
+
if used[i]:
|
|
108
|
+
continue
|
|
109
|
+
cum += weights[i]
|
|
110
|
+
if (total_w * r) < cum:
|
|
111
|
+
node = i
|
|
112
|
+
break
|
|
113
|
+
|
|
114
|
+
if node == -1:
|
|
115
|
+
node = 0
|
|
116
|
+
while used[node]:
|
|
117
|
+
node += 1
|
|
118
|
+
|
|
119
|
+
used[node] = True
|
|
82
120
|
|
|
83
121
|
return used
|
|
84
122
|
|
|
@@ -100,7 +138,8 @@ def compute_energy(sample, G_data, G_rows, G_cols):
|
|
|
100
138
|
def sample_for_solution(G_data, G_rows, G_cols, shots, thresholds, weights, dtype):
|
|
101
139
|
shots = max(1, shots >> 1)
|
|
102
140
|
n = G_rows.shape[0] - 1
|
|
103
|
-
|
|
141
|
+
max_edge = G_data.max()
|
|
142
|
+
tot_init_weight = weights.sum()
|
|
104
143
|
|
|
105
144
|
solutions = np.empty((shots, n), dtype=np.bool_)
|
|
106
145
|
energies = np.empty(shots, dtype=dtype)
|
|
@@ -120,7 +159,7 @@ def sample_for_solution(G_data, G_rows, G_cols, shots, thresholds, weights, dtyp
|
|
|
120
159
|
m += 1
|
|
121
160
|
|
|
122
161
|
# Second dimension: permutation within Hamming weight
|
|
123
|
-
sample = local_repulsion_choice(G_cols, G_data, G_rows,
|
|
162
|
+
sample = local_repulsion_choice(G_cols, G_data, G_rows, max_edge, weights, tot_init_weight, n, m)
|
|
124
163
|
solutions[s] = sample
|
|
125
164
|
energies[s] = compute_energy(sample, G_data, G_rows, G_cols)
|
|
126
165
|
|
|
@@ -14,7 +14,7 @@ except ImportError:
|
|
|
14
14
|
|
|
15
15
|
|
|
16
16
|
@njit
|
|
17
|
-
def update_repulsion_choice(G_func, nodes,
|
|
17
|
+
def update_repulsion_choice(G_func, nodes, max_edge, 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, nodes, 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(1.1920928955078125e-7, 1 - G_func(nodes[node], nodes[nbr]) /
|
|
25
|
+
weights[nbr] *= max(1.1920928955078125e-7, 1 - G_func(nodes[node], nodes[nbr]) / max_edge)
|
|
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, nodes,
|
|
30
|
+
def local_repulsion_choice(G_func, nodes, max_edge, weights, tot_init_weight, n, m):
|
|
31
31
|
"""
|
|
32
32
|
Pick m nodes out of n with repulsion bias:
|
|
33
33
|
- High-degree nodes are already less likely
|
|
@@ -39,10 +39,22 @@ def local_repulsion_choice(G_func, nodes, max_weight, weights, n, m, shot):
|
|
|
39
39
|
weights = weights.copy()
|
|
40
40
|
used = np.zeros(n, dtype=np.bool_) # False = available, True = used
|
|
41
41
|
|
|
42
|
-
#
|
|
43
|
-
|
|
42
|
+
# First bit:
|
|
43
|
+
r = np.random.rand()
|
|
44
|
+
cum = 0.0
|
|
45
|
+
node = 0
|
|
46
|
+
for i in range(n):
|
|
47
|
+
cum += weights[i]
|
|
48
|
+
if (tot_init_weight * r) < cum:
|
|
49
|
+
node = i
|
|
50
|
+
break
|
|
44
51
|
|
|
45
|
-
|
|
52
|
+
update_repulsion_choice(G_func, nodes, max_edge, weights, n, used, node)
|
|
53
|
+
|
|
54
|
+
if m == 1:
|
|
55
|
+
return used
|
|
56
|
+
|
|
57
|
+
for _ in range(1, m - 1):
|
|
46
58
|
# Count available
|
|
47
59
|
total_w = 0.0
|
|
48
60
|
for i in range(n):
|
|
@@ -67,11 +79,35 @@ def local_repulsion_choice(G_func, nodes, max_weight, weights, n, m, shot):
|
|
|
67
79
|
while used[node]:
|
|
68
80
|
node += 1
|
|
69
81
|
|
|
70
|
-
# Select node
|
|
71
|
-
used[node] = True
|
|
72
|
-
|
|
73
82
|
# Update answer and weights
|
|
74
|
-
update_repulsion_choice(G_func, nodes,
|
|
83
|
+
update_repulsion_choice(G_func, nodes, max_edge, weights, n, used, node)
|
|
84
|
+
|
|
85
|
+
# Count available
|
|
86
|
+
total_w = 0.0
|
|
87
|
+
for i in range(n):
|
|
88
|
+
if used[i]:
|
|
89
|
+
continue
|
|
90
|
+
total_w += weights[i]
|
|
91
|
+
|
|
92
|
+
# Normalize & sample
|
|
93
|
+
r = np.random.rand()
|
|
94
|
+
cum = 0.0
|
|
95
|
+
node = -1
|
|
96
|
+
for i in range(n):
|
|
97
|
+
if used[i]:
|
|
98
|
+
continue
|
|
99
|
+
cum += weights[i]
|
|
100
|
+
if (total_w * r) < cum:
|
|
101
|
+
node = i
|
|
102
|
+
break
|
|
103
|
+
|
|
104
|
+
if node == -1:
|
|
105
|
+
node = 0
|
|
106
|
+
while used[node]:
|
|
107
|
+
node += 1
|
|
108
|
+
|
|
109
|
+
# Select node
|
|
110
|
+
used[node] = True
|
|
75
111
|
|
|
76
112
|
return used
|
|
77
113
|
|
|
@@ -88,8 +124,9 @@ def compute_energy(sample, G_func, nodes, n_qubits):
|
|
|
88
124
|
|
|
89
125
|
|
|
90
126
|
@njit(parallel=True)
|
|
91
|
-
def sample_for_solution(G_func, nodes,
|
|
127
|
+
def sample_for_solution(G_func, nodes, max_edge, shots, thresholds, degrees_sum, weights, n, dtype):
|
|
92
128
|
shots = max(1, shots >> 1)
|
|
129
|
+
tot_init_weight = weights.sum()
|
|
93
130
|
|
|
94
131
|
solutions = np.empty((shots, n), dtype=np.bool_)
|
|
95
132
|
energies = np.empty(shots, dtype=dtype)
|
|
@@ -109,7 +146,7 @@ def sample_for_solution(G_func, nodes, max_weight, shots, thresholds, degrees_su
|
|
|
109
146
|
m += 1
|
|
110
147
|
|
|
111
148
|
# Second dimension: permutation within Hamming weight
|
|
112
|
-
sample = local_repulsion_choice(G_func, nodes,
|
|
149
|
+
sample = local_repulsion_choice(G_func, nodes, max_edge, weights, tot_init_weight, n, m)
|
|
113
150
|
solutions[s] = sample
|
|
114
151
|
energies[s] = compute_energy(sample, G_func, nodes, n)
|
|
115
152
|
|
|
@@ -162,11 +199,11 @@ def cpu_footer(shots, quality, n_qubits, G_func, nodes, dtype, epsilon):
|
|
|
162
199
|
|
|
163
200
|
maxcut_hamming_cdf(n_qubits, J_eff, degrees, quality, hamming_prob, dtype)
|
|
164
201
|
|
|
165
|
-
|
|
202
|
+
max_edge = degrees.sum()
|
|
166
203
|
degrees = None
|
|
167
204
|
J_eff = 1.0 / (1.0 + epsilon - J_eff)
|
|
168
205
|
|
|
169
|
-
best_solution, best_value = sample_for_solution(G_func, nodes, G_max, shots, hamming_prob,
|
|
206
|
+
best_solution, best_value = sample_for_solution(G_func, nodes, G_max, shots, hamming_prob, max_edge, J_eff, n_qubits, dtype)
|
|
170
207
|
|
|
171
208
|
bit_string, l, r = get_cut(best_solution, nodes)
|
|
172
209
|
|
|
@@ -174,10 +211,10 @@ def cpu_footer(shots, quality, n_qubits, G_func, nodes, dtype, epsilon):
|
|
|
174
211
|
|
|
175
212
|
|
|
176
213
|
@njit
|
|
177
|
-
def gpu_footer(shots, n_qubits, G_func, nodes, G_max, weights, degrees, hamming_prob,
|
|
214
|
+
def gpu_footer(shots, n_qubits, G_func, nodes, G_max, weights, degrees, hamming_prob, max_edge, dtype):
|
|
178
215
|
fix_cdf(hamming_prob)
|
|
179
216
|
|
|
180
|
-
best_solution, best_value = sample_for_solution(G_func, nodes, G_max, shots, hamming_prob,
|
|
217
|
+
best_solution, best_value = sample_for_solution(G_func, nodes, G_max, shots, hamming_prob, max_edge, weights, n_qubits, dtype)
|
|
181
218
|
|
|
182
219
|
bit_string, l, r = get_cut(best_solution, nodes)
|
|
183
220
|
|
|
@@ -104,14 +104,13 @@ def tsp_maxcut(G, k_neighbors=20, is_optimized=False, is_parallel=True, **kwargs
|
|
|
104
104
|
nodes = list(range(n_qubits))
|
|
105
105
|
G_m = G
|
|
106
106
|
|
|
107
|
-
path,
|
|
107
|
+
path, _ = tsp_symmetric(G_m, is_cyclic=False, monte_carlo=True, k_neighbors=k_neighbors, is_parallel=is_parallel)
|
|
108
108
|
l, r, cut_value = tsp_to_maxcut_bipartition(path, G_m)
|
|
109
|
-
partition = (l, r)
|
|
110
109
|
|
|
111
110
|
if not is_optimized:
|
|
112
|
-
bitstring, energy = early_exit(G_m,
|
|
111
|
+
bitstring, energy = early_exit(G_m, (l, r), nodes)
|
|
113
112
|
|
|
114
|
-
return bitstring, cut_value,
|
|
113
|
+
return bitstring, cut_value, ([nodes[x] for x in l], [nodes[x] for x in r]), energy
|
|
115
114
|
|
|
116
115
|
bitint = 0
|
|
117
116
|
for b in partition[0]:
|
|
@@ -120,7 +119,7 @@ def tsp_maxcut(G, k_neighbors=20, is_optimized=False, is_parallel=True, **kwargs
|
|
|
120
119
|
bitstring, cut_value, cut, energy = spin_glass_solver(G_m, best_guess=bitint, **kwargs)
|
|
121
120
|
l, r = get_cut(bitstring, nodes)
|
|
122
121
|
|
|
123
|
-
return bitstring, cut_value, (l, r), energy
|
|
122
|
+
return bitstring, cut_value, ([nodes[x] for x in l], [nodes[x] for x in r]), energy
|
|
124
123
|
|
|
125
124
|
|
|
126
125
|
@njit(parallel=True)
|
|
@@ -212,14 +211,13 @@ def tsp_maxcut_sparse(G, k_neighbors=20, is_optimized=False, is_parallel=True, *
|
|
|
212
211
|
nodes = list(range(n_qubits))
|
|
213
212
|
G_m = G
|
|
214
213
|
|
|
215
|
-
path,
|
|
214
|
+
path, _ = tsp_symmetric_sparse(G_m, k_neighbors=k_neighbors, is_parallel=is_parallel)
|
|
216
215
|
l, r, cut_value = tsp_to_maxcut_bipartition_sparse(path, G_m.data, G_m.indptr, G_m.indices)
|
|
217
|
-
partition = (l, r)
|
|
218
216
|
|
|
219
217
|
if not is_optimized:
|
|
220
|
-
bitstring, energy = early_exit_sparse(G_m.data, G_m.indptr, G_m.indices,
|
|
218
|
+
bitstring, energy = early_exit_sparse(G_m.data, G_m.indptr, G_m.indices, (l, r), nodes)
|
|
221
219
|
|
|
222
|
-
return bitstring, cut_value,
|
|
220
|
+
return bitstring, cut_value, ([nodes[x] for x in l], [nodes[x] for x in r]), energy
|
|
223
221
|
|
|
224
222
|
bitint = 0
|
|
225
223
|
for b in partition[0]:
|
|
@@ -228,7 +226,7 @@ def tsp_maxcut_sparse(G, k_neighbors=20, is_optimized=False, is_parallel=True, *
|
|
|
228
226
|
bitstring, cut_value, cut, energy = spin_glass_solver_sparse(G_m, best_guess=bitint, **kwargs)
|
|
229
227
|
l, r = get_cut(bitstring, nodes)
|
|
230
228
|
|
|
231
|
-
return bitstring, cut_value, (l, r), energy
|
|
229
|
+
return bitstring, cut_value, ([nodes[x] for x in l], [nodes[x] for x in r]), energy
|
|
232
230
|
|
|
233
231
|
|
|
234
232
|
@njit(parallel=True)
|
|
@@ -296,14 +294,13 @@ def early_exit_streaming(G_func, partition, nodes):
|
|
|
296
294
|
|
|
297
295
|
def tsp_maxcut_streaming(G_func, nodes, k_neighbors=20, is_optimized=False, is_parallel=True, **kwargs):
|
|
298
296
|
n_qubits = len(nodes)
|
|
299
|
-
path,
|
|
297
|
+
path, _ = tsp_symmetric_streaming(G_func, nodes, k_neighbors=k_neighbors, is_parallel=is_parallel)
|
|
300
298
|
l, r, cut_value = tsp_to_maxcut_bipartition_streaming(path, G_func)
|
|
301
|
-
partition = (l, r)
|
|
302
299
|
|
|
303
300
|
if not is_optimized:
|
|
304
|
-
bitstring, energy = early_exit_streaming(G_func,
|
|
301
|
+
bitstring, energy = early_exit_streaming(G_func, (l, r), nodes)
|
|
305
302
|
|
|
306
|
-
return bitstring, cut_value,
|
|
303
|
+
return bitstring, cut_value, ([nodes[x] for x in l], [nodes[x] for x in r]), energy
|
|
307
304
|
|
|
308
305
|
bitint = 0
|
|
309
306
|
for b in partition[0]:
|
|
@@ -312,4 +309,4 @@ def tsp_maxcut_streaming(G_func, nodes, k_neighbors=20, is_optimized=False, is_p
|
|
|
312
309
|
bitstring, cut_value, cut, energy = spin_glass_solver_streaming(G_func, nodes, best_guess=bitint, **kwargs)
|
|
313
310
|
l, r = get_cut(bitstring, nodes)
|
|
314
311
|
|
|
315
|
-
return bitstring, cut_value, (l, r), energy
|
|
312
|
+
return bitstring, cut_value, ([nodes[x] for x in l], [nodes[x] for x in r]), energy
|
|
@@ -51,7 +51,7 @@ ext_modules = [CMakeExtension('tfim_sampler')]
|
|
|
51
51
|
|
|
52
52
|
setup(
|
|
53
53
|
name='pyqrackising',
|
|
54
|
-
version='7.5.
|
|
54
|
+
version='7.5.3',
|
|
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
|