Skip to main content

VecEnv

Struct VecEnv 

Source
pub struct VecEnv<E: Env> { /* private fields */ }
Expand description

Synchronous vectorized environment.

Wraps a Vec<E> of homogeneous environments. All environments must share the same obs_dim and action_dim; this is validated lazily on the first step call to avoid redundant checks.

§Auto-reset

When step detects that environment i is done, it immediately calls reset() on it and places the resulting observation in the corresponding slot of VecStepResult::obs.

§Example

use oxicuda_rl::env::env::LinearQuadraticEnv;
use oxicuda_rl::env::vectorized::VecEnv;

let envs: Vec<_> = (0..4).map(|_| LinearQuadraticEnv::new(3, 50)).collect();
let mut ve = VecEnv::new(envs);
let obs = ve.reset_all().unwrap();
assert_eq!(obs.len(), 4 * 3);

Implementations§

Source§

impl<E: Env> VecEnv<E>

Source

pub fn new(envs: Vec<E>) -> Self

Create a new VecEnv from a non-empty vector of environments.

§Panics

Does not panic; returns an instance even with an empty envs slice (though subsequent calls will fail with RlError::DimensionMismatch).

Source

pub fn n_envs(&self) -> usize

Number of parallel environments.

Source

pub fn reset_all(&mut self) -> RlResult<Vec<f32>>

Reset all environments and return flattened observations.

Returns a Vec<f32> of length n_envs × obs_dim.

§Errors

Propagates any RlError from individual reset() calls.

Source

pub fn step(&mut self, actions: &[f32]) -> RlResult<VecStepResult>

Step all environments simultaneously.

actions must have length n_envs × action_dim; the slice is split into per-environment chunks before dispatch.

§Errors
  • RlError::DimensionMismatchactions.len() is not a multiple of n_envs, or a chunk length does not match the environment’s action_dim.
  • Any error propagated from individual step() or reset() calls.
Source

pub fn envs(&self) -> &[E]

Immutable access to the underlying environment slice.

Source

pub fn envs_mut(&mut self) -> &mut [E]

Mutable access to the underlying environment slice.

Trait Implementations§

Source§

impl<E: Debug + Env> Debug for VecEnv<E>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<E> Freeze for VecEnv<E>

§

impl<E> RefUnwindSafe for VecEnv<E>
where E: RefUnwindSafe,

§

impl<E> Send for VecEnv<E>
where E: Send,

§

impl<E> Sync for VecEnv<E>
where E: Sync,

§

impl<E> Unpin for VecEnv<E>
where E: Unpin,

§

impl<E> UnsafeUnpin for VecEnv<E>

§

impl<E> UnwindSafe for VecEnv<E>
where E: UnwindSafe,

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<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more