PyQrackIsing 8.9.3__tar.gz → 8.9.4__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-8.9.3/pyqrackising.egg-info → pyqrackising-8.9.4}/PKG-INFO +1 -1
  2. {pyqrackising-8.9.3 → pyqrackising-8.9.4}/pyproject.toml +1 -1
  3. {pyqrackising-8.9.3 → pyqrackising-8.9.4}/pyqrackising/maxcut_tfim.py +10 -44
  4. {pyqrackising-8.9.3 → pyqrackising-8.9.4}/pyqrackising/maxcut_tfim_sparse.py +10 -44
  5. {pyqrackising-8.9.3 → pyqrackising-8.9.4}/pyqrackising/maxcut_tfim_streaming.py +11 -44
  6. {pyqrackising-8.9.3 → pyqrackising-8.9.4/pyqrackising.egg-info}/PKG-INFO +1 -1
  7. {pyqrackising-8.9.3 → pyqrackising-8.9.4}/setup.py +1 -1
  8. {pyqrackising-8.9.3 → pyqrackising-8.9.4}/CMakeLists.txt +0 -0
  9. {pyqrackising-8.9.3 → pyqrackising-8.9.4}/LICENSE.md +0 -0
  10. {pyqrackising-8.9.3 → pyqrackising-8.9.4}/MANIFEST.in +0 -0
  11. {pyqrackising-8.9.3 → pyqrackising-8.9.4}/README.md +0 -0
  12. {pyqrackising-8.9.3 → pyqrackising-8.9.4}/pyqrackising/__init__.py +0 -0
  13. {pyqrackising-8.9.3 → pyqrackising-8.9.4}/pyqrackising/_pyqrack_ising.cpp +0 -0
  14. {pyqrackising-8.9.3 → pyqrackising-8.9.4}/pyqrackising/convert_tensor_network_to_tsp.py +0 -0
  15. {pyqrackising-8.9.3 → pyqrackising-8.9.4}/pyqrackising/generate_tfim_samples.py +0 -0
  16. {pyqrackising-8.9.3 → pyqrackising-8.9.4}/pyqrackising/kernels.cl +0 -0
  17. {pyqrackising-8.9.3 → pyqrackising-8.9.4}/pyqrackising/maxcut_tfim_util.py +0 -0
  18. {pyqrackising-8.9.3 → pyqrackising-8.9.4}/pyqrackising/spin_glass_solver.py +0 -0
  19. {pyqrackising-8.9.3 → pyqrackising-8.9.4}/pyqrackising/spin_glass_solver_sparse.py +0 -0
  20. {pyqrackising-8.9.3 → pyqrackising-8.9.4}/pyqrackising/spin_glass_solver_streaming.py +0 -0
  21. {pyqrackising-8.9.3 → pyqrackising-8.9.4}/pyqrackising/spin_glass_solver_util.py +0 -0
  22. {pyqrackising-8.9.3 → pyqrackising-8.9.4}/pyqrackising/tfim_magnetization.py +0 -0
  23. {pyqrackising-8.9.3 → pyqrackising-8.9.4}/pyqrackising/tfim_square_magnetization.py +0 -0
  24. {pyqrackising-8.9.3 → pyqrackising-8.9.4}/pyqrackising/tsp.py +0 -0
  25. {pyqrackising-8.9.3 → pyqrackising-8.9.4}/pyqrackising/tsp_maxcut.py +0 -0
  26. {pyqrackising-8.9.3 → pyqrackising-8.9.4}/pyqrackising.egg-info/SOURCES.txt +0 -0
  27. {pyqrackising-8.9.3 → pyqrackising-8.9.4}/pyqrackising.egg-info/dependency_links.txt +0 -0
  28. {pyqrackising-8.9.3 → pyqrackising-8.9.4}/pyqrackising.egg-info/not-zip-safe +0 -0
  29. {pyqrackising-8.9.3 → pyqrackising-8.9.4}/pyqrackising.egg-info/top_level.txt +0 -0
  30. {pyqrackising-8.9.3 → pyqrackising-8.9.4}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pyqrackising
3
- Version: 8.9.3
3
+ Version: 8.9.4
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 = "8.9.3"
15
+ version = "8.9.4"
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"}
@@ -68,7 +68,7 @@ def compute_energy(sample, G_m, n_qubits):
68
68
  val = G_m[u, v]
69
69
  energy += val if sample[u] == sample[v] else -val
70
70
 
71
- return energy
71
+ return -energy
72
72
 
73
73
 
74
74
  @njit
@@ -83,7 +83,7 @@ def compute_cut(sample, G_m, n_qubits):
83
83
 
84
84
 
85
85
  @njit(parallel=True)
86
- def sample_for_energy(G_m, max_edge, shots, thresholds, weights, repulsion_base):
86
+ def sample_measurement(G_m, max_edge, shots, thresholds, weights, repulsion_base, is_spin_glass):
87
87
  shots = max(1, shots >> 1)
88
88
  n = len(G_m)
89
89
  tot_init_weight = weights.sum()
@@ -92,7 +92,7 @@ def sample_for_energy(G_m, max_edge, shots, thresholds, weights, repulsion_base)
92
92
  energies = np.empty(shots, dtype=dtype)
93
93
 
94
94
  best_solution = solutions[0]
95
- best_energy = float("inf")
95
+ best_energy = -float("inf")
96
96
 
97
97
  improved = True
98
98
  while improved:
@@ -104,50 +104,19 @@ def sample_for_energy(G_m, max_edge, shots, thresholds, weights, repulsion_base)
104
104
  # Second dimension: permutation within Hamming weight
105
105
  sample = local_repulsion_choice(G_m, max_edge, weights, tot_init_weight, repulsion_base, n, m)
106
106
  solutions[s] = sample
107
- energies[s] = compute_energy(sample, G_m, n)
107
+ energies[s] = compute_energy(sample, G_m, n) if is_spin_glass else compute_cut(sample, G_m, n)
108
108
 
109
- best_index = np.argmin(energies)
109
+ best_index = np.argmax(energies)
110
110
  energy = energies[best_index]
111
- if energy < best_energy:
111
+ if energy > best_energy:
112
112
  best_energy = energy
113
113
  best_solution = solutions[best_index].copy()
114
114
  improved = True
115
115
 
116
- return best_solution, compute_cut(best_solution, G_m, n)
117
-
118
-
119
- @njit(parallel=True)
120
- def sample_for_cut(G_m, max_edge, shots, thresholds, weights, repulsion_base):
121
- shots = max(1, shots >> 1)
122
- n = len(G_m)
123
- tot_init_weight = weights.sum()
124
-
125
- solutions = np.empty((shots, n), dtype=np.bool_)
126
- cuts = np.empty(shots, dtype=dtype)
127
-
128
- best_solution = solutions[0]
129
- best_cut = -float("inf")
130
-
131
- improved = True
132
- while improved:
133
- improved = False
134
- for s in prange(shots):
135
- # First dimension: Hamming weight
136
- m = sample_mag(thresholds)
137
-
138
- # Second dimension: permutation within Hamming weight
139
- sample = local_repulsion_choice(G_m, max_edge, weights, tot_init_weight, repulsion_base, n, m)
140
- solutions[s] = sample
141
- cuts[s] = compute_cut(sample, G_m, n)
142
-
143
- best_index = np.argmax(cuts)
144
- cut = cuts[best_index]
145
- if cut > best_cut:
146
- best_cut = cut
147
- best_solution = solutions[best_index].copy()
148
- improved = True
116
+ if is_spin_glass:
117
+ best_energy = compute_cut(best_solution, G_m, n)
149
118
 
150
- return best_solution, best_cut
119
+ return best_solution, best_energy
151
120
 
152
121
 
153
122
  @njit(parallel=True)
@@ -182,10 +151,7 @@ def cpu_footer(shots, quality, n_qubits, G_m, nodes, is_spin_glass, anneal_t, an
182
151
  degrees = None
183
152
  J_eff = 1.0 / (1.0 + epsilon - J_eff)
184
153
 
185
- if is_spin_glass:
186
- best_solution, best_value = sample_for_energy(G_m, max_edge, shots, hamming_prob, J_eff, repulsion_base)
187
- else:
188
- best_solution, best_value = sample_for_cut(G_m, max_edge, shots, hamming_prob, J_eff, repulsion_base)
154
+ best_solution, best_value = sample_measurement(G_m, max_edge, shots, hamming_prob, J_eff, repulsion_base, is_spin_glass)
189
155
 
190
156
  bit_string, l, r = get_cut(best_solution, nodes)
191
157
 
@@ -78,7 +78,7 @@ def compute_energy(sample, G_data, G_rows, G_cols, n_qubits):
78
78
  val = G_data[col]
79
79
  energy += val if sample[u] == sample[v] else -val
80
80
 
81
- return energy
81
+ return -energy
82
82
 
83
83
 
84
84
  @njit
@@ -94,7 +94,7 @@ def compute_cut(sample, G_data, G_rows, G_cols, n_qubits):
94
94
 
95
95
 
96
96
  @njit(parallel=True)
97
- def sample_for_energy(max_edge, G_data, G_rows, G_cols, shots, thresholds, weights, repulsion_base):
97
+ def sample_measurement(max_edge, G_data, G_rows, G_cols, shots, thresholds, weights, repulsion_base, is_spin_glass):
98
98
  shots = max(1, shots >> 1)
99
99
  n = G_rows.shape[0] - 1
100
100
  tot_init_weight = weights.sum()
@@ -103,7 +103,7 @@ def sample_for_energy(max_edge, G_data, G_rows, G_cols, shots, thresholds, weigh
103
103
  energies = np.empty(shots, dtype=dtype)
104
104
 
105
105
  best_solution = solutions[0]
106
- best_energy = float("inf")
106
+ best_energy = -float("inf")
107
107
 
108
108
  improved = True
109
109
  while improved:
@@ -115,50 +115,19 @@ def sample_for_energy(max_edge, G_data, G_rows, G_cols, shots, thresholds, weigh
115
115
  # Second dimension: permutation within Hamming weight
116
116
  sample = local_repulsion_choice(G_cols, G_data, G_rows, max_edge, weights, tot_init_weight, repulsion_base, n, m)
117
117
  solutions[s] = sample
118
- energies[s] = compute_energy(sample, G_data, G_rows, G_cols, n)
118
+ energies[s] = compute_energy(sample, G_data, G_rows, G_cols, n) if is_spin_glass else compute_cut(sample, G_data, G_rows, G_cols, n)
119
119
 
120
- best_index = np.argmin(energies)
120
+ best_index = np.argmax(energies)
121
121
  energy = energies[best_index]
122
- if energy < best_energy:
122
+ if energy > best_energy:
123
123
  best_energy = energy
124
124
  best_solution = solutions[best_index].copy()
125
125
  improved = True
126
126
 
127
- return best_solution, compute_cut(best_solution, G_data, G_rows, G_cols, n)
128
-
129
-
130
- @njit(parallel=True)
131
- def sample_for_cut(max_edge, G_data, G_rows, G_cols, shots, thresholds, weights, repulsion_base):
132
- shots = max(1, shots >> 1)
133
- n = G_rows.shape[0] - 1
134
- tot_init_weight = weights.sum()
135
-
136
- solutions = np.empty((shots, n), dtype=np.bool_)
137
- cuts = np.empty(shots, dtype=dtype)
138
-
139
- best_solution = solutions[0]
140
- best_cut = -float("inf")
141
-
142
- improved = True
143
- while improved:
144
- improved = False
145
- for s in prange(shots):
146
- # First dimension: Hamming weight
147
- m = sample_mag(thresholds)
148
-
149
- # Second dimension: permutation within Hamming weight
150
- sample = local_repulsion_choice(G_cols, G_data, G_rows, max_edge, weights, tot_init_weight, repulsion_base, n, m)
151
- solutions[s] = sample
152
- cuts[s] = compute_cut(sample, G_data, G_rows, G_cols, n)
153
-
154
- best_index = np.argmax(cuts)
155
- cut = cuts[best_index]
156
- if cut > best_cut:
157
- best_cut = cut
158
- best_solution = solutions[best_index].copy()
159
- improved = True
127
+ if is_spin_glass:
128
+ best_energy = compute_cut(best_solution, G_data, G_rows, G_cols, n)
160
129
 
161
- return best_solution, best_cut
130
+ return best_solution, best_energy
162
131
 
163
132
 
164
133
  @njit(parallel=True)
@@ -197,10 +166,7 @@ def cpu_footer(shots, quality, n_qubits, max_edge, G_data, G_rows, G_col, nodes,
197
166
  degrees = None
198
167
  J_eff = 1.0 / (1.0 + epsilon - J_eff)
199
168
 
200
- if is_spin_glass:
201
- best_solution, best_value = sample_for_energy(max_edge, G_data, G_rows, G_col, shots, hamming_prob, J_eff, repulsion_base)
202
- else:
203
- best_solution, best_value = sample_for_cut(max_edge, G_data, G_rows, G_col, shots, hamming_prob, J_eff, repulsion_base)
169
+ best_solution, best_value = sample_measurement(max_edge, G_data, G_rows, G_col, shots, hamming_prob, J_eff, repulsion_base, is_spin_glass)
204
170
 
205
171
  bit_string, l, r = get_cut(best_solution, nodes)
206
172
 
@@ -68,7 +68,7 @@ def compute_energy(sample, G_func, nodes, n_qubits):
68
68
  val = G_func(nodes[u], nodes[v])
69
69
  energy += val if sample[u] == sample[v] else -val
70
70
 
71
- return energy
71
+ return -energy
72
72
 
73
73
 
74
74
  @njit
@@ -83,7 +83,7 @@ def compute_cut(sample, G_func, nodes, n_qubits):
83
83
 
84
84
 
85
85
  @njit(parallel=True)
86
- def sample_for_energy(G_func, nodes, max_edge, shots, thresholds, degrees_sum, weights, n, repulsion_base):
86
+ def sample_measurement(G_func, nodes, max_edge, shots, thresholds, degrees_sum, weights, n, repulsion_base, is_spin_glass):
87
87
  shots = max(1, shots >> 1)
88
88
  tot_init_weight = weights.sum()
89
89
 
@@ -91,7 +91,7 @@ def sample_for_energy(G_func, nodes, max_edge, shots, thresholds, degrees_sum, w
91
91
  energies = np.empty(shots, dtype=dtype)
92
92
 
93
93
  best_solution = solutions[0]
94
- best_energy = float("inf")
94
+ best_energy = -float("inf")
95
95
 
96
96
  improved = True
97
97
  while improved:
@@ -103,49 +103,19 @@ def sample_for_energy(G_func, nodes, max_edge, shots, thresholds, degrees_sum, w
103
103
  # Second dimension: permutation within Hamming weight
104
104
  sample = local_repulsion_choice(G_func, nodes, max_edge, weights, tot_init_weight, repulsion_base, n, m)
105
105
  solutions[s] = sample
106
- energies[s] = compute_energy(sample, G_func, nodes, n)
106
+ energies[s] = compute_energy(sample, G_func, nodes, n) if is_spin_glass else compute_cut(sample, G_func, nodes, n)
107
107
 
108
- best_index = np.argmin(energies)
108
+ best_index = np.argmax(energies)
109
109
  energy = energies[best_index]
110
- if energy < best_energy:
110
+ if energy > best_energy:
111
111
  best_energy = energy
112
112
  best_solution = solutions[best_index].copy()
113
113
  improved = True
114
114
 
115
- return best_solution, compute_cut(best_solution, G_func, nodes, n)
116
-
117
-
118
- @njit(parallel=True)
119
- def sample_for_cut(G_func, nodes, max_edge, shots, thresholds, degrees_sum, weights, n, repulsion_base):
120
- shots = max(1, shots >> 1)
121
- tot_init_weight = weights.sum()
122
-
123
- solutions = np.empty((shots, n), dtype=np.bool_)
124
- cuts = np.empty(shots, dtype=dtype)
125
-
126
- best_solution = solutions[0]
127
- best_cut = -float("inf")
128
-
129
- improved = True
130
- while improved:
131
- improved = False
132
- for s in prange(shots):
133
- # First dimension: Hamming weight
134
- m = sample_mag(thresholds)
135
-
136
- # Second dimension: permutation within Hamming weight
137
- sample = local_repulsion_choice(G_func, nodes, max_edge, weights, tot_init_weight, repulsion_base, n, m)
138
- solutions[s] = sample
139
- cuts[s] = compute_cut(sample, G_func, nodes, n)
140
-
141
- best_index = np.argmax(cuts)
142
- cut = cuts[best_index]
143
- if cut > best_cut:
144
- best_cut = cut
145
- best_solution = solutions[best_index].copy()
146
- improved = True
115
+ if is_spin_glass:
116
+ best_energy = compute_cut(best_solution, G_func, nodes, n)
147
117
 
148
- return best_solution, best_cut
118
+ return best_solution, best_energy
149
119
 
150
120
 
151
121
  @njit(parallel=True)
@@ -176,15 +146,12 @@ def init_J_and_z(G_func, nodes):
176
146
  def cpu_footer(shots, quality, n_qubits, G_func, nodes, is_spin_glass, anneal_t, anneal_h, repulsion_base):
177
147
  J_eff, degrees, max_edge = init_J_and_z(G_func, nodes)
178
148
  hamming_prob = maxcut_hamming_cdf(n_qubits, J_eff, degrees, quality, anneal_t, anneal_h)
179
- max_edge = degrees.sum()
149
+ degrees_sum = degrees.sum()
180
150
 
181
151
  degrees = None
182
152
  J_eff = 1.0 / (1.0 + epsilon - J_eff)
183
153
 
184
- if is_spin_glass:
185
- best_solution, best_value = sample_for_energy(G_func, nodes, max_edge, shots, hamming_prob, max_edge, J_eff, n_qubits, repulsion_base)
186
- else:
187
- best_solution, best_value = sample_for_cut(G_func, nodes, max_edge, shots, hamming_prob, max_edge, J_eff, n_qubits, repulsion_base)
154
+ best_solution, best_value = sample_measurement(G_func, nodes, max_edge, shots, hamming_prob, degrees_sum, J_eff, n_qubits, repulsion_base, is_spin_glass)
188
155
 
189
156
  bit_string, l, r = get_cut(best_solution, nodes)
190
157
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pyqrackising
3
- Version: 8.9.3
3
+ Version: 8.9.4
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='8.9.3',
54
+ version='8.9.4',
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