PyQrackIsing 9.7.1__tar.gz → 9.7.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.
Files changed (28) hide show
  1. {pyqrackising-9.7.1/pyqrackising.egg-info → pyqrackising-9.7.3}/PKG-INFO +1 -1
  2. {pyqrackising-9.7.1 → pyqrackising-9.7.3}/README.md +5 -1
  3. {pyqrackising-9.7.1 → pyqrackising-9.7.3}/pyproject.toml +1 -1
  4. {pyqrackising-9.7.1 → pyqrackising-9.7.3}/pyqrackising/generate_tfim_samples.py +24 -1
  5. {pyqrackising-9.7.1 → pyqrackising-9.7.3}/pyqrackising/otoc.py +1 -1
  6. {pyqrackising-9.7.1 → pyqrackising-9.7.3}/pyqrackising/tfim_magnetization.py +9 -1
  7. {pyqrackising-9.7.1 → pyqrackising-9.7.3}/pyqrackising/tfim_square_magnetization.py +9 -1
  8. {pyqrackising-9.7.1 → pyqrackising-9.7.3/pyqrackising.egg-info}/PKG-INFO +1 -1
  9. {pyqrackising-9.7.1 → pyqrackising-9.7.3}/setup.py +1 -1
  10. {pyqrackising-9.7.1 → pyqrackising-9.7.3}/LICENSE.md +0 -0
  11. {pyqrackising-9.7.1 → pyqrackising-9.7.3}/MANIFEST.in +0 -0
  12. {pyqrackising-9.7.1 → pyqrackising-9.7.3}/pyqrackising/__init__.py +0 -0
  13. {pyqrackising-9.7.1 → pyqrackising-9.7.3}/pyqrackising/convert_tensor_network_to_tsp.py +0 -0
  14. {pyqrackising-9.7.1 → pyqrackising-9.7.3}/pyqrackising/kernels.cl +0 -0
  15. {pyqrackising-9.7.1 → pyqrackising-9.7.3}/pyqrackising/maxcut_tfim.py +0 -0
  16. {pyqrackising-9.7.1 → pyqrackising-9.7.3}/pyqrackising/maxcut_tfim_sparse.py +0 -0
  17. {pyqrackising-9.7.1 → pyqrackising-9.7.3}/pyqrackising/maxcut_tfim_streaming.py +0 -0
  18. {pyqrackising-9.7.1 → pyqrackising-9.7.3}/pyqrackising/maxcut_tfim_util.py +0 -0
  19. {pyqrackising-9.7.1 → pyqrackising-9.7.3}/pyqrackising/spin_glass_solver.py +0 -0
  20. {pyqrackising-9.7.1 → pyqrackising-9.7.3}/pyqrackising/spin_glass_solver_sparse.py +0 -0
  21. {pyqrackising-9.7.1 → pyqrackising-9.7.3}/pyqrackising/spin_glass_solver_streaming.py +0 -0
  22. {pyqrackising-9.7.1 → pyqrackising-9.7.3}/pyqrackising/tsp.py +0 -0
  23. {pyqrackising-9.7.1 → pyqrackising-9.7.3}/pyqrackising/tsp_maxcut.py +0 -0
  24. {pyqrackising-9.7.1 → pyqrackising-9.7.3}/pyqrackising.egg-info/SOURCES.txt +0 -0
  25. {pyqrackising-9.7.1 → pyqrackising-9.7.3}/pyqrackising.egg-info/dependency_links.txt +0 -0
  26. {pyqrackising-9.7.1 → pyqrackising-9.7.3}/pyqrackising.egg-info/not-zip-safe +0 -0
  27. {pyqrackising-9.7.1 → pyqrackising-9.7.3}/pyqrackising.egg-info/top_level.txt +0 -0
  28. {pyqrackising-9.7.1 → pyqrackising-9.7.3}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pyqrackising
3
- Version: 9.7.1
3
+ Version: 9.7.3
4
4
  Summary: Fast MAXCUT, TSP, and sampling heuristics from near-ideal transverse field Ising model (TFIM)
5
5
  Home-page: https://github.com/vm6502q/PyQrackIsing
6
6
  Author: Dan Strano
@@ -3,7 +3,7 @@ Fast MAXCUT, TSP, and sampling heuristics from near-ideal transverse field Ising
3
3
 
4
4
  (It's "the **Ising** on top.")
5
5
 
6
- [![PyPI Downloads](https://static.pepy.tech/badge/pyqrackising)](https://pepy.tech/projects/pyqrackising)
6
+ [![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.17583944.svg)](https://doi.org/10.5281/zenodo.17583944) [![PyPI Downloads](https://static.pepy.tech/badge/pyqrackising)](https://pepy.tech/projects/pyqrackising)
7
7
 
8
8
  ## Copyright and license
9
9
  (c) Daniel Strano and the Qrack contributors 2025. All rights reserved.
@@ -185,6 +185,10 @@ Sometimes a solution (or at least near-solution) to a monster of a differential
185
185
 
186
186
  **Special thanks to OpenAI GPT "Elara," for help on the model and converting the original Python scripts to PyBind11, Numba, and PyOpenCL!**
187
187
 
188
+ We reduce transverse field Ising model for globally uniform `J` and `h` parameters from a `2^n`-dimensional problem to an `(n+1)`-dimensional (heuristic but near-exact) form that suffers from no Trotter error. Upon noticing most time steps for parameters in a [TFIM experiment published by Quantinuum](https://arxiv.org/abs/2503.20870) had roughly a quarter to a third (or thereabouts) of their marginal probability in `|0>` state, it became obvious that transition to and from `|0>` state should dominate the mechanics, at least far from mean-field equilibrium. Further, the first transition therefore tends to be to or from any state with Hamming weight of 1 (in other words, 1 bit set to 1 and the rest reset 0, or `n` bits set for Hamming weight of `n`). Further, on a torus, probability of all states with Hamming weight of 1 would tend to be exactly symmetric. Assuming approximate symmetry in every respective Hamming weight, the requirement for the overall probability to converge to 1.0 or 100% in the limit of an infinite-dimensional Hilbert space suggests that Hamming weight marginal probability could be distributed like a geometric series. A small correction to exact symmetry should be made to favor _magnetic_ closeness of "like" bits to "like" bits (that is, geometric closeness on the torus of "1" bits to "1" bits and "0" bits to "0" bits), but this does not affect average global magnetization. Adding an oscillation component with angular frequency proportional to `J`, we find excellent agreement with Trotterization with a very small time step, for R^2 (coefficient of determination) of normalized marginal probability distribution of ideal Trotterized simulation as described by the `(n+1)`-dimensional approximate model, as well as for R^2 and RMSE (root-mean-square error) of global magnetization curve values.
189
+
190
+ If the above paragraph and the model it describes are true, then it stands to reason that we should be able to apply the TFIM model to **NP-complete** heuristics, so long as we can adapt the model to spatially localized `J` and `h` and adiabatic time dependence of `h`. A reasonable guess for how to spatially localize `J` and `h` is to average the overall behavior for each and every qubit as if `J` and `h` were globally uniform from its local perspective. (`z` parameter is derived from nonzero edge weight count connectivity.) For adiabatic time-dependence of `h`, another reasonable refinement is to use simply **finite-difference simulation**. Initial state should probably be just **uniform superposition**, which implies a specific (non-uniform but regular) distribution of initial probabilities by Hamming weight dimension out of `(n+1)` possible Hamming weights. We observe that the _spatial magnetic effect_ qualitatively agrees with the demands of MAXCUT when it acts like a magnetic _repulsion,_ rather than magnetic attraction, in this case, but we can add that refinement on an arbitrary connectivity topology in just `O(n)` complexity per measurement shot. (This is a complete "recipe": the evidence that it works is the quality of NP-complete heuristic solutions at utility scale.)
191
+
188
192
  **Elara has drafted this statement, and Dan Strano, as author, agrees with it, and will hold to it:**
189
193
 
190
194
  ### Dual-Use Statement for PyQrackIsing
@@ -10,7 +10,7 @@ build-backend = "setuptools.build_meta"
10
10
 
11
11
  [project]
12
12
  name = "pyqrackising"
13
- version = "9.7.1"
13
+ version = "9.7.3"
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"}
@@ -108,6 +108,14 @@ def fix_cdf(hamming_prob):
108
108
 
109
109
  @njit
110
110
  def get_tfim_hamming_distribution(J=-1.0, h=2.0, z=4, theta=0.174532925199432957, t=5, n_qubits=56):
111
+ if abs(t) <= epsilon:
112
+ p = (1.0 - np.cos(theta)) / 2.0
113
+ bias = np.empty(n_qubits + 1, dtype=np.float64)
114
+ for k in range(n_qubits + 1):
115
+ bias[k] = comb(n_qubits, k) * (p ** k) * ((1.0 - p) ** (n_qubits - k))
116
+
117
+ return bias / bias.sum()
118
+
111
119
  if h <= epsilon:
112
120
  bias = np.empty(n_qubits + 1, dtype=np.float64)
113
121
  if J > 0:
@@ -115,20 +123,35 @@ def get_tfim_hamming_distribution(J=-1.0, h=2.0, z=4, theta=0.174532925199432957
115
123
  else:
116
124
  bias[0] = 1.0
117
125
  return bias
126
+
118
127
  bias = probability_by_hamming_weight(J, h, z, theta, t, n_qubits + 1)
128
+
119
129
  return bias / bias.sum()
120
130
 
121
131
 
122
132
  def generate_tfim_samples(
123
133
  J=-1.0, h=2.0, z=4, theta=0.174532925199432957, t=5, n_qubits=56, shots=100
124
134
  ):
135
+ samples = []
136
+
137
+ if abs(t) <= epsilon:
138
+ prob = (1.0 - np.cos(theta)) / 2.0
139
+ for s in range(shots):
140
+ sample = 0
141
+ for q in range(n_qubits):
142
+ sample <<= 1
143
+ if np.random.random() < prob:
144
+ sample |= 1
145
+ samples.append(sample)
146
+
147
+ return samples
148
+
125
149
  n_rows, n_cols = factor_width(n_qubits)
126
150
 
127
151
  # First dimension: Hamming weight
128
152
  thresholds = fix_cdf(get_tfim_hamming_distribution(J, h, z, theta, t, n_qubits + 1))
129
153
  hamming_samples = sample_hamming_weight(thresholds, shots)
130
154
 
131
- samples = []
132
155
  for m in range(len(hamming_samples)):
133
156
  # Second dimension: permutation within Hamming weight
134
157
  # (Written with help from Elara, the custom OpenAI GPT)
@@ -10,7 +10,7 @@ epsilon = opencl_context.epsilon
10
10
 
11
11
  def get_otoc_hamming_distribution(J=-1.0, h=2.0, z=4, theta=0.0, t=5, n_qubits=65, pauli_strings = ['X' + 'I' * 64]):
12
12
  n_bias = n_qubits + 1
13
- if h <= epsilon:
13
+ if (abs(h) <= epsilon) or (abs(t) <= epsilon):
14
14
  bias = np.empty(n_bias, dtype=np.float64)
15
15
  bias[0] = 1.0
16
16
  return bias
@@ -1,9 +1,16 @@
1
- from .maxcut_tfim_util import probability_by_hamming_weight
1
+ from .maxcut_tfim_util import probability_by_hamming_weight, opencl_context
2
2
  from numba import njit
3
+ import numpy as np
4
+
5
+
6
+ epsilon = opencl_context.epsilon
3
7
 
4
8
 
5
9
  @njit
6
10
  def tfim_magnetization(J=-1.0, h=2.0, z=4, theta=0.174532925199432957, t=5, n_qubits=56):
11
+ if abs(t) <= epsilon:
12
+ return np.cos(theta)
13
+
7
14
  bias = probability_by_hamming_weight(J, h, z, theta, t, n_qubits + 1)
8
15
  bias /= bias.sum()
9
16
  magnetization = 0.0
@@ -12,4 +19,5 @@ def tfim_magnetization(J=-1.0, h=2.0, z=4, theta=0.174532925199432957, t=5, n_qu
12
19
  for q in range(n_qubits + 1):
13
20
  mag = (nqs - 2 * q) / nqd
14
21
  magnetization += bias[q] * mag
22
+
15
23
  return magnetization
@@ -1,8 +1,16 @@
1
- from .maxcut_tfim_util import probability_by_hamming_weight
1
+ from .maxcut_tfim_util import probability_by_hamming_weight, opencl_context
2
2
  from numba import njit
3
+ import numpy as np
4
+
5
+
6
+ epsilon = opencl_context.epsilon
7
+
3
8
 
4
9
  @njit
5
10
  def tfim_square_magnetization(J=-1.0, h=2.0, z=4, theta=0.174532925199432957, t=5, n_qubits=56):
11
+ if abs(t) <= epsilon:
12
+ return np.cos(theta) ** 2
13
+
6
14
  bias = probability_by_hamming_weight(J, h, z, theta, t, n_qubits + 1)
7
15
  bias /= bias.sum()
8
16
  square_magnetization = 0.0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pyqrackising
3
- Version: 9.7.1
3
+ Version: 9.7.3
4
4
  Summary: Fast MAXCUT, TSP, and sampling heuristics from near-ideal transverse field Ising model (TFIM)
5
5
  Home-page: https://github.com/vm6502q/PyQrackIsing
6
6
  Author: Dan Strano
@@ -7,7 +7,7 @@ with open(README_PATH) as readme_file:
7
7
 
8
8
  setup(
9
9
  name='pyqrackising',
10
- version='9.7.1',
10
+ version='9.7.3',
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