Skip to main content

spin_sim/
lib.rs

1//! Pure-Rust Ising model Monte Carlo on periodic hypercubic lattices.
2//!
3//! # Algorithms
4//!
5//! | Move | Function |
6//! |------|----------|
7//! | Metropolis / Gibbs sweep | [`run_sweep_loop`] (`sweep_mode`) |
8//! | Wolff single-cluster | [`run_sweep_loop`] (`cluster_mode = "wolff"`) |
9//! | Swendsen-Wang | [`run_sweep_loop`] (`cluster_mode = "sw"`) |
10//! | Parallel tempering | [`run_sweep_loop`] (`pt_interval`) |
11//! | Houdayer ICM | [`run_sweep_loop`] (`houdayer_interval`) |
12//!
13//! Replicas are parallelized over threads with [`rayon`].
14//!
15//! # Quick start
16//!
17//! ```
18//! use spin_sim::{Lattice, Realization, run_sweep_loop};
19//!
20//! let lattice = Lattice::new(vec![16, 16]);
21//! let n_spins = lattice.n_spins;
22//! let n_dims = lattice.n_dims;
23//! let temps = vec![2.0, 2.27, 2.5];
24//!
25//! // Uniform ferromagnetic couplings
26//! let couplings = vec![1.0f32; n_spins * n_dims];
27//! let mut real = Realization::new(&lattice, couplings, &temps, 2, 42);
28//!
29//! let result = run_sweep_loop(
30//!     &lattice, &mut real,
31//!     2, temps.len(),
32//!     5000, 1000,
33//!     "metropolis",
34//!     Some(1), "wolff",
35//!     Some(1), None,
36//!     &|| {},
37//! );
38//! ```
39//!
40//! For a Python interface, see the [`peapods`](https://pypi.org/project/peapods/) package.
41
42pub mod lattice;
43pub mod simulation;
44
45mod clusters;
46mod energy;
47mod parallel;
48mod stats;
49mod sweep;
50mod tempering;
51
52pub use lattice::Lattice;
53pub use simulation::{aggregate_results, run_sweep_loop, Realization, SweepResult};