StreamBuffer#

class hybrid_aif.train.StreamBuffer[source]#

Bases: Module

A uniform replay buffer over a flat step stream. Device-side, a pytree.

Static shapes and traced counters like StaticBuffer, but capacity counts steps: extend() splices each episode onto one ring in completion order, and sample_windows() draws seq_len contiguous steps starting anywhere, so a window may cross episode boundaries; its is_first column marks the joins for observe(). Nothing is padded or truncated; eviction is FIFO by step.

Design: docs/design/amortization.md A12 chunk 2c §(d′)

data: Episode#

The step stream, one array per column, (capacity, ...).

size: Array#

The number of live steps (traced).

cursor: Array#

The next step slot to write (traced).

capacity: int#

The number of steps held.

seq_len: int#

The steps per sampled window.

schema: tuple[tuple[str, ColumnSpec], ...] = ()#

The task’s own columns, (name, ColumnSpec) pairs.

property pad_rules: dict[str, str]#

How fit_length() pads each task column, from the schema.

classmethod empty(capacity, seq_len, obs_dim, action_dim, extras=None)[source]#

An allocated, empty buffer. Shapes are fixed here and never change.

extras declares the task’s columns (ColumnSpec per name); every episode written must carry exactly those.

property windows: int#

How many distinct seq_len-step windows the live stream offers.

size − seq_len + 1, floored at 0: one window per valid start offset.

ready(batch_steps)[source]#

Whether the stream offers at least batch_steps windows yet. Host-side.

__init__(data, size, cursor, capacity, seq_len, schema=())#