Skip to main content

CompiledVecEnv

Struct CompiledVecEnv 

Source
pub struct CompiledVecEnv<C: CompiledEnv> { /* private fields */ }
Expand description

A batch of environments compiled ahead of time (CompiledEnv), stepped in parallel and reset automatically, like VecEnv (the same keys, so the same trajectories as a VecEnv of the environment).

§Examples

use ruxla_env::compiled::{CompiledEnv, StepInfo};
use ruxla_env::{CompiledVecEnv, StepBuffers};

let mut envs = CompiledVecEnv::new(env, 8, 0);
let len = envs.obs_len();
let (mut obs, mut final_obs) = (vec![0.0; 8 * len], vec![0.0; 8 * len]);
let (mut reward, mut terminated, mut truncated) = ([0.0; 8], [false; 8], [false; 8]);
envs.step_into(
    &[0; 8],
    StepBuffers {
        obs: &mut obs,
        reward: &mut reward,
        terminated: &mut terminated,
        truncated: &mut truncated,
        final_obs: &mut final_obs,
    },
);

Implementations§

Source§

impl<C: CompiledEnv> CompiledVecEnv<C>
where C::State: Send, C::Obs: Send,

Source

pub fn new(env: C, num_envs: usize, seed: i64) -> Self

Creates num_envs environments and resets them, with the keys of VecEnv::new.

Source

pub fn reset(&mut self, seed: Option<i64>)

Starts new episodes in every environment (see VecEnv::reset).

Source

pub fn num_envs(&self) -> usize

The number of environments.

Source

pub fn env(&self) -> &C

The environment.

Source

pub fn states(&self) -> &[C::State]

The current states.

Source

pub fn obs_len(&self) -> usize

The number of elements of one observation.

Source

pub fn obs_into(&self, out: &mut [f32])

Writes the current observations to a flat buffer, environment after environment.

§Panics

Panics if the buffer does not have CompiledVecEnv::obs_len elements per environment.

Source

pub fn set_num_threads(&mut self, threads: usize)

Uses threads threads (the caller included) for the steps.

§Panics

Panics if threads is zero.

Source

pub fn legal_action_masks_into(&self, out: &mut [bool]) -> bool

Writes the legal action mask of every environment to out (see VecEnv::legal_action_masks_into).

§Panics

Panics if out has the wrong size.

Source

pub fn num_threads(&self) -> usize

The number of threads that step the environments.

Source

pub fn step_into(&mut self, actions: &[i32], out: StepBuffers<'_>)

Steps every environment with its action, in parallel, resetting the episodes that end, and writes the results to flat buffers (see VecEnv::step_into).

§Panics

Panics if the number of actions differs from the number of environments, or a buffer has the wrong size.

Source

pub fn step_into_without_final( &mut self, actions: Actions<'_>, obs_out: &mut [f32], reward: &mut [f32], terminated: &mut [bool], truncated: &mut [bool], )

CompiledVecEnv::step_into_actions without the final observations: the step is the one without them (CompiledEnv::step_in_place), so the generated code does not compute the observation reached before a reset, and only the next observations are converted to obs.

§Panics

Panics if the number or kind of actions is wrong, or a buffer has the wrong size.

Source

pub fn step_into_actions(&mut self, actions: Actions<'_>, out: StepBuffers<'_>)

CompiledVecEnv::step_into with actions of any kind.

§Panics

Panics if the number or kind of actions is wrong, or a buffer has the wrong size.

Trait Implementations§

Source§

impl<C: Debug + CompiledEnv> Debug for CompiledVecEnv<C>
where C::State: Debug, C::Obs: Debug,

Source§

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

Formats the value using the given formatter. Read more
Source§

impl<C> DynVecEnv for CompiledVecEnv<C>
where C: CompiledEnv, C::State: Send, C::Obs: Send,

Source§

fn describe(&self) -> Value

The environment.
Source§

fn num_envs(&self) -> usize

The number of environments.
Source§

fn num_threads(&self) -> usize

The number of threads.
Source§

fn set_num_threads(&mut self, threads: usize)

Changes the number of threads.
Source§

fn reset(&mut self, seed: Option<i64>)

Starts new episodes.
Source§

fn obs_into(&self, out: &mut [f32])

Writes the observations.
Source§

fn step_into(&mut self, actions: Actions<'_>, out: StepBuffers<'_>)

Steps every environment.
Source§

fn legal_action_masks(&self, out: &mut [bool]) -> bool

Writes the legal action masks, if any.
Source§

fn step_without_final( &mut self, actions: Actions<'_>, obs: &mut [f32], reward: &mut [f32], terminated: &mut [bool], truncated: &mut [bool], )

Steps every environment without the final observations.

Auto Trait Implementations§

§

impl<C> !RefUnwindSafe for CompiledVecEnv<C>

§

impl<C> !UnwindSafe for CompiledVecEnv<C>

§

impl<C> Freeze for CompiledVecEnv<C>
where C: Freeze,

§

impl<C> Send for CompiledVecEnv<C>

§

impl<C> Sync for CompiledVecEnv<C>

§

impl<C> Unpin for CompiledVecEnv<C>
where C: Unpin, <C as CompiledEnv>::State: Unpin, <C as CompiledEnv>::Obs: Unpin,

§

impl<C> UnsafeUnpin for CompiledVecEnv<C>
where C: 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
§

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

§

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

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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.

§

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

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.