def run_ES(parameters, model:MODEL, utils): n_step = parameters['n_step'] n_protocol = 2**n_step exact_data = np.zeros((n_protocol,2), dtype=np.float64) # 15 digits precision b2_array = lambda n10 : np.array(list(np.binary_repr(n10, width=n_step)), dtype=np.int) st=time.time() # ---> measuring estimated time <--- model.update_protocol(b2_array(0)) psi = model.compute_evolved_state() model.compute_fidelity(psi_evolve=psi) model.compute_energy(psi_evolve=psi) print("Est. run time : \t %.3f s"%(0.5*n_protocol*(time.time()-st))) # ---> Starting real calculation <--- st=time.time() for p in range(n_protocol): model.update_protocol(b2_array(p)) psi = model.compute_evolved_state() exact_data[p] = (model.compute_fidelity(psi_evolve=psi), model.compute_energy(psi_evolve=psi)) outfile = utils.make_file_name(parameters,root=parameters['root']) with open(outfile,'wb') as f: pickle.dump(exact_data, f, protocol=4) print("Total run time : \t %.3f s"%(time.time()-st)) print("\n Thank you and goodbye !") f.close()
def main(): # Reading parameters from para.dat file parameters = utils.read_parameter_file() # Printing parameters for user utils.print_parameters(parameters) # Defining Hamiltonian H = HAMILTONIAN(**parameters) # Defines the model, and precomputes evolution matrices given set of states model = MODEL(H, parameters) L = 6 T = 0.1 n_step = 28 param = {'L' : L, 'T': T, 'n_step': n_step} file_name = make_file_name(param, root= "/projectnb/fheating/SGD/ES/dynamicQL/SA/ES/data/") with open(file_name, 'rb') as f: fidelities=pickle.load(f) nfid=fidelities.shape[0] fid_and_energy=np.empty((nfid,2),dtype=np.float) for i,f in zip(range(nfid),fidelity): if i%10000 == 0: print(i) model.update_protocol(b2_array(i, w = 28)) psi = model.compute_evolved_state() fid_and_energy[i][0]=model.compute_fidelity(psi_evolve = psi) fid_and_energy[i][1]=model.compute_energy(psi_evolve = psi) print(fid_and_energy[0],'\t',f) break with open("ES_L-06_T-0.500_n_step-28-test.pkl", ‘wb’) as f: fidelities=pickle.dump(fid_and_energy,f, protocol=4)