2.2. Compiling and running ALF#

This section focuses on the “ALF interface” part of pyALF, i.e. how to compile ALF and run ALF simulations. This revolves around the classes ALF_source and Simulation defined in the module py_alf that have already been briefly introduced in Section 2.1.

We start with some imports:

from pprint import pprint  # Pretty print
from py_alf import ALF_source, Simulation  # Interface with ALF

2.2.1. Class ALF_source#

The Class py_alf.ALF_source points to a folder containing the ALF source code. It has the following signature:

class ALF_source(
    alf_dir=os.getenv('ALF_DIR', './ALF'),
    branch=None,
    url='https://git.physik.uni-wuerzburg.de/ALF/ALF.git'
)

Where os.getenv('ALF_DIR', './ALF') gets the environment variable $ALF_DIR if present and otherwise returns './ALF'. If the directory alf_dir does exist, the program assumes it contains the ALF source code and will raise an Exception if that is not the case. If alf_dir does not exist, the source code will be cloned form url. If branch is set, git checks it out.

We will just use the default:

alf_src = ALF_source()

And see if it successfully found ALF:

alf_src.alf_dir
'/home/jonas/Programs/ALF'

We can use the function py_alf.ALF_source.get_ham_names() to see which Hamiltonians are implemented:

alf_src.get_ham_names()
['Kondo',
 'Hubbard',
 'Hubbard_Plain_Vanilla',
 'tV',
 'LRC',
 'Z2_Matter',
 'Spin_Peierls']

And then view the list of parameters and their default values for a particular Hamiltonian. The Hamiltonian-specific parameters are listed first, followed by the Hamiltonian-independent parameters.

pprint(alf_src.get_default_params('Hubbard'))
OrderedDict([('VAR_lattice',
              {'L1': {'comment': 'Length in direction a_1',
                      'defined_in_base': False,
                      'value': 6},
               'L2': {'comment': 'Length in direction a_2',
                      'defined_in_base': False,
                      'value': 6},
               'Lattice_type': {'comment': '',
                                'defined_in_base': False,
                                'value': 'Square'},
               'Model': {'comment': 'Value not relevant',
                         'defined_in_base': False,
                         'value': 'Hubbard'}}),
             ('VAR_Model_Generic',
              {'Beta': {'comment': 'Inverse temperature',
                        'defined_in_base': False,
                        'value': 5.0},
               'Bulk': {'comment': 'Twist as a vector potential (.T.), or at '
                                   'the boundary (.F.)',
                        'defined_in_base': False,
                        'value': True},
               'Checkerboard': {'comment': 'Whether checkerboard decomposition '
                                           'is used',
                                'defined_in_base': False,
                                'value': True},
               'Dtau': {'comment': 'Thereby Ltrot=Beta/dtau',
                        'defined_in_base': False,
                        'value': 0.1},
               'N_FL': {'comment': 'Number of flavors',
                        'defined_in_base': True,
                        'value': 1},
               'N_Phi': {'comment': 'Total number of flux quanta traversing '
                                    'the lattice',
                         'defined_in_base': False,
                         'value': 0},
               'N_SUN': {'comment': 'Number of colors',
                         'defined_in_base': True,
                         'value': 2},
               'Phi_X': {'comment': 'Twist along the L_1 direction, in units '
                                    'of the flux quanta',
                         'defined_in_base': False,
                         'value': 0.0},
               'Phi_Y': {'comment': 'Twist along the L_2 direction, in units '
                                    'of the flux quanta',
                         'defined_in_base': False,
                         'value': 0.0},
               'Projector': {'comment': 'Whether the projective algorithm is '
                                        'used',
                             'defined_in_base': True,
                             'value': False},
               'Symm': {'comment': 'Whether symmetrization takes place',
                        'defined_in_base': True,
                        'value': True},
               'Theta': {'comment': 'Projection parameter',
                         'defined_in_base': False,
                         'value': 10.0}}),
             ('VAR_Hubbard',
              {'Continuous': {'comment': 'Uses (T: continuous; F: discrete) HS '
                                         'transformation',
                              'defined_in_base': False,
                              'value': False},
               'Ham_U': {'comment': 'Hubbard interaction',
                         'defined_in_base': False,
                         'value': 4.0},
               'Ham_U2': {'comment': 'For bilayer systems',
                          'defined_in_base': False,
                          'value': 4.0},
               'Ham_chem': {'comment': 'Chemical potential',
                            'defined_in_base': False,
                            'value': 0.0},
               'Mz': {'comment': 'When true, sets the M_z-Hubbard model: Nf=2, '
                                 'demands that N_sun is even, HS field couples '
                                 'to the z-component of magnetization; '
                                 'otherwise, HS field couples to the density',
                      'defined_in_base': False,
                      'value': True},
               'ham_T': {'comment': 'Hopping parameter',
                         'defined_in_base': False,
                         'value': 1.0},
               'ham_T2': {'comment': 'For bilayer systems',
                          'defined_in_base': False,
                          'value': 1.0},
               'ham_Tperp': {'comment': 'For bilayer systems',
                             'defined_in_base': False,
                             'value': 1.0}}),
             ('VAR_QMC',
              {'Amplitude': {'comment': 'Width of the box distribution for '
                                        'update of type t=3,4 fields.  '
                                        'Defaults  to 1.0.',
                             'value': 1.0},
               'CPU_MAX': {'comment': 'Code stops after CPU_MAX hours, if 0 or '
                                      'not specified, the code stops after '
                                      'Nbin bins',
                           'value': 0.0},
               'Delta_t_Langevin_HMC': {'comment': 'Time step for Langevin or '
                                                   'HMC',
                                        'value': 0.1},
               'Global_moves': {'comment': 'Allows for global moves in space '
                                           'and time.',
                                'value': False},
               'Global_tau_moves': {'comment': 'Allows for global moves on a '
                                               'single time slice.',
                                    'value': False},
               'HMC': {'comment': 'HMC update', 'value': False},
               'LOBS_EN': {'comment': 'End measurements at time slice LOBS_EN',
                           'value': 0},
               'LOBS_ST': {'comment': 'Start measurements at time slice '
                                      'LOBS_ST',
                           'value': 0},
               'Langevin': {'comment': 'Langevin update', 'value': False},
               'Leapfrog_steps': {'comment': 'Number of leapfrog iterations',
                                  'value': 0},
               'Ltau': {'comment': '1 to calculate time-displaced Green '
                                   'functions; 0 otherwise.',
                        'value': 1},
               'Max_Force': {'comment': 'Max Force for Langevin', 'value': 5.0},
               'N_HMC_sweeps': {'comment': 'Number of HMC sweeps', 'value': 1},
               'N_global': {'comment': 'Number of global moves per sweep.',
                            'value': 1},
               'N_global_tau': {'comment': 'Number of global moves that will '
                                           'be carried out on a single time '
                                           'slice.',
                                'value': 1},
               'Nbin': {'comment': 'Number of bins.', 'value': 5},
               'Nsweep': {'comment': 'Number of sweeps per bin.', 'value': 20},
               'Nt_sequential_end': {'comment': '', 'value': -1},
               'Nt_sequential_start': {'comment': '', 'value': 0},
               'Nwrap': {'comment': 'Stabilization. Green functions will be '
                                    'computed from scratch after each time '
                                    'interval Nwrap*Dtau.',
                         'value': 10},
               'Propose_S0': {'comment': 'Proposes single spin flip moves with '
                                         'probability exp(-S0).',
                              'value': False},
               'sequential': {'comment': 'Conventional updating scheme',
                              'value': True}}),
             ('VAR_errors',
              {'N_Back': {'comment': 'If set to 1, substract background in '
                                     'correlation functions. Is ignored in '
                                     'Python analysis.',
                          'value': 1},
               'N_Cov': {'comment': 'If set to 1, covariance computed for '
                                    'time-displaced correlation functions. Is '
                                    'ignored in Python analysis.',
                         'value': 0},
               'N_auto': {'comment': 'If > 0, calculate autocorrelation. Is '
                                     'ignored in Python analysis.',
                          'value': 0},
               'N_rebin': {'comment': 'Rebinning: Number of bins to combine '
                                      'into one.',
                           'value': 1},
               'N_skip': {'comment': 'Number of bins to be skipped.',
                          'value': 1}}),
             ('VAR_TEMP',
              {'N_Tempering_frequency': {'comment': 'The frequency, in units '
                                                    'of sweeps, at which the '
                                                    'exchange moves are '
                                                    'carried out.',
                                         'value': 10},
               'N_exchange_steps': {'comment': 'Number of exchange moves.',
                                    'value': 6},
               'Tempering_calc_det': {'comment': 'Specifies whether the '
                                                 'fermion weight has to be '
                                                 'taken into account while '
                                                 'tempering. Can be set to .F. '
                                                 'if the parameters that get '
                                                 'varied only enter the Ising '
                                                 'action S_0',
                                      'value': True},
               'mpi_per_parameter_set': {'comment': 'Number of mpi-processes '
                                                    'per parameter set.',
                                         'value': 2}}),
             ('VAR_Max_Stoch',
              {'Checkpoint': {'comment': '', 'value': False},
               'NBins': {'comment': 'Number of bins for Monte Carlo.',
                         'value': 250},
               'NSweeps': {'comment': 'Number of sweeps per bin.', 'value': 70},
               'N_alpha': {'comment': 'Number of temperatures.', 'value': 14},
               'Ndis': {'comment': 'Number of boxes for histogram.',
                        'value': 2000},
               'Ngamma': {'comment': 'Number of Dirac delta-functions for '
                                     'parametrization.',
                          'value': 400},
               'Nwarm': {'comment': 'The Nwarm first bins will be ommitted.',
                         'value': 20},
               'Om_en': {'comment': 'Frequency range upper bound.',
                         'value': 10.0},
               'Om_st': {'comment': 'Frequency range lower bound.',
                         'value': -10.0},
               'R': {'comment': '', 'value': 1.2},
               'Tolerance': {'comment': '', 'value': 0.1},
               'alpha_st': {'comment': '', 'value': 1.0}})])

2.2.2. Class Simulation#

To set up a simulation, we create an instance of py_alf.Simulation, which has the signature

class Simulation(alf_src, ham_name, sim_dict, **kwargs)

where alf_src is an instance of py_alf.ALF_source, ham_name is the name of the Hamiltonian to simulate, sim_dict is a dictionary of parameter: value pairs overwriting the default parameters and **kwargs represents optional keyword arguments.

The minimal set of required arguments does not overwrite any default parameters:

sim = Simulation(alf_src, 'Hubbard', {})

Before running the simulation, ALF needs to be compiled.

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.

Preparation of the simulation is done by executing the following command:

sim.run()
Prepare directory "/home/jonas/dissertation/jb/chap4_pyalf/usage/ALF_data/Hubbard" 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

It is strongly advised to take a look at the info file info produced by ALF after a finished run, in particular the value of “Precision Green” and “Precision Phase”. As a rule of thumb, the means should be of order \(10^{-8}\) or smaller and the max should not be bigger than \(10^{-3}\). If they’re bigger, one should decrease the stabilization interval Nwrap (see parameter list 'VAR_QMC' above). In our case, they’re about right.

sim.print_info_file()
===== /home/jonas/dissertation/jb/chap4_pyalf/usage/ALF_data/Hubbard/info =====
 =====================================
 Model is      : Hubbard                                                         
 Lattice is    : Square                                                          
 # unit cells  :           36
 # of orbitals :            1
 Flux_1        :    0.0000000000000000     
 Flux_2        :    0.0000000000000000     
 Twist as phase factor in bulk
 HS  couples to z-component of spin
 Checkerboard  :  T
 Symm. decomp  :  T
 Finite temperture version
 Beta          :    5.0000000000000000     
 dtau,Ltrot_eff:   0.10000000000000001               50
 N_SUN         :            2
 N_FL          :            2
 t             :    1.0000000000000000     
 Ham_U         :    4.0000000000000000     
 t2            :    1.0000000000000000     
 Ham_U2        :    4.0000000000000000     
 Ham_tperp     :    1.0000000000000000     
 Ham_chem      :    0.0000000000000000     
 No initial configuration, Seed_in      790789
 Sweeps                              :           20
 Bins                                :            5
 No CPU-time limitation 
 Measure Int.                        :            1          50
 Stabilization,Wrap                  :           10
 Nstm                                :            5
 Ltau                                :            1
 # of interacting Ops per time slice :           36
 Default sequential updating 
 This executable represents commit 24234d19 of branch master.
  Precision Green  Mean, Max :    3.4949708528056399E-011   3.3070368266052697E-007
  Precision Phase, Max       :    0.0000000000000000     
  Precision tau    Mean, Max :    6.3437557434930669E-012   3.6803000015572795E-008
  Acceptance                 :   0.42958333333333332     
  Effective Acceptance       :   0.42958333333333332     
  CPU Time                   :    4.0360565509999997     

2.2.3. Specifying parameters#

Here is an example of a simulation with non-default parameters. We have changed the dimensions to 4 by 4 sites and increased the interaction \(U\) to \(4.0\) and the number of bins calculated to 20. Since we did not change the compile-time configuration (some of the **kwargs do), a recompilation is not required.

sim = Simulation(
    alf_src,
    'Hubbard',
    {
        # Model specific parameters
        'L1': 4,
        'L2': 4,
        'Ham_U': 4.0,
        # QMC parameters
        'Nbin': 20,
    },
)
sim.run()
Prepare directory "/home/jonas/dissertation/jb/chap4_pyalf/usage/ALF_data/Hubbard_L1=4_L2=4_U=4.0" 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

Note that the new simulation has been placed in ALF_data/Hubbard_L1=4_L2=4_U=4.0 relative to the current working directory. That is, simulations are placed in the folder {sim_root}/{sim_dir}, where sim_root defaults to 'ALF_data' and sim_dir is generated out of the Hamiltonian name and the non-default model specific parameters. A behavior that can be overwritten through the **kwargs. Note that Nbin does not enter sim_dir, since it is a QMC parameter and not a Hamiltonian parameter.

The monitoring in the info file does not show any stabilization issues:

sim.print_info_file()
===== /home/jonas/dissertation/jb/chap4_pyalf/usage/ALF_data/Hubbard_L1=4_L2=4_U=4.0/info =====
 =====================================
 Model is      : Hubbard                                                         
 Lattice is    : Square                                                          
 # unit cells  :           16
 # of orbitals :            1
 Flux_1        :    0.0000000000000000     
 Flux_2        :    0.0000000000000000     
 Twist as phase factor in bulk
 HS  couples to z-component of spin
 Checkerboard  :  T
 Symm. decomp  :  T
 Finite temperture version
 Beta          :    5.0000000000000000     
 dtau,Ltrot_eff:   0.10000000000000001               50
 N_SUN         :            2
 N_FL          :            2
 t             :    1.0000000000000000     
 Ham_U         :    4.0000000000000000     
 t2            :    1.0000000000000000     
 Ham_U2        :    4.0000000000000000     
 Ham_tperp     :    1.0000000000000000     
 Ham_chem      :    0.0000000000000000     
 No initial configuration, Seed_in      790789
 Sweeps                              :           20
 Bins                                :           20
 No CPU-time limitation 
 Measure Int.                        :            1          50
 Stabilization,Wrap                  :           10
 Nstm                                :            5
 Ltau                                :            1
 # of interacting Ops per time slice :           16
 Default sequential updating 
 This executable represents commit 24234d19 of branch master.
  Precision Green  Mean, Max :    3.6448966471271451E-011   2.5289980969123160E-007
  Precision Phase, Max       :    0.0000000000000000     
  Precision tau    Mean, Max :    8.7134381626013185E-012   2.0840410398792475E-007
  Acceptance                 :   0.42600781250000003     
  Effective Acceptance       :   0.42600781250000003     
  CPU Time                   :    3.8189617760000001     

2.2.4. Series of MPI runs#

Starting each run separately can be cumbersome, therefore we provide the following example, which creates a list of Simulation instances that can be run in a loop, performing a sweep in \(U\). To increase the statistics of the results, MPI parallelization is employed. Since the default MPI executable mpiexec does not fit with the MPI libraries used during compilation on the test machine, we have changed it to orterun. The option mpiexec_args=['--oversubscribe'] hands over the flag --oversubscribe to orterun, which allows it to run more MPI tasks than there are slots available, see the Open MPI documentation for details.

sims = [
    Simulation(
        alf_src,
        'Hubbard',
        {
            # Model specific parameters
            'L1': 4,
            'L2': 4,
            'Ham_U': U,
            # QMC parameters
            'Nbin': 20,
        },
        mpi=True,
        n_mpi=4,
        mpiexec='orterun',
        mpiexec_args=['--oversubscribe'],
    )
    for U in [1.0, 2.0, 3.0]]
sims
[<py_alf.simulation.Simulation at 0x7f1550971c10>,
 <py_alf.simulation.Simulation at 0x7f155c1bdc40>,
 <py_alf.simulation.Simulation at 0x7f157c102630>]

Note

The above employs Python’s list comprehensions, a convenient and readable way to create Python lists. Here is a simple example, employing list comprehension (and f-strings):

>>> [f'x={x}' for x in [1, 2, 3]]
['x=1', 'x=2', 'x=3']

Since we are changing from non-MPI to MPI, ALF has to be recompiled:

Warning

pyALF does not check how ALF has been compiled previously, so the user has to take care of issuing recompilation if necessary.

sims[0].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.

Loop over list of jobs:

for sim in sims:
    sim.run()
Prepare directory "/home/jonas/dissertation/jb/chap4_pyalf/usage/ALF_data/Hubbard_L1=4_L2=4_U=1.0" 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
Prepare directory "/home/jonas/dissertation/jb/chap4_pyalf/usage/ALF_data/Hubbard_L1=4_L2=4_U=2.0" 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
Prepare directory "/home/jonas/dissertation/jb/chap4_pyalf/usage/ALF_data/Hubbard_L1=4_L2=4_U=3.0" 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
for sim in sims:
    sim.print_info_file()
===== /home/jonas/dissertation/jb/chap4_pyalf/usage/ALF_data/Hubbard_L1=4_L2=4_U=1.0/info =====
 =====================================
 Model is      : Hubbard                                                         
 Lattice is    : Square                                                          
 # unit cells  :           16
 # of orbitals :            1
 Flux_1        :    0.0000000000000000     
 Flux_2        :    0.0000000000000000     
 Twist as phase factor in bulk
 HS  couples to z-component of spin
 Checkerboard  :  T
 Symm. decomp  :  T
 Finite temperture version
 Beta          :    5.0000000000000000     
 dtau,Ltrot_eff:   0.10000000000000001               50
 N_SUN         :            2
 N_FL          :            2
 t             :    1.0000000000000000     
 Ham_U         :    1.0000000000000000     
 t2            :    1.0000000000000000     
 Ham_U2        :    4.0000000000000000     
 Ham_tperp     :    1.0000000000000000     
 Ham_chem      :    0.0000000000000000     
 No initial configuration, Seed_in      814342
 Sweeps                              :           20
 Bins                                :           20
 No CPU-time limitation 
 Measure Int.                        :            1          50
 Stabilization,Wrap                  :           10
 Nstm                                :            5
 Ltau                                :            1
 # of interacting Ops per time slice :           16
 Default sequential updating 
 Number of mpi-processes :            4
 This executable represents commit 24234d19 of branch master.
  Precision Green  Mean, Max :    4.7770138116091871E-014   3.1588759386025345E-012
  Precision Phase, Max       :    0.0000000000000000     
  Precision tau    Mean, Max :    1.3814341899797833E-014   5.2165077812915683E-012
  Acceptance                 :   0.44432578125000000     
  Effective Acceptance       :   0.44432578125000000     
  CPU Time                   :    4.6781053379999999     

===== /home/jonas/dissertation/jb/chap4_pyalf/usage/ALF_data/Hubbard_L1=4_L2=4_U=2.0/info =====
 =====================================
 Model is      : Hubbard                                                         
 Lattice is    : Square                                                          
 # unit cells  :           16
 # of orbitals :            1
 Flux_1        :    0.0000000000000000     
 Flux_2        :    0.0000000000000000     
 Twist as phase factor in bulk
 HS  couples to z-component of spin
 Checkerboard  :  T
 Symm. decomp  :  T
 Finite temperture version
 Beta          :    5.0000000000000000     
 dtau,Ltrot_eff:   0.10000000000000001               50
 N_SUN         :            2
 N_FL          :            2
 t             :    1.0000000000000000     
 Ham_U         :    2.0000000000000000     
 t2            :    1.0000000000000000     
 Ham_U2        :    4.0000000000000000     
 Ham_tperp     :    1.0000000000000000     
 Ham_chem      :    0.0000000000000000     
 No initial configuration, Seed_in      814342
 Sweeps                              :           20
 Bins                                :           20
 No CPU-time limitation 
 Measure Int.                        :            1          50
 Stabilization,Wrap                  :           10
 Nstm                                :            5
 Ltau                                :            1
 # of interacting Ops per time slice :           16
 Default sequential updating 
 Number of mpi-processes :            4
 This executable represents commit 24234d19 of branch master.
  Precision Green  Mean, Max :    2.6978900287668899E-013   1.9449365382118167E-010
  Precision Phase, Max       :    0.0000000000000000     
  Precision tau    Mean, Max :    7.6016248578584409E-014   2.8435920285119209E-010
  Acceptance                 :   0.43524999999999997     
  Effective Acceptance       :   0.43524999999999997     
  CPU Time                   :    4.4471584740000001     

===== /home/jonas/dissertation/jb/chap4_pyalf/usage/ALF_data/Hubbard_L1=4_L2=4_U=3.0/info =====
 =====================================
 Model is      : Hubbard                                                         
 Lattice is    : Square                                                          
 # unit cells  :           16
 # of orbitals :            1
 Flux_1        :    0.0000000000000000     
 Flux_2        :    0.0000000000000000     
 Twist as phase factor in bulk
 HS  couples to z-component of spin
 Checkerboard  :  T
 Symm. decomp  :  T
 Finite temperture version
 Beta          :    5.0000000000000000     
 dtau,Ltrot_eff:   0.10000000000000001               50
 N_SUN         :            2
 N_FL          :            2
 t             :    1.0000000000000000     
 Ham_U         :    3.0000000000000000     
 t2            :    1.0000000000000000     
 Ham_U2        :    4.0000000000000000     
 Ham_tperp     :    1.0000000000000000     
 Ham_chem      :    0.0000000000000000     
 No initial configuration, Seed_in      814342
 Sweeps                              :           20
 Bins                                :           20
 No CPU-time limitation 
 Measure Int.                        :            1          50
 Stabilization,Wrap                  :           10
 Nstm                                :            5
 Ltau                                :            1
 # of interacting Ops per time slice :           16
 Default sequential updating 
 Number of mpi-processes :            4
 This executable represents commit 24234d19 of branch master.
  Precision Green  Mean, Max :    2.6692496305360124E-012   6.9421481896370096E-009
  Precision Phase, Max       :    0.0000000000000000     
  Precision tau    Mean, Max :    6.9494808527483376E-013   8.4657683641076176E-009
  Acceptance                 :   0.42918789062500001     
  Effective Acceptance       :   0.42918789062500001     
  CPU Time                   :    4.6657046165000002     

2.2.5. Parallel Tempering#

ALF offers the possibility to employ Parallel Tempering [4], also known as Exchange Monte Carlo [5], where simulations with different parameters but the same configuration space are run in parallel and can exchange configurations. A method developed to overcome ergodicity issues.

To use Parallel Tempering in pyALF, sim_dict has to be replaced by a list of dictionaries, for this we use again Python’s list comprehension syntax. This does also imply mpi=True, since Parallel Tempering needs MPI.

sim = Simulation(
    alf_src,
    'Hubbard',
    [
        {
            # Model specific parameters
            'L1': 4,
            'L2': 4,
            'Ham_U': U,
            # QMC parameters
            'Nbin': 20,
            'mpi_per_parameter_set': 2
        } for U in [2.5, 3.5]
    ],
    mpi=True,
    n_mpi=4,
    mpiexec='orterun',
    mpiexec_args=['--oversubscribe'],
)

Recompile for Parallel Tempering:

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.
sim.run()
Prepare directory "/home/jonas/dissertation/jb/chap4_pyalf/usage/ALF_data/temper_Hubbard_L1=4_L2=4_U=2.5" for Monte Carlo run.
Create new directory.
Prepare directory "/home/jonas/dissertation/jb/chap4_pyalf/usage/ALF_data/temper_Hubbard_L1=4_L2=4_U=2.5/Temp_0" for Monte Carlo run.
Create new directory.
Prepare directory "/home/jonas/dissertation/jb/chap4_pyalf/usage/ALF_data/temper_Hubbard_L1=4_L2=4_U=2.5/Temp_1" 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
sim.print_info_file()
Hide code cell output
===== /home/jonas/dissertation/jb/chap4_pyalf/usage/ALF_data/temper_Hubbard_L1=4_L2=4_U=2.5/Temp_0/info =====
 =====================================
 Model is      : Hubbard                                                         
 Lattice is    : Square                                                          
 # unit cells  :           16
 # of orbitals :            1
 Flux_1        :    0.0000000000000000     
 Flux_2        :    0.0000000000000000     
 Twist as phase factor in bulk
 HS  couples to z-component of spin
 Checkerboard  :  T
 Symm. decomp  :  T
 Finite temperture version
 Beta          :    5.0000000000000000     
 dtau,Ltrot_eff:   0.10000000000000001               50
 N_SUN         :            2
 N_FL          :            2
 t             :    1.0000000000000000     
 Ham_U         :    2.5000000000000000     
 t2            :    1.0000000000000000     
 Ham_U2        :    4.0000000000000000     
 Ham_tperp     :    1.0000000000000000     
 Ham_chem      :    0.0000000000000000     
 No initial configuration, Seed_in      814342
 Sweeps                              :           20
 Bins                                :           20
 No CPU-time limitation 
 Measure Int.                        :            1          50
 Stabilization,Wrap                  :           10
 Nstm                                :            5
 Ltau                                :            1
 # of interacting Ops per time slice :           16
 Default sequential updating 
 Number of mpi-processes :            2
 This executable represents commit 24234d19 of branch master.
 # of exchange steps             6
 Tempering frequency            10
 Tempering Calc_det    T
  Precision Green  Mean, Max :    8.1429282795048577E-013   2.3347972444298648E-009
  Precision Phase, Max       :    0.0000000000000000     
  Precision tau    Mean, Max :    2.2225127395136315E-013   1.4722775776299102E-009
  Acceptance                 :   0.43180859375000002     
  Effective Acceptance       :   0.43180859375000002     
  Acceptance Tempering       :    7.9166666666666663E-002
  CPU Time                   :    5.0431947450000001     

===== /home/jonas/dissertation/jb/chap4_pyalf/usage/ALF_data/temper_Hubbard_L1=4_L2=4_U=2.5/Temp_1/info =====
 =====================================
 Model is      : Hubbard                                                         
 Lattice is    : Square                                                          
 # unit cells  :           16
 # of orbitals :            1
 Flux_1        :    0.0000000000000000     
 Flux_2        :    0.0000000000000000     
 Twist as phase factor in bulk
 HS  couples to z-component of spin
 Checkerboard  :  T
 Symm. decomp  :  T
 Finite temperture version
 Beta          :    5.0000000000000000     
 dtau,Ltrot_eff:   0.10000000000000001               50
 N_SUN         :            2
 N_FL          :            2
 t             :    1.0000000000000000     
 Ham_U         :    3.5000000000000000     
 t2            :    1.0000000000000000     
 Ham_U2        :    4.0000000000000000     
 Ham_tperp     :    1.0000000000000000     
 Ham_chem      :    0.0000000000000000     
 No initial configuration, Seed_in      452938
 Sweeps                              :           20
 Bins                                :           20
 No CPU-time limitation 
 Measure Int.                        :            1          50
 Stabilization,Wrap                  :           10
 Nstm                                :            5
 Ltau                                :            1
 # of interacting Ops per time slice :           16
 Default sequential updating 
 Number of mpi-processes :            2
 This executable represents commit 24234d19 of branch master.
 # of exchange steps             6
 Tempering frequency            10
 Tempering Calc_det    T
  Precision Green  Mean, Max :    9.8914081827280095E-012   2.0703128211785327E-008
  Precision Phase, Max       :    0.0000000000000000     
  Precision tau    Mean, Max :    2.4669097933483736E-012   3.9006903842370155E-008
  Acceptance                 :   0.42687109374999999     
  Effective Acceptance       :   0.42687109374999999     
  Acceptance Tempering       :    7.9166666666666663E-002
  CPU Time                   :    5.0432830410000005     

The output from this command has been omitted for brevity.

2.2.6. Only preparing runs#

In many cases, it might not be feasible to execute ALF directly through pyALF, for example when using an HPC scheduler, but one might still like to use pyALF for preparing the simulation directories. In this case the two options copy_bin and only_prep of py_alf.Simulation.run() come in handy. Here we also demonstrate the keyword arguments sim_root and sim_dir.

import numpy as np
JK_list = np.linspace(0.0, 3.0, num=11)
print(JK_list)

sims = [
    Simulation(
        alf_src,
        'Kondo',
        {
            "Model": "Kondo",
            "Lattice_type": "Bilayer_square",
            "L1": 16,
            "L2": 16,
            "Ham_JK": JK,
            "Ham_Uf": 1.,
            "Beta": 20.0,
            "Nsweep": 500,
            "NBin": 400,
            "Ltau": 0,
            "CPU_MAX": 48
        },
        mpi=True,
        sim_root="KondoBilayerSquareL16",
        sim_dir=f"JK{JK:2.1f}",
    ) for JK in JK_list
]
[0.  0.3 0.6 0.9 1.2 1.5 1.8 2.1 2.4 2.7 3. ]

Do not forget to recompile when switching from Parallel Tempering back to normal MPI runs.

sims[0].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.
for sim in sims:
    sim.run(copy_bin=True, only_prep=True)
Prepare directory "/home/jonas/dissertation/jb/chap4_pyalf/usage/KondoBilayerSquareL16/JK0.0" for Monte Carlo run.
Create new directory.
Prepare directory "/home/jonas/dissertation/jb/chap4_pyalf/usage/KondoBilayerSquareL16/JK0.3" for Monte Carlo run.
Create new directory.
Prepare directory "/home/jonas/dissertation/jb/chap4_pyalf/usage/KondoBilayerSquareL16/JK0.6" for Monte Carlo run.
Create new directory.
Prepare directory "/home/jonas/dissertation/jb/chap4_pyalf/usage/KondoBilayerSquareL16/JK0.9" for Monte Carlo run.
Create new directory.
Prepare directory "/home/jonas/dissertation/jb/chap4_pyalf/usage/KondoBilayerSquareL16/JK1.2" for Monte Carlo run.
Create new directory.
Prepare directory "/home/jonas/dissertation/jb/chap4_pyalf/usage/KondoBilayerSquareL16/JK1.5" for Monte Carlo run.
Create new directory.
Prepare directory "/home/jonas/dissertation/jb/chap4_pyalf/usage/KondoBilayerSquareL16/JK1.8" for Monte Carlo run.
Create new directory.
Prepare directory "/home/jonas/dissertation/jb/chap4_pyalf/usage/KondoBilayerSquareL16/JK2.1" for Monte Carlo run.
Create new directory.
Prepare directory "/home/jonas/dissertation/jb/chap4_pyalf/usage/KondoBilayerSquareL16/JK2.4" for Monte Carlo run.
Create new directory.
Prepare directory "/home/jonas/dissertation/jb/chap4_pyalf/usage/KondoBilayerSquareL16/JK2.7" for Monte Carlo run.
Create new directory.
Prepare directory "/home/jonas/dissertation/jb/chap4_pyalf/usage/KondoBilayerSquareL16/JK3.0" for Monte Carlo run.
Create new directory.

Now there are 11 directories, ready for the job scheduler.

ls KondoBilayerSquareL16/*
KondoBilayerSquareL16/JK0.0:
ALF.out*  parameters  seeds

KondoBilayerSquareL16/JK0.3:
ALF.out*  parameters  seeds

KondoBilayerSquareL16/JK0.6:
ALF.out*  parameters  seeds

KondoBilayerSquareL16/JK0.9:
ALF.out*  parameters  seeds

KondoBilayerSquareL16/JK1.2:
ALF.out*  parameters  seeds

KondoBilayerSquareL16/JK1.5:
ALF.out*  parameters  seeds

KondoBilayerSquareL16/JK1.8:
ALF.out*  parameters  seeds

KondoBilayerSquareL16/JK2.1:
ALF.out*  parameters  seeds

KondoBilayerSquareL16/JK2.4:
ALF.out*  parameters  seeds

KondoBilayerSquareL16/JK2.7:
ALF.out*  parameters  seeds

KondoBilayerSquareL16/JK3.0:
ALF.out*  parameters  seeds