PyQrackIsing 9.15.5__tar.gz → 9.16.1__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 (36) hide show
  1. {pyqrackising-9.15.5/pyqrackising.egg-info → pyqrackising-9.16.1}/PKG-INFO +1 -1
  2. {pyqrackising-9.15.5 → pyqrackising-9.16.1}/README.md +1 -1
  3. {pyqrackising-9.15.5 → pyqrackising-9.16.1}/pyproject.toml +1 -1
  4. {pyqrackising-9.15.5 → pyqrackising-9.16.1}/pyqrackising/__init__.py +1 -0
  5. {pyqrackising-9.15.5 → pyqrackising-9.16.1}/pyqrackising/maxcut_tfim.py +10 -14
  6. {pyqrackising-9.15.5 → pyqrackising-9.16.1}/pyqrackising/maxcut_tfim_sparse.py +11 -12
  7. {pyqrackising-9.15.5 → pyqrackising-9.16.1}/pyqrackising/maxcut_tfim_streaming.py +10 -11
  8. {pyqrackising-9.15.5 → pyqrackising-9.16.1}/pyqrackising/maxcut_tfim_util.py +2 -9
  9. pyqrackising-9.16.1/pyqrackising/spin_glass_solver_hybrid.py +46 -0
  10. {pyqrackising-9.15.5 → pyqrackising-9.16.1/pyqrackising.egg-info}/PKG-INFO +1 -1
  11. {pyqrackising-9.15.5 → pyqrackising-9.16.1}/pyqrackising.egg-info/SOURCES.txt +1 -0
  12. {pyqrackising-9.15.5 → pyqrackising-9.16.1}/setup.py +1 -1
  13. {pyqrackising-9.15.5 → pyqrackising-9.16.1}/LICENSE.md +0 -0
  14. {pyqrackising-9.15.5 → pyqrackising-9.16.1}/MANIFEST.in +0 -0
  15. {pyqrackising-9.15.5 → pyqrackising-9.16.1}/pyqrackising/convert_tensor_network_to_tsp.py +0 -0
  16. {pyqrackising-9.15.5 → pyqrackising-9.16.1}/pyqrackising/generate_tfim_samples.py +0 -0
  17. {pyqrackising-9.15.5 → pyqrackising-9.16.1}/pyqrackising/kernels.cl +0 -0
  18. {pyqrackising-9.15.5 → pyqrackising-9.16.1}/pyqrackising/otoc.py +0 -0
  19. {pyqrackising-9.15.5 → pyqrackising-9.16.1}/pyqrackising/solve_maxcut_bnb.py +0 -0
  20. {pyqrackising-9.15.5 → pyqrackising-9.16.1}/pyqrackising/solve_maxcut_bnb_sparse.py +0 -0
  21. {pyqrackising-9.15.5 → pyqrackising-9.16.1}/pyqrackising/solve_maxcut_bnb_streaming.py +0 -0
  22. {pyqrackising-9.15.5 → pyqrackising-9.16.1}/pyqrackising/solve_maxcut_exact.py +0 -0
  23. {pyqrackising-9.15.5 → pyqrackising-9.16.1}/pyqrackising/solve_maxcut_exact_sparse.py +0 -0
  24. {pyqrackising-9.15.5 → pyqrackising-9.16.1}/pyqrackising/solve_maxcut_exact_streaming.py +0 -0
  25. {pyqrackising-9.15.5 → pyqrackising-9.16.1}/pyqrackising/spin_glass_solver.py +0 -0
  26. {pyqrackising-9.15.5 → pyqrackising-9.16.1}/pyqrackising/spin_glass_solver_sparse.py +0 -0
  27. {pyqrackising-9.15.5 → pyqrackising-9.16.1}/pyqrackising/spin_glass_solver_streaming.py +0 -0
  28. {pyqrackising-9.15.5 → pyqrackising-9.16.1}/pyqrackising/tfim_magnetization.py +0 -0
  29. {pyqrackising-9.15.5 → pyqrackising-9.16.1}/pyqrackising/tfim_square_magnetization.py +0 -0
  30. {pyqrackising-9.15.5 → pyqrackising-9.16.1}/pyqrackising/tsp.py +0 -0
  31. {pyqrackising-9.15.5 → pyqrackising-9.16.1}/pyqrackising/tsp_maxcut.py +0 -0
  32. {pyqrackising-9.15.5 → pyqrackising-9.16.1}/pyqrackising.egg-info/dependency_links.txt +0 -0
  33. {pyqrackising-9.15.5 → pyqrackising-9.16.1}/pyqrackising.egg-info/not-zip-safe +0 -0
  34. {pyqrackising-9.15.5 → pyqrackising-9.16.1}/pyqrackising.egg-info/requires.txt +0 -0
  35. {pyqrackising-9.15.5 → pyqrackising-9.16.1}/pyqrackising.egg-info/top_level.txt +0 -0
  36. {pyqrackising-9.15.5 → pyqrackising-9.16.1}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pyqrackising
3
- Version: 9.15.5
3
+ Version: 9.16.1
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
@@ -89,7 +89,7 @@ solution_bit_string, cut_value, node_groups, energy = spin_glass_solver(
89
89
  )
90
90
  # solution_bit_string, cut_value, node_groups, energy = spin_glass_solver(G, best_guess=maxcut_tfim(G, quality=6)[0])
91
91
  ```
92
- We also provide `spin_glass_solver_sparse(G)` and `spin_glass_solver_streaming(G_func, nodes)`. `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. `is_spin_glass` controls whether the solver optimizes for cut value or spin-glass energy. 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. `gray_iterations` gives manual control over how many iterations are carried out of a parallel Gray-code search on `best_guess`. `gray_seed_multiple` controls how many parallel search seeds (as a multiple of your CPU thread count) are tested for the best parallel seeds, and a value of `1` will perfectly cover the search space without collision if your node count is a power of 2. `bp_scale` controls opt-in and time complexity scaling for _belief propagation_ as a competing "warm start," with `None` disabling this option completely, `1.0` representing a budget of exactly `O(n^3)` time complexity, and lesser or greater values representing a linear multiplier on that budget. `bp_damping` similarly controls belief propagation damping.
92
+ We also provide `spin_glass_solver_sparse(G)`, `spin_glass_solver_streaming(G_func, nodes)`, and `spin_glass_hybrid(G)` (which combines the dense TFIM-based solver with a sparse local-optimization solver). `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. `is_spin_glass` controls whether the solver optimizes for cut value or spin-glass energy. 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. `gray_iterations` gives manual control over how many iterations are carried out of a parallel Gray-code search on `best_guess`. `gray_seed_multiple` controls how many parallel search seeds (as a multiple of your CPU thread count) are tested for the best parallel seeds, and a value of `1` will perfectly cover the search space without collision if your node count is a power of 2. `bp_scale` controls opt-in and time complexity scaling for _belief propagation_ as a competing "warm start," with `None` disabling this option completely, `1.0` representing a budget of exactly `O(n^3)` time complexity, and lesser or greater values representing a linear multiplier on that budget. `bp_damping` similarly controls belief propagation damping.
93
93
 
94
94
  These solvers above can be used as a "warm state" for _MaxSAT-based_ solvers or _branch-and-bound_ solvers, potentially to reach _exact_ solutions to MAXCUT:
95
95
 
@@ -7,7 +7,7 @@ build-backend = "setuptools.build_meta"
7
7
 
8
8
  [project]
9
9
  name = "pyqrackising"
10
- version = "9.15.5"
10
+ version = "9.16.1"
11
11
  requires-python = ">=3.8"
12
12
  description = "Fast MAXCUT, TSP, and sampling heuristics from near-ideal transverse field Ising model (TFIM)"
13
13
  readme = {file = "README.txt", content-type = "text/markdown"}
@@ -9,6 +9,7 @@ from .maxcut_tfim_util import probability_by_hamming_weight
9
9
  from .spin_glass_solver import spin_glass_solver
10
10
  from .spin_glass_solver_sparse import spin_glass_solver_sparse
11
11
  from .spin_glass_solver_streaming import spin_glass_solver_streaming
12
+ from .spin_glass_solver_hybrid import spin_glass_solver_hybrid
12
13
  from .tsp import tsp_symmetric, tsp_asymmetric
13
14
  from .tsp_maxcut import tsp_maxcut, tsp_maxcut_sparse, tsp_maxcut_streaming
14
15
  from .convert_tensor_network_to_tsp import convert_tensor_network_to_tsp, convert_quimb_tree_to_tsp
@@ -34,18 +34,15 @@ wgs = opencl_context.work_group_size
34
34
 
35
35
 
36
36
  @njit(cache=True)
37
- def update_repulsion_choice(G_m, weights, n, used, node, repulsion_base):
37
+ def update_repulsion_choice(G_m, weights, n, node, repulsion_base):
38
38
  # Select node
39
- used[node] = True
39
+ weights[node] = 0.0
40
40
 
41
41
  if abs(1.0 - repulsion_base) <= epsilon:
42
42
  return
43
43
 
44
44
  # Repulsion: penalize neighbors
45
- for nbr in range(n):
46
- if used[nbr]:
47
- continue
48
- weights[nbr] *= repulsion_base ** (-G_m[node, nbr])
45
+ weights *= repulsion_base ** (-G_m[node])
49
46
 
50
47
 
51
48
  # Written by Elara (OpenAI custom GPT) and improved by Dan Strano
@@ -57,25 +54,24 @@ def local_repulsion_choice(G_m, repulsion_base, n, m, s):
57
54
  - After choosing a node, its neighbors' probabilities are further reduced
58
55
  """
59
56
 
60
- used = np.zeros(n, dtype=np.bool_) # False = available, True = used
61
-
62
57
  # First bit:
63
58
  node = s % n
64
59
  if m == 1:
60
+ used = np.zeros(n, dtype=np.bool_)
65
61
  used[node] = True
66
62
  return used
67
63
 
68
64
  weights = np.ones(n, dtype=np.float64)
69
- update_repulsion_choice(G_m, weights, n, used, node, repulsion_base)
65
+ update_repulsion_choice(G_m, weights, n, node, repulsion_base)
70
66
 
71
67
  for _ in range(1, m - 1):
72
- node = bit_pick(weights, used, n)
73
- update_repulsion_choice(G_m, weights, n, used, node, repulsion_base)
68
+ node = bit_pick(weights, n)
69
+ update_repulsion_choice(G_m, weights, n, node, repulsion_base)
74
70
 
75
- node = bit_pick(weights, used, n)
76
- used[node] = True
71
+ node = bit_pick(weights, n)
72
+ weights[node] = 0.0
77
73
 
78
- return used
74
+ return weights == 0.0
79
75
 
80
76
 
81
77
  @njit(parallel=True, cache=True)
@@ -35,9 +35,9 @@ wgs = opencl_context.work_group_size
35
35
 
36
36
 
37
37
  @njit(cache=True)
38
- def update_repulsion_choice(G_data, G_rows, G_cols, weights, n, used, node, repulsion_base):
38
+ def update_repulsion_choice(G_data, G_rows, G_cols, weights, n, node, repulsion_base):
39
39
  # Select node
40
- used[node] = True
40
+ weights[node] = 0.0
41
41
 
42
42
  if abs(1.0 - repulsion_base) <= epsilon:
43
43
  return
@@ -45,12 +45,12 @@ def update_repulsion_choice(G_data, G_rows, G_cols, weights, n, used, node, repu
45
45
  # Repulsion: penalize neighbors
46
46
  for j in range(G_rows[node], G_rows[node + 1]):
47
47
  nbr = G_cols[j]
48
- if used[nbr]:
48
+ if weights[nbr] == 0.0:
49
49
  continue
50
50
  weights[nbr] *= repulsion_base ** (-G_data[j])
51
51
 
52
52
  for nbr in range(node):
53
- if used[nbr]:
53
+ if weights[nbr] == 0.0:
54
54
  continue
55
55
  start = G_rows[nbr]
56
56
  end = G_rows[nbr + 1]
@@ -68,25 +68,24 @@ def local_repulsion_choice(G_data, G_rows, G_cols, repulsion_base, n, m, s):
68
68
  - After choosing a node, its neighbors' probabilities are further reduced
69
69
  """
70
70
 
71
- used = np.zeros(n, dtype=np.bool_) # False = available, True = used
72
-
73
71
  # First bit:
74
72
  node = s % n
75
73
  if m == 1:
74
+ used = np.zeros(n, dtype=np.bool_)
76
75
  used[node] = True
77
76
  return used
78
77
 
79
78
  weights = np.ones(n, dtype=np.float64)
80
- update_repulsion_choice(G_data, G_rows, G_cols, weights, n, used, node, repulsion_base)
79
+ update_repulsion_choice(G_data, G_rows, G_cols, weights, n, node, repulsion_base)
81
80
 
82
81
  for _ in range(1, m - 1):
83
- node = bit_pick(weights, used, n)
84
- update_repulsion_choice(G_data, G_rows, G_cols, weights, n, used, node, repulsion_base)
82
+ node = bit_pick(weights, n)
83
+ update_repulsion_choice(G_data, G_rows, G_cols, weights, n, node, repulsion_base)
85
84
 
86
- node = bit_pick(weights, used, n)
87
- used[node] = True
85
+ node = bit_pick(weights, n)
86
+ weights[node] = 0.0
88
87
 
89
- return used
88
+ return weights == 0.0
90
89
 
91
90
 
92
91
  @njit(parallel=True, cache=True)
@@ -23,16 +23,16 @@ dtype = opencl_context.dtype
23
23
 
24
24
 
25
25
  @njit(cache=True)
26
- def update_repulsion_choice(G_func, nodes, weights, n, used, node, repulsion_base):
26
+ def update_repulsion_choice(G_func, nodes, weights, n, node, repulsion_base):
27
27
  # Select node
28
- used[node] = True
28
+ weights[node] = 0.0
29
29
 
30
30
  if abs(1.0 - repulsion_base) <= epsilon:
31
31
  return
32
32
 
33
33
  # Repulsion: penalize neighbors
34
34
  for nbr in range(n):
35
- if used[nbr]:
35
+ if weights[nbr] == 0.0:
36
36
  continue
37
37
  weights[nbr] *= repulsion_base ** (-G_func(nodes[node], nodes[nbr]))
38
38
 
@@ -46,25 +46,24 @@ def local_repulsion_choice(G_func, nodes, repulsion_base, n, m, s):
46
46
  - After choosing a node, its neighbors' probabilities are further reduced
47
47
  """
48
48
 
49
- used = np.zeros(n, dtype=np.bool_) # False = available, True = used
50
-
51
49
  # First bit:
52
50
  node = s % n
53
51
  if m == 1:
52
+ used = np.zeros(n, dtype=np.bool_)
54
53
  used[node] = True
55
54
  return used
56
55
 
57
56
  weights = np.ones(n, dtype=np.float64)
58
- update_repulsion_choice(G_func, nodes, weights, n, used, node, repulsion_base)
57
+ update_repulsion_choice(G_func, nodes, weights, n, node, repulsion_base)
59
58
 
60
59
  for _ in range(1, m - 1):
61
- node = bit_pick(weights, used, n)
62
- update_repulsion_choice(G_func, nodes, weights, n, used, node, repulsion_base)
60
+ node = bit_pick(weights, n)
61
+ update_repulsion_choice(G_func, nodes, weights, n, node, repulsion_base)
63
62
 
64
- node = bit_pick(weights, used, n)
65
- used[node] = True
63
+ node = bit_pick(weights, n)
64
+ weights[node] = 0.0
66
65
 
67
- return used
66
+ return weights == 0.0
68
67
 
69
68
 
70
69
  @njit(parallel=True, cache=True)
@@ -708,21 +708,14 @@ def sample_mag(cum_prob):
708
708
 
709
709
 
710
710
  @njit(cache=True)
711
- def bit_pick(weights, used, n):
711
+ def bit_pick(weights, n):
712
712
  # Count available
713
- p = 0.0
714
- for i in range(n):
715
- if used[i]:
716
- continue
717
- p += weights[i]
718
-
713
+ p = weights.sum()
719
714
  # Normalize & sample
720
715
  p *= np.random.rand()
721
716
  cum = 0.0
722
717
  node = 0
723
718
  for i in range(n):
724
- if used[i]:
725
- continue
726
719
  cum += weights[i]
727
720
  if p < cum:
728
721
  node = i
@@ -0,0 +1,46 @@
1
+ from .maxcut_tfim import maxcut_tfim
2
+ from .spin_glass_solver_sparse import spin_glass_solver_sparse
3
+
4
+ import networkx as nx
5
+
6
+
7
+ def spin_glass_solver_hybrid(
8
+ G,
9
+ quality=None,
10
+ shots=None,
11
+ is_maxcut_gpu=True,
12
+ is_spin_glass=True,
13
+ anneal_t=None,
14
+ anneal_h=None,
15
+ repulsion_base=None,
16
+ is_log=False,
17
+ gray_iterations=None,
18
+ gray_seed_multiple=None,
19
+ bp_scale=None,
20
+ bp_damping=0.5,
21
+ ):
22
+ if not isinstance(G, nx.Graph):
23
+ raise TypeError("G graph must be a networkx.Graph for maxcut_hybrid!")
24
+
25
+ guess, _, _ = maxcut_tfim(
26
+ G,
27
+ quality=quality,
28
+ shots=shots,
29
+ repulsion_base=repulsion_base,
30
+ is_maxcut_gpu=is_maxcut_gpu,
31
+ is_spin_glass=is_spin_glass,
32
+ anneal_t=anneal_t,
33
+ anneal_h=anneal_h
34
+ )
35
+
36
+ return spin_glass_solver_sparse(
37
+ G,
38
+ best_guess=guess,
39
+ is_maxcut_gpu=is_maxcut_gpu,
40
+ is_spin_glass=is_spin_glass,
41
+ is_log=is_log,
42
+ gray_iterations=gray_iterations,
43
+ gray_seed_multiple=gray_seed_multiple,
44
+ bp_scale=bp_scale,
45
+ bp_damping=bp_damping
46
+ )
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pyqrackising
3
- Version: 9.15.5
3
+ Version: 9.16.1
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
@@ -19,6 +19,7 @@ pyqrackising/solve_maxcut_exact.py
19
19
  pyqrackising/solve_maxcut_exact_sparse.py
20
20
  pyqrackising/solve_maxcut_exact_streaming.py
21
21
  pyqrackising/spin_glass_solver.py
22
+ pyqrackising/spin_glass_solver_hybrid.py
22
23
  pyqrackising/spin_glass_solver_sparse.py
23
24
  pyqrackising/spin_glass_solver_streaming.py
24
25
  pyqrackising/tfim_magnetization.py
@@ -7,7 +7,7 @@ with open(README_PATH) as readme_file:
7
7
 
8
8
  setup(
9
9
  name="pyqrackising",
10
- version="9.15.5",
10
+ version="9.16.1",
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