Expand description
The runner: the Trainer of a Monte Carlo campaign.
Runner::run takes a Scenario and a Grid and, for every condition in
order:
- asks the callbacks whether to run it (
Callback::on_condition_start); - builds the state with
Scenario::setup; - runs batches of
batchtrials in parallel, trialtdrawing fromstream(seed, name, condition index, t), merges their records in trial order, and after every batch evaluates the stopping rule and callsCallback::on_batch_end; after the first batch it checks that the targets of the rule are recorded (Stop::check_metrics), and the last batch ends at the bound of the rule on the trials (Stop::trial_limit); - hands the
ConditionResultto the callbacks and the loggers.
The results are identical whatever the number of threads (see crate). The batch
size only sets how often the rule is checked (a larger batch keeps every core busy, a
smaller one stops closer to an error or precision target); a bound on the trials is
met exactly, so that max_trials(1000) runs 1000 trials with batches of 32 as with
batches of 1.
Every condition runs at least one trial.
§Examples
use comnum_sim::prelude::*;
use comnum_mapping::{constellation::{Constellation, ConstellationKind}, source as sources};
use comnum_channel::awgn as channels;
use comnum_metrics as metrics;
use comnum_sim::scenario::from_fn;
let coin = from_fn("coin", |cond, rng, rec| {
let p = cond.f64("p")?;
rec.errors("heads", (rng.uniform() < p) as u64, 1);
Ok(())
});
let grid = Grid::new().axis("p", [0.1, 0.5]);
let one = Runner::new().seed(3).threads(1).batch(50).stop(Stop::max_trials(1000))
.run(&coin, &grid).unwrap();
let four = Runner::new().seed(3).threads(4).batch(50).stop(Stop::max_trials(1000))
.run(&coin, &grid).unwrap();
assert_eq!(one[0].metric("heads"), four[0].metric("heads")); // thread-count independent
assert!((one[1].metric("heads").unwrap().value() - 0.5).abs() < 0.05);Structs§
- Condition
Result - The result of one condition.
- RunInfo
- What the callbacks and loggers know about the run.
- RunReport
- The summary of a finished run.
- Runner
- The campaign runner (builder; see the module documentation).
Enums§
- Status
- How a condition ended.
Functions§
- metric_
columns - The names of the columns of the metric
namein a flat row (ConditionResult::row):name,name_loandname_hi(the estimate and its confidence interval),name_countandname_total(the errors and the events of a rate, the number of values of a mean twice).