PyQrackIsing 1.19.0__tar.gz → 1.20.0__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 (21) hide show
  1. {pyqrackising-1.19.0/PyQrackIsing.egg-info → pyqrackising-1.20.0}/PKG-INFO +1 -1
  2. {pyqrackising-1.19.0 → pyqrackising-1.20.0}/PyQrackIsing/maxcut_tfim.py +6 -6
  3. {pyqrackising-1.19.0 → pyqrackising-1.20.0}/PyQrackIsing/tsp_symmetric.py +15 -3
  4. {pyqrackising-1.19.0 → pyqrackising-1.20.0/PyQrackIsing.egg-info}/PKG-INFO +1 -1
  5. {pyqrackising-1.19.0 → pyqrackising-1.20.0}/README.md +3 -3
  6. {pyqrackising-1.19.0 → pyqrackising-1.20.0}/pyproject.toml +1 -1
  7. {pyqrackising-1.19.0 → pyqrackising-1.20.0}/setup.py +1 -1
  8. {pyqrackising-1.19.0 → pyqrackising-1.20.0}/CMakeLists.txt +0 -0
  9. {pyqrackising-1.19.0 → pyqrackising-1.20.0}/LICENSE.md +0 -0
  10. {pyqrackising-1.19.0 → pyqrackising-1.20.0}/MANIFEST.in +0 -0
  11. {pyqrackising-1.19.0 → pyqrackising-1.20.0}/PyQrackIsing/__init__.py +0 -0
  12. {pyqrackising-1.19.0 → pyqrackising-1.20.0}/PyQrackIsing/_pyqrack_ising.cpp +0 -0
  13. {pyqrackising-1.19.0 → pyqrackising-1.20.0}/PyQrackIsing/generate_tfim_samples.py +0 -0
  14. {pyqrackising-1.19.0 → pyqrackising-1.20.0}/PyQrackIsing/spin_glass_solver.py +0 -0
  15. {pyqrackising-1.19.0 → pyqrackising-1.20.0}/PyQrackIsing/tfim_magnetization.py +0 -0
  16. {pyqrackising-1.19.0 → pyqrackising-1.20.0}/PyQrackIsing/tfim_square_magnetization.py +0 -0
  17. {pyqrackising-1.19.0 → pyqrackising-1.20.0}/PyQrackIsing.egg-info/SOURCES.txt +0 -0
  18. {pyqrackising-1.19.0 → pyqrackising-1.20.0}/PyQrackIsing.egg-info/dependency_links.txt +0 -0
  19. {pyqrackising-1.19.0 → pyqrackising-1.20.0}/PyQrackIsing.egg-info/not-zip-safe +0 -0
  20. {pyqrackising-1.19.0 → pyqrackising-1.20.0}/PyQrackIsing.egg-info/top_level.txt +0 -0
  21. {pyqrackising-1.19.0 → pyqrackising-1.20.0}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: PyQrackIsing
3
- Version: 1.19.0
3
+ Version: 1.20.0
4
4
  Summary: Near-ideal closed-form solutions for transverse field Ising model (TFIM)
5
5
  Home-page: https://github.com/vm6502q/PyQrackIsing
6
6
  Author: Dan Strano
@@ -102,8 +102,8 @@ def maxcut_hamming_cdf(n_qubits, J_func, degrees, quality, hamming_prob):
102
102
 
103
103
  n_steps = 1 << quality
104
104
  delta_t = 1.0 / n_steps
105
- tot_t = 4.0 * n_steps * delta_t
106
- h_mult = 4.0 / tot_t
105
+ tot_t = 2.0 * n_steps * delta_t
106
+ h_mult = 2.0 / tot_t
107
107
  n_bias = n_qubits - 1
108
108
 
109
109
  theta = np.empty(n_qubits, dtype=np.float64)
@@ -350,7 +350,7 @@ def maxcut_tfim(
350
350
  group_size = n_qubits - 1
351
351
 
352
352
  if quality is None:
353
- quality = 4
353
+ quality = 3
354
354
 
355
355
  if shots is None:
356
356
  # Number of measurement shots
@@ -371,14 +371,14 @@ def maxcut_tfim(
371
371
  J_abs = abs(J)
372
372
  if J_abs > J_max:
373
373
  J_max = J_abs
374
- J_eff /= J_abs
374
+ J_eff /= J_max
375
375
 
376
376
  thresholds = init_thresholds(n_qubits)
377
377
 
378
378
  if IS_CUDA_AVAILABLE and cuda.is_available() and grid_size >= 128:
379
379
  delta_t = 1.0 / n_steps
380
- tot_t = 4.0 * n_steps * delta_t
381
- h_mult = 4.0 / tot_t
380
+ tot_t = 2.0 * n_steps * delta_t
381
+ h_mult = 2.0 / tot_t
382
382
  theta = init_theta(delta_t, tot_t, h_mult, n_qubits, J_eff, degrees)
383
383
 
384
384
  cuda_maxcut_hamming_cdf[grid_dims, group_size](delta_t, tot_t, h_mult, J_eff, degrees, theta, thresholds)
@@ -120,7 +120,9 @@ def targeted_three_opt(path, W, k_neighbors=20):
120
120
 
121
121
  return best_path, best_dist
122
122
 
123
- def tsp_symmetric(G, quality=0, shots=None, correction_quality=2, is_3_opt=True, k_neighbors=20, is_cyclic=True):
123
+ def tsp_symmetric(G, quality=0, shots=None, correction_quality=2, is_3_opt=True, k_neighbors=20, is_cyclic=True, is_cyclic_at_top=False):
124
+ is_cyclic_at_top |= is_cyclic
125
+
124
126
  nodes = None
125
127
  n_nodes = 0
126
128
  G_m = None
@@ -166,8 +168,8 @@ def tsp_symmetric(G, quality=0, shots=None, correction_quality=2, is_3_opt=True,
166
168
  continue
167
169
  G_b[i, j] = G_m[b[i], b[j]]
168
170
 
169
- sol_a = tsp_symmetric(G_a, quality=quality, is_cyclic=False, is_3_opt=False)
170
- sol_b = tsp_symmetric(G_b, quality=quality, is_cyclic=False, is_3_opt=False)
171
+ sol_a = tsp_symmetric(G_a, quality=quality, is_cyclic=False, is_cyclic_at_top=is_cyclic_at_top, is_3_opt=False)
172
+ sol_b = tsp_symmetric(G_b, quality=quality, is_cyclic=False, is_cyclic_at_top=is_cyclic_at_top, is_3_opt=False)
171
173
 
172
174
  path_a = [a[x] for x in sol_a[0]]
173
175
  path_b = [b[x] for x in sol_b[0]]
@@ -234,11 +236,21 @@ def tsp_symmetric(G, quality=0, shots=None, correction_quality=2, is_3_opt=True,
234
236
  path_a, path_b = path_b, path_a
235
237
  terminals_a, terminals_b = terminals_b, terminals_a
236
238
 
239
+ cycle_node = None
240
+ if is_cyclic_at_top:
241
+ cycle_node = best_path[0]
242
+ best_path += [cycle_node]
243
+
237
244
  best_path, best_weight = two_opt(best_path, G_m)
238
245
 
239
246
  if is_3_opt:
240
247
  best_path, best_weight = targeted_three_opt(best_path, G_m, k_neighbors)
241
248
 
249
+ if is_cyclic_at_top:
250
+ cycle_index = best_path.index(cycle_node)
251
+ best_weight -= G_m[best_path[cycle_index], best_path[cycle_index + 1]]
252
+ best_path = best_path[cycle_index + 1:] + best_path[:cycle_index]
253
+
242
254
  if is_cyclic:
243
255
  best_weight += G_m[best_path[-1], best_path[0]]
244
256
  best_path += [best_path[0]]
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: PyQrackIsing
3
- Version: 1.19.0
3
+ Version: 1.20.0
4
4
  Summary: Near-ideal closed-form solutions for transverse field Ising model (TFIM)
5
5
  Home-page: https://github.com/vm6502q/PyQrackIsing
6
6
  Author: Dan Strano
@@ -46,10 +46,10 @@ from PyQrackIsing import maxcut_tfim
46
46
  import networkx as nx
47
47
 
48
48
  G = nx.petersen_graph()
49
- best_solution_bit_string, best_cut_value, best_node_groups = maxcut_tfim(G, quality=4)
49
+ best_solution_bit_string, best_cut_value, best_node_groups = maxcut_tfim(G, quality=3)
50
50
  ```
51
51
 
52
- The (integer) `quality` setting is optional, with a default value of `4`, but you can turn it up for higher-quality results, or turn it down to save time. (You can also optionally specify the number of measurement `shots` as an argument, if you want specific fine-grained control over resource usage.) If you want to run MAXCUT on a graph with non-uniform edge weights, specify them as the `weight` attribute of each edge, with `networkx`. (If any `weight` attribute is not defined, the solver assumes it's `1.0` for that edge.)
52
+ The (integer) `quality` setting is optional, with a default value of `3`, but you can turn it up for higher-quality results, or turn it down to save time. (You can also optionally specify the number of measurement `shots` as an argument, if you want specific fine-grained control over resource usage.) If you want to run MAXCUT on a graph with non-uniform edge weights, specify them as the `weight` attribute of each edge, with `networkx`. (If any `weight` attribute is not defined, the solver assumes it's `1.0` for that edge.)
53
53
 
54
54
  Based on a combination of the TFIM-inspired MAXCUT solver and another technique for finding ground-state energy in quantum chemistry that we call the _"binary Clifford eigensolver,"_ we also provide an (approximate) spin glass ground-state solver:
55
55
  ```py
@@ -69,7 +69,7 @@ def generate_spin_glass_graph(n_nodes=16, degree=3, seed=None):
69
69
 
70
70
 
71
71
  G = generate_spin_glass_graph(n_nodes=64, seed=42)
72
- solution_bit_string, cut_value, node_groups, energy = spin_glass_solver(G, quality=4, correction_quality=2, best_guess=None)
72
+ solution_bit_string, cut_value, node_groups, energy = spin_glass_solver(G, quality=3, correction_quality=2, best_guess=None)
73
73
  # solution_bit_string, cut_value, node_groups, energy = spin_glass_solver(G, best_guess=maxcut_tfim(G, quality=8)[0])
74
74
  ```
75
75
  The (integer) `quality` setting is the same as `maxcut_tfim`. `correction_quality` controls an additional convex optimization procedure on top of `best_guess` and defaults to 4. `best_guess` gives the option to seed the algorithm with a best guess as to the maximal cut (as an integer, binary string, or list of booleans). By default, `spin_glass_solver()` uses `maxcut_tfim(G)` with passed-through `quality` as `best_guess`, which typically works well, but it could be seeded with higher `maxcut_tfim()` `quality` or Goemans-Williamson, for example. This function is designed with a sign convention for weights such that it can immediately be used as a MAXCUT solver itself: you might need to reverse the sign convention on your weights for spin glass graphs, but this is only convention.
@@ -12,7 +12,7 @@ build-backend = "setuptools.build_meta"
12
12
 
13
13
  [project]
14
14
  name = "PyQrackIsing"
15
- version = "1.19.0"
15
+ version = "1.20.0"
16
16
  requires-python = ">=3.8"
17
17
  description = "Near-ideal closed-form solutions for transverse field Ising model (TFIM)"
18
18
  readme = {file = "README.txt", content-type = "text/markdown"}
@@ -51,7 +51,7 @@ ext_modules = [CMakeExtension('tfim_sampler')]
51
51
 
52
52
  setup(
53
53
  name='PyQrackIsing',
54
- version='1.19.0',
54
+ version='1.20.0',
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)',
File without changes
File without changes
File without changes