PyQrackIsing 7.5.2__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.
Files changed (30) hide show
  1. {pyqrackising-7.5.2/pyqrackising.egg-info → pyqrackising-7.5.3}/PKG-INFO +1 -1
  2. {pyqrackising-7.5.2 → pyqrackising-7.5.3}/pyproject.toml +1 -1
  3. {pyqrackising-7.5.2 → pyqrackising-7.5.3}/pyqrackising/maxcut_tfim.py +48 -9
  4. {pyqrackising-7.5.2 → pyqrackising-7.5.3}/pyqrackising/maxcut_tfim_sparse.py +49 -10
  5. {pyqrackising-7.5.2 → pyqrackising-7.5.3}/pyqrackising/maxcut_tfim_streaming.py +53 -16
  6. {pyqrackising-7.5.2 → pyqrackising-7.5.3/pyqrackising.egg-info}/PKG-INFO +1 -1
  7. {pyqrackising-7.5.2 → pyqrackising-7.5.3}/setup.py +1 -1
  8. {pyqrackising-7.5.2 → pyqrackising-7.5.3}/CMakeLists.txt +0 -0
  9. {pyqrackising-7.5.2 → pyqrackising-7.5.3}/LICENSE.md +0 -0
  10. {pyqrackising-7.5.2 → pyqrackising-7.5.3}/MANIFEST.in +0 -0
  11. {pyqrackising-7.5.2 → pyqrackising-7.5.3}/README.md +0 -0
  12. {pyqrackising-7.5.2 → pyqrackising-7.5.3}/pyqrackising/__init__.py +0 -0
  13. {pyqrackising-7.5.2 → pyqrackising-7.5.3}/pyqrackising/_pyqrack_ising.cpp +0 -0
  14. {pyqrackising-7.5.2 → pyqrackising-7.5.3}/pyqrackising/convert_tensor_network_to_tsp.py +0 -0
  15. {pyqrackising-7.5.2 → pyqrackising-7.5.3}/pyqrackising/generate_tfim_samples.py +0 -0
  16. {pyqrackising-7.5.2 → pyqrackising-7.5.3}/pyqrackising/kernels.cl +0 -0
  17. {pyqrackising-7.5.2 → pyqrackising-7.5.3}/pyqrackising/maxcut_tfim_util.py +0 -0
  18. {pyqrackising-7.5.2 → pyqrackising-7.5.3}/pyqrackising/spin_glass_solver.py +0 -0
  19. {pyqrackising-7.5.2 → pyqrackising-7.5.3}/pyqrackising/spin_glass_solver_sparse.py +0 -0
  20. {pyqrackising-7.5.2 → pyqrackising-7.5.3}/pyqrackising/spin_glass_solver_streaming.py +0 -0
  21. {pyqrackising-7.5.2 → pyqrackising-7.5.3}/pyqrackising/spin_glass_solver_util.py +0 -0
  22. {pyqrackising-7.5.2 → pyqrackising-7.5.3}/pyqrackising/tfim_magnetization.py +0 -0
  23. {pyqrackising-7.5.2 → pyqrackising-7.5.3}/pyqrackising/tfim_square_magnetization.py +0 -0
  24. {pyqrackising-7.5.2 → pyqrackising-7.5.3}/pyqrackising/tsp.py +0 -0
  25. {pyqrackising-7.5.2 → pyqrackising-7.5.3}/pyqrackising/tsp_maxcut.py +0 -0
  26. {pyqrackising-7.5.2 → pyqrackising-7.5.3}/pyqrackising.egg-info/SOURCES.txt +0 -0
  27. {pyqrackising-7.5.2 → pyqrackising-7.5.3}/pyqrackising.egg-info/dependency_links.txt +0 -0
  28. {pyqrackising-7.5.2 → pyqrackising-7.5.3}/pyqrackising.egg-info/not-zip-safe +0 -0
  29. {pyqrackising-7.5.2 → pyqrackising-7.5.3}/pyqrackising.egg-info/top_level.txt +0 -0
  30. {pyqrackising-7.5.2 → pyqrackising-7.5.3}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pyqrackising
3
- Version: 7.5.2
3
+ Version: 7.5.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
@@ -12,7 +12,7 @@ build-backend = "setuptools.build_meta"
12
12
 
13
13
  [project]
14
14
  name = "pyqrackising"
15
- version = "7.5.2"
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, max_weight, weights, n, used, node):
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] / max_weight)
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, max_weight, weights, n, m, shot):
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
- # Update answer and weights
43
- update_repulsion_choice(G_m, max_weight, weights, n, used, shot % n)
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
- for _ in range(1, m):
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, max_weight, weights, n, used, node)
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
- max_weight = G_m.max()
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, max_weight, weights, n, m, s)
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, max_weight, weights, n, used, node):
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] / max_weight)
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] / max_weight)
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, max_weight, weights, n, m, shot):
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
- # Update answer and weights
53
- update_repulsion_choice(G_cols, G_data, G_rows, max_weight, weights, n, used, shot % n)
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
- for _ in range(1, m):
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, max_weight, weights, n, used, node)
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
- max_weight = G_data.max()
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, max_weight, weights, n, m, s)
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, max_weight, weights, n, used, node):
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]) / max_weight)
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, max_weight, weights, n, m, shot):
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
- # Update answer and weights
43
- update_repulsion_choice(G_func, nodes, max_weight, weights, n, used, shot % n)
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
- for _ in range(1, m):
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, max_weight, weights, n, used, node)
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, max_weight, shots, thresholds, degrees_sum, weights, n, dtype):
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, max_weight, weights, n, m, s)
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
- max_weight = degrees.sum()
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, max_weight, J_eff, n_qubits, dtype)
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, max_weight, dtype):
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, max_weight, weights, n_qubits, dtype)
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
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pyqrackising
3
- Version: 7.5.2
3
+ Version: 7.5.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
@@ -51,7 +51,7 @@ ext_modules = [CMakeExtension('tfim_sampler')]
51
51
 
52
52
  setup(
53
53
  name='pyqrackising',
54
- version='7.5.2',
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