1717from qiskit .quantum_info import Statevector
1818from qiskit .transpiler import CouplingMap
1919
20- from pyqrackising import get_tfim_hamming_distribution
20+ from pyqrack import QrackSimulator
2121
2222
2323# Factor the qubit width for torus dimensions that are close as possible to square
@@ -247,7 +247,7 @@ def main():
247247 if len (sys .argv ) > 4 :
248248 t1 = float (sys .argv [4 ])
249249 else :
250- t1 = dt * dt * dt
250+ t1 = dt
251251 if len (sys .argv ) > 5 :
252252 shots = int (sys .argv [5 ])
253253 else :
@@ -270,12 +270,15 @@ def main():
270270 for q in range (n_qubits ):
271271 qc .ry (theta , q )
272272
273+ experiment = QrackSimulator (n_qubits )
274+ experiment .run_qiskit_circuit (qc )
275+ qrack_probs = dict (Counter (experiment .measure_shots (qubits , shots )))
276+ for key in qrack_probs .keys ():
277+ qrack_probs [key ] /= shots
278+
273279 # The Aer circuit also starts with this initialization
274280 qc_aer = qc .copy ()
275281
276- # If we're using conventional simulation in the approximation model, collect samples over the depth series.
277- bias_0 = get_tfim_hamming_distribution (J = J , h = h , z = 4 , theta = theta , t = 0 , n_qubits = n_qubits )
278-
279282 control = AerSimulator (method = "statevector" )
280283 qc_aer = transpile (
281284 qc_aer ,
@@ -286,25 +289,23 @@ def main():
286289 job = control .run (qc_aer_sv )
287290 control_probs = Statevector (job .result ().get_statevector ()).probabilities ()
288291
289- result = calc_stats (
290- n_rows ,
291- n_cols ,
292- control_probs ,
293- bias_0 ,
294- 0
295- )
296-
297- # Add up the square residuals:
298- r_squared = result ["l2_difference" ] ** 2
299-
300292 n_bias = n_qubits + 1
301- mid = n_qubits / 2
302- bias_0 = np .zeros (n_bias , dtype = np .float64 )
293+ bias_0 = np .zeros (n_bias , dtype = float )
303294 magnetization_0 , sqr_magnetization_0 = 0 , 0
304- for key , value in enumerate (bias_0 ):
305- m = key - mid
295+ for key , value in qrack_probs .items ():
296+ m = 0
297+ h = 0
298+ for _ in range (n_qubits ):
299+ if key & 1 :
300+ h += 1
301+ m -= 1
302+ else :
303+ m += 1
304+ key >>= 1
305+ m /= n_qubits
306306 magnetization_0 += value * m
307307 sqr_magnetization_0 += value * m * m
308+ bias_0 [h ] += value
308309
309310 c_magnetization , c_sqr_magnetization = 0 , 0
310311 for p in range (1 << n_qubits ):
@@ -321,6 +322,17 @@ def main():
321322 ss = c_sqr_magnetization ** 2
322323 ssr = (c_sqr_magnetization - sqr_magnetization_0 ) ** 2
323324
325+ result = calc_stats (
326+ n_rows ,
327+ n_cols ,
328+ control_probs ,
329+ bias_0 ,
330+ 0
331+ )
332+
333+ # Add up the square residuals:
334+ r_squared = result ["l2_difference" ] ** 2
335+
324336 r_squared = 0
325337 ss = 0
326338 ssr = 0
0 commit comments