use crate::engine::config::RaceConfig;
use crate::engine::fitness::Fitness;
use crate::trainer::{RlStep, TabularStep};
pub struct TabularSpec<T: TabularStep + 'static = Box<dyn TabularStep>> {
pub data_dir: std::path::PathBuf,
pub config: RaceConfig,
pub fitness: Fitness,
pub trainer: T,
pub seed: Option<u64>,
pub run_dir: Option<std::path::PathBuf>,
}
pub struct RLSpec<T: RlStep + 'static = Box<dyn RlStep>> {
pub config: RaceConfig,
pub fitness: Fitness,
pub trainer: T,
pub seed: Option<u64>,
pub run_dir: Option<std::path::PathBuf>,
}
pub enum RunSpec<
TT: TabularStep + 'static = Box<dyn TabularStep>,
TR: RlStep + 'static = Box<dyn RlStep>,
> {
Tabular(TabularSpec<TT>),
RL(RLSpec<TR>),
}
impl RunSpec<Box<dyn TabularStep>, Box<dyn RlStep>> {
pub fn tabular<P: Into<std::path::PathBuf>>(
data_dir: impl Into<std::path::PathBuf>,
mut config: RaceConfig,
fitness: Fitness,
trainer: impl TabularStep + 'static,
seed: Option<u64>,
run_dir: Option<P>,
) -> Self {
config.mode_specific = crate::engine::config::ModeConfig::Tabular(
crate::engine::config::TabularConfig::default(),
);
Self::Tabular(TabularSpec {
data_dir: data_dir.into(),
config,
fitness,
trainer: Box::new(trainer),
seed,
run_dir: run_dir.map(|p| p.into()),
})
}
pub fn rl(
mut config: RaceConfig,
fitness: Fitness,
trainer: impl RlStep + 'static,
seed: Option<u64>,
run_dir: Option<std::path::PathBuf>,
) -> Self {
if !matches!(
config.mode_specific,
crate::engine::config::ModeConfig::Rl(_)
) {
config.mode_specific =
crate::engine::config::ModeConfig::Rl(crate::engine::config::RlConfig::default());
}
Self::RL(RLSpec {
config,
fitness,
trainer: Box::new(trainer),
seed,
run_dir,
})
}
pub fn with_trainer<U: TabularStep + 'static>(
self,
trainer: U,
) -> RunSpec<Box<dyn TabularStep>, Box<dyn RlStep>> {
match self {
RunSpec::Tabular(s) => RunSpec::Tabular(TabularSpec {
data_dir: s.data_dir,
config: s.config,
fitness: s.fitness,
trainer: Box::new(trainer),
seed: s.seed,
run_dir: s.run_dir,
}),
RunSpec::RL(s) => RunSpec::RL(RLSpec {
config: s.config,
fitness: s.fitness,
trainer: s.trainer,
seed: s.seed,
run_dir: s.run_dir,
}),
}
}
}
#[derive(Clone, Copy, Debug)]
pub struct StreamShape {
pub batch_size: usize,
pub eval_batch_size: usize,
}
impl StreamShape {
pub fn none() -> Self {
Self {
batch_size: 16,
eval_batch_size: 16,
}
}
pub fn with_batch_size(mut self, n: usize) -> Self {
self.batch_size = n;
self
}
pub fn with_eval_batch_size(mut self, n: usize) -> Self {
self.eval_batch_size = n;
self
}
pub fn uniform(n: usize) -> Self {
Self {
batch_size: n,
eval_batch_size: n,
}
}
}