statistical-physics
Skill0 starsChanged 2 days agoMITView on GitHub
Statistical mechanics on the computer: ensemble and thermostat choice, Monte Carlo samplers, autocorrelation-aware error bars, structure factors, finite-size scaling at transitions, and active matter. Use when a simulation result needs a statistical-mechanics check.
In this repository55 other files it gives its agents.
- advanced-optimizationSkill
- bayesian-inferenceSkill
- bayesian-pinnSkill
- bayesian-ude-workflowSkill
- catalyst-reactionsSkill
- continuum-mechanics-and-rheologySkill
- control-theorySkill
- creating-julia-appSkill
- debugging-toolkitSkill
- differential-equationsSkill
- differentiationSkill
- equation-discoverySkill
- experiment-trackingSkill
- fem-feaSkill
- julia-graph-neural-networksSkill
- julia-languageSkill
- julia-ml-and-dlSkill
- julia-model-deploymentSkill
- julia-paper-implementationSkill
- julia-pro-helpSkill
- julia-pro-modeSkill
- julia-reinforcement-learningSkill
- modeling-toolkitSkill
- neural-pdeSkill
- nonlinear-dynamicsSkill
- numerical-methods-implementationSkill
- package-development-workflowSkill
- performance-tuningSkill
- physical-learning-systemsSkill
- playbook-debugSkill
- playbook-model-validateSkill
- playbook-package-releaseSkill
- playbook-paper-implementSkill
- playbook-perfSkill
- playbook-test-specSkill
- principle-both-sidesSkill
- principle-breakingSkill
- principle-file-is-truthSkill
- principle-gateSkill
- principle-limitsSkill
- principle-loud-failureSkill
- principle-one-stepSkill
- principle-proof-listSkill
- principle-rebuttalSkill
- principle-runtime-surfaceSkill
- principle-three-boundsSkill
- principle-three-clocksSkill
- scientific-visualizationSkill
- sciml-and-diffeqSkill
- setup-julia-proSkill
- signal-processingSkill
- simulation-and-hpcSkill
- symbolic-mathSkill
- web-development-juliaSkill
- zarr-cloud-arraysSkill
The file
Files
Statistical Physics
Depth
| Topic | Where |
| MD setup and learned force fields | md-simulation-setup, ml-force-fields |
| transient networks, active matter | transient-networks-and-can |
Fix the ensemble first
| What you want | Ensemble | Thermostat, and what it costs |
| dynamics, transport coefficients | NVE | none — a thermostat corrupts the Green-Kubo integral |
| equilibrium averages at fixed T | NVT | Langevin (physical, cheap) or Nosé-Hoover (deterministic, ergodic only if the chain is long enough) |
| density under pressure | NPT | barostat + thermostat, and check the box is not drifting |
| adsorption, pore loading | grand canonical | insertion/deletion acceptance falls off exponentially with system size |
A thermostat changes the dynamics it is attached to. If you report a diffusion coefficient or a viscosity, either run NVE or show the thermostat-free and thermostatted results agree.
Samplers
| Update | Use for | Notes |
| Metropolis-Hastings | generic equilibrium sampling, lattice models, classical fluids | ~20 lines in Julia; acceptance tuned to 30–50% |
| Heat bath / Glauber | Ising-like lattices | no accept/reject, so no tuning |
| Cluster (Wolff, Swendsen-Wang) | near a continuous transition | removes critical slowing down; required once τ diverges |
| Wang-Landau | density of states, free energy across a first-order line | flat-histogram, self-tuning |
| Parallel tempering | rough landscapes, spin glasses, multimodal | swap acceptance min(1, exp((β_i - β_j)(E_i - E_j))) |
| Kinetic Monte Carlo | dynamics with a time-scale separation | Gillespie-type; the rate catalogue is the model |
Scale decides the ecosystem: above ~10⁶ spins or ~10⁴ atoms, drive LAMMPS or HOOMD-blue (they ship the update rules and MPI replica exchange) from Julia, and use Julia for the analysis. At research-prototype scale a hand-rolled Metropolis loop runs at C speed because the inner step is type-stable and allocation-free.
using StaticArrays, Random
@inline function ΔE(spins, i, j, L, J = 1.0)
s = spins[i, j]
nn = spins[mod1(i+1, L), j] + spins[mod1(i-1, L), j] +
spins[i, mod1(j+1, L)] + spins[i, mod1(j-1, L)]
2 * J * s * nn
end
function sweep!(spins, β, rng)
L = size(spins, 1)
for _ in 1:L^2
i, j = rand(rng, 1:L), rand(rng, 1:L)
δ = ΔE(spins, i, j, L)
if δ ≤ 0 || rand(rng) < exp(-β * δ)
spins[i, j] = -spins[i, j]
end
end
endThe trap in that loop is the rand(rng, 1:L), rand(rng, 1:L) pair per spin: it allocates nothing but it does draw two random numbers per site, which is where half the runtime goes. Draw one integer and decode it when speed matters.
Error bars on correlated samples
Consecutive samples are correlated, so std(x) / sqrt(N) is wrong by roughly sqrt(2τ). Compute the integrated autocorrelation time τ and report N_eff = N / (2τ).
- Log-binning is the cheapest estimator: recursively average neighbouring samples, and the plateau in
var_bin · bin_sizeis2τ · var. A variance that keeps rising with bin size means the run is too short. - Jackknife for derived quantities (ratios, susceptibilities, Binder cumulants), where error propagation through a ratio is messy.
- Bootstrap with a block length above
τwhen the estimator is not a smooth function of means.
Thermalisation is the same question: discard until the observable has decorrelated, not until a fixed number of sweeps feel like enough.
What the run must check
- Equilibration: the observable's running mean is flat over the last few τ, not just trending less.
- Fluctuation-dissipation:
C_v = β²(⟨E²⟩ - ⟨E⟩²)/Nfrom the fluctuations must agree with the derivative of⟨E⟩taken from a temperature scan. This catches a thermostat that is not actually sampling the canonical ensemble. - Structure factor
S(q)from the positions directly (or fromg(r)), withq_min = 2π/L: a peak below the box's smallest q is a finite-size artefact, not a phase. - Finite-size scaling: locate a transition by the crossing of a Binder cumulant across
L, then extrapolateT_c(L); a transition reported from a single box is a crossover. - Scaling relations (Rushbrooke, Widom) hold for the exponents you claim; if they do not, the exponents came from fits without error bars.
Active matter
Self-propelled particles break detailed balance, so equilibrium estimators do not apply: no Boltzmann reweighting, no free energy from a work average without an entropy-production term. Report the Péclet number, the run length in persistent-motion times, and analyse motility-induced phase separation by cluster statistics rather than by an order parameter borrowed from equilibrium.
Traps
std / sqrt(N)on a correlated chain. The error bar comes out too small bysqrt(2τ), andτnear a transition can be thousands of sweeps.- A thermostat on a dynamic measurement. The diffusion coefficient then measures the thermostat.
- One box, one temperature, a claimed transition. Locate it by a cumulant crossing and scale.
- A
g(r)orS(q)from a box smaller than the correlation length. The structure is truncated, not measured. - Wang-Landau without the
1/tflattening check. The histogram looks flat while the density of states is still biased.
Done when
The ensemble and thermostat match the quantity reported (NVE for transport, NVT/NPT for equilibrium averages), τ was measured and every error bar is quoted on N_eff rather than N, the fluctuation-dissipation or equipartition check agrees with an independent estimate, and any claimed transition was located by finite-size scaling across at least three box sizes with exponents that satisfy the scaling relations.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

