PyQrackIsing 9.7.7__tar.gz → 9.7.8__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.7/pyqrackising.egg-info → pyqrackising-9.7.8}/PKG-INFO +1 -1
  2. {pyqrackising-9.7.7 → pyqrackising-9.7.8}/README.md +1 -1
  3. {pyqrackising-9.7.7 → pyqrackising-9.7.8}/pyproject.toml +1 -1
  4. {pyqrackising-9.7.7 → pyqrackising-9.7.8}/pyqrackising/generate_tfim_samples.py +34 -20
  5. {pyqrackising-9.7.7 → pyqrackising-9.7.8/pyqrackising.egg-info}/PKG-INFO +1 -1
  6. {pyqrackising-9.7.7 → pyqrackising-9.7.8}/setup.py +1 -1
  7. {pyqrackising-9.7.7 → pyqrackising-9.7.8}/LICENSE.md +0 -0
  8. {pyqrackising-9.7.7 → pyqrackising-9.7.8}/MANIFEST.in +0 -0
  9. {pyqrackising-9.7.7 → pyqrackising-9.7.8}/pyqrackising/__init__.py +0 -0
  10. {pyqrackising-9.7.7 → pyqrackising-9.7.8}/pyqrackising/convert_tensor_network_to_tsp.py +0 -0
  11. {pyqrackising-9.7.7 → pyqrackising-9.7.8}/pyqrackising/kernels.cl +0 -0
  12. {pyqrackising-9.7.7 → pyqrackising-9.7.8}/pyqrackising/maxcut_tfim.py +0 -0
  13. {pyqrackising-9.7.7 → pyqrackising-9.7.8}/pyqrackising/maxcut_tfim_sparse.py +0 -0
  14. {pyqrackising-9.7.7 → pyqrackising-9.7.8}/pyqrackising/maxcut_tfim_streaming.py +0 -0
  15. {pyqrackising-9.7.7 → pyqrackising-9.7.8}/pyqrackising/maxcut_tfim_util.py +0 -0
  16. {pyqrackising-9.7.7 → pyqrackising-9.7.8}/pyqrackising/otoc.py +0 -0
  17. {pyqrackising-9.7.7 → pyqrackising-9.7.8}/pyqrackising/spin_glass_solver.py +0 -0
  18. {pyqrackising-9.7.7 → pyqrackising-9.7.8}/pyqrackising/spin_glass_solver_sparse.py +0 -0
  19. {pyqrackising-9.7.7 → pyqrackising-9.7.8}/pyqrackising/spin_glass_solver_streaming.py +0 -0
  20. {pyqrackising-9.7.7 → pyqrackising-9.7.8}/pyqrackising/tfim_magnetization.py +0 -0
  21. {pyqrackising-9.7.7 → pyqrackising-9.7.8}/pyqrackising/tfim_square_magnetization.py +0 -0
  22. {pyqrackising-9.7.7 → pyqrackising-9.7.8}/pyqrackising/tsp.py +0 -0
  23. {pyqrackising-9.7.7 → pyqrackising-9.7.8}/pyqrackising/tsp_maxcut.py +0 -0
  24. {pyqrackising-9.7.7 → pyqrackising-9.7.8}/pyqrackising.egg-info/SOURCES.txt +0 -0
  25. {pyqrackising-9.7.7 → pyqrackising-9.7.8}/pyqrackising.egg-info/dependency_links.txt +0 -0
  26. {pyqrackising-9.7.7 → pyqrackising-9.7.8}/pyqrackising.egg-info/not-zip-safe +0 -0
  27. {pyqrackising-9.7.7 → pyqrackising-9.7.8}/pyqrackising.egg-info/top_level.txt +0 -0
  28. {pyqrackising-9.7.7 → pyqrackising-9.7.8}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pyqrackising
3
- Version: 9.7.7
3
+ Version: 9.7.8
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
- [![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)
6
+ [![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.17618663.svg)](https://doi.org/10.5281/zenodo.17618663) [![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.
@@ -10,7 +10,7 @@ build-backend = "setuptools.build_meta"
10
10
 
11
11
  [project]
12
12
  name = "pyqrackising"
13
- version = "9.7.7"
13
+ version = "9.7.8"
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"}
@@ -5,6 +5,8 @@ import sys
5
5
  import numpy as np
6
6
  from numba import njit
7
7
 
8
+ from collections import Counter
9
+
8
10
 
9
11
  epsilon = opencl_context.epsilon
10
12
 
@@ -89,7 +91,7 @@ def expected_closeness_weight(n_rows, n_cols, hamming_weight):
89
91
  def sample_hamming_weight(thresholds, shots):
90
92
  hamming_samples = np.zeros(shots, dtype=np.int32)
91
93
  for s in range(shots):
92
- hamming_samples[s] = sample_mag(thresholds) + 1
94
+ hamming_samples[s] = sample_mag(thresholds)
93
95
 
94
96
  return hamming_samples
95
97
 
@@ -101,7 +103,7 @@ def fix_cdf(hamming_prob):
101
103
  for i in range(n_bias):
102
104
  tot_prob += hamming_prob[i]
103
105
  cum_prob[i] = tot_prob
104
- cum_prob[-1] = 2.0
106
+ cum_prob[-1] = 1.0
105
107
 
106
108
  return cum_prob
107
109
 
@@ -149,32 +151,44 @@ def generate_tfim_samples(
149
151
  n_rows, n_cols = factor_width(n_qubits)
150
152
 
151
153
  # First dimension: Hamming weight
152
- thresholds = fix_cdf(get_tfim_hamming_distribution(J, h, z, theta, t, n_qubits + 1))
153
- hamming_samples = sample_hamming_weight(thresholds, shots)
154
-
155
- for m in range(len(hamming_samples)):
156
- # Second dimension: permutation within Hamming weight
157
- # (Written with help from Elara, the custom OpenAI GPT)
158
- hs = hamming_samples[m]
159
- rands = []
160
- for s in range(hs):
161
- rands.append(np.random.random())
154
+ bias = get_tfim_hamming_distribution(J=J, h=h, z=z, theta=theta, t=t, n_qubits=n_qubits)
155
+ thresholds = fix_cdf(bias)
156
+ hamming_samples = dict(Counter(sample_hamming_weight(thresholds, shots)))
157
+
158
+ for h_weight, count in hamming_samples.items():
159
+ if h_weight == 0:
160
+ samples += count * [0]
161
+ continue
162
+
163
+ if h_weight == n_qubits:
164
+ samples += count * [(1 << n_qubits) - 1]
165
+ continue
166
+
167
+ rands = [np.random.random() for _ in range(count)]
162
168
  rands.sort()
163
169
  state_int = 0
164
170
  tot_prob = 0
165
171
  s = 0
166
- for combo in itertools.combinations(range(n_qubits), m):
172
+ # How closely grouped are "like" bits to "like"?
173
+ expected_closeness = expected_closeness_weight(n_rows, n_cols, h_weight)
174
+ h_weight_combos = math.comb(n_qubits, h_weight)
175
+ for combo in itertools.combinations(range(n_qubits), h_weight):
167
176
  state_int = sum(1 << pos for pos in combo)
168
- tot_prob += (1.0 + closeness_like_bits(state_int, n_rows, n_cols)) / (
169
- 1.0 + expected_closeness_weight(n_rows, n_cols, m)
170
- )
171
- while (s < hs) and (rands[s] <= tot_prob):
177
+ # When we add all "closeness" possibilities for the particular Hamming weight, we should maintain the (n+1) mean probability dimensions.
178
+ normed_closeness = (1 + closeness_like_bits(state_int, n_rows, n_cols)) / (1 + expected_closeness)
179
+ # Use a normalized weighted average that favors the (n+1)-dimensional model at later times.
180
+ # The (n+1)-dimensional marginal probability is the product of a function of Hamming weight and "closeness," split among all basis states with that specific Hamming weight.
181
+ tot_prob += normed_closeness / h_weight_combos
182
+ while (rands[s] <= tot_prob):
172
183
  samples.append(state_int)
173
184
  s += 1
174
- if s == hs:
185
+ if s == count:
186
+ break
187
+ if s == count:
175
188
  break
176
- for r in range(hs - s):
177
- samples.append(state_int)
189
+ if s < count:
190
+ samples += (count - s) * [state_int]
191
+
178
192
 
179
193
  np.random.shuffle(samples)
180
194
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pyqrackising
3
- Version: 9.7.7
3
+ Version: 9.7.8
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.7',
10
+ version='9.7.8',
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