Efficient and stable Determinant Quantum Monte Carlo simulations in Python
MIT License
Master | |||
Dev |
Efficient and stable Determinant Quantum Monte Carlo (DQMC) simulations of the Hubbard model in Python.
⚠️ WARNING: This project is still in development and might contain errors or change significantly in the future! |
---|
Uses just in time compilation (jit) and optional Fortran implementations for the most expensive methods of the Determinant Quantum Monte Carlo iteration to achieve efficient simulations accesable through a Python interface. The computation of the inversion of cyclic matrices is stabilized via the ASvQRD (Accurate Solution via QRD with column pivoting) algorithm (see Ref [6]) in order to obtain better results at low temperatures.
Install via pip
from github:
pip install git+https://github.com/dylanljones/dqmc.git@VERSION
or download/clone the package, navigate to the root directory and install via
pip install -e <folder path>
or the setup.py
script
python setup.py install
Run the Makefile
to compile the Fortran source code!
To run a simulation, run the python -m dqmc
command with a configuration text file
as parameter, for example:
python -m dqmc examples/chain.txt
Multiple simulations can be run by supplying keyword arguments. The command
python -m dqmc examples/chain.txt -mp 4 -hf -u 1 ... 4 -p moment
will run the DQMC simulation with the parameters of the file for the interaction
strengths 1, 2, 3, 4
at half filling (-hf
) and plot the local moment.
In order to use multiprocessing the number of processes can be specified by the
-mp
argument. Use
python -m dqmc --help
for more information.
shape
U
eps
t
mu
0
for half filling.dt
(optional)beta
(optional)dt
.temp
(optional)dt
.L
nequil
nsampl
nwraps
(optional)prodLen
(optional)recomp
(optional)See the examples
directory and the run_examples.py
script.
Average local moment <n_↑> + <n_↓> - 2 <n_↑ n_↓>
as a function of temperature
for different interaction strengths U
at half filling:
chain.txt | square.txt |
---|---|
The local moment begins to develop from its uncorrelated value 1/2
at a temperature
set by U
, and then saturate at low T
. The local moment does not reach 1
at
low temperatures because significant quantum fluctuations allow doubly occupied
and empty sites to occur even in the ground state. However, as U
increases,
these fluctuations are suppressed and the moment becomes better and better formed.
In order to run a simulation, a Hubbard model has to be constructed. This can be
done manually by initializing the included HubbardModel
:
import numpy as np
from dqmc import HubbardModel
# Initialize a square Hubbard model
vectors = np.eye(2)
model = HubbardModel(vectors, u=4., eps=0., hop=1., mu=0., beta=1/5)
model.add_atom() # Add an atom to the unit cell
model.add_connections(1) # Set nearest neighbor hoppings
# Build the lattice with periodic boundary conditions along both axis
model.build((5, 5), relative=True, periodic=(0, 1))
or by using the helper function hubbard_hypercube
to construct a d
-dimensional
hyper-rectangular Hubbard model with one atom in the unit cell and nearest neighbor
hopping:
from dqmc import hubbard_hypercube
shape = (5, 5)
model = hubbard_hypercube(shape, u=4., eps=0., hop=1., mu=0., beta=1/5, periodic=True)
Setting periodic=True
marks all axis as periodic.
To run a Determinant Quantum Monte carlo simulation the DQMC
-object can be used.
This is a wrapper of the main DQMC methods, which are contained in dqmc/dqmc.py
and use jit (just in time compilation) to improve performance:
from dqmc import hubbard_hypercube, mfuncs, DQMC
shape = (5, 5)
num_timesteps = 100
warmup, measure = 300, 3000
model = hubbard_hypercube(shape, u=4., eps=0., hop=1., mu=0., beta=1/5, periodic=True)
dqmc = DQMC(model, num_timesteps, num_recomp=1, prod_len=1, seed=0)
results, out = dqmc.simulate(warmup, measure, callback=mfuncs.occupation)
The simulate
-method measures the observables
gf_up
:<G_↑>
.gf_dn
:<G_↓>
.n_up
:<n_↑>
.n_dn
:<n_↓>
.n_double
:<n_↑ n_↓>
.local_moment
:<n_↑> + <n_↓> - 2 <n_↑ n_↓>
.out
:0
if no callback is passed)Additionally, the simulate
-method has a callback
parameter for measuring observables, which
expects a method of the form
def callback(self, *args, **kwargs):
...
return result
where self
is the DQMC
instance.
The returned result must be castable to a np.ndarray
for ensuring correct averaging after the
measurement sweeps. A collection of methods for measuring observables is contained
in the mfuncs
module.
The above steps can be simplified by creating a Parameter
object and calling the run_dqmc
-method.
from dqmc import run_dqmc, mfuncs, Parameters
shape = 10
u, eps, mu, hop = 4.0, 0.0, 0.0, 1.0
dt = 0.05
num_timesteps = 100
warmup, measure = 300, 3000
p = Parameters(shape, u, eps, hop, mu, dt, num_timesteps, warmup, measure)
gf_up, gf_dn, n_up, n_dn, n_double, moment, gftau0_up, gftau0_dn, occ = run_dqmc(p, callback=mfuncs.occupation)
The default observables are returned first, folled by the result of the callback (0
if no callback is passed).
To run multiple DQMC simulations in parallel use the run_dqmc_parallel
-method,
which internally calls the run_dqmc
-method. A list of Parameters
-objects
can be created via the map_params
-method:
from dqmc import map_params, run_dqmc_parallel
params = map_params(p, u=[1, 2, 3, 4, 5])
results = run_dqmc_parallel(params, max_workers=4)
ToDo's:
Before submitting pull requests, run the lints, tests and optionally the black formatter with the following commands from the root of the repo:
python -m black dqmc/
pre-commit run
or install the pre-commit hooks by running
pre-commit install