border_core/record.rs
1//! Types and traits for recording and managing training metrics.
2//!
3//! This module provides a comprehensive system for recording, storing, and managing
4//! various types of data during reinforcement learning training and evaluation.
5//! It includes support for different data types, aggregation, and flexible storage
6//! backends.
7//!
8//! # Core Components
9//!
10//! * [`Record`] - A flexible container for storing key-value pairs of various data types
11//! * [`RecordValue`] - An enum representing different types of values that can be stored
12//! * [`Recorder`] - A trait defining the interface for recording and storing data
13//! * [`RecordStorage`] - A storage system with aggregation capabilities
14//! * [`BufferedRecorder`] - A recorder that temporarily stores records in memory
15//! * [`NullRecorder`] - A recorder that discards all records (useful for testing)
16//!
17//! # Basic Usage
18//!
19//! ```rust
20//! use border_core::record::{Record, RecordValue};
21//!
22//! // following values are obtained with some process in reality
23//! let step = 1;
24//! let obs = vec![1f32, 2.0, 3.0, 4.0, 5.0];
25//! let reward = -1f32;
26//!
27//! let mut record = Record::empty();
28//! record.insert("Step", RecordValue::Scalar(step as f32));
29//! record.insert("Reward", RecordValue::Scalar(reward));
30//! record.insert("Obs", RecordValue::Array1(obs));
31//! ```
32//!
33//! # Integration with Training
34//!
35//! The recording system is designed to work seamlessly with the training process.
36//! The [`Trainer`](crate::Trainer) uses a [`Recorder`] to log training metrics
37//! and other relevant information during the training loop.
38//!
39//! # Data Types
40//!
41//! The module supports various data types through [`RecordValue`]:
42//!
43//! * `Scalar(f32)` - Single floating-point values
44//! * `DateTime(DateTime<Local>)` - Timestamps
45//! * `Array1(Vec<f32>)` - 1-dimensional arrays
46//! * `Array2(Vec<f32>, [usize; 2])` - 2-dimensional arrays with shape
47//! * `Array3(Vec<f32>, [usize; 3])` - 3-dimensional arrays with shape
48//! * `String(String)` - Text values
49//!
50//! [`HashMap`]: std::collections::HashMap
51mod base;
52mod buffered_recorder;
53mod null_recorder;
54mod recorder;
55mod storage;
56
57pub use base::{Record, RecordValue};
58pub use buffered_recorder::BufferedRecorder;
59pub use null_recorder::NullRecorder;
60pub use recorder::Recorder;
61pub use storage::RecordStorage;