Python code implementing Markov Chain Monte Carlo for 2D and 3D square-lattice Ising model.
- Numba JIT compiling supported
- Multiprocessing supported
Warning
Experiments for a large scale 3D-lattice Ising model consume a lot of energy and time. We strongly recommend you to use a server with decent multi-core CPUs.
It is possible to calculate mean energy, magnetization, specific heat, and susceptibility at various temperatures and save it to a csv file and a plot.
We ran this code for 16000 equilibration steps and 16000 Monte Carlo steps on a 30 x 30 x 30 lattice to get the result above.
Clone the repository:
git clone https://github.com/ising-model/ising-model-python
cd ising-model-python
Create a venv from this directory (NOTE: Python 3.12+ required)
python3 -m venv .venv
source .venv/bin.activate
To install requirements, run the command below after virtual environment has been activated:
pip install -r requirements.txtwhich has been modified to include "setuptools" and remove dependencies on the old numpy.disutils package, which as of Python 3.12+ no longer exists.
- size (default=30): Length of the lattice -> L
- dim (default=3): Dimension of the lattice -> D
- init_temp (default=1.5): Initial temperature -> T_0
- final_temp (default=6.5): Final temperature -> T_f
- temp_step (default=0.04): Temperature step -> dT
- eqstep (default=1000): Number of equilibration steps
- mcstep (default=1000): Number of Monte Carlo steps
- seed (default=0): Random seed
- n_proc (default=0): Number of processes for multiprocessing. If n_proc = 0, then use all CPU cores available
- no_record (default=record): Whether to record the result or not
- no_plot (default=plot): Whether to plot the result or not
To run experiments, run the command below:
python main.py --size 30 --dim 2 --init_temp 1.5 --final_temp 3.5 --temp_step 0.02 --eqstep 1000 --mcstep 1000python main.py --size 30 --dim 3 --init_temp 1.5 --final_temp 6.5 --temp_step 0.04 --eqstep 3000 --mcstep 3000We want to parallelize the sampling procedure using GPU.
We also want to speed up the process using various techniques (e.g. importance sampling).
If you have abundant knowledge of those techniques, please contact us!
