spin_sim/lib.rs
1//! Pure-Rust Ising model Monte Carlo on periodic Bravais lattices.
2//!
3//! # Algorithms
4//!
5//! | Move | Function |
6//! |------|----------|
7//! | Metropolis / Gibbs sweep | [`run_sweep_loop`] (`sweep_mode`) |
8//! | Wolff / Swendsen-Wang | [`run_sweep_loop`] (`cluster_mode`) |
9//! | Parallel tempering | [`run_sweep_loop`] (`pt_interval`) |
10//! | Houdayer / Jörg / CMR | [`run_sweep_loop`] (`overlap_cluster`) |
11//!
12//! Replicas are parallelized over threads with [`rayon`].
13//! Multiple disorder realizations can be run in parallel with [`run_sweep_parallel`].
14//!
15//! # Quick start
16//!
17//! ```
18//! use spin_sim::config::*;
19//! use spin_sim::{Lattice, Realization, run_sweep_loop};
20//!
21//! let lattice = Lattice::new(vec![16, 16]);
22//! let n_spins = lattice.n_spins;
23//! let n_neighbors = lattice.n_neighbors;
24//! let temps = vec![2.0, 2.27, 2.5];
25//!
26//! // Uniform ferromagnetic couplings
27//! let couplings = vec![1.0f32; n_spins * n_neighbors];
28//! let mut real = Realization::new(&lattice, couplings, &temps, 2, 42);
29//!
30//! let config = SimConfig {
31//! n_sweeps: 5000,
32//! warmup_sweeps: 1000,
33//! sweep_mode: SweepMode::Metropolis,
34//! cluster_update: Some(ClusterConfig {
35//! interval: 1,
36//! mode: ClusterMode::Wolff,
37//! collect_stats: false,
38//! }),
39//! pt_interval: Some(1),
40//! overlap_cluster: None,
41//! autocorrelation_max_lag: None,
42//! sequential: false,
43//! equilibration_diagnostic: false,
44//! };
45//!
46//! use std::sync::atomic::AtomicBool;
47//! let interrupted = AtomicBool::new(false);
48//! let result = run_sweep_loop(
49//! &lattice, &mut real, 2, temps.len(), &config, &interrupted, &|| {},
50//! ).unwrap();
51//! ```
52//!
53//! For a Python interface, see the [`peapods`](https://pypi.org/project/peapods/) package.
54
55pub mod config;
56pub mod geometry;
57pub mod simulation;
58pub mod spins;
59pub mod statistics;
60
61mod clusters;
62mod mcmc;
63mod parallel;
64
65pub use geometry::Lattice;
66pub use simulation::{run_sweep_loop, run_sweep_parallel, Realization};
67pub use statistics::{ClusterStats, Diagnostics, EquilCheckpoint, SweepResult};