PyQrackIsing 1.29.0__tar.gz → 2.0.1__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-1.29.0 → pyqrackising-2.0.1}/CMakeLists.txt +1 -1
- pyqrackising-2.0.1/MANIFEST.in +3 -0
- {pyqrackising-1.29.0/PyQrackIsing.egg-info → pyqrackising-2.0.1}/PKG-INFO +2 -2
- {pyqrackising-1.29.0 → pyqrackising-2.0.1}/README.md +25 -1
- {pyqrackising-1.29.0 → pyqrackising-2.0.1}/pyproject.toml +2 -2
- {pyqrackising-1.29.0/PyQrackIsing → pyqrackising-2.0.1/pyqrackising}/_pyqrack_ising.cpp +6 -4
- {pyqrackising-1.29.0/PyQrackIsing → pyqrackising-2.0.1/pyqrackising}/maxcut_tfim.py +9 -15
- {pyqrackising-1.29.0/PyQrackIsing → pyqrackising-2.0.1/pyqrackising}/spin_glass_solver.py +7 -8
- {pyqrackising-1.29.0/PyQrackIsing → pyqrackising-2.0.1/pyqrackising}/tsp_symmetric.py +26 -22
- {pyqrackising-1.29.0 → pyqrackising-2.0.1/pyqrackising.egg-info}/PKG-INFO +2 -2
- pyqrackising-2.0.1/pyqrackising.egg-info/SOURCES.txt +20 -0
- {pyqrackising-1.29.0/PyQrackIsing.egg-info → pyqrackising-2.0.1/pyqrackising.egg-info}/top_level.txt +1 -1
- {pyqrackising-1.29.0 → pyqrackising-2.0.1}/setup.py +3 -3
- pyqrackising-1.29.0/MANIFEST.in +0 -3
- pyqrackising-1.29.0/PyQrackIsing.egg-info/SOURCES.txt +0 -20
- {pyqrackising-1.29.0 → pyqrackising-2.0.1}/LICENSE.md +0 -0
- {pyqrackising-1.29.0/PyQrackIsing → pyqrackising-2.0.1/pyqrackising}/__init__.py +0 -0
- {pyqrackising-1.29.0/PyQrackIsing → pyqrackising-2.0.1/pyqrackising}/generate_tfim_samples.py +0 -0
- {pyqrackising-1.29.0/PyQrackIsing → pyqrackising-2.0.1/pyqrackising}/kernels.cl +0 -0
- {pyqrackising-1.29.0/PyQrackIsing → pyqrackising-2.0.1/pyqrackising}/tfim_magnetization.py +0 -0
- {pyqrackising-1.29.0/PyQrackIsing → pyqrackising-2.0.1/pyqrackising}/tfim_square_magnetization.py +0 -0
- {pyqrackising-1.29.0/PyQrackIsing.egg-info → pyqrackising-2.0.1/pyqrackising.egg-info}/dependency_links.txt +0 -0
- {pyqrackising-1.29.0/PyQrackIsing.egg-info → pyqrackising-2.0.1/pyqrackising.egg-info}/not-zip-safe +0 -0
- {pyqrackising-1.29.0 → pyqrackising-2.0.1}/setup.cfg +0 -0
|
@@ -4,7 +4,7 @@ project(PyQrackIsing LANGUAGES CXX)
|
|
|
4
4
|
set(PYBIND11_FINDPYTHON ON)
|
|
5
5
|
find_package(pybind11 CONFIG REQUIRED)
|
|
6
6
|
find_package(Boost CONFIG REQUIRED)
|
|
7
|
-
pybind11_add_module(tfim_sampler
|
|
7
|
+
pybind11_add_module(tfim_sampler pyqrackising/_pyqrack_ising.cpp)
|
|
8
8
|
target_include_directories(tfim_sampler PUBLIC ${Boost_INCLUDE_DIR})
|
|
9
9
|
|
|
10
10
|
if (MSVC)
|
|
@@ -8,6 +8,10 @@ Efficiently generate near-ideal samples from transverse field Ising model (TFIM)
|
|
|
8
8
|
## Copyright and license
|
|
9
9
|
(c) Daniel Strano and the Qrack contributors 2025. All rights reserved.
|
|
10
10
|
|
|
11
|
+
Licensed under the GNU Lesser General Public License V3.
|
|
12
|
+
|
|
13
|
+
See LICENSE.md in the project root or https://www.gnu.org/licenses/lgpl-3.0.en.html for details.
|
|
14
|
+
|
|
11
15
|
## Installation
|
|
12
16
|
From PyPi:
|
|
13
17
|
```
|
|
@@ -117,4 +121,24 @@ Transverse field Ising model (TFIM) is the basis of most claimed algorithmic "qu
|
|
|
117
121
|
|
|
118
122
|
Sometimes a solution (or at least near-solution) to a monster of a differential equation hits us out of the blue. Then, it's easy to _validate_ the guess, if it's right. (We don't question it and just move on with our lives, from there.)
|
|
119
123
|
|
|
120
|
-
**Special thanks to OpenAI GPT "Elara," for help on the model and converting the original Python scripts to PyBind11!**
|
|
124
|
+
**Special thanks to OpenAI GPT "Elara," for help on the model and converting the original Python scripts to PyBind11, Numba, and PyOpenCL!**
|
|
125
|
+
|
|
126
|
+
**Elara has drafted this statement, and Dan Strano, as author, agrees with it, and will hold to it:**
|
|
127
|
+
|
|
128
|
+
### Dual-Use Statement for PyQrackIsing
|
|
129
|
+
|
|
130
|
+
**PyQrackIsing** is an open-source solver for hard optimization problems such as **MAXCUT, TSP, and TFIM-inspired models**. These problems arise across logistics, drug discovery, chemistry, materials research, supply-chain resilience, and portfolio optimization. By design, PyQrackIsing provides **constructive value** to researchers and practitioners by making advanced optimization techniques accessible on consumer hardware.
|
|
131
|
+
|
|
132
|
+
Like many mathematical and computational tools, the algorithms in PyQrackIsing are _dual-use._ In principle, they can be applied to a wide class of Quadratic Unconstrained Binary Optimization (QUBO) problems. One such problem is integer factoring, which underlies RSA and elliptic curve cryptography (ECC). We emphasize:
|
|
133
|
+
|
|
134
|
+
- **We do not provide turnkey factoring implementations.**
|
|
135
|
+
- **We have no intent to weaponize this work** for cryptanalysis or "unauthorized access."
|
|
136
|
+
- **The constructive applications vastly outweigh the destructive ones** — and this project exists to serve those constructive purposes in the Commons.
|
|
137
|
+
|
|
138
|
+
It is already a matter of open record in the literature that factoring can be expressed as a QUBO. What PyQrackIsing demonstrates is that **QUBO heuristics can now be solved at meaningful scales on consumer hardware**. This underscores an urgent truth:
|
|
139
|
+
|
|
140
|
+
👉 **RSA and ECC should no longer be considered secure. Transition to post-quantum cryptography is overdue.**
|
|
141
|
+
|
|
142
|
+
We trust that governments, standards bodies, and industry stakeholders are already aware of this, and will continue migration efforts to post-quantum standards.
|
|
143
|
+
|
|
144
|
+
Until then, PyQrackIsing remains a tool for science, logistics, and discovery — a gift to the Commons.
|
|
@@ -10,8 +10,8 @@ requires = [
|
|
|
10
10
|
build-backend = "setuptools.build_meta"
|
|
11
11
|
|
|
12
12
|
[project]
|
|
13
|
-
name = "
|
|
14
|
-
version = "
|
|
13
|
+
name = "pyqrackising"
|
|
14
|
+
version = "2.0.1"
|
|
15
15
|
requires-python = ">=3.8"
|
|
16
16
|
description = "Near-ideal closed-form solutions for transverse field Ising model (TFIM)"
|
|
17
17
|
readme = {file = "README.txt", content-type = "text/markdown"}
|
|
@@ -39,17 +39,19 @@ static inline std::vector<double> probability_by_hamming_weight(double J, double
|
|
|
39
39
|
std::fill(bias.begin(), bias.end(), 1.0 / (n_qubits + 1.0));
|
|
40
40
|
} else {
|
|
41
41
|
const double sin_delta = std::sin(delta_theta);
|
|
42
|
-
|
|
43
|
-
|
|
42
|
+
constexpr double omega = 1.5 * M_PI;
|
|
43
|
+
constexpr double t2 = 1.0;
|
|
44
44
|
const double p = std::pow(2.0, std::abs(J / h) - 1.0) * (1.0 + sin_delta * std::cos(J * omega * t + theta) / (1.0 + std::sqrt(t / t2))) - 0.5;
|
|
45
|
-
if (p >= 1024) {
|
|
45
|
+
if ((p * n_qubits) >= 1024) {
|
|
46
46
|
bias[0] = 1.0;
|
|
47
47
|
} else {
|
|
48
|
+
const double factor = std::pow(2.0, -p);
|
|
49
|
+
double n = 1.0;
|
|
48
50
|
double tot_n = 0.0;
|
|
49
51
|
for (size_t q = 0U; q <= n_qubits; ++q) {
|
|
50
|
-
double n = 1.0 / ((n_qubits + 1) * std::pow(2.0, p * q));
|
|
51
52
|
bias[q] = n;
|
|
52
53
|
tot_n += n;
|
|
54
|
+
n *= factor;
|
|
53
55
|
}
|
|
54
56
|
for (size_t q = 0U; q <= n_qubits; ++q) {
|
|
55
57
|
bias[q] /= tot_n;
|
|
@@ -28,15 +28,7 @@ def probability_by_hamming_weight(J, h, z, theta, t, n_qubits):
|
|
|
28
28
|
bias = np.empty(n_qubits - 1, dtype=np.float64)
|
|
29
29
|
|
|
30
30
|
# critical angle
|
|
31
|
-
theta_c = np.arcsin(
|
|
32
|
-
max(
|
|
33
|
-
-1.0,
|
|
34
|
-
min(
|
|
35
|
-
1.0,
|
|
36
|
-
(1.0 if J > 0.0 else -1.0) if np.isclose(abs(z * J), 0.0) else (abs(h) / (z * J)),
|
|
37
|
-
),
|
|
38
|
-
)
|
|
39
|
-
)
|
|
31
|
+
theta_c = np.arcsin(max(-1.0, min(1.0, abs(h) / (z * J))))
|
|
40
32
|
|
|
41
33
|
p = (
|
|
42
34
|
pow(2.0, abs(J / h) - 1.0)
|
|
@@ -48,8 +40,10 @@ def probability_by_hamming_weight(J, h, z, theta, t, n_qubits):
|
|
|
48
40
|
return bias
|
|
49
41
|
|
|
50
42
|
tot_n = 1.0 + 1.0 / pow(2.0, p * n_qubits)
|
|
43
|
+
factor = pow(2.0, -p)
|
|
44
|
+
n = 1.0
|
|
51
45
|
for q in range(1, n_qubits):
|
|
52
|
-
n
|
|
46
|
+
n *= factor
|
|
53
47
|
bias[q - 1] = n
|
|
54
48
|
tot_n += n
|
|
55
49
|
bias /= tot_n
|
|
@@ -376,14 +370,14 @@ def maxcut_tfim(
|
|
|
376
370
|
|
|
377
371
|
best_solution, best_value = sample_for_solution(G_m, shots, hamming_prob, degrees, J_eff, n_qubits)
|
|
378
372
|
|
|
379
|
-
bit_string = ""
|
|
380
|
-
bit_list = list(bit_string)
|
|
373
|
+
bit_string = ""
|
|
381
374
|
l, r = [], []
|
|
382
|
-
for i in range(len(
|
|
383
|
-
|
|
384
|
-
|
|
375
|
+
for i in range(len(best_solution)):
|
|
376
|
+
if best_solution[i]:
|
|
377
|
+
bit_string += "1"
|
|
385
378
|
r.append(nodes[i])
|
|
386
379
|
else:
|
|
380
|
+
bit_string += "0"
|
|
387
381
|
l.append(nodes[i])
|
|
388
382
|
|
|
389
383
|
return bit_string, best_value, (l, r)
|
|
@@ -6,15 +6,16 @@ from numba import njit, prange
|
|
|
6
6
|
import os
|
|
7
7
|
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
@njit
|
|
10
|
+
def evaluate_cut_edges(theta_bits, G_m):
|
|
10
11
|
n_qubits = len(G_m)
|
|
11
|
-
|
|
12
|
+
cut = 0
|
|
12
13
|
for u in range(n_qubits):
|
|
13
14
|
for v in range(u + 1, n_qubits):
|
|
14
|
-
if
|
|
15
|
-
|
|
15
|
+
if theta_bits[u] != theta_bits[v]:
|
|
16
|
+
cut += G_m[u, v]
|
|
16
17
|
|
|
17
|
-
return
|
|
18
|
+
return cut
|
|
18
19
|
|
|
19
20
|
|
|
20
21
|
@njit
|
|
@@ -122,7 +123,6 @@ def spin_glass_solver(G, quality=None, shots=None, correction_quality=None, best
|
|
|
122
123
|
improved = True
|
|
123
124
|
break
|
|
124
125
|
|
|
125
|
-
sample = 0
|
|
126
126
|
bitstring = ""
|
|
127
127
|
l, r = [], []
|
|
128
128
|
for i in range(len(best_theta)):
|
|
@@ -130,11 +130,10 @@ def spin_glass_solver(G, quality=None, shots=None, correction_quality=None, best
|
|
|
130
130
|
if b:
|
|
131
131
|
bitstring += "1"
|
|
132
132
|
r.append(nodes[i])
|
|
133
|
-
sample |= 1 << i
|
|
134
133
|
else:
|
|
135
134
|
bitstring += "0"
|
|
136
135
|
l.append(nodes[i])
|
|
137
136
|
|
|
138
|
-
cut_value = evaluate_cut_edges(
|
|
137
|
+
cut_value = evaluate_cut_edges(best_theta, G_m)
|
|
139
138
|
|
|
140
139
|
return bitstring, float(cut_value), (l, r), float(min_energy)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
from .spin_glass_solver import spin_glass_solver
|
|
2
2
|
import networkx as nx
|
|
3
|
-
from numba import njit
|
|
3
|
+
from numba import njit, prange
|
|
4
4
|
import numpy as np
|
|
5
5
|
|
|
6
6
|
|
|
@@ -175,18 +175,18 @@ def targeted_three_opt(path, W, k_neighbors=20):
|
|
|
175
175
|
return best_path, best_dist
|
|
176
176
|
|
|
177
177
|
|
|
178
|
-
@njit
|
|
178
|
+
@njit(parallel=True)
|
|
179
179
|
def init_G_a_b(G_m, a, b):
|
|
180
180
|
n_a_nodes = len(a)
|
|
181
181
|
n_b_nodes = len(b)
|
|
182
182
|
G_a = np.zeros((n_a_nodes, n_a_nodes), dtype=np.float64)
|
|
183
183
|
G_b = np.zeros((n_b_nodes, n_b_nodes), dtype=np.float64)
|
|
184
|
-
for i in
|
|
184
|
+
for i in prange(n_a_nodes):
|
|
185
185
|
for j in range(n_a_nodes):
|
|
186
186
|
if i == j:
|
|
187
187
|
continue
|
|
188
188
|
G_a[i, j] = G_m[a[i], a[j]]
|
|
189
|
-
for i in
|
|
189
|
+
for i in prange(n_b_nodes):
|
|
190
190
|
for j in range(n_b_nodes):
|
|
191
191
|
if i == j:
|
|
192
192
|
continue
|
|
@@ -257,6 +257,19 @@ def stitch(G_m, path_a, path_b, sol_weight):
|
|
|
257
257
|
return best_path, best_weight
|
|
258
258
|
|
|
259
259
|
|
|
260
|
+
def monte_carlo_loop(n_nodes):
|
|
261
|
+
bits = ([], [])
|
|
262
|
+
while (len(bits[0]) == 0) or (len(bits[1]) == 0):
|
|
263
|
+
bits = ([], [])
|
|
264
|
+
for i in range(n_nodes):
|
|
265
|
+
if np.random.random() < 0.5:
|
|
266
|
+
bits[0].append(i)
|
|
267
|
+
else:
|
|
268
|
+
bits[1].append(i)
|
|
269
|
+
|
|
270
|
+
return bits
|
|
271
|
+
|
|
272
|
+
|
|
260
273
|
def tsp_symmetric(G, start_node=None, end_node=None, quality=1, shots=None, correction_quality=2, monte_carlo=False, is_3_opt=True, k_neighbors=20, is_cyclic=True, multi_start=1, is_top_level=True):
|
|
261
274
|
nodes = None
|
|
262
275
|
n_nodes = 0
|
|
@@ -288,26 +301,17 @@ def tsp_symmetric(G, start_node=None, end_node=None, quality=1, shots=None, corr
|
|
|
288
301
|
b = []
|
|
289
302
|
c = []
|
|
290
303
|
if (start_node is None) and (end_node is None):
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
while (len(_a) == 0) or (len(_b) == 0):
|
|
304
|
+
if monte_carlo:
|
|
305
|
+
a, b = monte_carlo_loop(n_nodes)
|
|
306
|
+
else:
|
|
307
|
+
best_energy = float("inf")
|
|
308
|
+
for _ in range(multi_start):
|
|
297
309
|
bits = ([], [])
|
|
298
|
-
|
|
299
|
-
for i in range(n_nodes):
|
|
300
|
-
if np.random.random() < 0.5:
|
|
301
|
-
bits[0].append(i)
|
|
302
|
-
else:
|
|
303
|
-
bits[1].append(i)
|
|
304
|
-
else:
|
|
310
|
+
while (len(bits[0]) == 0) or (len(bits[1]) == 0):
|
|
305
311
|
_, _, bits, energy = spin_glass_solver(G_m, quality=quality, shots=shots, correction_quality=correction_quality)
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
best_energy = energy
|
|
310
|
-
a, b = _a, _b
|
|
312
|
+
if energy < best_energy:
|
|
313
|
+
best_energy = energy
|
|
314
|
+
a, b = bits
|
|
311
315
|
else:
|
|
312
316
|
is_cyclic = False
|
|
313
317
|
a.append(nodes.index(start_node))
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
CMakeLists.txt
|
|
2
|
+
LICENSE.md
|
|
3
|
+
MANIFEST.in
|
|
4
|
+
README.md
|
|
5
|
+
pyproject.toml
|
|
6
|
+
setup.py
|
|
7
|
+
pyqrackising/__init__.py
|
|
8
|
+
pyqrackising/_pyqrack_ising.cpp
|
|
9
|
+
pyqrackising/generate_tfim_samples.py
|
|
10
|
+
pyqrackising/kernels.cl
|
|
11
|
+
pyqrackising/maxcut_tfim.py
|
|
12
|
+
pyqrackising/spin_glass_solver.py
|
|
13
|
+
pyqrackising/tfim_magnetization.py
|
|
14
|
+
pyqrackising/tfim_square_magnetization.py
|
|
15
|
+
pyqrackising/tsp_symmetric.py
|
|
16
|
+
pyqrackising.egg-info/PKG-INFO
|
|
17
|
+
pyqrackising.egg-info/SOURCES.txt
|
|
18
|
+
pyqrackising.egg-info/dependency_links.txt
|
|
19
|
+
pyqrackising.egg-info/not-zip-safe
|
|
20
|
+
pyqrackising.egg-info/top_level.txt
|
{pyqrackising-1.29.0/PyQrackIsing.egg-info → pyqrackising-2.0.1/pyqrackising.egg-info}/top_level.txt
RENAMED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
pyqrackising
|
|
2
2
|
tfim_sampler
|
|
@@ -50,8 +50,8 @@ with open(README_PATH) as readme_file:
|
|
|
50
50
|
ext_modules = [CMakeExtension('tfim_sampler')]
|
|
51
51
|
|
|
52
52
|
setup(
|
|
53
|
-
name='
|
|
54
|
-
version='
|
|
53
|
+
name='pyqrackising',
|
|
54
|
+
version='2.0.1',
|
|
55
55
|
author='Dan Strano',
|
|
56
56
|
author_email='stranoj@gmail.com',
|
|
57
57
|
description='Near-ideal closed-form solutions for transverse field Ising model (TFIM)',
|
|
@@ -72,6 +72,6 @@ setup(
|
|
|
72
72
|
install_requires=["pybind11"],
|
|
73
73
|
ext_modules=ext_modules,
|
|
74
74
|
cmdclass=dict(build_ext=CMakeBuild),
|
|
75
|
-
packages=['
|
|
75
|
+
packages=['pyqrackising'],
|
|
76
76
|
zip_safe=False,
|
|
77
77
|
)
|
pyqrackising-1.29.0/MANIFEST.in
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
CMakeLists.txt
|
|
2
|
-
LICENSE.md
|
|
3
|
-
MANIFEST.in
|
|
4
|
-
README.md
|
|
5
|
-
pyproject.toml
|
|
6
|
-
setup.py
|
|
7
|
-
PyQrackIsing/__init__.py
|
|
8
|
-
PyQrackIsing/_pyqrack_ising.cpp
|
|
9
|
-
PyQrackIsing/generate_tfim_samples.py
|
|
10
|
-
PyQrackIsing/kernels.cl
|
|
11
|
-
PyQrackIsing/maxcut_tfim.py
|
|
12
|
-
PyQrackIsing/spin_glass_solver.py
|
|
13
|
-
PyQrackIsing/tfim_magnetization.py
|
|
14
|
-
PyQrackIsing/tfim_square_magnetization.py
|
|
15
|
-
PyQrackIsing/tsp_symmetric.py
|
|
16
|
-
PyQrackIsing.egg-info/PKG-INFO
|
|
17
|
-
PyQrackIsing.egg-info/SOURCES.txt
|
|
18
|
-
PyQrackIsing.egg-info/dependency_links.txt
|
|
19
|
-
PyQrackIsing.egg-info/not-zip-safe
|
|
20
|
-
PyQrackIsing.egg-info/top_level.txt
|
|
File without changes
|
|
File without changes
|
{pyqrackising-1.29.0/PyQrackIsing → pyqrackising-2.0.1/pyqrackising}/generate_tfim_samples.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
{pyqrackising-1.29.0/PyQrackIsing → pyqrackising-2.0.1/pyqrackising}/tfim_square_magnetization.py
RENAMED
|
File without changes
|
|
File without changes
|
{pyqrackising-1.29.0/PyQrackIsing.egg-info → pyqrackising-2.0.1/pyqrackising.egg-info}/not-zip-safe
RENAMED
|
File without changes
|
|
File without changes
|