Minimal example

Minimal example#

In this bare-bones example we simulate the Hubbard model on the 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 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
filename: Hamiltonians/Hamiltonian_Kondo_smod.F90
filename: Hamiltonians/Hamiltonian_Hubbard_smod.F90
filename: Hamiltonians/Hamiltonian_Hubbard_Plain_Vanilla_smod.F90
filename: Hamiltonians/Hamiltonian_tV_smod.F90
filename: Hamiltonians/Hamiltonian_LRC_smod.F90
filename: Hamiltonians/Hamiltonian_Z2_Matter_smod.F90
Compiling program modules
Link program
Done.

5. Perform the simulation as specified in sim:

sim.run()
Prepare directory "/scratch/pyalf-docu/doc/source/usage/ALF_data/Hubbard_Square" for Monte Carlo run.
Create new directory.
Run /home/jschwab/Programs/ALF/Prog/ALF.out
 ALF Copyright (C) 2016 - 2021 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 /scratch/pyalf-docu/doc/source/usage/ALF_data/Hubbard_Square ###
/scratch/pyalf-docu/doc/source/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()
/scratch/pyalf-docu/doc/source/usage/ALF_data/Hubbard_Square
obs
continuous ham_chem ham_t ham_t2 ham_tperp ham_u ham_u2 mz l1 l2 ... SpinXY_tauK SpinXY_tauK_err SpinXY_tauR SpinXY_tauR_err SpinXY_tau_lattice SpinZ_tauK SpinZ_tauK_err SpinZ_tauR SpinZ_tauR_err SpinZ_tau_lattice
/scratch/pyalf-docu/doc/source/usage/ALF_data/Hubbard_Square 0 0.0 1.0 1.0 1.0 4.0 4.0 1 6 6 ... [[0.7166333059249843, 0.7702673353461202, 0.80... [[0.41109109738495303, 0.1943899413122643, 0.1... [[0.04862772103898162, -0.06317035245866442, 0... [[0.01568527860877001, 0.014336961963984148, 0... {'L1': [6.0, 0.0], 'L2': [0.0, 6.0], 'a1': [1.... [[0.7612628181106748, 0.5095215897954684, 0.51... [[0.1225255994814428, 0.01987242266793695, 0.0... [[0.11366625059261518, -0.1275646672041697, 0.... [[0.030126878813471026, 0.03152110650761888, 0... {'L1': [6.0, 0.0], 'L2': [0.0, 6.0], 'a1': [1....

1 rows × 110 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.983503
Ener_scal0_err         0.232685
Ener_scal_sign              1.0
Ener_scal_sign_err          0.0
Name: /scratch/pyalf-docu/doc/source/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 Quantum Monte Carlo, and a naive approach will quickly lead to wrong results.

Three of those caveats, namely numerical stability, warm-up and autocorrelation will 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 "/scratch/pyalf-docu/doc/source/usage/ALF_data/Hubbard_Square" for Monte Carlo run.
Resuming previous run.
Run /home/jschwab/Programs/ALF/Prog/ALF.out
 ALF Copyright (C) 2016 - 2021 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 /scratch/pyalf-docu/doc/source/usage/ALF_data/Hubbard_Square ###
/scratch/pyalf-docu/doc/source/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
/scratch/pyalf-docu/doc/source/usage/ALF_data/Hubbard_Square
Ener_scal0           -29.819654
Ener_scal0_err         0.135667
Ener_scal_sign              1.0
Ener_scal_sign_err          0.0
Name: /scratch/pyalf-docu/doc/source/usage/ALF_data/Hubbard_Square, dtype: object
print("\nRunning again reduced the error from\n", obs.iloc[0][['Ener_scal0_err']], "\nto\n", obs2.iloc[0][['Ener_scal0_err']])
Running again reduced the error from
 Ener_scal0_err    0.232685
Name: /scratch/pyalf-docu/doc/source/usage/ALF_data/Hubbard_Square, dtype: object 
to
 Ener_scal0_err    0.135667
Name: /scratch/pyalf-docu/doc/source/usage/ALF_data/Hubbard_Square, dtype: object