Skip to main content

Module callbacks

Module callbacks 

Source
Expand description

Callbacks: hooks into the run.

A Callback is called at the start and the end of the run, of every condition and after every batch of trials. It observes (progress display, monitoring) or steers the run through the Action it returns: skip a condition before it starts, stop a condition early, or stop the whole run after a condition. Every method has a default that does nothing, so a callback implements only the hooks it needs.

Built-in callbacks:

  • ProgressBar: one line per condition on the standard error (trials, wall time, the estimate and its interval for every metric), and a periodic progress line on long conditions;
  • SkipAfter: the classical shortcut of error-rate curves: once an error rate falls below a floor along an axis (for instance the BER along an SNR sweep), the following points of the same sweep are skipped, since they would need too many trials and bring no information.

§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;
// error probability 1, 1e-2, 1e-4, 1e-6: the point at 30 dB is skipped once the
// estimate at 20 dB falls below 1e-3
let s = from_fn("decay", |cond, rng, rec| {
    let p = 10f64.powf(-cond.f64("snr_db")? / 5.0);
    rec.errors("ber", (rng.uniform() < p) as u64, 1);
    Ok(())
});
let grid = Grid::new().axis("snr_db", [0.0, 10.0, 20.0, 30.0]);
let r = Runner::new()
    .stop(Stop::max_trials(2000))
    .callback(SkipAfter::below("ber", 1e-3, "snr_db"))
    .run(&s, &grid)
    .unwrap();
let status: Vec<&str> = r.iter().map(|c| c.status.as_str()).collect();
assert_eq!(status, ["completed", "completed", "completed", "skipped"]);

Structs§

ProgressBar
Progress lines on the standard error.
SkipAfter
Skip the rest of a sweep once an error rate is below a floor.

Enums§

Action
What a callback asks the runner to do.

Traits§

Callback
Hooks into a run (all optional).