Measurements
MonteCarloX separates what you measure from when you measure it. Measurement and Measurements are convenience helpers — they are not required for running MonteCarloX algorithms. You can always collect observables manually in your simulation loop.
Building blocks
Measurement: one observable paired with one data containerMeasurements: named collection with a shared schedule- schedule types:
IntervalSchedulePreallocatedSchedule
Step-based measurements (common in equilibrium loops)
using MonteCarloX
measurements = Measurements([
:energy => energy => Float64[],
:magnetization => magnetization => Float64[],
], interval=10)
# in your loop:
# measure!(measurements, sys, step)This records every 10 loop steps.
Time-based measurements (common in Gillespie loops)
using MonteCarloX
times = collect(0.0:0.1:10.0)
measurements = Measurements([
:N => (state -> state[:N]) => Float64[],
], times)
# in your loop:
# measure!(measurements, state, t)
# stop criterion: is_complete(measurements)PreallocatedSchedule handles event skipping by consuming all crossed checkpoints.
Data access and reset
measurements[:energy].data— raw storagedata(measurements, :energy)— convenience accessorreset!(measurements)— clears data and restarts schedule state
API reference
MonteCarloX.Measurement — Type
Measurement{F,T}A measurement consisting of an observable function and a data container.
Fields
observable::F: Function that extracts a value from the systemdata::T: Container for storing measurements (Vector, Histogram, etc.)
MonteCarloX.Measurements — Type
Measurements{K,S<:MeasurementSchedule}Container for multiple measurements with a shared schedule.
Fields
measurements::Dict{K, Measurement}: Dictionary of named measurementsschedule::S: Measurement schedule
MonteCarloX.MeasurementSchedule — Type
MeasurementScheduleAbstract type for different measurement scheduling strategies.
MonteCarloX.IntervalSchedule — Type
IntervalSchedule <: MeasurementScheduleSchedule measurements at regular intervals.
Fields
interval::Float64: Time/step interval between measurements_checkpoint::Float64: Internal checkpoint for next measurement
MonteCarloX.PreallocatedSchedule — Type
PreallocatedSchedule <: MeasurementScheduleSchedule measurements at pre-specified times.
Fields
times::Vector{Float64}: Sorted vector of measurement timescheckpoint_idx::Int: Current index in times vector
MonteCarloX.measure! — Function
measure!(measurement::Measurement, sys; kwargs...)Perform a single measurement by evaluating the observable on the system and storing the result.
measure!(measurements::Measurements{K, IntervalSchedule}, sys, t; kwargs...)Perform measurements at regular intervals (indefinite simulation).
measure!(measurements::Measurements{K, PreallocatedSchedule}, sys, t; kwargs...)Perform measurements at preallocated times (handles event skipping).
measure!(sys, event, t)Observe system sys at time t before modify!. Default is a no-op.
MonteCarloX.reset! — Method
reset!(measurement::Measurement)Reset a single measurement to its initial state by clearing its data container. For histogram-backed measurements this zeros the bin counts while preserving binning.
MonteCarloX.reset! — Method
reset!(schedule::MeasurementSchedule)Reset schedule counters/checkpoints back to their initial state.
MonteCarloX.reset! — Method
reset!(measurements::Measurements)Reset all measurement data containers and schedule state in-place.
MonteCarloX.times — Method
times(m::Measurements)Return the measurement time points for preallocated schedules.
MonteCarloX.data — Method
data(m::Measurements{K}, key::K)Return the raw data container for a named measurement.
MonteCarloX.is_complete — Function
is_complete(m::Measurements)Check if all scheduled measurements are complete. Returns false for interval-based schedules (indefinite).