PyQrackIsing 1.6.0__tar.gz → 1.7.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 (20) hide show
  1. {pyqrackising-1.6.0/PyQrackIsing.egg-info → pyqrackising-1.7.0}/PKG-INFO +1 -1
  2. {pyqrackising-1.6.0 → pyqrackising-1.7.0}/PyQrackIsing/maxcut_tfim.py +14 -12
  3. {pyqrackising-1.6.0 → pyqrackising-1.7.0}/PyQrackIsing/spin_glass_solver.py +8 -9
  4. {pyqrackising-1.6.0 → pyqrackising-1.7.0/PyQrackIsing.egg-info}/PKG-INFO +1 -1
  5. {pyqrackising-1.6.0 → pyqrackising-1.7.0}/README.md +1 -0
  6. {pyqrackising-1.6.0 → pyqrackising-1.7.0}/pyproject.toml +1 -1
  7. {pyqrackising-1.6.0 → pyqrackising-1.7.0}/setup.py +1 -1
  8. {pyqrackising-1.6.0 → pyqrackising-1.7.0}/CMakeLists.txt +0 -0
  9. {pyqrackising-1.6.0 → pyqrackising-1.7.0}/LICENSE.md +0 -0
  10. {pyqrackising-1.6.0 → pyqrackising-1.7.0}/MANIFEST.in +0 -0
  11. {pyqrackising-1.6.0 → pyqrackising-1.7.0}/PyQrackIsing/__init__.py +0 -0
  12. {pyqrackising-1.6.0 → pyqrackising-1.7.0}/PyQrackIsing/_pyqrack_ising.cpp +0 -0
  13. {pyqrackising-1.6.0 → pyqrackising-1.7.0}/PyQrackIsing/generate_tfim_samples.py +0 -0
  14. {pyqrackising-1.6.0 → pyqrackising-1.7.0}/PyQrackIsing/tfim_magnetization.py +0 -0
  15. {pyqrackising-1.6.0 → pyqrackising-1.7.0}/PyQrackIsing/tfim_square_magnetization.py +0 -0
  16. {pyqrackising-1.6.0 → pyqrackising-1.7.0}/PyQrackIsing.egg-info/SOURCES.txt +0 -0
  17. {pyqrackising-1.6.0 → pyqrackising-1.7.0}/PyQrackIsing.egg-info/dependency_links.txt +0 -0
  18. {pyqrackising-1.6.0 → pyqrackising-1.7.0}/PyQrackIsing.egg-info/not-zip-safe +0 -0
  19. {pyqrackising-1.6.0 → pyqrackising-1.7.0}/PyQrackIsing.egg-info/top_level.txt +0 -0
  20. {pyqrackising-1.6.0 → pyqrackising-1.7.0}/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.7.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
@@ -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)
@@ -85,11 +86,12 @@ def maxcut_tfim(
85
86
  # Number of measurement shots
86
87
  shots = n_qubits << quality
87
88
 
88
- J_eff = np.array([sum(-edge_attributes.get('weight', 1.0) for _, edge_attributes in G.adj[i].items()) for i in range(n_qubits)], dtype=np.float64)
89
+ J_eff = np.array([-sum(edge_attributes.get('weight', 1.0) for _, edge_attributes in G.adj[i].items()) for i in range(n_qubits)], dtype=np.float64)
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,22 +3,21 @@ 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):
19
18
  # Reconstruct Ising energy (note: MAXCUT flips sign!)
20
19
  spins = {i: 1 if theta_bits[i] else -1 for i in range(len(theta_bits))}
21
- energy = -sum(G[u][v].get("weight", 1) * spins[u] * spins[v] for u, v in G.edges())
20
+ energy = sum(G[u][v].get("weight", 1) * spins[u] * spins[v] for u, v in G.edges())
22
21
 
23
22
  return energy
24
23
 
@@ -35,7 +34,7 @@ def bootstrap_worker(args):
35
34
  return indices, energy, flipped
36
35
 
37
36
  def spin_glass_solver(G):
38
- cut_value, bitstring, cut_edges = maxcut_tfim(G, quality=6)
37
+ cut_value, bitstring, cut_edges = maxcut_tfim(G, quality=0)
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.7.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
@@ -71,6 +71,7 @@ def generate_spin_glass_graph(n_nodes=16, degree=3, seed=None):
71
71
  G = generate_spin_glass_graph(n_nodes=64, seed=42)
72
72
  cut_value, bitstring, cut_edges, min_energy = spin_glass_solver(G)
73
73
  ```
74
+ It 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.
74
75
 
75
76
  ## About
76
77
  Transverse field Ising model (TFIM) is the basis of most claimed algorithmic "quantum advantage," circa 2025, with the notable exception of Shor's integer factoring algorithm.
@@ -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.7.0"
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.7.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