mlmc.sampler.Sampler
- class mlmc.sampler.Sampler(sample_storage, sampling_pool, sim_factory, level_parameters, seed=1234)[source]
Manages sample scheduling, result collection, and persistent storage.
Coordinates the sampling pool, simulation factory, and sample storage: - schedules new samples according to target counts, - collects finished samples and writes them to storage, - handles failed samples and runtime (n_ops) bookkeeping.
- __init__(sample_storage, sampling_pool, sim_factory, level_parameters, seed=1234)[source]
Initialize sampler and prepare per-level simulation objects.
- Parameters:
sample_storage (
SampleStorage) – store scheduled samples, results and result structuresampling_pool (
SamplingPool) – sampling pool responsible for executing simulationssim_factory (
Simulation) – factory that creates level Simulation instances and provides result_format()level_parameters (
List[List[float]]) – List of per-level parameters (e.g. simulation steps)seed – global RNG seed used to seed NumPy’s RNG
Methods
__init__(sample_storage, sampling_pool, ...)Initialize sampler and prepare per-level simulation objects.
ask_sampling_pool_for_samples([sleep, timeout])Poll the sampling pool for finished simulations and store their results.
l_scheduled_samples()Return the currently scheduled sample counts per level.
process_adding_samples(n_estimated[, sleep, ...])Add newly estimated samples in batches, scheduling a fraction of the difference between current scheduled and newly estimated targets.
renew_failed_samples()Reschedule previously failed samples.
sample_range(n0, nL)Generate a geometric sequence of length L decreasing from n0 to nL.
schedule_samples([timeout, level_id, n_samples])Schedule new simulation samples in the sampling pool and record them in storage.
set_initial_n_samples([n_samples])Set initial target number of samples for each level.
set_level_target_n_samples(n_samples)Update the per-level target sample counts to at least the provided values.
set_scheduled_and_wait(n_scheduled, ...[, ...])Set scheduled sample targets and wait until a proportion of those samples finish.
Attributes
ADDING_SAMPLES_TIMEOUTn_finished_samplesRetrieve numbers of finished samples for all levels.
n_levelsReturn number of MLMC levels managed by this sampler.