PyQrackIsing 1.6.0__tar.gz → 1.6.2__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 (20) hide show
  1. {pyqrackising-1.6.0/PyQrackIsing.egg-info → pyqrackising-1.6.2}/PKG-INFO +1 -1
  2. {pyqrackising-1.6.0 → pyqrackising-1.6.2}/PyQrackIsing/maxcut_tfim.py +13 -11
  3. {pyqrackising-1.6.0 → pyqrackising-1.6.2}/PyQrackIsing/spin_glass_solver.py +8 -9
  4. {pyqrackising-1.6.0 → pyqrackising-1.6.2/PyQrackIsing.egg-info}/PKG-INFO +1 -1
  5. {pyqrackising-1.6.0 → pyqrackising-1.6.2}/README.md +1 -1
  6. {pyqrackising-1.6.0 → pyqrackising-1.6.2}/pyproject.toml +1 -1
  7. {pyqrackising-1.6.0 → pyqrackising-1.6.2}/setup.py +1 -1
  8. {pyqrackising-1.6.0 → pyqrackising-1.6.2}/CMakeLists.txt +0 -0
  9. {pyqrackising-1.6.0 → pyqrackising-1.6.2}/LICENSE.md +0 -0
  10. {pyqrackising-1.6.0 → pyqrackising-1.6.2}/MANIFEST.in +0 -0
  11. {pyqrackising-1.6.0 → pyqrackising-1.6.2}/PyQrackIsing/__init__.py +0 -0
  12. {pyqrackising-1.6.0 → pyqrackising-1.6.2}/PyQrackIsing/_pyqrack_ising.cpp +0 -0
  13. {pyqrackising-1.6.0 → pyqrackising-1.6.2}/PyQrackIsing/generate_tfim_samples.py +0 -0
  14. {pyqrackising-1.6.0 → pyqrackising-1.6.2}/PyQrackIsing/tfim_magnetization.py +0 -0
  15. {pyqrackising-1.6.0 → pyqrackising-1.6.2}/PyQrackIsing/tfim_square_magnetization.py +0 -0
  16. {pyqrackising-1.6.0 → pyqrackising-1.6.2}/PyQrackIsing.egg-info/SOURCES.txt +0 -0
  17. {pyqrackising-1.6.0 → pyqrackising-1.6.2}/PyQrackIsing.egg-info/dependency_links.txt +0 -0
  18. {pyqrackising-1.6.0 → pyqrackising-1.6.2}/PyQrackIsing.egg-info/not-zip-safe +0 -0
  19. {pyqrackising-1.6.0 → pyqrackising-1.6.2}/PyQrackIsing.egg-info/top_level.txt +0 -0
  20. {pyqrackising-1.6.0 → pyqrackising-1.6.2}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: PyQrackIsing
3
- Version: 1.6.0
3
+ Version: 1.6.2
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
@@ -49,24 +49,25 @@ def local_repulsion_choice(adjacency, degrees, weights, n, m):
49
49
  return mask
50
50
 
51
51
 
52
- def evaluate_cut_edges(samples, flat_edges):
53
- best_value = -1
52
+ def evaluate_cut_edges(samples, G):
53
+ best_value = float("-inf")
54
54
  best_solution = None
55
55
  best_cut_edges = None
56
+
56
57
  for state in samples:
57
58
  cut_edges = []
58
- for i in range(len(flat_edges) // 2):
59
- i2 = i << 1
60
- u, v = flat_edges[i2], flat_edges[i2 + 1]
59
+ cut_value = 0
60
+ for u, v, data in G.edges(data=True):
61
61
  if ((state >> u) & 1) != ((state >> v) & 1):
62
62
  cut_edges.append((u, v))
63
- cut_size = len(cut_edges)
64
- if cut_size > best_value:
65
- best_value = cut_size
63
+ cut_value += data.get("weight", 1.0)
64
+
65
+ if cut_value > best_value:
66
+ best_value = cut_value
66
67
  best_solution = state
67
68
  best_cut_edges = cut_edges
68
69
 
69
- return best_value, best_solution, best_cut_edges
70
+ return float(best_value), best_solution, best_cut_edges
70
71
 
71
72
 
72
73
  # By Gemini (Google Search AI)
@@ -89,7 +90,8 @@ def maxcut_tfim(
89
90
  degrees = np.array([sum(abs(edge_attributes.get('weight', 1.0)) for _, edge_attributes in G.adj[i].items()) for i in range(n_qubits)], dtype=np.float64)
90
91
  thresholds = tfim_sampler._maxcut_hamming_cdf(J_eff, degrees, quality)
91
92
  G_dict = nx.to_dict_of_lists(G)
92
- weights = 1.0 / (degrees + 1.0)
93
+ J_max = max(J_eff)
94
+ weights = 1.0 / (1.0 + (J_max - J_eff))
93
95
  samples = []
94
96
  for s in range(shots):
95
97
  # First dimension: Hamming weight
@@ -101,6 +103,6 @@ def maxcut_tfim(
101
103
  # Second dimension: permutation within Hamming weight
102
104
  samples.append(local_repulsion_choice(G_dict, degrees, weights, n_qubits, m))
103
105
 
104
- best_value, best_solution, best_cut_edges = evaluate_cut_edges(samples, [int(item) for tup in G.edges() for item in tup])
106
+ best_value, best_solution, best_cut_edges = evaluate_cut_edges(samples, G)
105
107
 
106
108
  return best_value, int_to_bitstring(best_solution, n_qubits), best_cut_edges
@@ -3,16 +3,15 @@ import multiprocessing
3
3
  import os
4
4
 
5
5
 
6
- def evaluate_cut_edges(state, flat_edges):
6
+ def evaluate_cut_edges(state, G):
7
7
  cut_edges = []
8
- for i in range(len(flat_edges) // 2):
9
- i2 = i << 1
10
- u, v = flat_edges[i2], flat_edges[i2 + 1]
8
+ cut_value = 0
9
+ for u, v, data in G.edges(data=True):
11
10
  if ((state >> u) & 1) != ((state >> v) & 1):
12
11
  cut_edges.append((u, v))
13
- cut_size = len(cut_edges)
12
+ cut_value += data.get("weight", 1.0)
14
13
 
15
- return cut_size, cut_edges
14
+ return float(cut_value), cut_edges
16
15
 
17
16
 
18
17
  def compute_energy(theta_bits, G):
@@ -34,8 +33,8 @@ def bootstrap_worker(args):
34
33
 
35
34
  return indices, energy, flipped
36
35
 
37
- def spin_glass_solver(G):
38
- cut_value, bitstring, cut_edges = maxcut_tfim(G, quality=6)
36
+ def spin_glass_solver(G, quality=0):
37
+ cut_value, bitstring, cut_edges = maxcut_tfim(G, quality)
39
38
  best_theta = [ b == '1' for b in list(bitstring)]
40
39
  min_energy = compute_energy(best_theta, G)
41
40
  n_qubits = len(best_theta)
@@ -94,6 +93,6 @@ def spin_glass_solver(G):
94
93
  if b:
95
94
  sample |= 1 << i
96
95
 
97
- cut_value, cut_edges = evaluate_cut_edges(sample, [int(item) for tup in G.edges() for item in tup])
96
+ cut_value, cut_edges = evaluate_cut_edges(sample, G)
98
97
 
99
98
  return cut_value, bitstring, cut_edges, min_energy
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: PyQrackIsing
3
- Version: 1.6.0
3
+ Version: 1.6.2
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
@@ -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
- cut_value, bitstring, cut_edges, min_energy = spin_glass_solver(G)
72
+ cut_value, bitstring, cut_edges, min_energy = spin_glass_solver(G, quality=0)
73
73
  ```
74
74
 
75
75
  ## About
@@ -10,7 +10,7 @@ build-backend = "setuptools.build_meta"
10
10
 
11
11
  [project]
12
12
  name = "PyQrackIsing"
13
- version = "1.6.0"
13
+ version = "1.6.2"
14
14
  requires-python = ">=3.8"
15
15
  description = "Near-ideal closed-form solutions for transverse field Ising model (TFIM)"
16
16
  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.6.0',
54
+ version='1.6.2',
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