API
This is the documentation of the Arianna module's functions, types and structures.
API Reference
Index
Arianna.Arianna
Arianna.Action
Arianna.AriannaAlgorithm
Arianna.AriannaSystem
Arianna.DAT
Arianna.Format
Arianna.Metropolis
Arianna.Metropolis
Arianna.Move
Arianna.Move
Arianna.Policy
Arianna.PrintTimeSteps
Arianna.Simulation
Arianna.Simulation
Arianna.StoreBackups
Arianna.StoreCallbacks
Arianna.StoreLastFrames
Arianna.StoreParameters
Arianna.StoreParameters
Arianna.StoreTrajectories
Arianna.TXT
Arianna.build_schedule
Arianna.build_schedule
Arianna.build_schedule
Arianna.callback_acceptance
Arianna.delta_log_target_density
Arianna.finalise
Arianna.finalise
Arianna.initialise
Arianna.initialise
Arianna.invert_action!
Arianna.log_proposal_density
Arianna.make_step!
Arianna.make_step!
Arianna.mc_step!
Arianna.mc_sweep!
Arianna.perform_action!
Arianna.raise_error
Arianna.revert_action!
Arianna.run!
Arianna.sample_action!
Arianna.store_trajectory
Arianna.unnormalised_log_target_density
Arianna.write_algorithm
Arianna.write_algorithm
Arianna.write_parameters
Types and Functions
Arianna.Arianna
— Modulemodule Arianna
Arianna is a flexible and extensible framework for Monte Carlo simulations. Instead of acting as a black-box simulator, it provides a modular structure where users define their own system and Monte Carlo "moves".
Arianna.Action
— Typeabstract type Action
Abstract type representing Monte Carlo actions/moves that can be performed on a system.
Concrete subtypes must implement:
sample_action!(action, policy, parameters, system, rng)
: Sample a new action from the policyperform_action!(system, action)
: Apply the action to modify the system stateinvert_action!(action, system)
: Invert/reverse the actionlog_proposal_density(action, policy, parameters, system)
: Log probability density of proposing this action
Optional methods:
revert_action!(system, action)
: Optimized version of perform_action! that can reuse cached values
Arianna.AriannaAlgorithm
— Typeabstract type AriannaAlgorithm
Abstract type for Simulation algorithms.
Arianna.AriannaSystem
— Typeabstract type AriannaSystem
Abstract type representing a system that can be simulated using methods defined in the Arianna
module.
Arianna.DAT
— TypeDAT <: Format
Format type for data (.dat) file output.
Arianna.Format
— TypeFormat
Abstract type for output file formats.
Arianna.Metropolis
— TypeMetropolis{P,R<:AbstractRNG,C<:Function} <: AriannaAlgorithm
A struct representing a Metropolis Monte Carlo algorithm.
Fields
pools::Vector{P}
: Vector of independent pools (one for each system)sweepstep::Int
: Number of Monte Carlo steps per sweepseed::Int
: Random number seedrngs::Vector{R}
: Vector of random number generatorsparallel::Bool
: Flag to parallelise over different threadscollecter::C
: Transducer to collect results from parallelised loops
Type Parameters
P
: Type of the poolR
: Type of the random number generatorC
: Type of the transducer
Arianna.Metropolis
— MethodMetropolis(chains; pool=missing, sweepstep=1, seed=1, R=Xoshiro, parallel=false, extras...)
Create a new Metropolis instance.
Arguments
chains
: Vector of systems to run the algorithm onpool
: Pool of moves to perform sweeps oversweepstep
: Number of Monte Carlo steps per sweepseed
: Random number seedR
: Type of the random number generatorparallel
: Flag to parallelise over different threadsextras
: Additional keyword arguments
Returns
algorithm
: Metropolis instance
Arianna.Move
— TypeMove{A<:Action,P<:Policy,V<:AbstractArray,T<:AbstractFloat}
A struct representing a Monte Carlo move with an associated action, policy, and parameters.
Fields
action::A
: The action to be performed in the movepolicy::P
: The policy used to propose actionsparameters::V
: Parameters of the policyweight::T
: Weight/probability of selecting this move in a sweeptotal_calls::Int
: Total number of times this move has been attemptedaccepted_calls::Int
: Number of times this move has been accepted
Type Parameters
A
: Type of the actionP
: Type of the policyV
: Type of the parameter arrayT
: Type of the weight (floating point)
Arianna.Move
— MethodMove(action, policy, parameters, weight)
Create a new Move instance.
Arguments
action
: The action to be performed in the movepolicy
: The policy used to propose actionsparameters
: Parameters of the policyweight
: Weight/probability of selecting this move in a sweep
Arianna.Policy
— Typeabstract type Policy
Abstract type representing proposal policies for Monte Carlo actions.
A Policy defines how actions are sampled and their proposal probabilities are calculated. Concrete subtypes work together with specific Action types to implement the proposal mechanism.
Arianna.PrintTimeSteps
— TypePrintTimeSteps <: AriannaAlgorithm
Algorithm to display a progress bar and current timestep during simulation.
Arianna.Simulation
— Typemutable struct Simulation{S, A, VS}
A structure representing a Monte Carlo simulation.
Fields
chains::Vector{S}
: Vector of independent Arianna systems.algorithms::A
: List of algorithms.steps::Int
: Number of MC sweeps.t::Int
: Current time step.schedulers::VS
: List of schedulers (one for each algorithm).counters::Vector{Int}
: Counters for the schedulers (one for each algorithm).path::String
: Simulation path.verbose::Bool
: Flag for verbose output.
Arianna.Simulation
— MethodSimulation(chains, algorithm_list, steps; path="data", verbose=false)
Create a new Simulation
instance from a list of algorithm constructors.
Arguments
chains
: Vector of independent Arianna systems.algorithm_list
: List of algorithm constructors.steps
: Number of MC sweeps.path="data"
: Simulation path.verbose=false
: Flag for verbose output.
Arianna.StoreBackups
— TypeStoreBackups <: AriannaAlgorithm
Algorithm to create backup files of system states during simulation.
Fields
dirs::Vector{String}
: Directories for storing backup filesfmt::Format
: Format type for output filesstore_first::Bool
: Whether to store backups at initializationstore_last::Bool
: Whether to store backups at finalization
Arianna.StoreCallbacks
— TypeStoreCallbacks{V} <: AriannaAlgorithm
Algorithm to store callback values during simulation.
Fields
callbacks::V
: Vector of callback functions to evaluatepaths::Vector{String}
: Paths to output files for each callbackfiles::Vector{IOStream}
: File handles for writing callback valuesstore_first::Bool
: Whether to store callback values at initializationstore_last::Bool
: Whether to store callback values at finalization
Constructor
StoreCallbacks(callbacks::V, path; store_first::Bool=true, store_last::Bool=false)
Create a new StoreCallbacks instance.
Arguments
callbacks::V
: Vector of callback functionspath
: Base path for output filesstore_first=true
: Store values at initializationstore_last=false
: Store values at finalization
Arianna.StoreLastFrames
— TypeStoreLastFrames <: AriannaAlgorithm
Algorithm to store the final state of each system at the end of simulation.
Fields
paths::Vector{String}
: Paths to output filesfmt::Format
: Format type for output files
Arianna.StoreParameters
— TypeStoreParameters{V<:AbstractArray} <: AriannaAlgorithm
A struct representing a parameter store.
Fields
paths::Vector{String}
: Vector of paths to the parameter filesfiles::Vector{IOStream}
: Vector of open file streams to the parameter filesparameters_list::V
: List of parameters to storestore_first::Bool
: Flag to store the parameters at the first stepstore_last::Bool
: Flag to store the parameters at the last step
Type Parameters
V
: Type of the parameter array
Arianna.StoreParameters
— MethodStoreParameters(chains; dependencies=missing, path=missing, ids=missing, store_first=true, store_last=false, extras...)
Create a new StoreParameters instance.
Arguments
chains
: Vector of chains to store the parameters ofdependencies
: Dependencies of the parameter storepath
: Path to the parameter filesids
: IDs of the parameters to storestore_first
: Flag to store the parameters at the first stepstore_last
: Flag to store the parameters at the last stepextras
: Additional keyword arguments
Returns
algorithm
: StoreParameters instance
Arianna.StoreTrajectories
— TypeStoreTrajectories{F<:Format} <: AriannaAlgorithm
Algorithm to store system trajectories during simulation.
Fields
paths::Vector{String}
: Paths to output filesfiles::Vector{IOStream}
: File handles for writing trajectoriesfmt::F
: Format type for output filesstore_first::Bool
: Whether to store trajectories at initializationstore_last::Bool
: Whether to store trajectories at finalization
Arianna.TXT
— TypeTXT <: Format
Format type for text (.txt) file output.
Arianna.build_schedule
— Methodbuild_schedule(steps::Int, burn::Int, base::AbstractFloat)
Create a vector of timestep from burn
to steps
log-spaced with base base
.
Arianna.build_schedule
— Methodbuild_schedule(steps::Int, burn::Int, Δt::Int)
Create a vector of timestep from burn
to steps
at intervals Δt
.
Arianna.build_schedule
— Methodbuild_schedule(steps::Int, burn::Int, block::Vector{Int})
Create a vector of timestep from burn
to steps
with repeated blocks specified by block
.
Arianna.callback_acceptance
— Methodcallback_acceptance(simulation)
Calculate the mean acceptance rate of the Metropolis algorithm.
Arguments
simulation
: Simulation to calculate the acceptance rate of
Arianna.delta_log_target_density
— Methoddelta_log_target_density(x₁, x₂, system::AriannaSystem)
Calculate the change in log target density between two states.
Arguments
x₁
: Initial statex₂
: Final statesystem
: System object
Arianna.finalise
— Methodfinalise(::AriannaAlgorithm, ::Simulation)
Finalise the algorithm for the given simulation.
Arianna.finalise
— Methodstore_lastframe(io, system, t, fmt::Format)
Store the final state of the system at time t to the given IO stream in the specified format.
Arianna.initialise
— Methodinitialise(::AriannaAlgorithm, ::Simulation)
Initialise the algorithm for the given simulation.
Arianna.initialise
— Methodstore_backup(io, system, t, fmt::Format)
Store a backup of the system state at time t to the given IO stream in the specified format.
Arianna.invert_action!
— Methodinvert_action!(action::Action, system::AriannaSystem)
Invert/reverse an action.
Arguments
action
: Action to invertsystem
: System the action was applied to
Arianna.log_proposal_density
— Methodlog_proposal_density(action, policy, parameters, system::AriannaSystem)
Calculate the log probability density of proposing the given action.
Arguments
action
: Proposed actionpolicy
: Policy used for proposalparameters
: Parameters of the policysystem
: System the action is applied to
Arianna.make_step!
— Methodmake_step!(::Simulation, ::AriannaAlgorithm)
Perform a single step of the algorithm in the simulation.
Arianna.make_step!
— Methodmake_step!(simulation::Simulation, algorithm::Metropolis)
Perform a single step of the Metropolis algorithm.
Arguments
simulation
: Simulation to perform the step onalgorithm
: Metropolis instance
Arianna.mc_step!
— Methodmc_step!(system::AriannaSystem, action::Action, policy::Policy, parameters::AbstractArray{T}, rng) where {T<:AbstractFloat}
Perform a single Monte Carlo step.
Arguments
system
: System to modifyaction
: Action to performpolicy
: Policy used for proposalparameters
: Parameters of the policyrng
: Random number generator
Arianna.mc_sweep!
— Methodmc_sweep!(system::AriannaSystem, pool, rng; mc_steps=1)
Perform a Monte Carlo sweep over a pool of moves.
Arguments
system
: System to modifypool
: Pool of moves to perform sweeps overrng
: Random number generatormc_steps
: Number of Monte Carlo steps per sweep
Arianna.perform_action!
— Methodperform_action!(system::AriannaSystem, action::Action)
Apply the action to modify the system state.
Arguments
system
: System to modifyaction
: Action to perform
Returns
A tuple of (x₁, x₂) containing the old and new states
Arianna.raise_error
— Methodraise_error(s)
Helper function to raise errors for unimplemented required methods.
Arguments
s
: String describing the missing method implementation
Arianna.revert_action!
— Methodrevert_action!(system, action::Action)
Optimized version of perform_action! that can reuse cached values.
Arguments
system
: System to modifyaction
: Action to perform
Arianna.run!
— Methodrun!(simulation::Simulation)
Run the Monte Carlo simulation.
Arguments
simulation::Simulation
: The simulation instance to run.
Arianna.sample_action!
— Methodsample_action!(action::Action, policy::Policy, parameters, system::AriannaSystem, rng)
Sample a new action from the policy.
Arguments
action
: Action to be sampledpolicy
: Policy to sample fromparameters
: Parameters of the policysystem
: System the action will be applied torng
: Random number generator
Arianna.store_trajectory
— Methodstore_trajectory(io, system::AriannaSystem, t, fmt::Format)
Store the system trajectory at time t to the given IO stream in the specified format.
Arianna.unnormalised_log_target_density
— Methodunnormalised_log_target_density(x, system)
Calculate the unnormalized log probability density of a system state.
Arguments
x
: System statesystem
: System object
Arianna.write_algorithm
— Methodwrite_algorithm(io, algorithm::AriannaAlgorithm, scheduler)
Write a summary of the algorithm on the given IO stream.
Arianna.write_algorithm
— Methodwrite_algorithm(io, algorithm::Metropolis, scheduler)
Write the algorithm to a string.
Arguments
io
: IO stream to write toalgorithm
: Algorithm to writescheduler
: Scheduler to write
Arianna.write_parameters
— Methodwrite_parameters(::Policy, parameters)
Write the parameters of a policy to a string.
Arguments
policy
: Policy to write the parameters ofparameters
: Parameters of the policy