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.


This 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!(mc::YourMC, ctx::MCContext, params::AbstractDict)

Executed when a simulation is started from scratch.

Carlo.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.

Missing docstring.

Missing docstring for Carlo.measure!(::AbstractMC, ::MCContext). Check Documenter's build log for details.

Carlo.write_checkpoint(mc::YourMC, out::HDF5.Group)

Save the complete state of the simulation to out.

Carlo.read_checkpoint!(mc::YourMC, in::HDF5.Group)

Read the state of the simulation from in.

Carlo.register_evaluables(mc::Type{YourMC}, eval::Evaluator, 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.


Returns true if the simulation is thermalized.

measure!(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.