PyQrackIsing 1.5.0__tar.gz → 1.5.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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: PyQrackIsing
3
- Version: 1.5.0
3
+ Version: 1.5.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
@@ -73,33 +73,38 @@ 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(py::array_t<double, py::array::c_style | py::array::forcecast> _degrees, int mult_log2) {
77
- auto buf = _degrees.request();
78
- size_t n_qubits = buf.shape[0];
79
- double* degrees = static_cast<double*>(buf.ptr);
76
+ std::vector<double> maxcut_hamming_cdf(
77
+ py::array_t<double, py::array::c_style | py::array::forcecast> _J_func,
78
+ py::array_t<double, py::array::c_style | py::array::forcecast> _degrees,
79
+ int mult_log2
80
+ ) {
81
+ auto bufj = _J_func.request();
82
+ size_t n_qubits = bufj.shape[0];
83
+ double* J_func = static_cast<double*>(bufj.ptr);
84
+ double* degrees = static_cast<double*>(_degrees.request().ptr);
80
85
  const int n_steps = n_qubits << mult_log2;
81
86
  const int shots = n_qubits << mult_log2;
82
87
  const double delta_t = 1.0 / (n_steps << (mult_log2 >> 1));
83
88
  const double h_mult = (1 << (mult_log2 >> 1)) / (n_steps * delta_t);
84
- std::vector<double> hamming_prob(n_qubits - 1, 0.0);
89
+ std::vector<double> hamming_prob(n_qubits - 1U, 0.0);
85
90
 
86
91
  for (int step = 0; step < n_steps; ++step) {
87
92
  double t = step * delta_t;
88
93
  double tm1 = (step - 1) * delta_t;
89
94
  for (int q = 0; q < n_qubits; ++q) {
90
95
  const double& z = degrees[q];
91
- const double J_eff = -z;
96
+ const double J_eff = J_func[q];
92
97
  const double h_t = h_mult * t;
93
98
  auto bias = probability_by_hamming_weight(J_eff, h_t, z, 0.0, t, n_qubits);
94
99
  if (step == 0) {
95
100
  for (size_t i = 0U; i < hamming_prob.size(); ++i) {
96
- hamming_prob[i] += bias[i + 1];
101
+ hamming_prob[i] += bias[i + 1U];
97
102
  }
98
103
  continue;
99
104
  }
100
105
  auto last_bias = probability_by_hamming_weight(J_eff, h_t, z, 0.0, tm1, n_qubits);
101
106
  for (size_t i = 0U; i < hamming_prob.size(); ++i) {
102
- hamming_prob[i] += bias[i + 1] - last_bias[i + 1];
107
+ hamming_prob[i] += bias[i + 1U] - last_bias[i + 1U];
103
108
  }
104
109
  }
105
110
  }
@@ -1,6 +1,7 @@
1
1
  import networkx as nx
2
2
  import numpy as np
3
3
  import tfim_sampler
4
+ from numba import njit
4
5
 
5
6
 
6
7
  # Written by Elara (OpenAI custom GPT)
@@ -49,6 +50,7 @@ def local_repulsion_choice(adjacency, degrees, weights, n, m):
49
50
  return mask
50
51
 
51
52
 
53
+ @njit
52
54
  def evaluate_cut_edges(samples, flat_edges):
53
55
  best_value = -1
54
56
  best_solution = None
@@ -76,7 +78,7 @@ def int_to_bitstring(integer, length):
76
78
 
77
79
  def maxcut_tfim(
78
80
  G,
79
- quality = 10,
81
+ quality = 12,
80
82
  shots = None,
81
83
  ):
82
84
  # Number of qubits/nodes
@@ -85,8 +87,9 @@ def maxcut_tfim(
85
87
  # Number of measurement shots
86
88
  shots = n_qubits << quality
87
89
 
88
- degrees = np.array([sum(abs(edge_attributes.get('weight', 1.0)) for neighbor, edge_attributes in G.adj[i].items()) for i in range(n_qubits)], dtype=np.float64)
89
- thresholds = tfim_sampler._maxcut_hamming_cdf(degrees, quality)
90
+ 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)
91
+ 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)
92
+ thresholds = tfim_sampler._maxcut_hamming_cdf(J_eff, degrees, quality)
90
93
  G_dict = nx.to_dict_of_lists(G)
91
94
  weights = 1.0 / (degrees + 1.0)
92
95
  samples = []
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: PyQrackIsing
3
- Version: 1.5.0
3
+ Version: 1.5.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
@@ -5,12 +5,13 @@ requires = [
5
5
  "setuptools",
6
6
  "networkx",
7
7
  "numpy",
8
+ "numba",
8
9
  ]
9
10
  build-backend = "setuptools.build_meta"
10
11
 
11
12
  [project]
12
13
  name = "PyQrackIsing"
13
- version = "1.5.0"
14
+ version = "1.5.2"
14
15
  requires-python = ">=3.8"
15
16
  description = "Near-ideal closed-form solutions for transverse field Ising model (TFIM)"
16
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.5.0',
54
+ version='1.5.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
File without changes