Commit 8444fa60 authored by Jefferson Stafusa E. Portela's avatar Jefferson Stafusa E. Portela
Browse files

Improving tutorial notebooks, especially parallel_tempering.

parent c79a564a
%% 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 0 - A minimal ALF run
## 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:
# 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:
## How to do parallel tempering in ALF
%% Cell type:markdown id: tags:
Parallel tempering can be used for overcoming sampling issues in part of the parameter space. For a chosen parameter and parameter values, parallel simulations are carried out at the different parameter values, with Monte Carlo sampling taking place over the extended ensemble.
Note that ALF must be recompiled when using this feature for the first time.
Bellow we go through the steps for using this feature: setting the simulation parameters, including the tempering ones, 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:
1. Create a list of dictionaries, specifying the parameters.
2. Create a list of dictionaries, specifying the necessary parameters.
Here we are varying Hubbard interaction strength `ham_U`.
%% Cell type:code id: tags:
``` python
sim_dicts = []
for ham_U in [3.5, 4.]:
for ham_U in [3.5, 4.0]:
sim_dicts.append({ # Model and simulation parameters for each Simulation instance
"Model": "Hubbard", # Base model
"Lattice_type": "Square", # Lattice type
"L1": 4, # Lattice length in the first unit vector direction
"L2": 1, # Lattice length in the second unit vector direction
'ham_T': 1.0, # Hopping parameter
'ham_U': ham_U, # Hubbard interaction
'ham_Tperp': 0.0, # For bilayer systems
'beta': 2.0, # Inverse temperature
"NSweep": 100, # Number of sweeps
"NBin": 100, # Number of bins
'Dtau': 0.1, # 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
)
```
%% Cell type:markdown id: tags:
2. Create instances of `Simulation`, specifying the necessary parameters, in particular the different $\Delta \tau$ values:
3. Create an instance of `Simulation` using the parameters above and also set ALF to run in parallel using MPI.
%% Cell type:code id: tags:
``` python
sim = Simulation(
'Hubbard', # Hamiltonian to use
sim_dicts,
n_mpi = 4,
mpiexec='mpiexec.openmpi'
'Hubbard', # Hamiltonian to use
sim_dicts, # Setting non-default parameters
n_mpi = 4, # Number of MPI processes
mpiexec='mpiexec.openmpi' # Command for invoking parallel executables
)
```
%% Cell type:markdown id: tags:
3. Compile ALF, downloading it first if not found locally. This may take a few minutes:
4. Set environment and compilation variables.
%% Cell type:code id: tags:
``` python
sim.config
```
%% Output
'GNU MPI TEMPERING'
%% Cell type:code id: tags:
``` python
sim.compile()
```
%% Output
%% Cell type:markdown id: tags:
Compiling ALF... Done.
5. Compile ALF, downloading it first if not found locally. This may take a few minutes:
%% Cell type:code id: tags:
``` python
sim.run()
sim.compile()
```
%% Output
Prepare directory "/home/jonas/Programs/pyALF/temper_Hubbard_Square_L1=4_L2=1_T=1.0_U=3.5_Tperp=0.0_Dtau=0.1" for Monte Carlo run.
Prepare directory "/home/jonas/Programs/pyALF/temper_Hubbard_Square_L1=4_L2=1_T=1.0_U=3.5_Tperp=0.0_Dtau=0.1/Temp_0" for Monte Carlo run.
Resuming previous run.
Prepare directory "/home/jonas/Programs/pyALF/temper_Hubbard_Square_L1=4_L2=1_T=1.0_U=3.5_Tperp=0.0_Dtau=0.1/Temp_1" for Monte Carlo run.
Resuming previous run.
Run /home/jonas/Programs/pyALF/ALF/Prog/Hubbard.out
%% Cell type:code id: tags:
``` python
sim.analysis()
```
Compiling ALF... Done.
%% Output
%% Cell type:markdown id: tags:
Analysing Part_scal
Analysing Kin_scal
Analysing Ener_scal
Analysing Acc_Temp_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
Analysing Part_scal
Analysing Kin_scal
Analysing Ener_scal
Analysing Acc_Temp_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
6. Perform the simulations, as specified in `sim`:
%% Cell type:code id: tags:
``` python
sim.run()
```
%% Output
Prepare directory "/home/jonas/Programs/pyALF/temper_Hubbard_Square_L1=4_L2=1_T=1.0_U=3.5_Tperp=0.0_Dtau=0.1" for Monte Carlo run.
Prepare directory "/home/jonas/Programs/pyALF/temper_Hubbard_Square_L1=4_L2=1_T=1.0_U=3.5_Tperp=0.0_Dtau=0.1/Temp_0" for Monte Carlo run.
Resuming previous run.
Prepare directory "/home/jonas/Programs/pyALF/temper_Hubbard_Square_L1=4_L2=1_T=1.0_U=3.5_Tperp=0.0_Dtau=0.1/Temp_1" for Monte Carlo run.
Resuming previous run.
Run /home/jonas/Programs/pyALF/ALF/Prog/Hubbard.out
%% Cell type:markdown id: tags:
7. Perform some simple analyses:
%% Cell type:code id: tags:
``` python
sim.analysis()
```
%% Output
Analysing Part_scal
Analysing Kin_scal
Analysing Ener_scal
Analysing Acc_Temp_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
Analysing Part_scal
Analysing Kin_scal
Analysing Ener_scal
Analysing Acc_Temp_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:code id: tags:
``` python
```
......
This diff is collapsed.
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