PyQrackIsing 1.10.2__tar.gz → 1.10.4__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.10.2/PyQrackIsing.egg-info → pyqrackising-1.10.4}/PKG-INFO +1 -1
  2. {pyqrackising-1.10.2 → pyqrackising-1.10.4}/PyQrackIsing/_pyqrack_ising.cpp +9 -6
  3. {pyqrackising-1.10.2 → pyqrackising-1.10.4}/PyQrackIsing/maxcut_tfim.py +7 -3
  4. {pyqrackising-1.10.2 → pyqrackising-1.10.4}/PyQrackIsing/spin_glass_solver.py +8 -4
  5. {pyqrackising-1.10.2 → pyqrackising-1.10.4/PyQrackIsing.egg-info}/PKG-INFO +1 -1
  6. {pyqrackising-1.10.2 → pyqrackising-1.10.4}/pyproject.toml +1 -1
  7. {pyqrackising-1.10.2 → pyqrackising-1.10.4}/setup.py +1 -1
  8. {pyqrackising-1.10.2 → pyqrackising-1.10.4}/CMakeLists.txt +0 -0
  9. {pyqrackising-1.10.2 → pyqrackising-1.10.4}/LICENSE.md +0 -0
  10. {pyqrackising-1.10.2 → pyqrackising-1.10.4}/MANIFEST.in +0 -0
  11. {pyqrackising-1.10.2 → pyqrackising-1.10.4}/PyQrackIsing/__init__.py +0 -0
  12. {pyqrackising-1.10.2 → pyqrackising-1.10.4}/PyQrackIsing/generate_tfim_samples.py +0 -0
  13. {pyqrackising-1.10.2 → pyqrackising-1.10.4}/PyQrackIsing/tfim_magnetization.py +0 -0
  14. {pyqrackising-1.10.2 → pyqrackising-1.10.4}/PyQrackIsing/tfim_square_magnetization.py +0 -0
  15. {pyqrackising-1.10.2 → pyqrackising-1.10.4}/PyQrackIsing/tsp_symmetric.py +0 -0
  16. {pyqrackising-1.10.2 → pyqrackising-1.10.4}/PyQrackIsing.egg-info/SOURCES.txt +0 -0
  17. {pyqrackising-1.10.2 → pyqrackising-1.10.4}/PyQrackIsing.egg-info/dependency_links.txt +0 -0
  18. {pyqrackising-1.10.2 → pyqrackising-1.10.4}/PyQrackIsing.egg-info/not-zip-safe +0 -0
  19. {pyqrackising-1.10.2 → pyqrackising-1.10.4}/PyQrackIsing.egg-info/top_level.txt +0 -0
  20. {pyqrackising-1.10.2 → pyqrackising-1.10.4}/README.md +0 -0
  21. {pyqrackising-1.10.2 → pyqrackising-1.10.4}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: PyQrackIsing
3
- Version: 1.10.2
3
+ Version: 1.10.4
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
@@ -73,18 +73,21 @@ static inline std::string int_to_bitstring(BigInteger integer, size_t length) {
73
73
  return s;
74
74
  }
75
75
 
76
- std::vector<double> maxcut_hamming_cdf(std::vector<double> J_func, std::vector<double> degrees, int mult_log2) {
77
- size_t n_qubits = J_func.size();
78
- const int n_steps = n_qubits << mult_log2;
79
- const int shots = n_qubits << mult_log2;
76
+ std::vector<double> maxcut_hamming_cdf(size_t n_qubits, std::vector<double> J_func, std::vector<double> degrees, int mult_log2) {
77
+ if (!n_qubits) {
78
+ return std::vector<double>();
79
+ }
80
+
81
+ const size_t n_steps = n_qubits << mult_log2;
82
+ const size_t shots = n_qubits << mult_log2;
80
83
  const double delta_t = 1.0 / (n_steps << (mult_log2 >> 1));
81
84
  const double h_mult = (1 << (mult_log2 >> 1)) / (n_steps * delta_t);
82
85
  std::vector<double> hamming_prob(n_qubits - 1U, 0.0);
83
86
 
84
- for (int step = 0; step < n_steps; ++step) {
87
+ for (size_t step = 0; step < n_steps; ++step) {
85
88
  double t = step * delta_t;
86
89
  double tm1 = (step - 1) * delta_t;
87
- for (int q = 0; q < n_qubits; ++q) {
90
+ for (size_t q = 0; q < n_qubits; ++q) {
88
91
  const double& z = degrees[q];
89
92
  const double J_eff = J_func[q];
90
93
  const double h_t = h_mult * t;
@@ -86,13 +86,16 @@ def maxcut_tfim(
86
86
  nodes = list(G.nodes())
87
87
  n_qubits = len(nodes)
88
88
 
89
+ if n_qubits == 0:
90
+ return '', 0, ([], [])
91
+
89
92
  if shots is None:
90
93
  # Number of measurement shots
91
94
  shots = n_qubits << quality
92
95
 
93
96
  J_eff = np.array([-sum(edge_attributes.get('weight', 1.0) for _, edge_attributes in G.adj[n].items()) for n in nodes], dtype=np.float64)
94
97
  degrees = np.array([sum(abs(edge_attributes.get('weight', 1.0)) for _, edge_attributes in G.adj[n].items()) for n in nodes], dtype=np.float64)
95
- thresholds = tfim_sampler._maxcut_hamming_cdf(J_eff, degrees, quality)
98
+ thresholds = tfim_sampler._maxcut_hamming_cdf(n_qubits, J_eff, degrees, quality)
96
99
  G_dict = nx.to_dict_of_lists(G)
97
100
  J_max = max(J_eff)
98
101
  weights = 1.0 / (1.0 + (J_max - J_eff))
@@ -119,7 +122,8 @@ def maxcut_tfim(
119
122
 
120
123
  best_solution, best_value = evaluate_cut_edges(samples, edge_keys, edge_values)
121
124
 
122
- bit_list = list(int_to_bitstring(best_solution, n_qubits))
125
+ bit_string = int_to_bitstring(best_solution, n_qubits)
126
+ bit_list = list(bit_string)
123
127
  l, r = [], []
124
128
  for i in range(len(bit_list)):
125
129
  b = (bit_list[i] == '1')
@@ -128,4 +132,4 @@ def maxcut_tfim(
128
132
  else:
129
133
  l.append(nodes[i])
130
134
 
131
- return bit_list, best_value, (l, r)
135
+ return bit_string, best_value, (l, r)
@@ -56,7 +56,13 @@ def int_to_bitstring(integer, length):
56
56
  return (bin(integer)[2:].zfill(length))[::-1]
57
57
 
58
58
 
59
- def spin_glass_solver(G, quality=2, best_guess=None):
59
+ def spin_glass_solver(G, quality=1, best_guess=None):
60
+ nodes = list(G.nodes())
61
+ n_qubits = len(nodes)
62
+
63
+ if n_qubits == 0:
64
+ return '', 0, ([], [])
65
+
60
66
  bitstring = ''
61
67
  if isinstance(best_guess, str):
62
68
  bitstring = best_guess
@@ -65,10 +71,8 @@ def spin_glass_solver(G, quality=2, best_guess=None):
65
71
  elif isinstance(best_guess, list):
66
72
  bitstring = "".join(["1" if b else "0" for b in best_guess])
67
73
  else:
68
- bitstring, _, _ = maxcut_tfim(G, quality=0)
74
+ bitstring, _, _ = maxcut_tfim(G, quality=max(0, quality - 1))
69
75
  best_theta = [ b == '1' for b in list(bitstring)]
70
- nodes = list(G.nodes())
71
- n_qubits = len(nodes)
72
76
 
73
77
  edge_keys = []
74
78
  edge_values = []
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: PyQrackIsing
3
- Version: 1.10.2
3
+ Version: 1.10.4
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
@@ -11,7 +11,7 @@ build-backend = "setuptools.build_meta"
11
11
 
12
12
  [project]
13
13
  name = "PyQrackIsing"
14
- version = "1.10.2"
14
+ version = "1.10.4"
15
15
  requires-python = ">=3.8"
16
16
  description = "Near-ideal closed-form solutions for transverse field Ising model (TFIM)"
17
17
  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.10.2',
54
+ version='1.10.4',
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
File without changes