2.1. Minimal example#
In this bare-bones example we simulate the Hubbard model with default the default presets: 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 ALF_source
and Simulation
classes from the py_alf
python module, which provide the interface with ALF:
from py_alf import ALF_source, Simulation # Interface with ALF
2. Create an instance of ALF_source
, downloading the ALF source code from the ALF repository, if alf_dir
does not exist. Gets alf_dir
from environment variable $ALF_DIR
, or defaults to "./ALF"
, if not present:
alf_src = ALF_source()
3. Create an instance of Simulation
, overwriting default parameters as desired:
sim = Simulation(
alf_src,
"Hubbard", # Name of Hamiltonian
{ # Dictionary overwriting default parameters
"Lattice_type": "Square"
},
machine='GNU' # Change to "intel", or "PGI" if gfortran is not installed
)
4. Compile ALF. The first time it will also download and compile HDF5, which could take \(\sim\)15 minutes.
sim.compile()
Compiling ALF...
Cleaning up Prog/
Cleaning up Libraries/
Cleaning up Analysis/
Compiling Libraries
Compiling Analysis
Compiling Program
Parsing Hamiltonian parameters
filenames: Hamiltonians/Hamiltonian_Kondo_smod.F90 Hamiltonians/Hamiltonian_Kondo_read_write_parameters.F90
filenames: Hamiltonians/Hamiltonian_Hubbard_smod.F90 Hamiltonians/Hamiltonian_Hubbard_read_write_parameters.F90
filenames: Hamiltonians/Hamiltonian_Hubbard_Plain_Vanilla_smod.F90 Hamiltonians/Hamiltonian_Hubbard_Plain_Vanilla_read_write_parameters.F90
filenames: Hamiltonians/Hamiltonian_tV_smod.F90 Hamiltonians/Hamiltonian_tV_read_write_parameters.F90
filenames: Hamiltonians/Hamiltonian_LRC_smod.F90 Hamiltonians/Hamiltonian_LRC_read_write_parameters.F90
filenames: Hamiltonians/Hamiltonian_Z2_Matter_smod.F90 Hamiltonians/Hamiltonian_Z2_Matter_read_write_parameters.F90
filenames: Hamiltonians/Hamiltonian_Spin_Peierls_smod.F90 Hamiltonians/Hamiltonian_Spin_Peierls_read_write_parameters.F90
Compiling program modules
Link program
Done.
5. Perform the simulation as specified in sim
:
sim.run()
Prepare directory "/home/jonas/dissertation/jb/chap4_pyalf/usage/ALF_data/Hubbard_Square" for Monte Carlo run.
Create new directory.
Run /home/jonas/Programs/ALF/Prog/ALF.out
ALF Copyright (C) 2016 - 2022 The ALF project contributors
This Program comes with ABSOLUTELY NO WARRANTY; for details see license.GPL
This is free software, and you are welcome to redistribute it under certain conditions.
No initial configuration
6. Perform some simple analysis:
sim.analysis()
### Analyzing /home/jonas/dissertation/jb/chap4_pyalf/usage/ALF_data/Hubbard_Square ###
/home/jonas/dissertation/jb/chap4_pyalf/usage
Scalar observables:
Ener_scal
Kin_scal
Part_scal
Pot_scal
Histogram observables:
Equal time observables:
Den_eq
Green_eq
SpinT_eq
SpinXY_eq
SpinZ_eq
Time displaced observables:
Den_tau
Green_tau
SpinT_tau
SpinXY_tau
SpinZ_tau
7. Read analysis results into a Pandas Dataframe with one row per simulation, containing parameters and observables:
obs = sim.get_obs()
/home/jonas/dissertation/jb/chap4_pyalf/usage/ALF_data/Hubbard_Square
No orbital locations saved.
obs
continuous | ham_chem | ham_t | ham_t2 | ham_tperp | ham_u | ham_u2 | mz | l1 | l2 | ... | SpinXY_tauK_err | SpinXY_tauR | SpinXY_tauR_err | SpinXY_tau_lattice | SpinZ_tauK | SpinZ_tauK_err | SpinZ_tauR | SpinZ_tauR_err | SpinZ_tau_lattice | lattice | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
/home/jonas/dissertation/jb/chap4_pyalf/usage/ALF_data/Hubbard_Square | 0 | 0.0 | 1.0 | 1.0 | 1.0 | 4.0 | 4.0 | 1 | 6 | 6 | ... | [[0.22628722504548163, 0.376854598540396, 0.01... | [[0.0575988003757765, -0.10378742200169441, 0.... | [[0.012488346667988096, 0.036871289378231954, ... | {'L1': [6.0, 0.0], 'L2': [0.0, 6.0], 'a1': [1.... | [[0.9040036362033993, 0.5628191896020671, 0.61... | [[0.14947867503118553, 0.06006336638595224, 0.... | [[0.10134420531394882, -0.11445552391592617, 0... | [[0.06273438448505807, 0.0563907804306374, 0.0... | {'L1': [6.0, 0.0], 'L2': [0.0, 6.0], 'a1': [1.... | {'L1': [6.0, 0.0], 'L2': [0.0, 6.0], 'N_coord'... |
1 rows × 111 columns
\(\bullet\) The internal energy of the system (and its error) are accessed by:
obs.iloc[0][['Ener_scal0', 'Ener_scal0_err', 'Ener_scal_sign', 'Ener_scal_sign_err']]
Ener_scal0 -29.821914
Ener_scal0_err 0.13032
Ener_scal_sign 1.0
Ener_scal_sign_err 0.0
Name: /home/jonas/dissertation/jb/chap4_pyalf/usage/ALF_data/Hubbard_Square, dtype: object
Warning
While it is very easy to get some results, as demonstrated right now, there are many caveats with using QMC, and a naive approach will quickly lead to wrong results.
Three of those caveats, namely numerical stability, warmup and autocorrelation will later be briefly addressed. For more details, please refer to the ALF documentation.
\(\bullet\) The simulation can be resumed by calling sim.run()
again, increasing the precision of results:
sim.run()
sim.analysis()
obs2 = sim.get_obs()
obs2.iloc[0][['Ener_scal0', 'Ener_scal0_err', 'Ener_scal_sign', 'Ener_scal_sign_err']]
Prepare directory "/home/jonas/dissertation/jb/chap4_pyalf/usage/ALF_data/Hubbard_Square" for Monte Carlo run.
Resuming previous run.
Run /home/jonas/Programs/ALF/Prog/ALF.out
ALF Copyright (C) 2016 - 2022 The ALF project contributors
This Program comes with ABSOLUTELY NO WARRANTY; for details see license.GPL
This is free software, and you are welcome to redistribute it under certain conditions.
### Analyzing /home/jonas/dissertation/jb/chap4_pyalf/usage/ALF_data/Hubbard_Square ###
/home/jonas/dissertation/jb/chap4_pyalf/usage
Scalar observables:
Ener_scal
Kin_scal
Part_scal
Pot_scal
Histogram observables:
Equal time observables:
Den_eq
Green_eq
SpinT_eq
SpinXY_eq
SpinZ_eq
Time displaced observables:
Den_tau
Green_tau
SpinT_tau
SpinXY_tau
SpinZ_tau
/home/jonas/dissertation/jb/chap4_pyalf/usage/ALF_data/Hubbard_Square
No orbital locations saved.
Ener_scal0 -29.609245
Ener_scal0_err 0.136803
Ener_scal_sign 1.0
Ener_scal_sign_err 0.0
Name: /home/jonas/dissertation/jb/chap4_pyalf/usage/ALF_data/Hubbard_Square, dtype: object
print(f"""Running again changed the error
from {obs.iloc[0]['Ener_scal0_err']}
to {obs2.iloc[0]['Ener_scal0_err']}""")
Running again changed the error
from 0.13032001865023543
to 0.13680286324412563
The error was not actually reduced as expected, hinting at problems with e.g. warmup, autocorrelation, or fat tails.