Skip to main content

Module loggers

Module loggers 

Source
Expand description

Loggers: where the results go.

A Logger receives every ConditionResult as soon as the condition ends, and the RunReport at the end of the run.

  • CsvLogger writes one row per condition as it completes (and flushes), so that a long campaign leaves usable partial results. The columns are those of ConditionResult::row: index, the keys of the condition, status, trials, wall_s, then for every metric <m>, <m>_lo, <m>_hi (the confidence interval) and <m>_count, <m>_total (errors and trials of a rate, or the number of values of a mean); those of the first condition that ran.
  • JsonLogger writes the full report at the end of the run: the run information (run_header: scenario, seed, batch, threads, stopping rule, confidence, library version and commit, configuration, start time), the wall time, and every condition with its metrics and, under dropped, the number of values each metric dropped (non-finite or of the other kind, see Record::dropped; an empty mapping when none was).

§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 dir = std::env::temp_dir().join("comnum-doc-loggers");
std::fs::create_dir_all(&dir).unwrap();
let s = from_fn("toss", |_, rng, rec| { rec.errors("p", rng.bit() as u64, 1); Ok(()) });
Runner::new()
    .stop(Stop::max_trials(64))
    .logger(CsvLogger::new(dir.join("toss.csv")))
    .logger(JsonLogger::new(dir.join("toss.json")))
    .run(&s, &Grid::new().axis("n", [1usize, 2]))
    .unwrap();
let csv = std::fs::read_to_string(dir.join("toss.csv")).unwrap();
assert!(csv.starts_with("index,n,status,trials,wall_s,p,p_lo,p_hi,p_count,p_total\n"));
assert_eq!(csv.lines().count(), 3);
let json = std::fs::read_to_string(dir.join("toss.json")).unwrap();
assert!(json.contains("\"scenario\": \"toss\""));

Structs§

CsvLogger
One CSV row per condition (ConditionResult::row), written as the conditions complete.
JsonLogger
The full report as JSON, written at the end of the run.

Traits§

Logger
A destination of the results.

Functions§

create_parent_dir
Create the parent directories of path (none for a bare file name).
csv_field
A CSV field (RFC 4180): s itself, or quoted with its quotes doubled when it holds a comma, a quote or a line break.
run_header
The fields of the run information that head every JSON report (of a run, of a search and of a verification), encoded: scenario, seed, batch, threads, stop, confidence, version, commit, config (the configuration as a JSON document, null if unknown) and started_unix_s.
value_json
A value of a condition as JSON (a number, a string or a boolean).
write_json
Write a JSON document to path, its parent directories created.