spin-sim
Pure-Rust Ising and XY Monte Carlo on periodic lattices: hypercubic, or any Bravais
lattice given by forward neighbor offsets (Lattice::with_offsets).
Algorithms
- Single-spin flips (Metropolis, Gibbs)
- Swendsen-Wang cluster updates
- Wolff single-cluster updates
- Parallel tempering (replica exchange)
- Overlap cluster moves (Houdayer / pairN / Jörg / CMR / permN / gpermN / replica Monte Carlo) for spin glasses
- Open and antiperiodic boundaries as a coupling transform (
Lattice::boundary_factors)
Replicas are parallelized over threads with rayon.
Usage
use *;
use ;
let lattice = new;
let temps = vec!;
let n_replicas = 2;
// A fixed ±1 pattern (+1 along axis 0, -1 along axis 1) is unfrustrated;
// draw random signs per bond for a ±J spin glass.
let couplings: =
.map
.collect;
let mut real = new;
let config = SimConfig ;
use AtomicBool;
let interrupted = new;
let result = run_sweep_loop.unwrap;
println!;
Upgrading from 0.2.0
0.3.0 changes public struct literals and enums; no legacy wrapper types are provided. To keep 0.2.0's move schedule:
ClusterConfigandOverlapClusterConfig: addaction: ClusterAction::Update(cluster graphs can now also be observed without flipping spins).OverlapClusterConfig: addmax_temperature: None.SimConfig: addpt_schedule: PtSchedule::SingleRandomEdgeandautocorrelation_backend: AutocorrelationBackend::Ring.OverlapClusterBuildMode::Jorgis nowJorg(usize); useJorg(2). The new variantsPair(usize)andRmc, andSweepMode::None, break exhaustive matches.
Realization seeds are now derived per system rather than base_seed + i, so a given
seed produces different trajectories than in 0.2.0.
Also new in 0.3.0:
SimConfig::validateis an inherent method returningResult<(), String>; thevalidatordependency is gone.SimConfighas a new fieldconditional_link_overlap(settrueto keep the link-overlap sums per overlap bin) andXyConfiga new fieldmeasure_interval(set1).- Overlap modes
Perm(usize)andGaugedPerm(usize)break exhaustive matches; their size must be between 2 and 8, as validation now enforces. - Moments of a call that measured nothing are NaN instead of zero, and a τ of a series
without variance is NaN instead of 0.5. Each τ has a
*_convergedflag. - Interval events keep their phase across calls;
resetrestarts it. - Lattices with an extent of 1 are rejected.
SweepResult,ClusterStats,DiagnosticsandGraphObservationSummarygained fields (per-disorder samples, energy τ, FK visit counts, overlap and replica Monte Carlo counters, 3D wrapping and cluster moments).- Swendsen-Wang Houdayer, pair and Jörg moves now update single-site clusters, so their trajectories differ from earlier builds.
Python
For a batteries-included Python interface, see peapods.
XY models
XySimulation and XyConfig expose periodic hypercubic XY sampling with finite
signed couplings, embedded SW/Wolff, Metropolis, Gibbs (heat bath), optional
overrelaxation and PT.
Spins and physical moments use f64; the driver and cluster traversal are shared
with Ising. See the XY guide for conventions, dilution, block
statistics and finite-size validation, and the XySimulation Rust API docs.