PyQrackIsing 9.16.3__tar.gz → 9.16.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 (38) hide show
  1. {pyqrackising-9.16.3/pyqrackising.egg-info → pyqrackising-9.16.4}/PKG-INFO +1 -1
  2. {pyqrackising-9.16.3 → pyqrackising-9.16.4}/pyproject.toml +1 -1
  3. pyqrackising-9.16.4/pyqrackising/fermi_hubbard_validation_qiskit.py +278 -0
  4. pyqrackising-9.16.4/pyqrackising/fermi_hubbard_validation_qrack.py +207 -0
  5. {pyqrackising-9.16.3 → pyqrackising-9.16.4}/pyqrackising/generate_tfim_samples.py +1 -1
  6. {pyqrackising-9.16.3 → pyqrackising-9.16.4/pyqrackising.egg-info}/PKG-INFO +1 -1
  7. {pyqrackising-9.16.3 → pyqrackising-9.16.4}/pyqrackising.egg-info/SOURCES.txt +2 -0
  8. {pyqrackising-9.16.3 → pyqrackising-9.16.4}/setup.py +1 -1
  9. {pyqrackising-9.16.3 → pyqrackising-9.16.4}/LICENSE.md +0 -0
  10. {pyqrackising-9.16.3 → pyqrackising-9.16.4}/MANIFEST.in +0 -0
  11. {pyqrackising-9.16.3 → pyqrackising-9.16.4}/README.md +0 -0
  12. {pyqrackising-9.16.3 → pyqrackising-9.16.4}/pyqrackising/__init__.py +0 -0
  13. {pyqrackising-9.16.3 → pyqrackising-9.16.4}/pyqrackising/convert_tensor_network_to_tsp.py +0 -0
  14. {pyqrackising-9.16.3 → pyqrackising-9.16.4}/pyqrackising/kernels.cl +0 -0
  15. {pyqrackising-9.16.3 → pyqrackising-9.16.4}/pyqrackising/maxcut_tfim.py +0 -0
  16. {pyqrackising-9.16.3 → pyqrackising-9.16.4}/pyqrackising/maxcut_tfim_sparse.py +0 -0
  17. {pyqrackising-9.16.3 → pyqrackising-9.16.4}/pyqrackising/maxcut_tfim_streaming.py +0 -0
  18. {pyqrackising-9.16.3 → pyqrackising-9.16.4}/pyqrackising/maxcut_tfim_util.py +0 -0
  19. {pyqrackising-9.16.3 → pyqrackising-9.16.4}/pyqrackising/otoc.py +0 -0
  20. {pyqrackising-9.16.3 → pyqrackising-9.16.4}/pyqrackising/solve_maxcut_bnb.py +0 -0
  21. {pyqrackising-9.16.3 → pyqrackising-9.16.4}/pyqrackising/solve_maxcut_bnb_sparse.py +0 -0
  22. {pyqrackising-9.16.3 → pyqrackising-9.16.4}/pyqrackising/solve_maxcut_bnb_streaming.py +0 -0
  23. {pyqrackising-9.16.3 → pyqrackising-9.16.4}/pyqrackising/solve_maxcut_exact.py +0 -0
  24. {pyqrackising-9.16.3 → pyqrackising-9.16.4}/pyqrackising/solve_maxcut_exact_sparse.py +0 -0
  25. {pyqrackising-9.16.3 → pyqrackising-9.16.4}/pyqrackising/solve_maxcut_exact_streaming.py +0 -0
  26. {pyqrackising-9.16.3 → pyqrackising-9.16.4}/pyqrackising/spin_glass_solver.py +0 -0
  27. {pyqrackising-9.16.3 → pyqrackising-9.16.4}/pyqrackising/spin_glass_solver_hybrid.py +0 -0
  28. {pyqrackising-9.16.3 → pyqrackising-9.16.4}/pyqrackising/spin_glass_solver_sparse.py +0 -0
  29. {pyqrackising-9.16.3 → pyqrackising-9.16.4}/pyqrackising/spin_glass_solver_streaming.py +0 -0
  30. {pyqrackising-9.16.3 → pyqrackising-9.16.4}/pyqrackising/tfim_magnetization.py +0 -0
  31. {pyqrackising-9.16.3 → pyqrackising-9.16.4}/pyqrackising/tfim_square_magnetization.py +0 -0
  32. {pyqrackising-9.16.3 → pyqrackising-9.16.4}/pyqrackising/tsp.py +0 -0
  33. {pyqrackising-9.16.3 → pyqrackising-9.16.4}/pyqrackising/tsp_maxcut.py +0 -0
  34. {pyqrackising-9.16.3 → pyqrackising-9.16.4}/pyqrackising.egg-info/dependency_links.txt +0 -0
  35. {pyqrackising-9.16.3 → pyqrackising-9.16.4}/pyqrackising.egg-info/not-zip-safe +0 -0
  36. {pyqrackising-9.16.3 → pyqrackising-9.16.4}/pyqrackising.egg-info/requires.txt +0 -0
  37. {pyqrackising-9.16.3 → pyqrackising-9.16.4}/pyqrackising.egg-info/top_level.txt +0 -0
  38. {pyqrackising-9.16.3 → pyqrackising-9.16.4}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pyqrackising
3
- Version: 9.16.3
3
+ Version: 9.16.4
4
4
  Summary: Fast MAXCUT, TSP, and sampling heuristics from near-ideal transverse field Ising model (TFIM)
5
5
  Home-page: https://github.com/vm6502q/PyQrackIsing
6
6
  Author: Dan Strano
@@ -7,7 +7,7 @@ build-backend = "setuptools.build_meta"
7
7
 
8
8
  [project]
9
9
  name = "pyqrackising"
10
- version = "9.16.3"
10
+ version = "9.16.4"
11
11
  requires-python = ">=3.8"
12
12
  description = "Fast MAXCUT, TSP, and sampling heuristics from near-ideal transverse field Ising model (TFIM)"
13
13
  readme = {file = "README.txt", content-type = "text/markdown"}
@@ -0,0 +1,278 @@
1
+ import math
2
+ import os
3
+ import sys
4
+ import statistics
5
+ import time
6
+
7
+ from collections import Counter
8
+
9
+ import numpy as np
10
+
11
+ from scipy.stats import distributions as dists
12
+
13
+ import matplotlib.pyplot as plt
14
+
15
+ from qiskit import QuantumCircuit
16
+ from qiskit.circuit.library import RZZGate
17
+ from qiskit.compiler import transpile
18
+ from qiskit_aer.backends import AerSimulator
19
+ from qiskit.quantum_info import Statevector
20
+
21
+ from pyqrack import QrackSimulator
22
+ from pyqrackising import generate_fermi_hubbard_samples
23
+
24
+
25
+ def factor_width(width, is_transpose=False):
26
+ col_len = math.floor(math.sqrt(width))
27
+ while ((width // col_len) * col_len) != width:
28
+ col_len -= 1
29
+ row_len = width // col_len
30
+
31
+ return (col_len, row_len) if is_transpose else (row_len, col_len)
32
+
33
+
34
+ def index(i, j, n_cols):
35
+ return i * n_cols + j
36
+
37
+
38
+ def zz_rotation(qc, q1, q2, theta):
39
+ # Implements exp(-i theta Z⊗Z)
40
+ qc.cx(q1, q2)
41
+ qc.rz(2 * theta, q2)
42
+ qc.cx(q1, q2)
43
+
44
+ def first_order_tfim(qc, n_rows, n_cols, J, h, dt):
45
+ theta_zz = J * dt
46
+
47
+ # ---- Horizontal even bonds ----
48
+ for i in range(n_rows):
49
+ for j in range(0, n_cols - 1, 2):
50
+ q1 = index(i, j, n_cols)
51
+ q2 = index(i, j + 1, n_cols)
52
+ zz_rotation(qc, q1, q2, theta_zz)
53
+
54
+ # ---- Horizontal odd bonds ----
55
+ for i in range(n_rows):
56
+ for j in range(1, n_cols - 1, 2):
57
+ q1 = index(i, j, n_cols)
58
+ q2 = index(i, j + 1, n_cols)
59
+ zz_rotation(qc, q1, q2, theta_zz)
60
+
61
+ # ---- Vertical even bonds ----
62
+ for j in range(n_cols):
63
+ for i in range(0, n_rows - 1, 2):
64
+ q1 = index(i, j, n_cols)
65
+ q2 = index(i + 1, j, n_cols)
66
+ zz_rotation(qc, q1, q2, theta_zz)
67
+
68
+ # ---- Vertical odd bonds ----
69
+ for j in range(n_cols):
70
+ for i in range(1, n_rows - 1, 2):
71
+ q1 = index(i, j, n_cols)
72
+ q2 = index(i + 1, j, n_cols)
73
+ zz_rotation(qc, q1, q2, theta_zz)
74
+
75
+ def brick_wall_tfim_step(n_rows, n_cols, J, h, dt):
76
+ """
77
+ Single first-order Trotter step for 2D TFIM
78
+ using brick-wall decomposition.
79
+ """
80
+ n_qubits = n_rows * n_cols
81
+ qc = QuantumCircuit(n_qubits)
82
+ theta_x = h * dt
83
+
84
+ first_order_tfim(qc, n_rows, n_cols, J, h, dt / 2)
85
+
86
+ # ---- Transverse field ----
87
+ for q in range(n_qubits):
88
+ qc.rx(2 * theta_x, q)
89
+
90
+ first_order_tfim(qc, n_rows, n_cols, J, h, dt / 2)
91
+
92
+ return qc
93
+
94
+
95
+ def init_beta(n_qubits):
96
+ n_bias = n_qubits + 1
97
+ thresholds = np.empty(n_bias, dtype=np.float64)
98
+ normalizer = 0
99
+ for q in range(n_qubits >> 1):
100
+ normalizer += math.comb(n_qubits, q) << 1
101
+ if n_qubits & 1:
102
+ normalizer += math.comb(n_qubits, n_qubits >> 1)
103
+ p = 1
104
+ for q in range(n_qubits >> 1):
105
+ val = p / normalizer
106
+ thresholds[q] = val
107
+ thresholds[n_bias - (q + 1)] = val
108
+ p = math.comb(n_qubits, q + 1)
109
+ if n_qubits & 1:
110
+ thresholds[n_qubits >> 1] = p / normalizer
111
+
112
+ return thresholds
113
+
114
+
115
+ def calc_stats(ideal_probs, pqi_probs, shots):
116
+ # For QV, we compare probabilities of (ideal) "heavy outputs."
117
+ # If the probability is above 2/3, the protocol certifies/passes the qubit width.
118
+ n_pow = len(ideal_probs)
119
+ n = int(round(math.log2(n_pow)))
120
+ threshold = statistics.median(ideal_probs)
121
+ u_u = 1 / n_pow
122
+ diff_sqr = 0
123
+ noise = 0
124
+ numer = 0
125
+ denom = 0
126
+ sum_hog_prob = 0
127
+ ideal_sqr_mag = 0
128
+ exp_sqr_mag = 0
129
+ for i in range(n_pow):
130
+ exp = pqi_probs.get(i, 0)
131
+ ideal = ideal_probs[i]
132
+
133
+ # L2 distance
134
+ diff_sqr += (ideal - exp) ** 2
135
+ noise += exp * (1 - exp) / shots
136
+
137
+ # XEB / EPLG
138
+ denom += (ideal - u_u) ** 2
139
+ numer += (ideal - u_u) * (exp - u_u)
140
+
141
+ # QV / HOG
142
+ if ideal > threshold:
143
+ sum_hog_prob += exp
144
+
145
+ perm = i
146
+ m = 0
147
+ for _ in range(n):
148
+ m += -1 if (perm & 1) else 1
149
+ perm >>= 1
150
+ m /= n
151
+ m *= m
152
+ ideal_sqr_mag += ideal * m
153
+ exp_sqr_mag += exp * m
154
+
155
+ l2_diff = diff_sqr ** (1 / 2)
156
+ l2_diff_debiased = math.sqrt(max(diff_sqr - noise, 0.0))
157
+ xeb = numer / denom
158
+ if xeb > 1.0:
159
+ xeb = 2.0 - xeb
160
+ if xeb < 0.0:
161
+ xeb = 0.0
162
+
163
+ return {
164
+ "qubits": n,
165
+ "l2_difference": float(l2_diff),
166
+ "l2_difference_debiased": float(l2_diff_debiased),
167
+ "xeb_rectified": float(xeb),
168
+ "hog_prob": float(sum_hog_prob),
169
+ "ideal_sqr_mag": float(ideal_sqr_mag),
170
+ "sqr_mag_diff": float(exp_sqr_mag - ideal_sqr_mag),
171
+ }
172
+
173
+
174
+ def normalize_counts(counts, shots):
175
+ return {k: v / shots for k, v in counts.items()}
176
+
177
+
178
+ def main():
179
+ n_qubits = 6
180
+ depth = 40
181
+ z = 4
182
+
183
+ # Quantinuum settings
184
+ J, h, dt = -1.0, 2.0, 0.125
185
+ theta = math.pi / 18
186
+
187
+ # Pure ferromagnetic
188
+ # J, h, dt = -1.0, 0.0, 0.25
189
+ # theta = 0
190
+
191
+ # Pure transverse field
192
+ # J, h, dt = 0.0, 2.0, 0.25
193
+ # theta = -math.pi / 2
194
+
195
+ # Critical point (symmetry breaking)
196
+ # J, h, dt = -1.0, 1.0, 0.25
197
+ # theta = -math.pi / 4
198
+
199
+ if len(sys.argv) > 1:
200
+ n_qubits = int(sys.argv[1])
201
+ if len(sys.argv) > 2:
202
+ depth = int(sys.argv[2])
203
+ if len(sys.argv) > 3:
204
+ dt = float(sys.argv[3])
205
+ if len(sys.argv) > 4:
206
+ shots = int(sys.argv[4])
207
+ else:
208
+ shots = max(65536, 1 << (n_qubits + 2))
209
+
210
+ print(f"Qubits: {n_qubits}")
211
+
212
+ n_rows, n_cols = factor_width(n_qubits, False)
213
+ qubits = list(range(n_qubits))
214
+
215
+ # Set the initial temperature by theta.
216
+ qc_aer = QuantumCircuit(n_qubits)
217
+ for q in range(n_qubits):
218
+ qc_aer.ry(theta, q)
219
+
220
+ qc_step = brick_wall_tfim_step(n_rows, n_cols, J, h, dt)
221
+ qc_step = transpile(
222
+ qc_step,
223
+ basis_gates=QrackSimulator.get_qiskit_basis_gates(),
224
+ )
225
+
226
+ control = AerSimulator(method="statevector")
227
+
228
+ r_squared = 0.0
229
+ r_squared_db = 0.0
230
+ r_squared_xeb = 0.0
231
+ ss = 0.0
232
+ ssr = 0.0
233
+
234
+ for d in range(1, depth + 1):
235
+ t = d * dt
236
+
237
+ # Run the Trotterized simulation with Aer and get the marginal probabilities.
238
+ qc_aer = qc_aer.compose(qc_step)
239
+ qc_aer_sv = qc_aer.copy()
240
+ qc_aer_sv.save_statevector()
241
+ job = control.run(qc_aer_sv)
242
+ ideal_probs = Statevector(job.result().get_statevector()).probabilities()
243
+
244
+ # The magnetization components are weighted by (n+1) symmetric "bias" terms over possible Hamming weights.
245
+ pqi_probs = normalize_counts(dict(Counter(
246
+ generate_fermi_hubbard_samples(J=J, h=h, z=z, theta=theta, t=t, n_qubits=n_qubits, shots=shots)
247
+ )), shots)
248
+
249
+ result = calc_stats(ideal_probs, pqi_probs, shots)
250
+
251
+ # Add up the square residuals:
252
+ r_squared += result["l2_difference"] ** 2
253
+ r_squared_db += result["l2_difference_debiased"] ** 2
254
+ r_squared_xeb += (1.0 - result["xeb_rectified"]) ** 2
255
+
256
+ # Save the sum of squares and sum of square residuals on the magnetization curve values.
257
+ ss += result["ideal_sqr_mag"] ** 2
258
+ ssr += result["sqr_mag_diff"] ** 2
259
+
260
+ # R^2 and RMSE are elementary and standard measures of goodness-of-fit with simple definitions.
261
+ # Ideal marginal probability would be 1.0, each depth step. Squared and summed, that's depth.
262
+ r_squared = 1.0 - r_squared / depth
263
+ r_squared_db = 1.0 - r_squared_db / depth
264
+ r_squared_xeb = 1.0 - r_squared_xeb / depth
265
+ rmse = (ssr / depth) ** (1 / 2)
266
+ sm_r_squared = 1.0 - (ssr / ss)
267
+
268
+ print("L2 norm similarity R^2: " + str(r_squared))
269
+ print("L2 norm debiased similarity R^2: " + str(r_squared_db))
270
+ print("XEB (rectified) R^2: " + str(r_squared_xeb))
271
+ print("Square magnetization RMSE: " + str(rmse))
272
+ print("Square magnetization R^2: " + str(sm_r_squared))
273
+
274
+ return 0
275
+
276
+
277
+ if __name__ == "__main__":
278
+ sys.exit(main())
@@ -0,0 +1,207 @@
1
+ # Fermi-Hubbard / XXZ-Heisenberg validation, v2
2
+ # by Dan Strano and Claude (Anthropic)
3
+ #
4
+ # TFIM -> Fermi-Hubbard disclaimer):
5
+ # - This is a mean-field / entropy-based heuristic correction, not derived
6
+ # from the Heisenberg Hamiltonian in closed form. It was benchmarked at
7
+ # ONE parameter point (n_qubits=6, Quantinuum J/h/dt/theta defaults) and
8
+ # has not been swept across parameter space or system size.
9
+ # - Direct numerical comparison (see hamming_conservation_test.py) shows
10
+ # that RXX+RYY+RZZ terms, despite each individually commuting with total
11
+ # Hamming weight (Sz) in isolation, measurably shift BOTH the mean and
12
+ # the variance of the true Hamming-weight marginal relative to pure TFIM
13
+ # once interleaved with the transverse-field Trotter steps -- this is a
14
+ # real correction, not just added entropy/noise, and the entropy-blend
15
+ # approach here only captures it directionally, via a proxy signal, not
16
+ # from the actual mean-shift mechanism. A first-principles closed-form
17
+ # ansatz (analogous to the original TFIM derivation, this time fit
18
+ # against RZZ+RXX+RYY+RX Trotter data) is the right next step and has
19
+ # NOT been done here.
20
+
21
+ import math
22
+ import numpy as np
23
+ import statistics
24
+ import sys
25
+
26
+ from collections import Counter
27
+
28
+ from qiskit import QuantumCircuit
29
+ from qiskit.circuit.library import RZZGate, RXXGate, RYYGate
30
+ from qiskit.compiler import transpile
31
+
32
+ from pyqrack import QrackSimulator
33
+
34
+ from pyqrackising.generate_tfim_samples import generate_fermi_hubbard_samples
35
+
36
+
37
+ def factor_width(width, is_transpose=False):
38
+ col_len = math.floor(math.sqrt(width))
39
+ while ((width // col_len) * col_len) != width:
40
+ col_len -= 1
41
+ row_len = width // col_len
42
+
43
+ return (col_len, row_len) if is_transpose else (row_len, col_len)
44
+
45
+
46
+ def edge_layers(n_rows, n_cols):
47
+ horiz_even = [(r * n_cols + c, r * n_cols + (c + 1) % n_cols) for r in range(n_rows) for c in range(0, n_cols, 2)]
48
+ horiz_odd = [(r * n_cols + c, r * n_cols + (c + 1) % n_cols) for r in range(n_rows) for c in range(1, n_cols, 2)]
49
+ vert_even = [(r * n_cols + c, ((r + 1) % n_rows) * n_cols + c) for r in range(1, n_rows, 2) for c in range(n_cols)]
50
+ vert_odd = [(r * n_cols + c, ((r + 1) % n_rows) * n_cols + c) for r in range(0, n_rows, 2) for c in range(n_cols)]
51
+ return [horiz_even, horiz_odd, vert_even, vert_odd]
52
+
53
+
54
+ def trotter_step_heisenberg(circ, qubits, lattice_shape, J, h, dt, Jxy=None):
55
+ """The CORRECT ideal circuit for Fermi-Hubbard/Heisenberg validation:
56
+ RZZ + RXX + RYY (isotropic hopping+interaction) + RX (transverse field).
57
+ Jxy defaults to J (isotropic Heisenberg + field)."""
58
+ if Jxy is None:
59
+ Jxy = J
60
+ n_rows, n_cols = lattice_shape
61
+ for q in qubits:
62
+ circ.rx(h * dt, q)
63
+ for layer in edge_layers(n_rows, n_cols):
64
+ for q1, q2 in layer:
65
+ circ.append(RZZGate(2 * J * dt), [q1, q2])
66
+ circ.append(RXXGate(2 * Jxy * dt), [q1, q2])
67
+ circ.append(RYYGate(2 * Jxy * dt), [q1, q2])
68
+ for q in qubits:
69
+ circ.rx(h * dt, q)
70
+ return circ
71
+
72
+
73
+ def normalize_counts(counts, shots):
74
+ return {k: v / shots for k, v in counts.items()}
75
+
76
+
77
+ def calc_stats(ideal_probs, pqi_probs, shots):
78
+ n_pow = len(ideal_probs)
79
+ n = int(round(math.log2(n_pow)))
80
+ threshold = statistics.median(ideal_probs)
81
+ u_u = 1 / n_pow
82
+ diff_sqr = 0
83
+ noise = 0
84
+ numer = 0
85
+ denom = 0
86
+ sum_hog_prob = 0
87
+ ideal_sqr_mag = 0
88
+ exp_sqr_mag = 0
89
+ for i in range(n_pow):
90
+ exp = pqi_probs.get(i, 0)
91
+ ideal = ideal_probs[i]
92
+ diff_sqr += (ideal - exp) ** 2
93
+ noise += exp * (1 - exp) / shots
94
+ denom += (ideal - u_u) ** 2
95
+ numer += (ideal - u_u) * (exp - u_u)
96
+ if ideal > threshold:
97
+ sum_hog_prob += exp
98
+ perm = i
99
+ m = 0
100
+ for _ in range(n):
101
+ m += -1 if (perm & 1) else 1
102
+ perm >>= 1
103
+ m /= n
104
+ m *= m
105
+ ideal_sqr_mag += ideal * m
106
+ exp_sqr_mag += exp * m
107
+
108
+ l2_diff = diff_sqr ** 0.5
109
+ l2_diff_debiased = math.sqrt(max(diff_sqr - noise, 0.0))
110
+ xeb = numer / denom
111
+ if xeb > 1.0:
112
+ xeb = 2.0 - xeb
113
+ if xeb < 0.0:
114
+ xeb = 0.0
115
+
116
+ return {
117
+ "qubits": n,
118
+ "l2_difference": float(l2_diff),
119
+ "l2_difference_debiased": float(l2_diff_debiased),
120
+ "xeb_rectified": float(xeb),
121
+ "hog_prob": float(sum_hog_prob),
122
+ "ideal_sqr_mag": float(ideal_sqr_mag),
123
+ "sqr_mag_diff": float(exp_sqr_mag - ideal_sqr_mag),
124
+ }
125
+
126
+
127
+ def main():
128
+ n_qubits = 6
129
+ depth = 40
130
+ z = 4
131
+
132
+ # Quantinuum settings
133
+ J, h, dt = -1.0, 2.0, 0.125
134
+ theta = math.pi / 18
135
+
136
+ # Pure ferromagnetic
137
+ # J, h, dt = -1.0, 0.0, 0.25
138
+ # theta = 0
139
+
140
+ # Pure transverse field
141
+ # J, h, dt = 0.0, 2.0, 0.25
142
+ # theta = -math.pi / 2
143
+
144
+ # Critical point (symmetry breaking)
145
+ # J, h, dt = -1.0, 1.0, 0.25
146
+ # theta = -math.pi / 4
147
+
148
+ if len(sys.argv) > 1:
149
+ n_qubits = int(sys.argv[1])
150
+ if len(sys.argv) > 2:
151
+ depth = int(sys.argv[2])
152
+ if len(sys.argv) > 3:
153
+ dt = float(sys.argv[3])
154
+ if len(sys.argv) > 4:
155
+ shots = int(sys.argv[4])
156
+ else:
157
+ shots = 1 << (n_qubits + 2)
158
+
159
+ print(f"Qubits: {n_qubits} (ideal = RZZ+RXX+RYY+RX Heisenberg+field circuit)")
160
+
161
+ n_rows, n_cols = factor_width(n_qubits)
162
+ qubits = list(range(n_qubits))
163
+
164
+ qc = QuantumCircuit(n_qubits)
165
+ for q in range(n_qubits):
166
+ qc.ry(theta, q)
167
+ control = QrackSimulator(n_qubits)
168
+ basis_gates = QrackSimulator.get_qiskit_basis_gates()
169
+ qc = transpile(qc, basis_gates=basis_gates)
170
+ control.run_qiskit_circuit(qc)
171
+
172
+ r_squared = r_squared_db = r_squared_xeb = ss = ssr = 0.0
173
+ for d in range(1, depth + 1):
174
+ t = d * dt
175
+ step_circ = QuantumCircuit(n_qubits)
176
+ trotter_step_heisenberg(step_circ, qubits, (n_rows, n_cols), J, h, dt)
177
+ step_circ = transpile(step_circ, basis_gates=basis_gates)
178
+ control.run_qiskit_circuit(step_circ)
179
+ control_probs = control.out_probs()
180
+
181
+ pqi_probs = normalize_counts(dict(Counter(
182
+ generate_fermi_hubbard_samples(J=J, h=h, z=z, theta=theta, t=t, n_qubits=n_qubits, shots=shots)
183
+ )), shots)
184
+
185
+ result = calc_stats(control_probs, pqi_probs, shots)
186
+ r_squared += result["l2_difference"] ** 2
187
+ r_squared_db += result["l2_difference_debiased"] ** 2
188
+ r_squared_xeb += (1.0 - result["xeb_rectified"]) ** 2
189
+ ss += result["ideal_sqr_mag"] ** 2
190
+ ssr += result["sqr_mag_diff"] ** 2
191
+
192
+ r_squared = 1.0 - r_squared / depth
193
+ r_squared_db = 1.0 - r_squared_db / depth
194
+ r_squared_xeb = 1.0 - r_squared_xeb / depth
195
+ rmse = (ssr / depth) ** 0.5
196
+ sm_r_squared = 1.0 - (ssr / ss)
197
+
198
+ print("L2 norm similarity R^2: " + str(r_squared))
199
+ print("L2 norm debiased similarity R^2: " + str(r_squared_db))
200
+ print("XEB (rectified) R^2: " + str(r_squared_xeb))
201
+ print("Square magnetization RMSE: " + str(rmse))
202
+ print("Square magnetization R^2: " + str(sm_r_squared))
203
+ return 0
204
+
205
+
206
+ if __name__ == "__main__":
207
+ sys.exit(main())
@@ -257,7 +257,7 @@ def generate_tfim_samples(J=-1.0, h=2.0, z=4, theta=0.174532925199432957, t=5, n
257
257
  # "Nice" constants: omega = 4, phi = -3/2, tau = 1/3
258
258
  # These are actually a "guess" to move from FITTED to analytical closed-form beta(t)
259
259
  omega_b, phi, tau = 4.0, -1.5, (1.0 / 3.0)
260
- A_peak = 15.0
260
+ A_peak = 12.0
261
261
 
262
262
  @njit(cache=True)
263
263
  def A_of_r(J, h, z):
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pyqrackising
3
- Version: 9.16.3
3
+ Version: 9.16.4
4
4
  Summary: Fast MAXCUT, TSP, and sampling heuristics from near-ideal transverse field Ising model (TFIM)
5
5
  Home-page: https://github.com/vm6502q/PyQrackIsing
6
6
  Author: Dan Strano
@@ -5,6 +5,8 @@ pyproject.toml
5
5
  setup.py
6
6
  pyqrackising/__init__.py
7
7
  pyqrackising/convert_tensor_network_to_tsp.py
8
+ pyqrackising/fermi_hubbard_validation_qiskit.py
9
+ pyqrackising/fermi_hubbard_validation_qrack.py
8
10
  pyqrackising/generate_tfim_samples.py
9
11
  pyqrackising/kernels.cl
10
12
  pyqrackising/maxcut_tfim.py
@@ -7,7 +7,7 @@ with open(README_PATH) as readme_file:
7
7
 
8
8
  setup(
9
9
  name="pyqrackising",
10
- version="9.16.3",
10
+ version="9.16.4",
11
11
  author="Dan Strano",
12
12
  author_email="stranoj@gmail.com",
13
13
  description="Fast MAXCUT, TSP, and sampling heuristics from near-ideal transverse field Ising model (TFIM)",
File without changes
File without changes
File without changes
File without changes