PyQrackIsing 9.15.1__tar.gz → 9.15.2__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.15.1/pyqrackising.egg-info → pyqrackising-9.15.2}/PKG-INFO +1 -1
- {pyqrackising-9.15.1 → pyqrackising-9.15.2}/pyproject.toml +1 -1
- {pyqrackising-9.15.1 → pyqrackising-9.15.2}/pyqrackising/generate_tfim_samples.py +58 -75
- {pyqrackising-9.15.1 → pyqrackising-9.15.2/pyqrackising.egg-info}/PKG-INFO +1 -1
- {pyqrackising-9.15.1 → pyqrackising-9.15.2}/setup.py +1 -1
- {pyqrackising-9.15.1 → pyqrackising-9.15.2}/LICENSE.md +0 -0
- {pyqrackising-9.15.1 → pyqrackising-9.15.2}/MANIFEST.in +0 -0
- {pyqrackising-9.15.1 → pyqrackising-9.15.2}/README.md +0 -0
- {pyqrackising-9.15.1 → pyqrackising-9.15.2}/pyqrackising/__init__.py +0 -0
- {pyqrackising-9.15.1 → pyqrackising-9.15.2}/pyqrackising/convert_tensor_network_to_tsp.py +0 -0
- {pyqrackising-9.15.1 → pyqrackising-9.15.2}/pyqrackising/kernels.cl +0 -0
- {pyqrackising-9.15.1 → pyqrackising-9.15.2}/pyqrackising/maxcut_tfim.py +0 -0
- {pyqrackising-9.15.1 → pyqrackising-9.15.2}/pyqrackising/maxcut_tfim_sparse.py +0 -0
- {pyqrackising-9.15.1 → pyqrackising-9.15.2}/pyqrackising/maxcut_tfim_streaming.py +0 -0
- {pyqrackising-9.15.1 → pyqrackising-9.15.2}/pyqrackising/maxcut_tfim_util.py +0 -0
- {pyqrackising-9.15.1 → pyqrackising-9.15.2}/pyqrackising/otoc.py +0 -0
- {pyqrackising-9.15.1 → pyqrackising-9.15.2}/pyqrackising/solve_maxcut_bnb.py +0 -0
- {pyqrackising-9.15.1 → pyqrackising-9.15.2}/pyqrackising/solve_maxcut_bnb_sparse.py +0 -0
- {pyqrackising-9.15.1 → pyqrackising-9.15.2}/pyqrackising/solve_maxcut_bnb_streaming.py +0 -0
- {pyqrackising-9.15.1 → pyqrackising-9.15.2}/pyqrackising/solve_maxcut_exact.py +0 -0
- {pyqrackising-9.15.1 → pyqrackising-9.15.2}/pyqrackising/solve_maxcut_exact_sparse.py +0 -0
- {pyqrackising-9.15.1 → pyqrackising-9.15.2}/pyqrackising/solve_maxcut_exact_streaming.py +0 -0
- {pyqrackising-9.15.1 → pyqrackising-9.15.2}/pyqrackising/spin_glass_solver.py +0 -0
- {pyqrackising-9.15.1 → pyqrackising-9.15.2}/pyqrackising/spin_glass_solver_sparse.py +0 -0
- {pyqrackising-9.15.1 → pyqrackising-9.15.2}/pyqrackising/spin_glass_solver_streaming.py +0 -0
- {pyqrackising-9.15.1 → pyqrackising-9.15.2}/pyqrackising/tfim_magnetization.py +0 -0
- {pyqrackising-9.15.1 → pyqrackising-9.15.2}/pyqrackising/tfim_square_magnetization.py +0 -0
- {pyqrackising-9.15.1 → pyqrackising-9.15.2}/pyqrackising/tsp.py +0 -0
- {pyqrackising-9.15.1 → pyqrackising-9.15.2}/pyqrackising/tsp_maxcut.py +0 -0
- {pyqrackising-9.15.1 → pyqrackising-9.15.2}/pyqrackising.egg-info/SOURCES.txt +0 -0
- {pyqrackising-9.15.1 → pyqrackising-9.15.2}/pyqrackising.egg-info/dependency_links.txt +0 -0
- {pyqrackising-9.15.1 → pyqrackising-9.15.2}/pyqrackising.egg-info/not-zip-safe +0 -0
- {pyqrackising-9.15.1 → pyqrackising-9.15.2}/pyqrackising.egg-info/requires.txt +0 -0
- {pyqrackising-9.15.1 → pyqrackising-9.15.2}/pyqrackising.egg-info/top_level.txt +0 -0
- {pyqrackising-9.15.1 → pyqrackising-9.15.2}/setup.cfg +0 -0
|
@@ -7,7 +7,7 @@ build-backend = "setuptools.build_meta"
|
|
|
7
7
|
|
|
8
8
|
[project]
|
|
9
9
|
name = "pyqrackising"
|
|
10
|
-
version = "9.15.
|
|
10
|
+
version = "9.15.2"
|
|
11
11
|
requires-python = ">=3.8"
|
|
12
12
|
description = "Fast MAXCUT, TSP, and sampling heuristics from near-ideal transverse field Ising model (TFIM)"
|
|
13
13
|
readme = {file = "README.txt", content-type = "text/markdown"}
|
|
@@ -49,7 +49,8 @@ from collections import Counter
|
|
|
49
49
|
epsilon = opencl_context.epsilon
|
|
50
50
|
|
|
51
51
|
|
|
52
|
-
#
|
|
52
|
+
# ── Geometry ───────────────────────────────────────────────────────────────────
|
|
53
|
+
|
|
53
54
|
def random_fixed_hamming_state(n_qubits, h):
|
|
54
55
|
bits = np.zeros(n_qubits, dtype=np.bool_)
|
|
55
56
|
bits[:h] = True
|
|
@@ -59,116 +60,100 @@ def random_fixed_hamming_state(n_qubits, h):
|
|
|
59
60
|
state <<= 1
|
|
60
61
|
if b:
|
|
61
62
|
state |= 1
|
|
62
|
-
|
|
63
63
|
return state
|
|
64
64
|
|
|
65
65
|
|
|
66
66
|
def build_neighbors(n_rows, n_cols):
|
|
67
67
|
L = n_rows * n_cols
|
|
68
68
|
neighbors = [[] for _ in range(L)]
|
|
69
|
-
|
|
70
69
|
for i in range(n_rows):
|
|
71
70
|
for j in range(n_cols):
|
|
72
71
|
idx = i * n_cols + j
|
|
73
|
-
|
|
74
72
|
right = i * n_cols + ((j + 1) % n_cols)
|
|
75
|
-
left
|
|
76
|
-
down
|
|
77
|
-
up
|
|
78
|
-
|
|
73
|
+
left = i * n_cols + ((j - 1) % n_cols)
|
|
74
|
+
down = ((i + 1) % n_rows) * n_cols + j
|
|
75
|
+
up = ((i - 1) % n_rows) * n_cols + j
|
|
79
76
|
neighbors[idx] = [right, left, down, up]
|
|
80
|
-
|
|
81
77
|
return neighbors
|
|
82
78
|
|
|
83
79
|
|
|
84
|
-
def
|
|
85
|
-
|
|
80
|
+
def count_unlike_edges(state, neighbors):
|
|
81
|
+
unlike = 0
|
|
86
82
|
visited = set()
|
|
87
|
-
|
|
88
83
|
for i, nbrs in enumerate(neighbors):
|
|
89
84
|
si = (state >> i) & 1
|
|
90
85
|
for j in nbrs:
|
|
91
86
|
if (j, i) in visited:
|
|
92
87
|
continue
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
like += 1
|
|
88
|
+
if si != ((state >> j) & 1):
|
|
89
|
+
unlike += 1
|
|
96
90
|
visited.add((i, j))
|
|
97
|
-
|
|
98
|
-
return like
|
|
91
|
+
return unlike
|
|
99
92
|
|
|
100
93
|
|
|
101
94
|
def delta_like_edges(state, i, j, neighbors):
|
|
102
95
|
si = (state >> i) & 1
|
|
103
96
|
sj = (state >> j) & 1
|
|
104
|
-
|
|
105
97
|
delta = 0
|
|
106
|
-
|
|
107
98
|
for idx in [i, j]:
|
|
108
99
|
s_old = (state >> idx) & 1
|
|
109
|
-
|
|
110
100
|
for nbr in neighbors[idx]:
|
|
111
101
|
if nbr == i or nbr == j:
|
|
112
102
|
continue
|
|
113
|
-
|
|
114
|
-
s_nbr = (state >> nbr) & 1
|
|
115
|
-
|
|
103
|
+
s_nbr = (state >> nbr) & 1
|
|
116
104
|
old_like = s_old == s_nbr
|
|
117
105
|
new_spin = sj if idx == i else si
|
|
118
106
|
new_like = new_spin == s_nbr
|
|
119
|
-
|
|
120
|
-
delta += int(new_like) - int(old_like)
|
|
121
|
-
|
|
122
|
-
# handle edge between i and j if neighbors
|
|
107
|
+
delta += int(new_like) - int(old_like)
|
|
123
108
|
if j in neighbors[i]:
|
|
124
|
-
|
|
125
|
-
new_like = sj == si
|
|
126
|
-
delta += int(new_like) - int(old_like)
|
|
127
|
-
|
|
109
|
+
delta += int(sj == si) - int(si == sj)
|
|
128
110
|
return delta
|
|
129
111
|
|
|
130
112
|
|
|
113
|
+
# ── Spatial sampler: repulsive Kawasaki ───────────────────────────────────────
|
|
114
|
+
# Electrons carry intrinsic magnetic dipole moments; antiparallel (unlike)
|
|
115
|
+
# neighbours have lower magnetic potential energy. The acceptance criterion
|
|
116
|
+
# therefore unconditionally favours unlike neighbours, independent of J.
|
|
117
|
+
|
|
131
118
|
def sample_fixed_hamming_weight(h_weight, count, n_rows, n_cols, burnin=10):
|
|
132
119
|
if count == 0:
|
|
133
120
|
return []
|
|
134
121
|
|
|
135
|
-
n_qubits
|
|
136
|
-
neighbors
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
122
|
+
n_qubits = n_rows * n_cols
|
|
123
|
+
neighbors = build_neighbors(n_rows, n_cols)
|
|
124
|
+
total_edges = 2 * n_qubits # 4 neighbours per site, each edge once → 2n
|
|
125
|
+
|
|
126
|
+
unlike_edges = 0
|
|
127
|
+
attempts = 0
|
|
128
|
+
while unlike_edges == 0:
|
|
129
|
+
state = random_fixed_hamming_state(n_qubits, h_weight)
|
|
130
|
+
unlike_edges = count_unlike_edges(state, neighbors)
|
|
131
|
+
attempts += 1
|
|
132
|
+
if attempts > 1000:
|
|
133
|
+
return [state] * count
|
|
134
|
+
|
|
135
|
+
samples = []
|
|
136
|
+
burn = burnin * n_qubits
|
|
146
137
|
thinning = n_qubits
|
|
147
138
|
|
|
148
|
-
ones
|
|
149
|
-
zeros = set(
|
|
139
|
+
ones = set(i for i in range(n_qubits) if (state >> i) & 1)
|
|
140
|
+
zeros = set(i for i in range(n_qubits) if not (state >> i) & 1)
|
|
150
141
|
|
|
151
142
|
for step in range(burn + thinning * count):
|
|
152
|
-
# choose random 1-bit and 0-bit
|
|
153
|
-
|
|
154
143
|
i = random.choice(tuple(ones))
|
|
155
144
|
j = random.choice(tuple(zeros))
|
|
156
145
|
|
|
157
|
-
|
|
158
|
-
|
|
146
|
+
delta_like = delta_like_edges(state, i, j, neighbors)
|
|
147
|
+
new_unlike = unlike_edges - delta_like # unlike = total - like
|
|
159
148
|
|
|
160
|
-
if
|
|
161
|
-
|
|
162
|
-
if np.random.random() <
|
|
149
|
+
if new_unlike > 0:
|
|
150
|
+
# Repulsive: accept proportional to new_unlike / unlike_edges
|
|
151
|
+
if np.random.random() < new_unlike / unlike_edges:
|
|
163
152
|
state ^= 1 << i
|
|
164
|
-
ones.remove(i)
|
|
165
|
-
zeros.add(i)
|
|
166
|
-
|
|
153
|
+
ones.remove(i); zeros.add(i)
|
|
167
154
|
state ^= 1 << j
|
|
168
|
-
zeros.remove(j)
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
like_edges = new_like
|
|
155
|
+
zeros.remove(j); ones.add(j)
|
|
156
|
+
unlike_edges = new_unlike
|
|
172
157
|
|
|
173
158
|
if step >= burn and (step - burn) % thinning == 0:
|
|
174
159
|
samples.append(state)
|
|
@@ -176,22 +161,21 @@ def sample_fixed_hamming_weight(h_weight, count, n_rows, n_cols, burnin=10):
|
|
|
176
161
|
return samples
|
|
177
162
|
|
|
178
163
|
|
|
164
|
+
# ── Numba helpers ──────────────────────────────────────────────────────────────
|
|
165
|
+
|
|
179
166
|
@njit(cache=True)
|
|
180
167
|
def factor_width(width, is_transpose=False):
|
|
181
168
|
col_len = math.floor(math.sqrt(width))
|
|
182
169
|
while ((width // col_len) * col_len) != width:
|
|
183
170
|
col_len -= 1
|
|
184
171
|
row_len = width // col_len
|
|
185
|
-
|
|
186
172
|
return (col_len, row_len) if is_transpose else (row_len, col_len)
|
|
187
173
|
|
|
188
174
|
|
|
189
175
|
@njit(cache=True)
|
|
190
176
|
def comb(n, k):
|
|
191
|
-
if (k < 0) or (k > n):
|
|
192
|
-
|
|
193
|
-
if (k == 0) or (k == n):
|
|
194
|
-
return 1
|
|
177
|
+
if (k < 0) or (k > n): return 0
|
|
178
|
+
if (k == 0) or (k == n): return 1
|
|
195
179
|
res = 1
|
|
196
180
|
for i in range(1, k + 1):
|
|
197
181
|
res = res * (n - k + i) // i
|
|
@@ -201,13 +185,12 @@ def comb(n, k):
|
|
|
201
185
|
@njit(cache=True)
|
|
202
186
|
def fix_cdf(hamming_prob):
|
|
203
187
|
tot_prob = 0.0
|
|
204
|
-
n_bias
|
|
188
|
+
n_bias = len(hamming_prob)
|
|
205
189
|
cum_prob = np.empty(n_bias, dtype=np.float64)
|
|
206
190
|
for i in range(n_bias):
|
|
207
|
-
tot_prob
|
|
208
|
-
cum_prob[i]
|
|
191
|
+
tot_prob += hamming_prob[i]
|
|
192
|
+
cum_prob[i] = tot_prob
|
|
209
193
|
cum_prob[-1] = 1.0
|
|
210
|
-
|
|
211
194
|
return cum_prob
|
|
212
195
|
|
|
213
196
|
|
|
@@ -232,6 +215,8 @@ def get_tfim_hamming_distribution(J=-1.0, h=2.0, z=4, theta=0.174532925199432957
|
|
|
232
215
|
return probability_by_hamming_weight(J, h, z, theta, t, n_qubits + 1, normalized=True, omega=omega)
|
|
233
216
|
|
|
234
217
|
|
|
218
|
+
# ── Public generators ──────────────────────────────────────────────────────────
|
|
219
|
+
|
|
235
220
|
def generate_tfim_samples(J=-1.0, h=2.0, z=4, theta=0.174532925199432957, t=5, n_qubits=56, shots=100):
|
|
236
221
|
samples = []
|
|
237
222
|
|
|
@@ -244,13 +229,12 @@ def generate_tfim_samples(J=-1.0, h=2.0, z=4, theta=0.174532925199432957, t=5, n
|
|
|
244
229
|
if np.random.random() < prob:
|
|
245
230
|
sample |= 1
|
|
246
231
|
samples.append(sample)
|
|
247
|
-
|
|
248
232
|
return samples
|
|
249
233
|
|
|
250
234
|
n_rows, n_cols = factor_width(n_qubits)
|
|
251
235
|
|
|
252
|
-
#
|
|
253
|
-
bias
|
|
236
|
+
# Dimension 1: Hamming weight with time-dependent envelope
|
|
237
|
+
bias = get_tfim_hamming_distribution(J=J, h=h, z=z, theta=theta, t=t, n_qubits=n_qubits)
|
|
254
238
|
counts = np.random.multinomial(shots, bias)
|
|
255
239
|
|
|
256
240
|
samples += [0] * counts[0]
|
|
@@ -258,22 +242,21 @@ def generate_tfim_samples(J=-1.0, h=2.0, z=4, theta=0.174532925199432957, t=5, n
|
|
|
258
242
|
if n_qubits > 1:
|
|
259
243
|
samples += [int(1 << np.random.randint(n_qubits)) for _ in range(counts[1])]
|
|
260
244
|
if n_qubits > 2:
|
|
261
|
-
mask
|
|
245
|
+
mask = (1 << n_qubits) - 1
|
|
262
246
|
samples += [(mask ^ int(1 << np.random.randint(n_qubits))) for _ in range(counts[-2])]
|
|
263
247
|
|
|
264
|
-
#
|
|
248
|
+
# Dimension 2: spatial magnetic localization (repulsive dipole coupling)
|
|
265
249
|
for h_weight in range(2, len(bias) - 2):
|
|
266
250
|
samples += sample_fixed_hamming_weight(h_weight, counts[h_weight], n_rows, n_cols)
|
|
267
251
|
|
|
268
252
|
np.random.shuffle(samples)
|
|
269
|
-
|
|
270
253
|
return samples
|
|
271
254
|
|
|
272
255
|
|
|
273
256
|
def generate_fermi_hubbard_samples(J=-1.0, h=2.0, z=4, theta=0.174532925199432957, t=5, n_qubits=56, shots=100, omega=1.5 * np.pi):
|
|
274
257
|
shots_x, shots_y, shots_z = np.random.multinomial(shots, [1 / 3, 1 / 3, 1 / 3])
|
|
275
258
|
return (
|
|
276
|
-
generate_tfim_samples(J=J,
|
|
259
|
+
generate_tfim_samples(J=J, h=h, z=z, theta=theta, t=t, n_qubits=n_qubits, shots=shots_z)
|
|
277
260
|
+ generate_tfim_samples(J=-h, h=-J, z=z, theta=theta + np.pi / 2, t=t, n_qubits=n_qubits, shots=shots_x)
|
|
278
|
-
+ generate_tfim_samples(J=J,
|
|
261
|
+
+ generate_tfim_samples(J=J, h=h, z=z, theta=theta + np.pi / 2, t=t, n_qubits=n_qubits, shots=shots_y)
|
|
279
262
|
)
|
|
@@ -7,7 +7,7 @@ with open(README_PATH) as readme_file:
|
|
|
7
7
|
|
|
8
8
|
setup(
|
|
9
9
|
name="pyqrackising",
|
|
10
|
-
version="9.15.
|
|
10
|
+
version="9.15.2",
|
|
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
|
|
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
|