use std::collections::BTreeSet;
use serde::{Deserialize, Serialize};
use super::{MetricKey, NodeId};
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, Default)]
#[serde(rename_all = "snake_case")]
pub enum ExecutionMode {
#[default]
SingleThread,
Rayon,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, Default)]
#[serde(rename_all = "snake_case")]
pub enum ConfidenceLevel {
P90,
#[default]
P95,
P99,
}
impl ConfidenceLevel {
pub fn z_score(self) -> f64 {
match self {
Self::P90 => 1.644_853_626_951_472_2,
Self::P95 => 1.959_963_984_540_054,
Self::P99 => 2.575_829_303_548_900_4,
}
}
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct CaptureConfig {
pub capture_nodes: BTreeSet<NodeId>,
pub capture_metrics: BTreeSet<MetricKey>,
pub every_n_steps: u64,
pub include_step_zero: bool,
pub include_final_state: bool,
}
impl Default for CaptureConfig {
fn default() -> Self {
Self {
capture_nodes: BTreeSet::new(),
capture_metrics: BTreeSet::new(),
every_n_steps: 1,
include_step_zero: true,
include_final_state: true,
}
}
}
impl CaptureConfig {
pub fn disabled() -> Self {
Self { include_step_zero: false, include_final_state: false, ..Self::default() }
}
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct RunConfig {
pub seed: u64,
pub max_steps: u64,
pub capture: CaptureConfig,
}
impl Default for RunConfig {
fn default() -> Self {
Self { seed: 0, max_steps: 100, capture: CaptureConfig::default() }
}
}
impl RunConfig {
pub fn for_seed(seed: u64) -> Self {
Self { seed, ..Self::default() }
}
pub fn with_max_steps(mut self, max_steps: u64) -> Self {
self.max_steps = max_steps;
self
}
pub fn with_capture(mut self, capture: CaptureConfig) -> Self {
self.capture = capture;
self
}
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct BatchRunTemplate {
pub max_steps: u64,
pub capture: CaptureConfig,
}
impl Default for BatchRunTemplate {
fn default() -> Self {
Self { max_steps: 100, capture: CaptureConfig::default() }
}
}
impl BatchRunTemplate {
pub fn with_max_steps(mut self, max_steps: u64) -> Self {
self.max_steps = max_steps;
self
}
pub fn with_capture(mut self, capture: CaptureConfig) -> Self {
self.capture = capture;
self
}
pub fn to_run_config(&self, seed: u64) -> RunConfig {
RunConfig { seed, max_steps: self.max_steps, capture: self.capture.clone() }
}
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct BatchConfig {
pub runs: u64,
pub base_seed: u64,
pub execution_mode: ExecutionMode,
pub run_template: BatchRunTemplate,
}
impl Default for BatchConfig {
fn default() -> Self {
Self {
runs: 1,
base_seed: 0,
execution_mode: ExecutionMode::default(),
run_template: BatchRunTemplate::default(),
}
}
}
impl BatchConfig {
pub fn for_runs(runs: u64) -> Self {
Self { runs, ..Self::default() }
}
pub fn with_execution_mode(mut self, execution_mode: ExecutionMode) -> Self {
self.execution_mode = execution_mode;
self
}
pub fn with_base_seed(mut self, base_seed: u64) -> Self {
self.base_seed = base_seed;
self
}
pub fn with_run_template(mut self, run_template: BatchRunTemplate) -> Self {
self.run_template = run_template;
self
}
pub fn with_max_steps(mut self, max_steps: u64) -> Self {
self.run_template.max_steps = max_steps;
self
}
pub fn with_capture(mut self, capture: CaptureConfig) -> Self {
self.run_template.capture = capture;
self
}
}