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 theEnv
traitR
- The replay buffer type that implements theReplayBufferBase
trait
Required Methods§
Sourcefn write(&mut self, record: Record)
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
Provided Methods§
Sourcefn save_model(&self, base: &Path, agent: &Box<dyn Agent<E, R>>) -> Result<()>
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 savedagent
- 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.
Sourcefn load_model(
&self,
base: &Path,
agent: &mut Box<dyn Agent<E, R>>,
) -> Result<()>
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 savedagent
- 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.