pub struct EnvPool<E: Environment> { /* private fields */ }Expand description
A pool of environments for parallel execution
EnvPool manages multiple environment instances and executes operations across them in parallel using Rayon’s thread pool. This provides significant performance improvements over sequential execution.
§Performance
For N environments with average step time T:
- Sequential: O(N * T)
- Parallel: O(max(T)) ≈ O(T) when N ≤ num_cores
This can provide 10-100x speedups depending on environment complexity and number of CPU cores available.
§Action type
EnvPool is currently restricted to discrete-action envs
(E::Action = i64). The pool’s step signature passes
&[i64] because every existing trainer and example expects a
dense vector of integer action indices. Adding pool support for
continuous-action envs (e.g. SAC) is a separate follow-up; see
issue #61 for the rationale behind the associated-type design.
Implementations§
Source§impl<E: Environment<Action = i64> + Send> EnvPool<E>
impl<E: Environment<Action = i64> + Send> EnvPool<E>
Sourcepub fn reset(&mut self) -> Vec<Vec<f32>>where
E: Send,
pub fn reset(&mut self) -> Vec<Vec<f32>>where
E: Send,
Reset all environments in parallel
Returns a vector of initial observations, one per environment.
§Example
let observations = pool.reset();
assert_eq!(observations.len(), 4);Sourcepub fn observation_space(&self) -> SpaceInfo
pub fn observation_space(&self) -> SpaceInfo
Get observation space information from first environment
Sourcepub fn action_space(&self) -> SpaceInfo
pub fn action_space(&self) -> SpaceInfo
Get action space information from first environment
Source§impl<E: Environment<Action = i64> + Send> EnvPool<E>
impl<E: Environment<Action = i64> + Send> EnvPool<E>
Sourcepub fn step_structured(&mut self, actions: &[i64]) -> PoolStepResult<Vec<f32>>
pub fn step_structured(&mut self, actions: &[i64]) -> PoolStepResult<Vec<f32>>
Step all environments and return structured result
This is a convenience method that unpacks individual StepResults into a single PoolStepResult with parallel vectors.
Auto Trait Implementations§
impl<E> Freeze for EnvPool<E>
impl<E> RefUnwindSafe for EnvPool<E>where
E: RefUnwindSafe,
impl<E> Send for EnvPool<E>where
E: Send,
impl<E> Sync for EnvPool<E>where
E: Sync,
impl<E> Unpin for EnvPool<E>where
E: Unpin,
impl<E> UnsafeUnpin for EnvPool<E>
impl<E> UnwindSafe for EnvPool<E>where
E: UnwindSafe,
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> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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