Sampler creation¶
Sampler controls the execution of MLMC samples.
First, import mlmc package and define basic MLMC parameters.
import mlmc
n_levels = 3 # number of MLMC levels
step_range = [0.5, 0.005] # simulation steps at the coarsest and finest levels
level_parameters = mlmc.estimator.determine_level_parameters(n_levels, step_range)
# level_parameters determine each level simulation steps
# level_parameters can be manually prescribed as a list of lists
Prepare a simulation, it must be instance of class that inherits from mlmc.sim.simulation.Simulation
.
simulation_factory = mlmc.SynthSimulation()
Create a sampling pool.
sampling_pool = mlmc.OneProcessPool()
You can also use mlmc.sampling_pool.ProcessPool
which supports parallel execution of MLMC samples.
In order to use PBS (portable batch system), employ mlmc.sampling_pool_pbs.SamplingPoolPBS
.
Create a sample storage. It contains sample’s related data e.g. simulation result.
# Memory() storage keeps samples in the computer main memory
sample_storage = mlmc.Memory()
We support also HDF5 file storage mlmc.sample_storage_hdf.SampleStorageHDF
.
Finally, create a sampler that manages scheduling MLMC samples and also saves the results.
sampler = mlmc.Sampler(sample_storage=sample_storage,
sampling_pool=sampling_pool,
sim_factory=simulation_factory,
level_parameters=level_parameters)