"**Note**: To run a fresh simulation - instead of performing a refinement over previous run(s) - the Monte Carlo run directory should deleted before rerunning."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"---\n",
"## Exercises\n",
"1. Rerun once again and check the new improvement in precision.\n",
"2. Look at a few other observables (`sim.analysis()` outputs the names of those available).\n",
"3. Change the lattice size by adding, e.g., `\"L1\": 4,` and `\"L2\": 1,` to the simulation parameters definitions of `sim` (step 2)."
]
}
],
"metadata": {
...
...
%% 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:
# A minimal ALF run
%% Cell type:markdown id: tags:
In this bare-bones example we use the pyALF interface to run the canonical Hubbard model on a default configuration: a $6\times6$ square grid, with interaction strength $U=4$ and inverse temperature $\beta = 5 $.
Bellow we go through the steps for performing the simulation and outputting observables.
---
1. Import `Simulation` class from the `py_alf` python module, which provides the interface with ALF:
%% Cell type:code id: tags:
``` python
frompy_alfimportSimulation# Interface with ALF
```
%% Cell type:markdown id: tags:
2. Create an instance of `Simulation`, setting parameters as desired:
%% Cell type:code id: tags:
``` python
sim=Simulation(
"Hubbard",# Hamiltonian
{# Model and simulation parameters for each Simulation instance
"Model":"Hubbard",# Base model
"Lattice_type":"Square"},# Lattice type
)
```
%% 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
sim.compile()# Compilation needs to be performed only once
```
%%%% Output: stream
Compiling ALF... Done.
%% Cell type:markdown id: tags:
4. Perform the simulation as specified in `sim`:
%% Cell type:code id: tags:
``` python
sim.run()# Perform the actual simulation in ALF
```
%%%% Output: stream
Prepare directory "/home/jonas/Programs/pyALF/Hubbard_Hubbard_Square" for Monte Carlo run.
Create new directory.
Run /home/jonas/Programs/pyALF/ALF/Prog/Hubbard.out
%% Cell type:markdown id: tags:
5. Perform some simple analyses:
%% Cell type:code id: tags:
``` python
sim.analysis()# Perform default analysis; list observables
```
%%%% Output: stream
Analysing Part_scal
Analysing Kin_scal
Analysing Ener_scal
Analysing Pot_scal
Analysing SpinT_eq
Analysing SpinZ_eq
Analysing SpinXY_eq
Analysing Green_eq
Analysing Den_eq
Analysing SpinZ_tau
Analysing Den_tau
Analysing SpinXY_tau
Analysing SpinT_tau
Analysing Green_tau
%% Cell type:markdown id: tags:
6. Store computed observables list:
%% Cell type:code id: tags:
``` python
obs=sim.get_obs()# Dictionary for the observables
```
%% Cell type:markdown id: tags:
which are available for further analyses. For instance, the internal energy of the system (and its error) is accessed by:
%% Cell type:code id: tags:
``` python
obs['Ener_scalJ']['obs']
```
%%%% Output: execute_result
array([[-29.983503, 0.232685]])
%% Cell type:markdown id: tags:
---
7. Running again: The simulation can be resumed to increase the precision of the results.
%% Cell type:code id: tags:
``` python
sim.run()
sim.analysis()
obs2=sim.get_obs()
print(obs2['Ener_scalJ']['obs'])
print("\nRunning again reduced the error from ",obs['Ener_scalJ']['obs'][0][1]," to ",obs2['Ener_scalJ']['obs'][0][1],".")
```
%%%% Output: stream
Prepare directory "/home/jonas/Programs/pyALF/Hubbard_Hubbard_Square" for Monte Carlo run.
Resuming previous run.
Run /home/jonas/Programs/pyALF/ALF/Prog/Hubbard.out
Analysing Part_scal
Analysing Kin_scal
Analysing Ener_scal
Analysing Pot_scal
Analysing SpinT_eq
Analysing SpinZ_eq
Analysing SpinXY_eq
Analysing Green_eq
Analysing Den_eq
Analysing SpinZ_tau
Analysing Den_tau
Analysing SpinXY_tau
Analysing SpinT_tau
Analysing Green_tau
[[-29.819654 0.135667]]
Running again reduced the error from 0.232685 to 0.135667 .
%% Cell type:markdown id: tags:
**Note**: To run a fresh simulation - instead of performing a refinement over previous run(s) - the Monte Carlo run directory should deleted before rerunning.
%% Cell type:markdown id: tags:
---
## Exercises
1. Rerun once again and check the new improvement in precision.
2. Look at a few other observables (`sim.analysis()` outputs the names of those available).
3. Change the lattice size by adding, e.g., `"L1": 4,` and `"L2": 1,` to the simulation parameters definitions of `sim` (step 2).
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:
# Testing against ED - Hubbard
# Testing against ED - Hubbard on a ring
%% Cell type:markdown id: tags:
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:
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:')
fordtauin[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: stream
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: stream
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
fori,siminenumerate(sims):
sim.run()# Perform the actual simulation in ALF
```
%%%% Output: stream
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
fori,siminenumerate(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