pub struct MmapReplayBuffer { /* private fields */ }Expand description
When replay buffer exceeds RAM capacity, transparently spill to disk. Uses mmap for lazy loading – only pages actually accessed are read.
Architecture:
hot: in-memoryReplayBufferfor recent data (fast sampling)cold: memory-mapped file for overflow data (ring-buffer with wrapping)- Sampling prefers hot data but can reach into cold
Implementations§
Source§impl MmapReplayBuffer
impl MmapReplayBuffer
Sourcepub fn new(
hot_capacity: usize,
total_capacity: usize,
obs_dim: usize,
act_dim: usize,
cold_path: PathBuf,
) -> Result<Self, RloxError>
pub fn new( hot_capacity: usize, total_capacity: usize, obs_dim: usize, act_dim: usize, cold_path: PathBuf, ) -> Result<Self, RloxError>
Create a new mmap-backed replay buffer.
hot_capacity records are kept in memory. When exceeded, the oldest
hot records spill to the cold file at cold_path. The total number of
records stored (hot + cold) is capped at total_capacity.
Sourcepub fn push(&mut self, record: ExperienceRecord) -> Result<(), RloxError>
pub fn push(&mut self, record: ExperienceRecord) -> Result<(), RloxError>
Push a record. If the hot buffer is full, the oldest hot record is spilled to cold storage before the new record is inserted.
Sourcepub fn push_batch(
&mut self,
obs_batch: &[f32],
next_obs_batch: &[f32],
actions_batch: &[f32],
rewards: &[f32],
terminated: &[f32],
truncated: &[f32],
) -> Result<(), RloxError>
pub fn push_batch( &mut self, obs_batch: &[f32], next_obs_batch: &[f32], actions_batch: &[f32], rewards: &[f32], terminated: &[f32], truncated: &[f32], ) -> Result<(), RloxError>
Push multiple transitions at once from flat arrays.
obs_batch shape: [n * obs_dim], next_obs_batch: same,
actions_batch: [n * act_dim], others: [n].
§terminated / truncated convention
These take &[f32] (not bool) for compatibility with numpy arrays
from the Python side. Non-zero values are treated as true.
This differs from push which accepts native bool.
Trait Implementations§
Source§impl Debug for MmapReplayBuffer
impl Debug for MmapReplayBuffer
Auto Trait Implementations§
impl Freeze for MmapReplayBuffer
impl RefUnwindSafe for MmapReplayBuffer
impl Send for MmapReplayBuffer
impl Sync for MmapReplayBuffer
impl Unpin for MmapReplayBuffer
impl UnwindSafe for MmapReplayBuffer
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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