Metropolis Monte Carlo sampler for the 2D Ising model with periodic boundaries (J=1). It produces 1,000 configurations from a 10×10 lattice by default (1,000,000 spin-flip attempts, saving every 1,000 steps) and writes them with energies to training_data.txt.
- Python 3.8+ (tested on 3.12)
Generate the default dataset:
python ising_mcmc.pyWith verbose progress every 50k steps:
python ising_mcmc.py --verbose --log-interval 50000Tune temperature (beta = 1/kT), lattice size, sampling cadence, and output path:
python ising_mcmc.py --beta 0.2 --steps 100000000 --sample-interval 10000 --verbose --log-interval 50000Set a seed for reproducibility:
python ising_mcmc.py --seed 42training_data.txt is CSV-like with a header:
energy,spin
-79.000000,"[1, 0, 1, ...]"
energy: absolute total energy of the lattice at that snapshot (ground-state degeneracy treated symmetrically).spin: flattened row-major list of spins, encoded as 0/1 for (-1/+1).
- Coupling
J=1; periodic boundary conditions. - Uses the Metropolis acceptance rule with single-spin flips.