PyQrackIsing 1.7.0__tar.gz → 1.8.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.7.0/PyQrackIsing.egg-info → pyqrackising-1.8.0}/PKG-INFO +1 -1
  2. {pyqrackising-1.7.0 → pyqrackising-1.8.0}/PyQrackIsing/spin_glass_solver.py +29 -35
  3. {pyqrackising-1.7.0 → pyqrackising-1.8.0/PyQrackIsing.egg-info}/PKG-INFO +1 -1
  4. {pyqrackising-1.7.0 → pyqrackising-1.8.0}/README.md +3 -3
  5. {pyqrackising-1.7.0 → pyqrackising-1.8.0}/pyproject.toml +1 -1
  6. {pyqrackising-1.7.0 → pyqrackising-1.8.0}/setup.py +1 -1
  7. {pyqrackising-1.7.0 → pyqrackising-1.8.0}/CMakeLists.txt +0 -0
  8. {pyqrackising-1.7.0 → pyqrackising-1.8.0}/LICENSE.md +0 -0
  9. {pyqrackising-1.7.0 → pyqrackising-1.8.0}/MANIFEST.in +0 -0
  10. {pyqrackising-1.7.0 → pyqrackising-1.8.0}/PyQrackIsing/__init__.py +0 -0
  11. {pyqrackising-1.7.0 → pyqrackising-1.8.0}/PyQrackIsing/_pyqrack_ising.cpp +0 -0
  12. {pyqrackising-1.7.0 → pyqrackising-1.8.0}/PyQrackIsing/generate_tfim_samples.py +0 -0
  13. {pyqrackising-1.7.0 → pyqrackising-1.8.0}/PyQrackIsing/maxcut_tfim.py +0 -0
  14. {pyqrackising-1.7.0 → pyqrackising-1.8.0}/PyQrackIsing/tfim_magnetization.py +0 -0
  15. {pyqrackising-1.7.0 → pyqrackising-1.8.0}/PyQrackIsing/tfim_square_magnetization.py +0 -0
  16. {pyqrackising-1.7.0 → pyqrackising-1.8.0}/PyQrackIsing.egg-info/SOURCES.txt +0 -0
  17. {pyqrackising-1.7.0 → pyqrackising-1.8.0}/PyQrackIsing.egg-info/dependency_links.txt +0 -0
  18. {pyqrackising-1.7.0 → pyqrackising-1.8.0}/PyQrackIsing.egg-info/not-zip-safe +0 -0
  19. {pyqrackising-1.7.0 → pyqrackising-1.8.0}/PyQrackIsing.egg-info/top_level.txt +0 -0
  20. {pyqrackising-1.7.0 → pyqrackising-1.8.0}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: PyQrackIsing
3
- Version: 1.7.0
3
+ Version: 1.8.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
@@ -1,4 +1,5 @@
1
1
  from .maxcut_tfim import maxcut_tfim
2
+ import itertools
2
3
  import multiprocessing
3
4
  import os
4
5
 
@@ -21,6 +22,7 @@ def compute_energy(theta_bits, G):
21
22
 
22
23
  return energy
23
24
 
25
+
24
26
  # Parallelization by Elara (OpenAI custom GPT):
25
27
  def bootstrap_worker(args):
26
28
  theta, G, indices = args
@@ -33,24 +35,39 @@ def bootstrap_worker(args):
33
35
 
34
36
  return indices, energy, flipped
35
37
 
36
- def spin_glass_solver(G):
37
- cut_value, bitstring, cut_edges = maxcut_tfim(G, quality=0)
38
+
39
+ # By Gemini (Google Search AI)
40
+ def int_to_bitstring(integer, length):
41
+ return (bin(integer)[2:].zfill(length))[::-1]
42
+
43
+
44
+ def spin_glass_solver(G, quality=2, best_guess=None):
45
+ bitstring = ''
46
+ if isinstance(best_guess, str):
47
+ bitstring = best_guess
48
+ elif isinstance(best_guess, int):
49
+ bitstring = int_to_bitstring(best_guess)
50
+ elif isinstance(best_guess, list):
51
+ bitstring = "".join(["1" if b else "0" for b in best_guess])
52
+ else:
53
+ cut_value, bitstring, cut_edges = maxcut_tfim(G, quality=0)
38
54
  best_theta = [ b == '1' for b in list(bitstring)]
39
- min_energy = compute_energy(best_theta, G)
40
55
  n_qubits = len(best_theta)
41
- iter_count = 0
56
+ min_energy = compute_energy(best_theta, G)
42
57
  improved = True
43
58
  while improved:
44
59
  improved = False
45
- improved_1qb = True
46
- while improved_1qb:
47
- improved_1qb = False
60
+ for k in range(1, quality + 1):
61
+ if n_qubits < k:
62
+ break
63
+
48
64
  theta = best_theta.copy()
65
+ args = []
66
+
67
+ for combo in itertools.combinations(range(n_qubits), k):
68
+ args.append((theta, G, combo))
49
69
 
50
70
  with multiprocessing.Pool(processes=os.cpu_count()) as pool:
51
- args = []
52
- for i in range(n_qubits):
53
- args.append((theta, G, (i,)))
54
71
  results = pool.map(bootstrap_worker, args)
55
72
 
56
73
  results.sort(key=lambda r: r[1])
@@ -59,31 +76,8 @@ def spin_glass_solver(G):
59
76
  min_energy = energy
60
77
  for i in range(len(indices)):
61
78
  best_theta[indices[i]] = flipped[i]
62
- improved_1qb = True
63
-
64
- iter_count += 1
65
-
66
- if n_qubits < 2:
67
- break
68
-
69
- theta = best_theta.copy()
70
-
71
- with multiprocessing.Pool(processes=os.cpu_count()) as pool:
72
- args = []
73
- for i in range(n_qubits):
74
- for j in range(i + 1, n_qubits):
75
- args.append((theta, G, (i, j)))
76
- results = pool.map(bootstrap_worker, args)
77
-
78
- results.sort(key=lambda r: r[1])
79
- indices, energy, flipped = results[0]
80
- if energy < min_energy:
81
- min_energy = energy
82
- for i in range(len(indices)):
83
- best_theta[indices[i]] = flipped[i]
84
- improved = True
85
-
86
- iter_count += 1
79
+ improved = True
80
+ break
87
81
 
88
82
  sample = 0
89
83
  bitstring = ""
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: PyQrackIsing
3
- Version: 1.7.0
3
+ Version: 1.8.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
@@ -68,10 +68,10 @@ def generate_spin_glass_graph(n_nodes=16, degree=3, seed=None):
68
68
  return G
69
69
 
70
70
 
71
- G = generate_spin_glass_graph(n_nodes=64, seed=42)
72
- cut_value, bitstring, cut_edges, min_energy = spin_glass_solver(G)
71
+ G = generate_spin_glass_graph(n_nodes=64, seed=42, best_guess=None)
72
+ cut_value, bitstring, cut_edges, min_energy = spin_glass_solver(G, quality=2)
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
+ The `quality` setting default is `2`, and overhead grows roughly like the qubit count to the power of `quality` (so `O(n ** 2)` for default). `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). 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.
75
75
 
76
76
  ## About
77
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.7.0"
13
+ version = "1.8.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.7.0',
54
+ version='1.8.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