Public interfaces

Documentation for SpinMonteCarlo.jl's public interface (exported).

Driver

SpinMonteCarlo.runMCFunction
runMC(param::Parameter)
runMC(params::AbstractArray{Parameter}
      ;
      parallel::Bool=false,
      autoID::Bool=true)

Runs Monte Carlo simulation(s) and returns calculated observables.

Restart

If a checkpoint file named "$(param["Checkpoint Filename Prefix"])_$(param["ID"]).dat" exists and param["Checkpoint Interval"] > 0.0, runMC loads this file and restarts the pending simulation. NOTE: Restart will fail if the version or the system image of julia change (see the doc of Serialization.serialize ).

Keyward arguments

  • autoID: If true, "ID"s will be set (overwritten) as params[i]["ID"] = i. Because a child seed is derived from ("Seed", "ID"), this is what makes a set of simulations sharing one "Seed" use distinct random number streams.
  • parallel: If true, runs simulations in parallel (uses pmap instead of map).

Required keys in param

  • "Model"
  • "Lattice"
  • "Update Method"

Optional keys in param

  • "MCS": The number of Monte Carlo steps after thermalization
    • Default: 8192
  • "Thermalization": The number of Monte Carlo steps for thermalization
    • Default: MCS>>3
  • "Binning Size": The size of binning
    • Default: 0
  • "Number of Bins": The number of bins
    • Default: 0
    • If both "Binning Size" and "Number of Bins" are not given, "Binning Size" is set to floor(sqrt(MCS)).
  • "Seed": The initial seed of the random number generator.
    • Default: determined randomly (the generator is seeded from system entropy)
    • When "ID" is also given, a child seed is derived from the pair ("Seed", "ID"), so simulations sharing one seed still use distinct random number streams. The derivation is arithmetic and reproduces across julia versions; it requires "Seed" to be an integer.
  • "RNG": The type (not an instance) of the random number generator.
    • Default: Random.Xoshiro
    • Only the constructor the other keys call for is needed: T(seed) when "Seed" is given, T() when it is not. Random.RandomDevice and Random.TaskLocalRNG provide only the latter, so they work only without "Seed".
    • Random.MersenneTwister selects the generator used before v1.3.
  • "Checkpoint Filename Prefix": See the "Restart" section.
    • Default: "cp"
  • "ID": Job ID. Used both for the checkpoint filename (see the "Restart" section) and, together with "Seed", for deriving a per-job random number stream.
    • Default: 0. Note that no child seed is derived when the key itself is absent, so a single runMC(param) without "ID" depends on "Seed" alone.
  • "Checkpoint Interval": Time interval between writing checkpoint file in seconds.
    • Default: 0.0, this means that NO checkpoint file will be loaded and saved.
  • "Snapshot Interval": Number of measurement MCS between snapshot writes. This is measured in MCS, not seconds. A value of 0 disables snapshots.
    • Default: 0
    • When restarting with snapshots enabled before and after the checkpoint, changing this value or "Thermalization" is rejected to preserve the snapshot schedule, as is shrinking "MCS" below the progress the checkpoint holds. Parameters driving the chain itself ("Update Method", "T", "J", ...) are not checked: restarting with a different temperature is allowed and produces snapshots that do not correspond to a single simulation.
  • "Snapshot Filename Prefix": Prefix for snapshot files. The filename is "<prefix>_<ID>.txt".
    • Default: "snapshot"
source

Lattice

Base.sizeFunction
size(lat::Lattice, [dim::Integer])
size(model::Model, [dim::Integer])

Returns the size of lattice.

source
SpinMonteCarlo.sitesFunction
sites(lat::Lattice, [sitetype::Integer])
sites(model::Model, [sitetype::Integer])

Returns an iterator over sites with sitetype (if omitted, over all sites)

source
SpinMonteCarlo.bondsFunction
bonds(lat::Lattice, [bondtype::Integer])
bonds(model::Model, [bondtype::Integer])

Returns an iterator over bonds with bondtype (if omitted, over all bonds)

source
SpinMonteCarlo.numsitesFunction
numsites(lat::Lattice)
numsites(model::Model)

Returns the number of all sites.

source
numsites(lat::Lattice, sitetype::Integer)
numsites(model::Model, sitetype::Integer)

Returns the number of sitetype sites.

source
SpinMonteCarlo.numbondsFunction
numbonds(lat::Lattice)
numbonds(model::Model)

Returns the number of all bonds.

source
numbonds(lat::Lattice, bondtype::Integer)
numbonds(model::Model, bondtype::Integer)

Returns the number of bondtype bonds.

source
SpinMonteCarlo.neighborsFunction
neighbors(site::Site)
neighbors(lat::Lattice, site::Integer)
neighbors(model::Model, site::Integer)

Returns the index pairs of neighbor sites and bonds of site.

source
SpinMonteCarlo.neighborsitesFunction
neighborsites(site::Site)
neighborsites(lat::Lattice, site::Integer)
neighborsites(model::Model, site::Integer)

Returns the indecies of neighbor sites of site.

source
SpinMonteCarlo.neighborbondsFunction
neighborbonds(site::Site)
neighborbonds(lat::Lattice, site::Integer)
neighborbonds(model::Model, site::Integer)

Returns the indecies of neighbor bonds of site.

source
SpinMonteCarlo.sourceFunction
source(bond::Bond)
source(lat::Lattice, bond::Integer)
source(model::Model, bond::Integer)

Returns the source site index of bond.

source
SpinMonteCarlo.targetFunction
target(bond::Bond)
target(lat::Lattice, bond::Integer)
target(model::Model, bond::Integer)

Returns the target site of bond.

source
SpinMonteCarlo.sitetypeFunction
sitetype(site::Site)
sitetype(lat::Lattice, site::Integer)
sitetype(model::Model, site::Integer)

Returns the type of site

source
SpinMonteCarlo.bondtypeFunction
bondtype(bond::Bond)
bondtype(lat::Lattice, bond::Integer)
bondtype(model::Model, bond::Integer)

Returns the type of bond.

source
SpinMonteCarlo.sitecoordinateFunction
sitecoordinate(site::Site)
sitecoordinate(lat::Lattice, site::Integer)
sitecoordinate(model::Model, site::Integer)

Returns the coordinate of the site in the Cartesian system

source
SpinMonteCarlo.bonddirectionFunction
bonddirection(bond::Bond)
bonddirection(lat::Lattice, bond::Integer)
bonddirection(model::Model, bond::Integer)

Returns the unnormalized direction of the bond as vector in the Cartesian system

source
SpinMonteCarlo.cellcoordinateFunction
cellcoordinate(site::Site)
cellcoordinate(lat::Lattice, site::Integer)
cellcoordinate(model::Model, site::Integer)

Returns the coordinate of the cell including site in the Lattice system

source

Model

SpinMonteCarlo.IsingType

Ising model with energy $E = -\sum_{ij} J_{ij} \sigma_i \sigma_j$, where $\sigma_i$ takes value of 1 (up spin) or -1 (down spin).

source
SpinMonteCarlo.PottsType

Q state Potts model with energy $E = -\sum_{i,j} \delta_{\sigma_i, \sigma_j}$, where $\sigma_i$ takes an integer value from $1$ to $Q$ and $\delta$ is a Kronecker's delta. Order parameter (total magnetization) is defined as \begin{equation} M = \frac{Q-1}{Q}N1 - \frac{1}{Q}(N-N1), \end{equation} where $N$ is the number of sites and $N_1$ is the number of $\sigma=1$ spins.

source
SpinMonteCarlo.ClockType

Q state clock model with energy $E = -\sum_{ij} J_{ij} \cos(\theta_i - \theta_j)$, where $\theta_i = 2\pi \sigma_i/Q$ and $\sigma_i$ takes an integer value from $1$ to $Q$.

source
SpinMonteCarlo.XYType

XY model with energy $E = -\sum_{ij} J_{ij} \cos(\theta_i - \theta_j)$, where $\theta_i = 2\pi \sigma_i$ and $\sigma_i \in [0, 1)$.

source
SpinMonteCarlo.AshkinTellerType

AshkinTeller model with energy $E = -\sum_{ij} J^\sigma_{ij} \sigma_i \sigma_j + J^\tau_{ij} \tau_i \tau_j + K_{ij} \sigma_i \sigma_j \tau_i \tau_j$, where $\sigma_i$ and $\tau_i$ takes value of 1 (up spin) or -1 (down spin).

source
SpinMonteCarlo.QuantumXXZType

Spin-$S$ XXZ model represented as the following Hamiltonian,

$\mathcal{H} = \sum_{i,j} \left[ J_{ij}^z S_i^z S_j^z + \frac{J_{ij}^{xy}}{2} (S_i^+ S_j^- + S_i^-S_j^+) \right] - \sum_i \Gamma_i S_i^x,$

where $S^x, S^y, S^z$ are $x, y$ and $z$ component of spin operator with length $S$, and $S^\pm \equiv S^x \pm iS^y$ are ladder operator. A state is represented by a product state (spins at $\tau=0$) of local $S^z$ diagonal basis and an operator string (perturbations). A local spin with length $S$ is represented by a symmetrical summation of $2S$ sub spins with length $1/2$.

source

Update method

An index of model parameter (e.g., Js) is corresponding to sitetype or bondtype.

SpinMonteCarlo.SW_update!Function
SW_update!(model, param::Parameter)

Updates spin configuration by Swendsen-Wang algorithm

Frustrated systems

For Ising, cluster updates remain exact for any sign of couplings (antiferromagnetic and mixed-sign cases included): only satisfied bonds (J σ σ > 0) are activated, and whole clusters are flipped. On unfrustrated (bipartite) lattices an antiferromagnet is gauge-equivalent to a ferromagnet, and clusters track the staggered correlations, so the usual acceleration is retained. On frustrated lattices (loops with an odd number of antiferromagnetic bonds, e.g. an antiferromagnet on the triangular lattice), results are still unbiased, but clusters decouple from the physical correlations and grow large (eventually percolating) already at temperatures where physical correlations are still short-ranged; expect no speedup over local_update! (this is a relaxation issue, not a correctness issue).

source
SpinMonteCarlo.Wolff_update!Function
Wolff_update!(model, param::Parameter)

Updates spin configuration by Wolff algorithm

Frustrated systems

The same caveat as SW_update! applies: exact for any sign of couplings, but no acceleration should be expected on frustrated lattices.

source
SpinMonteCarlo.loop_update!Function
loop_update!(model, param::Parameter)

Updates spin configuration by loop algorithm

source
loop_update!(model, param::Parameter)
loop_update!(model, T::Real,
             Jz::AbstractArray,
             Jxy::AbstractArray,
             Gamma:AbstractArray)

Updates spin configuration by loop algorithm under the temperature T = param["T"] and coupling constants Jz, Jxy and transverse field Gamma

source

Estimator

SpinMonteCarlo.simple_estimatorFunction
simple_estimator(model::Ising, T::Real, Js::AbstractArray)

Returns the following observables as Dict{String, Any}

Observables

  • "Energy"
    • energy density
  • "Energy^2"
    • square of energy density
  • "Magnetization"
    • magnetization density
  • "|Magnetization|"
    • absolute value of magnetization density
  • "Magnetization^2"
    • square of magnetization density
  • "Magnetization^4"
    • quadruple of magnetization density
source
simple_estimator(model::Clock, T::Real, Js::AbstractArray)
simple_estimator(model::XY, T::Real, Js::AbstractArray)

Returns the following observables as Dict{String, Any}

Observables

  • "Energy"
    • Energy per spin (site)
  • "Energy^2"
  • "|Magnetization|"
    • Absolute value of total magnetization per spin (order paremeter)
  • "|Magnetization|^2"
  • "|Magnetization|^4"
  • "Magnetization x"
    • x component of total magnetization per spin (order paremeter)
  • "|Magnetization x|"
  • "Magnetization x^2"
  • "Magnetization x^4"
  • "Magnetization y"
    • y component of total magnetization per spin (order paremeter)
  • "|Magnetization y|"
  • "Magnetization y^2"
  • "Magnetization y^4"
  • "Helicity Modulus x"
  • "Helicity Modulus y"
source
simple_estimator(model::AshkinTeller, T::Real, Jsigma, Jtau, K)

Returns the following observables as Dict{String, Any}

Observables

  • "Energy"
    • energy density
  • "Energy^2"
    • square of energy density
  • "|Magnetization|"
    • absolute value of magnetization density, $|m| = \sqrt{ (\sum_i \sigma_i )^2 + (\sum_i \tau_i)^2 } / N$
  • "|Magnetization|^2"
    • square of magnetization density
  • "|Magnetization|^4"
    • quadruple of magnetization density
  • "Magnetization sigma"
    • magnetization density (sigma spin)
  • "|Magnetization sigma|"
  • "Magnetization sigma^2"
  • "Magnetization sigma^4"
  • "Magnetization tau"
    • magnetization density (tau spin)
  • "|Magnetization tau|"
  • "Magnetization tau^2"
  • "Magnetization tau^4"
source
SpinMonteCarlo.improved_estimatorFunction
improved_estimator(model::Ising, T::Real, Js::AbstractArray, sw::SWInfo)

Returns the following observables as Dict{String, Any} using cluster information sw

Observables

  • "Energy"
    • energy density
  • "Energy^2"
    • square of energy density
  • "Magnetization"
    • magnetization density
  • "|Magnetization|"
    • absolute value of magnetization density
  • "Magnetization^2"
    • square of magnetization density
  • "Magnetization^4"
    • quadruple of magnetization density
  • "Clustersize^2"
    • $\sum_c r_c^2$, where $r_c$ is the size density of $c$-th cluster
  • "Clustersize^4"
    • $\sum_c r_c^4$
  • "Clustersize^2 Clustersize^2"
    • $\sum_{c\ne c'} r_c^2 r_{c'}^2$
source
improved_estimator(model::Potts, T::Real, Js::AbstractArray, sw::SWInfo)

Returns the following observables as Dict{String, Any} using cluster information sw

Observables

  • "Energy"
    • energy density
  • "Energy^2"
    • square of energy density
  • "Magnetization"
    • magnetization density
  • "|Magnetization|"
    • absolute value of magnetization density
  • "|Magnetization|^2"
    • square of magnetization density
  • "|Magnetization|^4"
    • quadruple of magnetization density
  • "Clustersize^2"
    • $\sum_c r_c^2$, where $r_c$ is the size density of $c$-th cluster
  • "Clustersize^4"
    • $\sum_c r_c^4$
  • "Clustersize^2 Clustersize^2"
    • $\sum_{c\ne c'} r_c^2 r_{c'}^2$
source
improved_estimator(model::QuantumXXZ, T::Real, Js::AbstractArray, uf::UnionFind)

Returns the following observables as Dict{String, Any} using loop information uf

Observables

  • "Sign"
    • Sign of the weight function
  • "Sign * Energy"
    • Energy per spin (site)
  • "Sign * Energy^2"
  • "Sign * Magnetization"
    • Total magnetization (Sz) per spin (site)
  • "Sign * |Magnetization|"
  • "Sign * Magnetization^2"
  • "Sign * Magnetization^4"
source

Observables

SpinMonteCarlo.binningFunction
binning(obs::SimpleObservable; binsize::Int = 0, numbins::Int = 0)
binning(obs::SimpleVectorObservable; binsize::Int = 0, numbins::Int = 0)

Binning the observable `obs`.
Either `binsize` or `numbins` can be given. If both are given, `ArgumentError` is thrown.
If both are not given, `binsize` is set to `floor(sqrt(count(obs)))`.
source
SpinMonteCarlo.jackknifeFunction
jackknife(obs::ScalarObservable)

Construct a Jackknife observable from a scalar observable
source
jackknife(obsset::MCObservableSet)

Construct a JackknifeSet from a MCObservableSet
source
jackknife(obs::VectorObservable)

Construct a JackknifeVector observable from a vector observable
source
SpinMonteCarlo.extrapolate_tauFunction
extrapolate_tau(b::BinningObservable, point::Int=5)
extrapolate_tau(b::BinningVectorObservable, point::Int=5)

Extrapolates the autocorrelation time to the infinite bin size limit.

tau is evaluated on the last point binning levels and fitted against the inverse bin size by unweighted least squares; the intercept is the estimate. Returns (value, error) for a scalar observable and (values, errors) for a vector one, where the error is a 1-sigma standard error on the intercept.

Throws ArgumentError if fewer than three binning levels are used for the fit (i.e. min(point, maxlevel(b)) < 3), or if a level holds fewer than two bins and its statistic is therefore not finite.

Note

Before v1.3.0 the error was the half-width of a 95% confidence interval, which is the standard error scaled by quantile(TDist(dof), 0.975) with dof the number of fitted levels minus two.

source
SpinMonteCarlo.extrapolate_stderrorFunction
extrapolate_stderror(b::BinningObservable, point::Int=5)
extrapolate_stderror(b::BinningVectorObservable, point::Int=5)

Extrapolates the standard error to the infinite bin size limit.

Behaves like extrapolate_tau but extrapolates stderror instead of tau. The second element of the return value is a 1-sigma standard error on the extrapolated value, not the extrapolated value's own confidence interval.

source

Snapshot

runMC writes spin configurations when param["Snapshot Interval"] is a positive number of measurement MCS (thermalization steps are never sampled). The file is "$(param["Snapshot Filename Prefix"])_$(param["ID"]).txt", one configuration per line, values separated by spaces. Nothing identifies the model or lattice in the file, so keeping track of which run produced which file is up to you.

The flattening follows Julia's column-major order, so the length of a row is not always the number of sites:

ModelRow lengthOrderValues
Isingnumsitessite±1
Potts, Clocknumsitessite1 to Q
XYnumsitessiteσ ∈ [0,1), angle θ = 2πσ
AshkinTeller2 * numsitesσ₁ τ₁ σ₂ τ₂ …±1

Two runs sharing an "ID" and prefix write to the same file, exactly as they would share a checkpoint file.

SpinMonteCarlo.snapshotFunction
snapshot(model::Model)

Return a vector containing the model's current spin configuration. The returned vector does not share memory with the model.

The generic implementation requires model.spins to be an AbstractMatrix{<:Number}. It follows Julia's column-major order. In particular, Ashkin-Teller spins are ordered as σ₁ τ₁ σ₂ τ₂ …; the other classical models have one value per site. For the XY model, each value is the internal σ ∈ [0, 1) representation, with the physical angle given by θ = 2πσ.

source
SpinMonteCarlo.save_snapshotFunction
save_snapshot(io::IO, model::Model; sep=" ")
save_snapshot(filename::AbstractString, model::Model; sep=" ", append=false)

Write the model's current spin configuration as one line of separator-delimited text. The filename form truncates an existing file unless append=true.

source
SpinMonteCarlo.load_snapshotsFunction
load_snapshots(source; sep=nothing)
load_snapshots(T::Type{<:Number}, source; sep=nothing)

Load separator-delimited snapshot configurations from an IO or filename. Each data line becomes one column of the returned snapshot_length × nconfigs matrix. Lines whose first non-whitespace character is # and lines that split into no tokens are ignored. The default element type is Float64.

source

Removed API

Utility

SpinMonteCarlo.convert_parameterFunction
convert_parameter(model, param)

Generates arguments of updater and estimator.

Example

julia> model = Ising(chain_lattice(4));

julia> p = convert_parameter(model, Parameter("J"=>1.0))
(1.0, [1.0, 1.0]) # T and Js

julia> p = convert_parameter(model, Parameter("J"=>[1.5, 0.5]))
(1.0, [1.5, 0.5]) # J can take a vector whose size is `numbondtypes(model)`

julia> model.spins
4-element Array{Int64,1}:
  1
  1
  1
 -1

julia> local_update!(model, p...);

julia> model.spins
4-element Array{Int64,1}:
  1
  1
 -1
 -1
source
SpinMonteCarlo.convert_parameterMethod
convert_parameter(model::Ising, param::Parameter)

Keynames:

  • "T": a scalar (default: 1.0).
  • "J": a vector with numbondtypes(model) elements (default: 1.0).
source
SpinMonteCarlo.convert_parameterMethod
convert_parameter(model::Potts, param::Parameter)

Keynames:

  • "T": a scalar (default: 1.0).
  • "J": a vector with numbondtypes(model) elements (default: 1.0).
source
SpinMonteCarlo.convert_parameterMethod
convert_parameter(model::Clock, param::Parameter)

Keynames:

  • "T": a scalar (default: 1.0).
  • "J": a vector with numbondtypes(model) elements (default: 1.0).
source
SpinMonteCarlo.convert_parameterMethod
convert_parameter(model::XY, param::Parameter)

Keynames:

  • "T": a scalar (default: 1.0).
  • "J": a vector with numbondtypes(model) elements (default: 1.0).
source
SpinMonteCarlo.convert_parameterMethod
convert_parameter(model::AshkinTeller, param::Parameter)

Keynames:

  • "T": a scalar (default: 1.0).
  • "Jsigma": a vector with numbondtypes(model) elements (default: 1.0).
  • "Jtau": a vector with numbondtypes(model) elements (default: 1.0).
  • "K": a vector with numbondtypes(model) elements (default: 0.0).
source
SpinMonteCarlo.convert_parameterMethod
convert_parameter(model::QuantumXXZ, param::Parameter)

Keynames:

  • "T": a scalar (default: 1.0).
  • "Jz": a vector with numbondtypes(model) elements (default: 1.0).
  • "Jxy": a vector with numbondtypes(model) elements (default: 1.0).
  • "Gamma": a vector with numsitetypes(model) elements (default: 0.0).
source