# 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!`

— Function`Carlo.init!(mc::YourMC, ctx::MCContext, params::AbstractDict)`

Executed when a simulation is started from scratch.

`Carlo.sweep!`

— Function`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 for `Carlo.measure!(::AbstractMC, ::MCContext)`

. Check Documenter's build log for details.

`Carlo.write_checkpoint`

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

Save the complete state of the simulation to `out`

.

`Carlo.read_checkpoint!`

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

Read the state of the simulation from `in`

.

`Carlo.register_evaluables`

— Function`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.

`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`

— Function`is_thermalized(ctx::MCContext)::Bool`

Returns true if the simulation is thermalized.

`Carlo.measure!`

— Method`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.