The goal of this project is to provide a highly modular, TensorFlow-based framework for simulating the dynamics of classical spin systems. By leveraging TensorFlow, the project aims to utilize vectorization and potential GPU acceleration to efficiently simulate large lattices and complex interactions. The framework is designed to be easily extensible, allowing researchers to define new models, interactions, and dynamic rules with minimal effort.
The project currently supports the following features:
- Models: unit-vector spin models including Ising (discrete) and Spherical (continuous) systems.
- Interactions: Arbitrary pairwise coupling tensors, with built-in generators for Periodic Nearest-Neighbor, Decaying, Curie-Weiss, and Gaussian random interactions.
- Dynamics: Metropolis-Hastings Monte Carlo dynamics.
- Measurements: Real-time tracking of scalar observables (Energy, Magnetization) and susceptibility.
Compared to other available options for Spin Dynamics:
- TensorFlow Backend: Utilizes modern tensor operations for performance, significantly speeding up updates on large lattices compared to pure Python loops.
- Modular Architecture: Decouples the physical model (spins), the interaction topology (couplings), and the time evolution (dynamics), making it easier to mix and match components.
- Flexible Tracking: Includes a specialized
Trackerclass that can conceptually handle any observable that can be computed from the system state, recording history efficiently usingTensorArrays.
The core logic resides in src/spin_engine, organized into four main modules. Here is how they interact:
Purpose: Defines the physical system, including the lattice structure, spin dimensionality (discrete vs continuous), and the energy function.
- Interactions: Holds
spin_state(the actual configuration) andinteraction_matrix(the couplings). - Key Class:
BaseSpinSystemprovides the interface.IsingSystemandSphericalSystemare concrete implementations.
Purpose: Generates the coupling tensors (
- Interactions: Used by
modelsto initialize the system's Hamiltonian. - Key Classes:
PeriodicNearestNeighborInteraction(standard d-dimensional lattice),DecayingInteraction,CurieWeissInteraction.
Purpose: Defines the rules for time evolution.
-
Interactions: Takes a
systemand modifies itsspin_stateover time. -
Key Classes:
-
MetropolisHastings: Performs Monte Carlo sweeps. It proposes changes (flips or rotations), computes energy differences ($\Delta E$ ), and accepts/rejects based on thermal probabilities. -
Tracker: Observes the simulation. It is passed to thesweepmethod to record measurements at specified intervals.
-
Purpose: Defines observables to be tracked.
- Interactions: Instantiated with a
systemreference. Called byTrackerduring the simulation to compute values like total energy or magnetization. - Key Classes:
Energy,Magnetization,MagneticSusceptibility.
- Define Interaction: Generate an interaction matrix (e.g., Nearest Neighbor).
- Create Model: Initialize a System (e.g., Ising) with the lattice size and interaction matrix.
- Setup Logic: Instantiate
MetropolisHastingsdynamics with the system. - Prepare Tracking: Create a
Trackerwith desiredMeasurements. - Run: Execute
dynamics.sweep(), passing theTracker.
The examples/ directory contains scripts demonstrating the framework capabilities.
The script examples/ising.py performs a temperature sweep on a 2D Ising model. It illustrates phase transitions by tracking magnetization across different inverse temperatures (Beta).
The following plot shows the Monte Carlo time evolution of magnetization for various temperatures. Note the rapid convergence to zero magnetization at high temperatures (low Beta) and stable non-zero magnetization at low temperatures (high Beta).
The project successfully reproduces the critical behavior of the 2D Ising model. The plot below shows the magnetic susceptibility peaking around the critical point (
Lucas Gomes de Oliveira Corbanez
- Email: lucascorbanez@gmail.com
- Institutional: lucas.gomes.oliveira@uel.br

