Skip to main content

ReplayBuffer

Struct ReplayBuffer 

Source
pub struct ReplayBuffer { /* private fields */ }
Expand description

Circular fixed-capacity owner for off-policy transitions.

Batched append and deterministic uniform sampling are recorded on the one owning runtime. Cursor and size are host control metadata and never require a Matrix readback.

Implementations§

Source§

impl ReplayBuffer

Source

pub fn new(runtime: &Runtime, config: ReplayConfig) -> Result<Self>

Allocate empty circular replay storage on runtime.

§Errors

Returns an error for zero capacity, non-F32/I32 actions, invalid field ranks or extents, GPU-index overflow, or allocation failure.

Source

pub fn append(&self, transition: &ReplayTransition) -> Result<()>

Record one batched circular append.

§Errors

Returns an error unless the batch is nonempty, no larger than capacity, all fields match the configured shape/dtype/runtime contract, source and retained storage do not alias, and GPU recording succeeds.

Source

pub fn sample(&self, batch_size: usize, seed: u64) -> Result<ReplayBatch>

Record deterministic uniform sampling with replacement.

The returned U32 index vector identifies every sampled physical replay slot exactly.

§Errors

Returns an error while storage is empty, for a zero sample count, on GPU indexing/allocation failure, or when recording fails.

Source

pub fn reset(&self)

Forget all retained transitions without recording device work.

Existing bytes remain inaccessible until overwritten by later appends.

Source

pub fn is_full(&self) -> bool

Return whether capacity is completely occupied.

Source

pub fn len(&self) -> usize

Return the number of accessible transitions.

Source

pub const fn is_empty(&self) -> bool

Return whether no transition is accessible.

Source

pub const fn capacity(&self) -> usize

Return the fixed transition capacity.

Source

pub fn cursor(&self) -> usize

Return the physical slot that receives the next append lane.

Source

pub const fn config(&self) -> &ReplayConfig

Return the validated replay configuration.

Source

pub fn capture_state(&self) -> Result<ReplayBufferState>

Capture the complete active replay contents, size, and circular write cursor into a host-owned snapshot.

This is an explicit host-observation boundary: pending GPU appends on the owning runtime are flushed before reading the active 0..len() slots.

§Errors

Returns an error when any storage readback fails or element counts overflow host indexing.

Source

pub fn restore_state(&self, state: &ReplayBufferState) -> Result<()>

Restore a captured replay snapshot into this buffer fail-closed.

Validates schema equality, circular-cursor invariants, and payload lengths before uploading active transitions into physical slots 0..len and flushing the owning runtime.

§Errors

Returns an error if state has a mismatched configuration or malformed fields, or if device upload or synchronization fails.

Source

pub fn save(&self, path: impl AsRef<Path>) -> Result<()>

Atomically persist the active replay contents, size, and cursor to path.

§Errors

Returns an error when readback, encoding, temporary write, flush, or rename fails.

Source

pub fn load_into(&self, path: impl AsRef<Path>) -> Result<()>

Load a persisted replay file from path into this buffer fail-closed.

§Errors

Returns crate::ErrorKind::CheckpointCorrupt for malformed, truncated, or checksum-invalid files, or another error on schema mismatch or device restore failure.

Auto Trait Implementations§

§

impl !Freeze for ReplayBuffer

§

impl !RefUnwindSafe for ReplayBuffer

§

impl !Send for ReplayBuffer

§

impl !Sync for ReplayBuffer

§

impl !UnwindSafe for ReplayBuffer

§

impl Forget for ReplayBuffer

§

impl Move for ReplayBuffer

§

impl Unpin for ReplayBuffer
where *const u8 is !null: Unpin, Rc<RefCell<RuntimeState>>: Unpin, Rc<StorageInner>: Unpin, Rc<MatrixSemantic>: Unpin, Rc<()>: Unpin,

§

impl UnsafeUnpin for ReplayBuffer
where *const u8 is !null: UnsafeUnpin, PhantomData<usize>: UnsafeUnpin, *const RcInner<RefCell<RuntimeState>> is !null: UnsafeUnpin, PhantomData<RcInner<RefCell<RuntimeState>>>: UnsafeUnpin, *const RcInner<StorageInner> is !null: UnsafeUnpin, PhantomData<RcInner<StorageInner>>: UnsafeUnpin, *const RcInner<MatrixSemantic> is !null: UnsafeUnpin, PhantomData<RcInner<MatrixSemantic>>: UnsafeUnpin, PhantomData<Rc<()>>: UnsafeUnpin,

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<S, T> Duplex<S> for T
where T: FromSample<S> + ToSample<S>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<S> FromSample<S> for S

Source§

fn from_sample_(s: S) -> S

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<F, T> IntoSample<T> for F
where T: FromSample<F>,

Source§

fn into_sample(self) -> T

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> ToSample<U> for T
where U: FromSample<T>,

Source§

fn to_sample_(self) -> U

Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.