parmsi['t'+str(i)+'[Time]'] = ','.join([mathematica(J[i]) for J in Jt]) # parmsi['t'+str(i)+'[Time]'] = ','.join([mathematica(JW(W)[i]) for W in ramp(W_i, W_f, xi, tau, dt)]) for i in range(L): parmsi['U'+str(i)+'[Time]'] = ','.join([mathematica(U[i]) for U in Ut]) # parmsi['U'+str(i)+'[Time]'] = ','.join([mathematica(UW(W)[i]) for W in ramp(W_i, W_f, xi, tau, dt)]) parmslist.append(parmsi) input_file = pyalps.writeInputFiles(basename+'.dynamic',parmslist) res = pyalps.runApplication('mps_evolve',input_file,writexml=True) end = datetime.datetime.now() ## simulation results # data = pyalps.loadIterationMeasurements(pyalps.getResultFiles(prefix=basename+'.dynamic'), what=['Overlap', 'Local density', 'Local density squared', 'One body density matrix', 'Density density']) data = pyalps.loadIterationMeasurements(pyalps.getResultFiles(prefix=basename+'.dynamic'), what=['Overlap', 'Energy']) coords = [] for d1 in data: for s1 in d1: for d in s1: for s in d: if(s.props['observable'] == 'One body density matrix'): coords = (s.x[:,0], s.x[:,1]) XY = pyalps.collectXY(data, x='Time', y='Overlap', foreach=['tau']) p = [[[(x + 1)*dt, 1-abs(y**2)] for (x, y) in zip(xy.x, xy.y)] for xy in XY] XY = pyalps.collectXY(data, x='Time', y='Energy', foreach=['tau']) E = [[[(x + 1)*dt, y] for (x, y) in zip(xy.x, xy.y)] for xy in XY]
p['TIMESTEPS'] = nsteps p['tau'] = tau # not used in the simulation, but useful in the evaluation below p['Jz'] = z p['ALWAYS_MEASURE'] = 'Local Magnetization' p['chkp_each'] = nsteps p['measure_each'] = 5 p['COMPLEX'] = 1 parms.append(p) ## write input files and run application input_file = pyalps.writeInputFiles(basename, parms) res = pyalps.runApplication('mps_evolve', input_file) ## simulation results data = pyalps.loadIterationMeasurements(pyalps.getResultFiles(prefix=basename), what=['Local Magnetization']) for q in pyalps.flatten(data): L = q.props['L'] #Compute the integrated flow of magnetization through the center \Delta M=\sum_{n>L/2}^{L} (<S_n^z(t)>+1/2) #\Delta M= L/4 loc = 0.5 * (L / 2) #\Delta M-=<S_n^z(t)> from n=L/2 to L q.y = np.array([0.5 * (L / 2) - sum(q.y[0][L / 2:L])]) #Plot the Error in the magnetization one site to the right of the chain center Mag = pyalps.collectXY(data, x='Time', y='Local Magnetization', foreach=['Jz']) for d in Mag: d.x = (d.x + 1) * d.props['DT'] plt.figure()
# parmsi['TIMESTEPS'] = int(2*tau / dt) # for i in range(L-1): # parmsi['t'+str(i)+'[Time]'] = ','.join([mathematica(JW(W)[i]) for W in quench(W_i, W_f, xi, 2*tau, dt)]) # for i in range(L): # parmsi['U'+str(i)+'[Time]'] = ','.join([mathematica(UW(W)[i]) for W in quench(W_i, W_f, xi, 2*tau, dt)]) # parmslist.append(parmsi) input_file = pyalps.writeInputFiles(basename + ".dynamic", parmslist) res = pyalps.runApplication("mps_evolve", input_file, writexml=True) end = datetime.datetime.now() ## simulation results data = pyalps.loadIterationMeasurements( pyalps.getResultFiles(prefix=basename + ".dynamic"), what=["Energy", "Local density", "Local density squared", "One body density matrix", "Density density"], ) coords = [] for d1 in data: for s1 in d1: for d in s1: for s in d: if s.props["observable"] == "One body density matrix": coords = (s.x[:, 0], s.x[:, 1]) XY = pyalps.collectXY(data, x="Time", y="Energy", foreach=["tau"]) E = [[[(x + 1) * dt, y] for (x, y) in zip(xy.x, xy.y)] for xy in XY][0] # XY = pyalps.collectXY(data, x='Time', y='Overlap', foreach=['tau']) # p = [[[(x + 1)*dt, 1-abs(y**2)] for (x, y) in zip(xy.x, xy.y)] for xy in XY]
parms['t'+str(i)+'[Time]'] = ','.join([mathematica(JW(W)[i]) for W in quench(W_i, W_f, xi, tf, dt)]) for i in range(L): parms['U'+str(i)+'[Time]'] = ','.join([mathematica(UW(W)[i]) for W in quench(W_i, W_f, xi, tf, dt)]) parmslist = [parms] # print mathematica([JW(W)[0] for W in quench(W_i, W_f, xi, tf, dt)]) # print mathematica([UW(W)[0] for W in quench(W_i, W_f, xi, tf, dt)]) # quit() input_file = pyalps.writeInputFiles(basename+'.dynamic',parmslist) res = pyalps.runApplication('mps_evolve',input_file,writexml=True) end = datetime.datetime.now() ## simulation results data = pyalps.loadIterationMeasurements(pyalps.getResultFiles(prefix=basename+'.dynamic'), what=['Energy', 'Local density', 'Local density squared', 'One body density matrix', 'Density density']) coords = [] for d1 in data: for s1 in d1: for d in s1: for s in d: if(s.props['observable'] == 'One body density matrix'): coords = (s.x[:,0], s.x[:,1]) XY = pyalps.collectXY(data, x='Time', y='Energy', foreach=['tau']) E = [[[(x + 1)*dt, y] for (x, y) in zip(xy.x, xy.y)] for xy in XY][0] XY = pyalps.collectXY(data, x='Time', y='Local density', foreach=['tau']) n = [[[(x + 1)*dt, y] for (x, y) in zip(xy.x, xy.y)] for xy in XY][0]
#write the input file and run the simulation input_file = pyalps.writeInputFiles('parm_spin_one', parms) res = pyalps.runApplication('mps_optim', input_file, writexml=True) #load all measurements for all states data = pyalps.loadEigenstateMeasurements( pyalps.getResultFiles(prefix='parm_spin_one')) # print properties of the eigenvector: for s in data[0]: print(s.props['observable'], ' : ', s.y[0]) # load and plot iteration history iterations = pyalps.loadIterationMeasurements( pyalps.getResultFiles(prefix='parm_spin_one'), what=['Energy', 'TruncatedWeight']) energy_iteration = pyalps.collectXY(pyalps.flatten(iterations), 'iteration', 'Energy') for d in energy_iteration: d.x = range(0, len(d.y)) truncation_iteration = pyalps.collectXY(pyalps.flatten(iterations), 'iteration', 'TruncatedWeight') for d in truncation_iteration: d.x = range(0, len(d.y)) plt.figure() pyalps.plot.plot(energy_iteration) plt.title('Iteration history of ground state energy (S=1)') plt.ylabel('$E_0$') plt.xlabel('iteration')
pass basename = 'SingleSite/ss.' parms['N_total'] = 14 # parms['initial_local_N'] = '3,2,2,2,2,2,2,2,2,2'#'1,1,1,1,1,1,1,1,0,0'#'2,2,1,1,1,1,1,1,1,1' input_file = pyalps.writeInputFiles(basename + str(resi), [parms]) pyalps.runApplication('mps_optim', input_file, writexml=True) #load all measurements for all states data = pyalps.loadEigenstateMeasurements(pyalps.getResultFiles(prefix=basename)) for d in data: for s in d: if(s.props['observable'] == 'Energy'): print s.y[0] if(s.props['observable'] == 'Local density'): print s.y[0] iters = pyalps.loadIterationMeasurements(pyalps.getResultFiles(prefix=basename), what=['Energy']) # print iters en_vs_iter = pyalps.collectXY(iters, x='iteration', y='Energy') # print en_vs_iter Es = np.array([Ei for (i, Ei) in sorted(zip([int(xi) for xi in en_vs_iter[0].x[0:-1:20]], en_vs_iter[0].y[0:-1:20]))[-40:-1]]) Es2 = Es[1:-1] - Es[0:-2] print Es2 plt.figure() # pyalps.plot.plot(en_vs_iter) plt.plot(Es) # plt.yscale('log') plt.show()
p['MEASURE_OVERLAP[Overlap]'] = initstate p['ALWAYS_MEASURE'] = 'Overlap' p['chkp_each'] = ns p['measure_each'] = 10 p['update_each'] = 1 p['COMPLEX'] = 1 parms.append(p) ## write input files and run application input_file = pyalps.writeInputFiles(basename + '.dynamic', parms) res = pyalps.runApplication('mps_evolve', input_file) ## simulation results data = pyalps.loadIterationMeasurements(pyalps.getResultFiles(prefix=basename + '.dynamic'), what=['Overlap']) LE = pyalps.collectXY(data, x='Time', y='Overlap', foreach=['tau']) for d in pyalps.flatten(LE): d.x = (d.x + 1.) * d.props['dt'] # convert time index to real time d.y = abs( d.y)**2 # Loschmidt Echo defined as the module squared of the overlap d.props['label'] = r'$\tau={0}$'.format(d.props['tau']) plt.figure() pyalps.plot.plot(LE) plt.xlabel('Time $t$') plt.ylabel('Loschmidt Echo $|< \psi(0)|\psi(t) > |^2$') plt.title('Loschmidt Echo vs. Time') plt.legend(loc='lower right')