def save(self, filename): pyalps.save_parameters(filename, {'L':self.L, 'BETA':self.beta, 'SWEEPS':self.n, 'THERMALIZATION':self.ntherm}) self.abs_magnetization.save(filename) self.energy.save(filename) self.magnetization.save(filename) self.magnetization_2.save(filename) self.magnetization_4.save(filename)
print "Potential Energy = " + str(pot) + " +/- " + str(pot_error) + "\tCorrelation time: " + str(pot_tau) print "Kinetic Energy = " + str(kin) + " +/- " + str(kin_error) + "\tCorrelation time: " + str(kin_tau) if HAVE_ALPS: print '+++ ALPS binning analysis:' print "Potential Energy = " + str(pot_obs.mean) + " +/- " + str(pot_obs.error) + "\tCorrelation time: " + str(pot_obs.tau) print "Kinetic Energy = " + str(kin_obs.mean) + " +/- " + str(kin_obs.error) + "\tCorrelation time: " + str(kin_obs.tau) # The following error estimate ignores cross-correlations between T and V. # Do you have an idea how to fix that? print "Total Energy = " + str(pot+kin) + " +/- " + str(pot_error+kin_error) print 'Exact result E = ' + str(.5*w/np.tanh(.5*w*beta)) # Write results to HDF5 file conforming to the ALPS HDF5 scheme # cf. https://alps.comp-phys.org/mediawiki/index.php/Documentation:The_HDF5_scheme_documentation if HAVE_ALPS: resultfile = 'pyresults.h5' pyalps.save_parameters(resultfile,{'THERMALIZATION':thermal_steps, 'SWEEPS':steps, 'T':1./beta, 'M':M}) pot_obs.save('pyresults.h5') kin_obs.save('pyresults.h5') # Plot raw samples plt.figure() plt.title('Energy samples') plt.xlabel('MC step') plt.ylabel('potential energy') plt.scatter(range(steps),potential_energy,label='$V_i$') plt.plot([0,steps-1],[pot,pot],label='$\\bar{V}$') #plt.scatter(range(steps),kinetic_energy,label='$T_i$') #plt.plot([0,steps-1],[kin,kin],label='$\\bar{T}$') plt.legend() # Plot running mean