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
Builds ALF from the master branch.
Sets up the parameter file for the 6-site Hubbard model.
Compiles and loops over various updating schemes.
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
Amplitudearound 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) andMax_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 inContinuousfield 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 forN_Global/N_Global_MALA_sweepssub-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 orderDelta_t_Langevin_HMCthat 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_stepssteps of sizeDelta_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:
from py_alf import ALF_source, Simulation # Interface with ALF2. Point ALF_source at the existing local ALF checkout, instead of cloning a fresh copy:
alf_src = ALF_source(
url="https://github.com/ALF-QMC/ALF",
branch="305-proposal-of-updates-with-langevin-equation",
)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:
# Parameters shared by every simulation in the sweep
base_params = {
"Lattice_type": "N_leg_ladder",
"L1": 1,
"L2": 6,
"Model": "Hubbard",
"Checkerboard": True,
"Symm": True,
"N_SUN": 2,
"N_FL": 1,
"Dtau": 0.1,
"Beta": 4.0,
"Projector": False,
"Theta": 10.0,
"Nwrap": 10,
"NSweep": 500,
"NBin": 5,
"Ltau": 0,
"Mz": True,
"ham_T": 1.0,
"ham_chem": 0.0,
"ham_U": 4.0,
"Propose_S0": False,
"Amplitude": 0.5,
"Delta_t_MALA_sequential": 0.5,
"Max_Force_MALA_sequential": 5.0,
"Global_tau_moves": False,
"N_global_tau": 6,
"N_global_tau_MALA": 1,
"Delta_t_MALA_global_tau": 0.5,
"Max_Force_MALA_global_tau": 5.0,
"Delta_t_MALA_global": 0.5,
"Max_Force_MALA_global": 5.0,
"CPU_MAX":0.017,
}
# Each entry below overrides base_params for one run. Add, remove, or edit
# entries here to sweep over any variable(s), e.g. Continuous, Propose_MALA,
# or Delta_t_MALA_sequential.
variants = {
"Run_2.2.1": {"desc": "Sequential update, discrete field",
"Sequential": True,"Continuous": False, "Sequential_MALA": False},
"Run_2.2.2.1": {"desc": "Sequential update, continuous field, no MALA",
"Sequential": True,"Continuous": True, "Sequential_MALA": False},
"Run_2.2.2.2": {"desc": "Sequential update, continuous field, with MALA",
"Sequential": True,"Continuous": True, "Sequential_MALA": True},
"Run_2.2.3.1": {"desc": "Sequential + global tau moves, continuous field, no MALA",
"Sequential": True, "Global_tau_moves": True, "Continuous": True, "Sequential_MALA": False},
"Run_2.2.3.2": {"desc": "Sequential + global tau moves, continuous field, with MALA",
"Sequential": True, "Global_tau_moves": True, "Continuous": True, "Sequential_MALA": True},
"Run_2.3.1.1": {"desc": "Sequential MALA + global moves (N_Global=10)",
"Sequential": True, "Continuous": True, "Sequential_MALA": True,
"Global_moves": True, "N_Global": 10},
"Run_2.3.1.2": {"desc": "Sequential MALA + global MALA moves (N_Global_MALA_sweeps=10)",
"Sequential": True, "Continuous": True, "Sequential_MALA": True,
"Global_MALA_moves": True, "N_Global_MALA_sweeps": 10},
"Run_2.3.3" : {"desc": "Langevin dynamics update",
"Sequential": False, "Langevin": True, "Continuous": True, "Delta_t_Langevin_HMC": 0.1, "Max_Force":5.0},
"Run_2.3.4" : {"desc": "HMC update",
"Sequential": False, "HMC": True, "Continuous": True, "Delta_t_Langevin_HMC": 0.5, "Leapfrog_steps":100, "NSweep": 50,},
}
descriptions = {}
sims = {}
for sim_dir, overrides in variants.items():
overrides = overrides.copy()
descriptions[sim_dir] = overrides.pop("desc", "")
params = {**base_params, **overrides}
sims[sim_dir] = Simulation(
alf_src,
"Hubbard",
params,
machine='GNU', # Change to "intel", or "PGI" if gfortran is not installed
mpi=True,
devel=False,
sim_dir=sim_dir,
)4. Compile ALF. The first time it will also download and compile HDF5, which could take minutes.
next(iter(sims.values())).compile()
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:
for sim_dir, sim in sims.items():
sim.run()
sim.analysis()
obs = sim.get_obs()
# dots in sim_dir are not valid in identifiers, so sanitize for the variable name
var_name = f"Energy_{sim_dir.replace('.', '_')}"
globals()[var_name] = obs.iloc[0][['Ener_scal0', 'Ener_scal0_err', 'Ener_scal_sign', 'Ener_scal_sign_err']]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¶
for sim_dir in sims:
var_name = f"Energy_{sim_dir.replace('.', '_')}"
print(f"{var_name}: {descriptions.get(sim_dir, '')}")
print(globals()[var_name])
print()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.