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.
CsvLoggerwrites one row per condition as it completes (and flushes), so that a long campaign leaves usable partial results. The columns are those ofConditionResult::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.JsonLoggerwrites 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, underdropped, the number of values each metric dropped (non-finite or of the other kind, seeRecord::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. - Json
Logger - 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):
sitself, 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,nullif unknown) andstarted_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.