Commit 1b69cad4 authored by Jefferson Stafusa E. Portela's avatar Jefferson Stafusa E. Portela
Browse files

Organizational: putting the notebooks in their own directory - for now just...

Organizational: putting the notebooks in their own directory - for now just copying them there, since one has to do ` export PYTHONPATH="/local/path/to/pyALF:$PYTHONPATH"  `, so that is a change which we should discuss first.
parent 3d5d5aba
%% 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
from py_alf import Simulation # 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
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
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
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
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
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).