Skip to main content

TrainingRun

Struct TrainingRun 

Source
pub struct TrainingRun {
    pub metadata: RunMetadata,
    /* private fields */
}
Expand description

Manages the on-disk artefacts for a single training run.

Directory layout:

runs/<name>/<version>/<YYYYMMDD_HHMMSS>/
    metadata.json          ← name, version, step counts, timestamps
    config.json            ← serialized hyperparams (written by caller)
    checkpoints/
        step_<N>.mpk       ← periodic checkpoints
        latest.mpk         ← symlink-equivalent: overwritten each checkpoint
        best.mpk           ← best eval-reward checkpoint
    train_episodes.jsonl   ← one EpisodeRecord per line (training)
    eval_episodes.jsonl    ← one tagged EpisodeRecord per line (eval)

TrainingRun is not generic over the neural network backend. It manages directories and JSON; the caller (e.g. DqnTrainer) handles actual network serialization by using the paths returned by the checkpoint methods.

§Usage

// Start a new run
let run = TrainingRun::create("cartpole", "v1")?;
run.write_config(&(&config, &encoder, &mapper))?;

// During training
run.log_train_episode(&episode_record)?;
run.update_metadata(total_steps, total_episodes)?;
// (save network to run.checkpoint_path(step) yourself)

// Resume
let run = TrainingRun::resume("runs/cartpole/v1")?; // picks latest

Fields§

§metadata: RunMetadata

Loaded/created metadata.

Implementations§

Source§

impl TrainingRun

Source

pub fn create( name: impl Into<String>, version: impl Into<String>, ) -> Result<Self>

Create a brand-new run directory under runs/<name>/<version>/<timestamp>/.

Returns an error if the directory cannot be created or metadata cannot be written.

Source

pub fn resume(base_path: impl AsRef<Path>) -> Result<Self>

Resume the most recent run found under base_path.

base_path can be:

  • An exact run directory (runs/cartpole/v1/20260322_120000) — used directly.
  • A name/version directory (runs/cartpole/v1) — picks the lexicographically latest subdirectory (timestamps sort correctly).
  • A name directory (runs/cartpole) — picks latest version, then latest run.

Returns an error if no run is found or metadata.json is missing/corrupt.

Source

pub fn dir(&self) -> &Path

The root directory of this run.

Source

pub fn write_config<T: Serialize>(&self, config: &T) -> Result<()>

Write an arbitrary serialisable value to config.json.

Typically called once after create with a tuple of (&config, &encoder, &action_mapper).

Source

pub fn checkpoint_path(&self, step: usize) -> PathBuf

Path for a numbered checkpoint: checkpoints/step_<N>.mpk.

Pass this to DqnAgent::save (or network.save_file).

Source

pub fn latest_checkpoint_path(&self) -> PathBuf

Path for the rolling “latest” checkpoint: checkpoints/latest.mpk.

Overwrite this on every checkpoint save so users can always resume from the most recent state without knowing the step number.

Source

pub fn best_checkpoint_path(&self) -> PathBuf

Path for the best-eval-reward checkpoint: checkpoints/best.mpk.

Source

pub fn prune_checkpoints(&self, keep: usize) -> Result<()>

Delete old numbered checkpoints, keeping the keep most recent.

latest.mpk and best.mpk are never deleted.

Source

pub fn log_train_episode(&self, record: &EpisodeRecord) -> Result<()>

Append an episode record to train_episodes.jsonl.

Source

pub fn log_eval_episode( &self, record: &EpisodeRecord, total_steps: usize, ) -> Result<()>

Append an episode record (tagged with total_steps_at_eval) to eval_episodes.jsonl.

Source

pub fn update_metadata( &mut self, total_steps: usize, total_episodes: usize, ) -> Result<()>

Update step/episode counts and last_updated timestamp, then flush to disk.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoComptime for T

Source§

fn comptime(self) -> Self

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more