Trait Recorder

Source
pub trait Recorder<E, R>
where E: Env, R: ReplayBufferBase,
{ // Required methods fn write(&mut self, record: Record); fn store(&mut self, record: Record); fn flush(&mut self, step: i64); // Provided methods fn save_model( &self, base: &Path, agent: &Box<dyn Agent<E, R>>, ) -> Result<()> { ... } fn load_model( &self, base: &Path, agent: &mut Box<dyn Agent<E, R>>, ) -> Result<()> { ... } }
Expand description

A trait for recording training metrics and managing model persistence.

The Recorder trait defines an interface for handling various aspects of reinforcement learning training, including:

  • Recording training metrics and observations
  • Storing and aggregating records
  • Managing model checkpoints

§Type Parameters

  • E - The environment type that implements the Env trait
  • R - The replay buffer type that implements the ReplayBufferBase trait

Required Methods§

Source

fn write(&mut self, record: Record)

Writes a record to the recorder’s output destination.

This method is called for each record that needs to be written immediately, such as during training or evaluation.

§Arguments
  • record - The record to be written
Source

fn store(&mut self, record: Record)

Stores a record for later processing or aggregation.

This method is used to collect records that will be processed together, typically during a flush operation.

§Arguments
  • record - The record to be stored
Source

fn flush(&mut self, step: i64)

Writes aggregated values from stored records.

This method is called to process and write any accumulated records, typically at the end of an episode or training step.

§Arguments
  • step - The current training step or episode number

Provided Methods§

Source

fn save_model(&self, base: &Path, agent: &Box<dyn Agent<E, R>>) -> Result<()>

Saves the current state of the agent’s model.

This method is used to create checkpoints of the agent’s model during training. The implementation should handle the specific requirements of the agent’s model format and storage needs.

§Arguments
  • base - The base path where the model should be saved
  • agent - The agent whose model should be saved
§Returns

A Result indicating success or failure of the save operation

§Note

The default implementation is unimplemented and will panic if called. Implementations should override this method to provide model saving functionality.

Source

fn load_model( &self, base: &Path, agent: &mut Box<dyn Agent<E, R>>, ) -> Result<()>

Loads a previously saved model state into the agent.

This method is used to restore an agent’s model from a checkpoint. The implementation should handle the specific requirements of the agent’s model format and storage needs.

§Arguments
  • base - The base path where the model was saved
  • agent - The agent whose model should be loaded
§Returns

A Result indicating success or failure of the load operation

§Note

The default implementation is unimplemented and will panic if called. Implementations should override this method to provide model loading functionality.

Implementors§

Source§

impl<E, R> Recorder<E, R> for BufferedRecorder<E, R>
where E: Env, R: ReplayBufferBase,

Source§

impl<E, R> Recorder<E, R> for NullRecorder<E, R>
where E: Env, R: ReplayBufferBase,