Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

A Jupyter notebook for: Metropolis, MALA, HMC and Langevin updates.

This notebook uses the pyALF interface to solve the 6-site Hubbard chain with different sampling schemes included in the ALF code. Aside from the Langevin mode — where the discretized-time evolution introduces a systematic error — all schemes sample the same underlying distribution and should reproduce the same energy within error bars. The notebook

  1. Builds ALF from the master branch.

  2. Sets up the parameter file for the 6-site Hubbard model.

  3. Compiles and loops over various updating schemes.

  4. At the end, a comparison of energies is provided.

Overview of updating schemes

  • Sequential Metropolis (discrete field): The classic single-spin-flip Metropolis update. The Hubbard-Stratonovich field is discrete (Ising-like), and each field variable is proposed to flip and accepted/rejected via the Metropolis ratio.

  • Sequential Metropolis (continuous field): Same single-site sweep structure, but the Hubbard-Stratonovich field is continuous. Proposals are drawn from a symmetric window of width Amplitude around the current value.

  • Sequential MALA (Metropolis-Adjusted Langevin Algorithm): A continuous-field, single-site update where the proposal is drawn using the local force (gradient of the action) as a drift term, followed by a Metropolis accept/reject step to guarantee detailed balance. Controlled by Delta_t_MALA_sequential (step size) and Max_Force_MALA_sequential (force clipping for stability).

  • Global tau moves: Instead of updating one field variable at a time, all fields, or a user defined set of fields are updated together on the time slice. This can be combined with plain Metropolis or MALA-type proposals (Delta_t_MALA_global_tau, Max_Force_MALA_global_tau) to improve autocorrelation/ergodicity, especially in Continuous field mode.

  • Global moves: Updates involving the whole field configuration (all time slices and sites) proposed simultaneously, again optionally combined with a MALA-like drift (Global_MALA_moves, Delta_t_MALA_global, Max_Force_MALA_global) and repeated for N_Global/N_Global_MALA_sweeps sub-sweeps per global step.

  • Langevin dynamics: A continuous-field update that evolves the fields using a stochastic differential equation (deterministic drift from the force plus Gaussian noise), with discretization time step Delta_t_Langevin_HMC. There is no Metropolis correction step, so this introduces a systematic bias of order Delta_t_Langevin_HMC that vanishes only in the limit of small time step.

  • Hybrid Monte Carlo (HMC): Introduces fictitious momenta conjugate to the continuous fields and integrates Hamilton’s equations via a leapfrog scheme (Leapfrog_steps steps of size Delta_t_Langevin_HMC), followed by a Metropolis accept/reject step on the full trajectory. This removes the systematic Langevin bias while still exploiting gradient information for efficient, low-autocorrelation moves.

See the Documentation in the ALF source tree for the full technical description of the update algorithms and force computations.

1. Import ALF_source and Simulation from py_alf:

2. Point ALF_source at the existing local ALF checkout, instead of cloning a fresh copy:

Output
Checking out branch 305-proposal-of-updates-with-langevin-equation
Your branch is up to date with 'origin/305-proposal-of-updates-with-langevin-equation'.
Already on '305-proposal-of-updates-with-langevin-equation'

3. Define the simulation, overwriting the default parameters to reproduce the Hubbard / N_leg_ladder / MALA setup from parameters:

4. Compile ALF. The first time it will also download and compile HDF5, which could take ∼15\sim15 minutes.

Output
Checking out branch 305-proposal-of-updates-with-langevin-equation
Your branch is up to date with 'origin/305-proposal-of-updates-with-langevin-equation'.
Already on '305-proposal-of-updates-with-langevin-equation'
Compiling ALF... 
Cleaning up Prog/
Cleaning up Libraries/
Cleaning up Analysis/
Compiling Libraries
ar: creating archive modules_90.a
ar: creating archive libqrref.a
Compiling Analysis
Compiling Program
Compiling program modules
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
Link program
Done.

Run and analyze all variants

Loop over every entry in sims, run/analyze it, and store the energy in a variable Energy_<sim_dir> (with dots replaced by underscores), then print all of them:

Output
Prepare directory "/Users/fassaad/Programs/ALF/wiki/source/ALF_data/Run_2.2.1" for Monte Carlo run.
Resuming previous run.
Run /Users/fassaad/Programs/ALF/ALF/Prog/ALF.out
 ALF Copyright (C) 2016 - 2026 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.
 Setting N_FL = 2 since this is mandatory for Mz-Hubbard model
### Analyzing /Users/fassaad/Programs/ALF/wiki/source/ALF_data/Run_2.2.1 ###
/Users/fassaad/Programs/ALF/wiki/source
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:
/Users/fassaad/Programs/ALF/wiki/source/ALF_data/Run_2.2.1
No orbital locations saved.
Prepare directory "/Users/fassaad/Programs/ALF/wiki/source/ALF_data/Run_2.2.2.1" for Monte Carlo run.
Resuming previous run.
Run /Users/fassaad/Programs/ALF/ALF/Prog/ALF.out
 ALF Copyright (C) 2016 - 2026 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.
 Setting N_FL = 2 since this is mandatory for Mz-Hubbard model
### Analyzing /Users/fassaad/Programs/ALF/wiki/source/ALF_data/Run_2.2.2.1 ###
/Users/fassaad/Programs/ALF/wiki/source
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:
/Users/fassaad/Programs/ALF/wiki/source/ALF_data/Run_2.2.2.1
No orbital locations saved.
Prepare directory "/Users/fassaad/Programs/ALF/wiki/source/ALF_data/Run_2.2.2.2" for Monte Carlo run.
Resuming previous run.
Run /Users/fassaad/Programs/ALF/ALF/Prog/ALF.out
 ALF Copyright (C) 2016 - 2026 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.

 ATTENTION:     Base implementation of Ham_Langevin_HMC_S0_single is being called!
 This uses the subroutine Ham_Langevin_HMC_S0, which provides all bosonic forces.
 Since Ham_Langevin_HMC_S0_single only requires one force this might be inefficient.
 Consider overwriting this routine according to the model in your Hamiltonian.
 Suppressing further printouts of this message.


 ATTENTION:     Base implementation of Ham_Langevin_HMC_S0_single is being called!
 This uses the subroutine Ham_Langevin_HMC_S0, which provides all bosonic forces.
 Since Ham_Langevin_HMC_S0_single only requires one force this might be inefficient.
 Consider overwriting this routine according to the model in your Hamiltonian.
 Suppressing further printouts of this message.

 Setting N_FL = 2 since this is mandatory for Mz-Hubbard model
### Analyzing /Users/fassaad/Programs/ALF/wiki/source/ALF_data/Run_2.2.2.2 ###
/Users/fassaad/Programs/ALF/wiki/source
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:
/Users/fassaad/Programs/ALF/wiki/source/ALF_data/Run_2.2.2.2
No orbital locations saved.
Prepare directory "/Users/fassaad/Programs/ALF/wiki/source/ALF_data/Run_2.2.3.1" for Monte Carlo run.
Resuming previous run.
Run /Users/fassaad/Programs/ALF/ALF/Prog/ALF.out
 ALF Copyright (C) 2016 - 2026 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.
 Setting N_FL = 2 since this is mandatory for Mz-Hubbard model
 Warning: Nt_sequential_end is smaller than Nt_sequential_start
 Warning: Nt_sequential_end is smaller than Nt_sequential_start
### Analyzing /Users/fassaad/Programs/ALF/wiki/source/ALF_data/Run_2.2.3.1 ###
/Users/fassaad/Programs/ALF/wiki/source
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:
/Users/fassaad/Programs/ALF/wiki/source/ALF_data/Run_2.2.3.1
No orbital locations saved.
Prepare directory "/Users/fassaad/Programs/ALF/wiki/source/ALF_data/Run_2.2.3.2" for Monte Carlo run.
Resuming previous run.
Run /Users/fassaad/Programs/ALF/ALF/Prog/ALF.out
 ALF Copyright (C) 2016 - 2026 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.
 Warning: Nt_sequential_end is smaller than Nt_sequential_start
 Warning: Nt_sequential_end is smaller than Nt_sequential_start
 Setting N_FL = 2 since this is mandatory for Mz-Hubbard model
### Analyzing /Users/fassaad/Programs/ALF/wiki/source/ALF_data/Run_2.2.3.2 ###
/Users/fassaad/Programs/ALF/wiki/source
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:
/Users/fassaad/Programs/ALF/wiki/source/ALF_data/Run_2.2.3.2
No orbital locations saved.
Prepare directory "/Users/fassaad/Programs/ALF/wiki/source/ALF_data/Run_2.3.1.1" for Monte Carlo run.
Resuming previous run.
Run /Users/fassaad/Programs/ALF/ALF/Prog/ALF.out
 ALF Copyright (C) 2016 - 2026 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.

 User implementation of Global_move is being called!
 Choose a random site and flip all the fields along the time direction


 User implementation of Global_move is being called!
 Choose a random site and flip all the fields along the time direction


 ATTENTION:     Base implementation of Ham_Langevin_HMC_S0_single is being called!
 This uses the subroutine Ham_Langevin_HMC_S0, which provides all bosonic forces.
 Since Ham_Langevin_HMC_S0_single only requires one force this might be inefficient.
 Consider overwriting this routine according to the model in your Hamiltonian.
 Suppressing further printouts of this message.


 ATTENTION:     Base implementation of Ham_Langevin_HMC_S0_single is being called!
 This uses the subroutine Ham_Langevin_HMC_S0, which provides all bosonic forces.
 Since Ham_Langevin_HMC_S0_single only requires one force this might be inefficient.
 Consider overwriting this routine according to the model in your Hamiltonian.
 Suppressing further printouts of this message.

 Setting N_FL = 2 since this is mandatory for Mz-Hubbard model
### Analyzing /Users/fassaad/Programs/ALF/wiki/source/ALF_data/Run_2.3.1.1 ###
/Users/fassaad/Programs/ALF/wiki/source
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:
/Users/fassaad/Programs/ALF/wiki/source/ALF_data/Run_2.3.1.1
No orbital locations saved.
Prepare directory "/Users/fassaad/Programs/ALF/wiki/source/ALF_data/Run_2.3.1.2" for Monte Carlo run.
Resuming previous run.
Run /Users/fassaad/Programs/ALF/ALF/Prog/ALF.out
 ALF Copyright (C) 2016 - 2026 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.

 User implementation of Global_MALA_move is being called!
 Choose a random site and flip all the fields along the time direction


 User implementation of Global_MALA_move is being called!
 Choose a random site and flip all the fields along the time direction


 ATTENTION:     Base implementation of Ham_Langevin_HMC_S0_single is being called!
 This uses the subroutine Ham_Langevin_HMC_S0, which provides all bosonic forces.
 Since Ham_Langevin_HMC_S0_single only requires one force this might be inefficient.
 Consider overwriting this routine according to the model in your Hamiltonian.
 Suppressing further printouts of this message.


 ATTENTION:     Base implementation of Ham_Langevin_HMC_S0_single is being called!
 This uses the subroutine Ham_Langevin_HMC_S0, which provides all bosonic forces.
 Since Ham_Langevin_HMC_S0_single only requires one force this might be inefficient.
 Consider overwriting this routine according to the model in your Hamiltonian.
 Suppressing further printouts of this message.

 Setting N_FL = 2 since this is mandatory for Mz-Hubbard model
### Analyzing /Users/fassaad/Programs/ALF/wiki/source/ALF_data/Run_2.3.1.2 ###
/Users/fassaad/Programs/ALF/wiki/source
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:
/Users/fassaad/Programs/ALF/wiki/source/ALF_data/Run_2.3.1.2
No orbital locations saved.
Prepare directory "/Users/fassaad/Programs/ALF/wiki/source/ALF_data/Run_2.3.3" for Monte Carlo run.
Resuming previous run.
Run /Users/fassaad/Programs/ALF/ALF/Prog/ALF.out
 ALF Copyright (C) 2016 - 2026 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.
 Setting N_FL = 2 since this is mandatory for Mz-Hubbard model
### Analyzing /Users/fassaad/Programs/ALF/wiki/source/ALF_data/Run_2.3.3 ###
/Users/fassaad/Programs/ALF/wiki/source
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:
/Users/fassaad/Programs/ALF/wiki/source/ALF_data/Run_2.3.3
No orbital locations saved.
Prepare directory "/Users/fassaad/Programs/ALF/wiki/source/ALF_data/Run_2.3.4" for Monte Carlo run.
Resuming previous run.
Run /Users/fassaad/Programs/ALF/ALF/Prog/ALF.out
 ALF Copyright (C) 2016 - 2026 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.
 Setting N_FL = 2 since this is mandatory for Mz-Hubbard model
### Analyzing /Users/fassaad/Programs/ALF/wiki/source/ALF_data/Run_2.3.4 ###
/Users/fassaad/Programs/ALF/wiki/source
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:
/Users/fassaad/Programs/ALF/wiki/source/ALF_data/Run_2.3.4
No orbital locations saved.

Compare the results

Energy_Run_2_2_1: Sequential update, discrete field
Ener_scal0           -2.818637
Ener_scal0_err        0.002908
Ener_scal_sign             1.0
Ener_scal_sign_err         0.0
Name: /Users/fassaad/Programs/ALF/wiki/source/ALF_data/Run_2.2.1, dtype: object

Energy_Run_2_2_2_1: Sequential update, continuous field, no MALA
Ener_scal0           -2.818797
Ener_scal0_err        0.020747
Ener_scal_sign             1.0
Ener_scal_sign_err         0.0
Name: /Users/fassaad/Programs/ALF/wiki/source/ALF_data/Run_2.2.2.1, dtype: object

Energy_Run_2_2_2_2: Sequential update, continuous field, with MALA
Ener_scal0           -2.814951
Ener_scal0_err        0.005089
Ener_scal_sign             1.0
Ener_scal_sign_err         0.0
Name: /Users/fassaad/Programs/ALF/wiki/source/ALF_data/Run_2.2.2.2, dtype: object

Energy_Run_2_2_3_1: Sequential + global tau moves, continuous field, no MALA
Ener_scal0            -2.84342
Ener_scal0_err        0.026758
Ener_scal_sign             1.0
Ener_scal_sign_err         0.0
Name: /Users/fassaad/Programs/ALF/wiki/source/ALF_data/Run_2.2.3.1, dtype: object

Energy_Run_2_2_3_2: Sequential + global tau moves, continuous field, with MALA
Ener_scal0           -2.850885
Ener_scal0_err        0.027842
Ener_scal_sign             1.0
Ener_scal_sign_err         0.0
Name: /Users/fassaad/Programs/ALF/wiki/source/ALF_data/Run_2.2.3.2, dtype: object

Energy_Run_2_3_1_1: Sequential MALA + global moves (N_Global=10)
Ener_scal0           -2.819502
Ener_scal0_err        0.004833
Ener_scal_sign             1.0
Ener_scal_sign_err         0.0
Name: /Users/fassaad/Programs/ALF/wiki/source/ALF_data/Run_2.3.1.1, dtype: object

Energy_Run_2_3_1_2: Sequential MALA + global MALA moves (N_Global_MALA_sweeps=10)
Ener_scal0           -2.822262
Ener_scal0_err        0.011694
Ener_scal_sign             1.0
Ener_scal_sign_err         0.0
Name: /Users/fassaad/Programs/ALF/wiki/source/ALF_data/Run_2.3.1.2, dtype: object

Energy_Run_2_3_3: Langevin dynamics update
Ener_scal0           -2.872756
Ener_scal0_err        0.009704
Ener_scal_sign        0.099993
Ener_scal_sign_err    0.000001
Name: /Users/fassaad/Programs/ALF/wiki/source/ALF_data/Run_2.3.3, dtype: object

Energy_Run_2_3_4: HMC update
Ener_scal0           -2.81722
Ener_scal0_err        0.01476
Ener_scal_sign            1.0
Ener_scal_sign_err        0.0
Name: /Users/fassaad/Programs/ALF/wiki/source/ALF_data/Run_2.3.4, dtype: object

Note: Calling sim.run() again resumes the simulation, accumulating more bins and reducing the error bar on the energy. Delete the run directory under ALF_data/ first if you want to start a fresh MALA run instead.