pub struct AsyncCollector { /* private fields */ }Expand description
Asynchronous rollout collector that runs env stepping and GAE computation in a background thread, sending completed batches through a channel.
The collector requires two external function pointers:
action_fn: given flat observations[n_envs * obs_dim], returns(actions_flat, log_probs)where actions are[n_envs * act_dim]and log_probs are[n_envs].value_fn: given flat observations[n_envs * obs_dim], returns value estimates[n_envs].
This design lets the Python side own the neural network while Rust handles the tight env-stepping loop.
Implementations§
Source§impl AsyncCollector
impl AsyncCollector
Sourcepub fn start(
envs: Box<dyn BatchSteppable>,
n_steps: usize,
gamma: f64,
gae_lambda: f64,
tx: Sender<RolloutBatch>,
value_fn: Arc<dyn Fn(&[f32]) -> Vec<f64> + Send + Sync>,
action_fn: Arc<dyn Fn(&[f32]) -> (Vec<f32>, Vec<f64>) + Send + Sync>,
) -> Self
pub fn start( envs: Box<dyn BatchSteppable>, n_steps: usize, gamma: f64, gae_lambda: f64, tx: Sender<RolloutBatch>, value_fn: Arc<dyn Fn(&[f32]) -> Vec<f64> + Send + Sync>, action_fn: Arc<dyn Fn(&[f32]) -> (Vec<f32>, Vec<f64>) + Send + Sync>, ) -> Self
Start the collector in a background thread.
The collector will repeatedly:
- Collect
n_stepsof experience from all envs - Compute GAE advantages and returns
- Send the resulting
RolloutBatchthroughtx
It stops when stop() is called or the channel is disconnected.
Sourcepub fn is_stopped(&self) -> bool
pub fn is_stopped(&self) -> bool
Check whether the collector has been asked to stop.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for AsyncCollector
impl !RefUnwindSafe for AsyncCollector
impl Send for AsyncCollector
impl Sync for AsyncCollector
impl Unpin for AsyncCollector
impl !UnwindSafe for AsyncCollector
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
Mutably borrows from an owned value. Read more
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>
Converts
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>
Converts
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