Implementing your algorithm
To run your own Monte Carlo algorithm with Carlo, you need to implement the AbstractMC
interface documented in this file. For an example implementation showcasing all the features, take a look at the Ising example implementation.
Carlo.AbstractMC
— TypeThis type is an interface for implementing your own Monte Carlo algorithm that will be run by Carlo.
The following methods all need to be defined for your Monte Carlo algoritm type (here referred to as YourMC <: AbstractMC
). See Parallel run mode for a slightly different interface that allows inner MPI parallelization of your algorithm.
Carlo.init!
— FunctionCarlo.init!(mc::YourMC, ctx::MCContext, params::AbstractDict)
Executed when a simulation is started from scratch.
Carlo.sweep!
— FunctionCarlo.sweep!(mc::YourMC, ctx::MCContext)
Perform one Monte Carlo sweep or update to the configuration.
Doing measurements is supported during this step as some algorithms require doing so for efficiency. Remember to check for is_thermalized
in that case.
Carlo.measure!
— FunctionCarlo.measure!(mc::YourMC, ctx::MCContext)
Perform one Monte Carlo measurement.
Carlo.write_checkpoint
— FunctionCarlo.write_checkpoint(mc::YourMC, out::HDF5.Group)
Save the complete state of the simulation to out
.
Carlo.read_checkpoint!
— FunctionCarlo.read_checkpoint!(mc::YourMC, in::HDF5.Group)
Read the state of the simulation from in
.
Carlo.register_evaluables
— FunctionCarlo.register_evaluables(mc::Type{YourMC}, eval::AbstractEvaluator, params::AbstractDict)
This function is used to calculate postprocessed quantities from quantities that were measured during the simulation. Common examples are variances or ratios of observables.
See evaluables for more details.
Interfacing with Carlo features
The MCContext
type, passed to your code by some of the functions above enables to use some features provided by Carlo.
Carlo.MCContext
— TypeHolds the Carlo-internal state of the simulation and provides an interface to
- Random numbers: the public field
MCContext.rng
is a random number generator (see rng) - Measurements: see
measure!(::MCContext, ::Symbol, ::Any)
- Simulation state: see
is_thermalized
Carlo.is_thermalized
— Functionis_thermalized(ctx::MCContext)::Bool
Returns true if the simulation is thermalized.
Carlo.measure!
— Methodmeasure!(ctx::MCContext, name::Symbol, value)
Measure a sample for the observable named name
. The sample value
may be either a scalar or vector of a float type.