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>
impl<C: CompiledEnv> CompiledVecEnv<C>
Sourcepub fn new(env: C, num_envs: usize, seed: i64) -> Self
pub fn new(env: C, num_envs: usize, seed: i64) -> Self
Creates num_envs environments and resets them, with the keys of
VecEnv::new.
Sourcepub fn reset(&mut self, seed: Option<i64>)
pub fn reset(&mut self, seed: Option<i64>)
Starts new episodes in every environment (see VecEnv::reset).
Sourcepub fn obs_into(&self, out: &mut [f32])
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.
Sourcepub fn set_num_threads(&mut self, threads: usize)
pub fn set_num_threads(&mut self, threads: usize)
Sourcepub fn legal_action_masks_into(&self, out: &mut [bool]) -> bool
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.
Sourcepub fn num_threads(&self) -> usize
pub fn num_threads(&self) -> usize
The number of threads that step the environments.
Sourcepub fn step_into(&mut self, actions: &[i32], out: StepBuffers<'_>)
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.
Sourcepub fn step_into_without_final(
&mut self,
actions: Actions<'_>,
obs_out: &mut [f32],
reward: &mut [f32],
terminated: &mut [bool],
truncated: &mut [bool],
)
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.
Sourcepub fn step_into_actions(&mut self, actions: Actions<'_>, out: StepBuffers<'_>)
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.