Commit 5409ee5c authored by Jefferson Stafusa E. Portela's avatar Jefferson Stafusa E. Portela
Browse files

Minor.

parent b069f5e2
%% 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:
## Example 1 - Testing against ED
# Testing against ED - Hubbard
%% Cell type:markdown id: tags:
In this second example (following _Example 0 - A minimal ALF run_) we run the code with the Mz choice of Hubbard Stratonovitch transformation on a four site ring, at $U/t=4$ and inverse temperature $ \beta t = 2 $. For this set of parameters, the exact internal energy reads:
In this example we run the code with the Mz choice of Hubbard Stratonovitch transformation on a four site ring, at $U/t=4$ and inverse temperature $ \beta t = 2 $. For this set of parameters, the exact internal energy reads:
$$
\left\langle -t \sum_{\langle i,j\rangle, \sigma} c_{i,\sigma}^{\dagger} c_{j,\sigma}^{\phantom\dagger} + U \sum_{i=1}^{N} n_{i,\uparrow}n_{j,\downarrow} \right\rangle = -1.47261997 t
$$
To reproduce this result we will have to 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 analyzing the data.
---
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': 'N_leg_ladder', # Lattice type
'L1': 4, # Lattice length in the first unit vector direction
'L2': 1, # 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': 4.0, # Inverse temperature
'Ltau': 0, # '1' for time-displaced Green functions; '0' otherwise
'NSweep': 2000, # 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_N_leg_ladder_L1=4_L2=1_Checkerboard=False_Symm=True_T=1.0_U=4.0_Tperp=0.0_beta=4.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_N_leg_ladder_L1=4_L2=1_Checkerboard=False_Symm=True_T=1.0_U=4.0_Tperp=0.0_beta=4.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_N_leg_ladder_L1=4_L2=1_Checkerboard=False_Symm=True_T=1.0_U=4.0_Tperp=0.0_beta=4.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_N_leg_ladder_L1=4_L2=1_Checkerboard=False_Symm=True_T=1.0_U=4.0_Tperp=0.0_beta=4.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_N_leg_ladder_L1=4_L2=1_Checkerboard=False_Symm=True_T=1.0_U=4.0_Tperp=0.0_beta=4.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_N_leg_ladder_L1=4_L2=1_Checkerboard=False_Symm=True_T=1.0_U=4.0_Tperp=0.0_beta=4.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:
[[-1.913795 0.008008]
[-1.910943 0.006356]
[-1.914801 0.003687]]
%% 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
[-1.91153819 -0.13415236] [0.0072138 0.3858579]
<ErrorbarContainer object of 3 artists>
%% Cell type:code id: tags:
``` python
```
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment