Commit b069f5e2 by Jefferson Stafusa E. Portela

 %% Cell type:markdown id: tags: # ALF Tutorial 2.0 ## Introductory examples and exercises %% Cell type:markdown id: tags: This notebook is part of the [Tutorial 2.0](https://git.physik.uni-wuerzburg.de/ALF/ALF_Tutorial) for the quantum Monte Carlo simulation package [*Algorithms for Lattice Fermions* - ALF](https://git.physik.uni-wuerzburg.de/ALF/ALF_code), and can be found, together with its required files, in the [pyALF repository](https://git.physik.uni-wuerzburg.de/ALF/pyALF). ALF is compiled from source, which is downloaded from the [ALF repository](https://git.physik.uni-wuerzburg.de:ALF) when not found locally. [**REMEMBER TO UPDATE GIT ADDRESSES**] %% Cell type:markdown id: tags: # Trotter systematic error - Hubbard on the square lattice %% Cell type:markdown id: tags: In this example we run the code with the Mz choice of Hubbard-Stratonovitch transformation (i.e., coupled to the z-component of the spin) on a 6x6 site square lattice, at $U/t=4$ half-band filling, and inverse temperature $\beta t = 5$. We carry out a systematic $\Delta \tau t$ extrapolation keeping $\Delta \tau t L_\text{Trotter} = 2$ constant. Recall that the formulation of the auxiliary field QMC approach is based on the Trotter decomposition $$e^{-\Delta \tau \left( A + B \right ) } = e^{-\Delta \tau A } e^{-\Delta \tau B } + {\cal O} \left( \Delta \tau^2 \right)$$ The overall error produced by this approximation is of the order $\Delta \tau^2$. Bellow we go through the steps for performing this extrapolation: setting the simulation parameters, running it and analysing the data. A reference plot for this analyses is found in [ALF documentation](https://git.physik.uni-wuerzburg.de/ALF/ALF_code/-/blob/master/Documentation/ALF_v1.0.pdf), 2.3.2 Symmetric Trotter decomposition. --- 1. Import Simulation class from the py_alf python module, which provides the interface with ALF, as well as mathematics and plotting packages: %% Cell type:code id: tags:  python from py_alf import Simulation # Interface with ALF # import numpy as np # Numerical library from scipy.optimize import curve_fit # Numerical library import matplotlib.pyplot as plt # Plotting library  %% Cell type:markdown id: tags: 2. Create instances of Simulation, specifying the necessary parameters, in particular the different $\Delta \tau$ values: %% Cell type:code id: tags:  python sims = [] # Vector of Simulation instances print('dtau values used:') for dtau in [0.05, 0.1, 0.15]: # Values of dtau print(dtau) sim = Simulation( 'Hubbard', # Hamiltonian { # Model and simulation parameters for each Simulation instance 'Model': 'Hubbard', # Base model 'Lattice_type': 'Square', # Lattice type 'L1': 6, # Lattice length in the first unit vector direction 'L2': 6, # Lattice length in the second unit vector direction 'Checkerboard': False, # Whether checkerboard decomposition is used or not 'Symm': True, # Whether symmetrization takes place 'ham_T': 1.0, # Hopping parameter 'ham_U': 4.0, # Hubbard interaction 'ham_Tperp': 0.0, # For bilayer systems 'beta': 5.0, # Inverse temperature 'Ltau': 0, # '1' for time-displaced Green functions; '0' otherwise 'NSweep': 200, # Number of sweeps 'NBin': 10, # Number of bins 'Dtau': dtau, # Only dtau varies between simulations, Ltrot=beta/Dtau 'Mz': True, # If true, sets the M_z-Hubbard model: Nf=2, N_sum=1, }, # HS field couples to z-component of magnetization alf_dir='~/Programs/ALF', # Local ALF copy, if present ) sims.append(sim)  %% Output dtau values used: 0.05 0.1 0.15 %% Cell type:markdown id: tags: 3. Compile ALF, downloading it first if not found locally. This may take a few minutes: %% Cell type:code id: tags:  python sims[0].compile() # Compilation needs to be performed only once  %% Output Compiling ALF... Done. %% Cell type:markdown id: tags: 4. Perform the simulations, as specified in each element of sim: %% Cell type:code id: tags:  python for i, sim in enumerate(sims): sim.run() # Perform the actual simulation in ALF  %% Output Prepare directory "/home/stafusa/Jobs/Uni-Wuerzburg/ALF/pyALF/Hubbard_Square_L1=6_L2=6_Checkerboard=False_Symm=True_T=1.0_U=4.0_Tperp=0.0_beta=5.0_Dtau=0.05_Mz=True" for Monte Carlo run. Create new directory. Run /home/stafusa/Programs/ALF/Prog/Hubbard.out Prepare directory "/home/stafusa/Jobs/Uni-Wuerzburg/ALF/pyALF/Hubbard_Square_L1=6_L2=6_Checkerboard=False_Symm=True_T=1.0_U=4.0_Tperp=0.0_beta=5.0_Dtau=0.1_Mz=True" for Monte Carlo run. Create new directory. Run /home/stafusa/Programs/ALF/Prog/Hubbard.out Prepare directory "/home/stafusa/Jobs/Uni-Wuerzburg/ALF/pyALF/Hubbard_Square_L1=6_L2=6_Checkerboard=False_Symm=True_T=1.0_U=4.0_Tperp=0.0_beta=5.0_Dtau=0.15_Mz=True" for Monte Carlo run. Create new directory. Run /home/stafusa/Programs/ALF/Prog/Hubbard.out %% Cell type:markdown id: tags: 5. Calculate the internal energies: %% Cell type:code id: tags:  python ener = np.empty((3, 2)) # Matrix for storing energy values dtaus = np.empty((3,)) # Matrix for Dtau values, for plotting for i, sim in enumerate(sims): print(sim.sim_dir) # Directory containing the simulation output sim.analysis() # Perform default analysis dtaus[i] = sim.sim_dict['Dtau'] # Store Dtau value ener[i] = sim.get_obs(['Ener_scalJ'])['Ener_scalJ']['obs'] # Store internal energy  %% Output /home/stafusa/Jobs/Uni-Wuerzburg/ALF/pyALF/Hubbard_Square_L1=6_L2=6_Checkerboard=False_Symm=True_T=1.0_U=4.0_Tperp=0.0_beta=5.0_Dtau=0.05_Mz=True Analysing Pot_scal Analysing Part_scal Analysing Kin_scal Analysing Ener_scal Analysing SpinT_eq Analysing Den_eq Analysing Green_eq Analysing SpinZ_eq Analysing SpinXY_eq /home/stafusa/Jobs/Uni-Wuerzburg/ALF/pyALF/Hubbard_Square_L1=6_L2=6_Checkerboard=False_Symm=True_T=1.0_U=4.0_Tperp=0.0_beta=5.0_Dtau=0.1_Mz=True Analysing Pot_scal Analysing Part_scal Analysing Kin_scal Analysing Ener_scal Analysing SpinT_eq Analysing Den_eq Analysing Green_eq Analysing SpinZ_eq Analysing SpinXY_eq /home/stafusa/Jobs/Uni-Wuerzburg/ALF/pyALF/Hubbard_Square_L1=6_L2=6_Checkerboard=False_Symm=True_T=1.0_U=4.0_Tperp=0.0_beta=5.0_Dtau=0.15_Mz=True Analysing Pot_scal Analysing Part_scal Analysing Kin_scal Analysing Ener_scal Analysing SpinT_eq Analysing Den_eq Analysing Green_eq Analysing SpinZ_eq Analysing SpinXY_eq %% Cell type:code id: tags:  python print('For Dtau values', dtaus, 'the measured energies are:\n', ener)  %% Output For Dtau values [0.05 0.1 0.15] the measured energies are: [[-29.743579 0.058593] [-29.76641 0.047186] [-29.851836 0.039172]] %% Cell type:code id: tags:  python plt.errorbar(dtaus**2, ener[:, 0], ener[:, 1]) def func(x, y0, a): return y0 + a*x**2 popt1, pcov = curve_fit(func, dtaus, ener[:, 0], sigma=ener[:, 1], absolute_sigma=True) perr1 = np.sqrt(np.diag(pcov)) print(popt1, perr1) xs = np.linspace(0., dtaus.max()) plt.plot(xs**2, func(xs, *popt1)) plt.errorbar(0, popt1[0], perr1[0])  %% Output [-29.71904967 -5.78152768] [0.05403036 3.28474149]