A flexible and extensible framework for simulating classical spin systems on arbitrary lattices using the Metropolis-Hastings Monte Carlo algorithm. The code supports a variety of models and interaction structures, enabling the study of statistical mechanics phenomena in both standard and exotic settings.
The energy of a spin configuration is defined by a general quadratic form:
$$
\mathcal{H} = \sum_{pq} J_{pq} \sigma_p \sigma_q
$$
where
-
Ising Model
Spins$\sigma_i = \pm 1$ on a lattice, with Hamiltonian: $$ \mathcal{H}{\text{Ising}} = -\sum{ij} J_{ij} \sigma_i \sigma_j - \sum_i h_i \sigma_i $$ Supports arbitrary interaction matrices and external fields. -
Spherical Model
Continuous spins constrained by$\sum_i \sigma_i^2 = N$ , with Hamiltonian: $$ \mathcal{H}{\text{Spherical}} = -\sum{ij} J_{ij} \sigma_i \sigma_j - \sum_i h_i \sigma_i $$ The spherical constraint can be enforced optionally. -
$\mathbb{Z}_2$ Gauge Model
Defined on 2D lattices with link variables and plaquette interactions. The Hamiltonian is constructed from products of link variables around plaquettes, supporting arbitrary coupling matrices. $$ \mathcal{H}{\text{Z2 Gauge}} = -\sum{p} \prod_{\ell \in p} \sigma_\ell $$
The simulation uses the Metropolis-Hastings algorithm to sample spin configurations according to the Boltzmann distribution at inverse temperature
- Ising Model: Random single-spin flips.
- Spherical Model: Random pairwise spin rotations, optionally enforcing the spherical constraint.
-
$\mathbb{Z}_2$ Gauge Model: Random flips of gauge links.
Energy changes are computed efficiently using local field updates and explicit matrix operations.
- Arbitrary lattice dimension and size.
- Multiple replicas for parallel simulation.
- User-defined interaction matrices and external fields.
- Observable tracking: energy, magnetization, overlap matrix, plaquette values, Wilson loops (for gauge models).
- Multi-temperature sweeps for studying phase transitions.
- Parallel programming and GPU acceleration via TensorFlow for high-performance simulations.
- TensorFlow-based for efficient computation and automatic differentiation.
This project is a work in progress.
Features, APIs, and documentation may change. Contributions and feedback are welcome.
-
Define the interaction matrix
$J_{pq}$ and (optionally) the external field. -
Initialize a
SpinSystemwith desired parameters (lattice size, model type, etc.). -
Run simulations using
metropolis_sweepormulti_temperature_sweep. - Analyze observables such as energy, magnetization, and overlaps.
- Sandvik, A. W. (2010). Computational Studies of Quantum Spin Systems.
- Altieri, A. (2024). Introduction to the Theory of Spin Glasses.
- Bienzobaz, P. (2012). Quantização Canônica e Integração Funcional.