Skip to main content

BatchedEngine

Struct BatchedEngine 

Source
pub struct BatchedEngine { /* private fields */ }
Expand description

Batched simulation engine owning N lockstep worlds.

Created from N WorldConfigs with an optional ObsSpec. All worlds must share the same space topology (validated at construction).

The primary interface is step_and_observe(): step all worlds, then extract observations into a contiguous buffer using ObsPlan::execute_batch().

Implementations§

Source§

impl BatchedEngine

Source

pub fn new( configs: Vec<WorldConfig>, obs_spec: Option<&ObsSpec>, ) -> Result<Self, BatchError>

Create a batched engine from N world configs.

If obs_spec is provided, compiles an ObsPlan from the first world’s space. All worlds must have the same cell_count (defensive check).

§Errors

Returns BatchError::Config if any world fails to construct, or BatchError::Observe if the obs plan fails to compile.

Source

pub fn step_and_observe( &mut self, commands: &[Vec<Command>], output: &mut [f32], mask: &mut [u8], ) -> Result<BatchResult, BatchError>

Step all worlds and extract observations in one call.

commands must have exactly num_worlds() entries. output must have at least num_worlds() * obs_output_len() elements. mask must have at least num_worlds() * obs_mask_len() bytes.

Returns per-world tick IDs and metrics.

Source

pub fn step_all( &mut self, commands: &[Vec<Command>], ) -> Result<BatchResult, BatchError>

Step all worlds without observation extraction.

Source

pub fn observe_all( &self, output: &mut [f32], mask: &mut [u8], ) -> Result<Vec<ObsMetadata>, BatchError>

Extract observations from all worlds without stepping.

Used after reset_all() to get initial observations.

Source

pub fn reset_world(&mut self, idx: usize, seed: u64) -> Result<(), BatchError>

Reset a single world by index.

Source

pub fn reset_all(&mut self, seeds: &[u64]) -> Result<(), BatchError>

Reset all worlds with per-world seeds.

Source

pub fn num_worlds(&self) -> usize

Number of worlds in the batch.

Source

pub fn obs_output_len(&self) -> usize

Per-world observation output length (f32 elements).

Source

pub fn obs_mask_len(&self) -> usize

Per-world observation mask length (bytes).

Source

pub fn world_tick(&self, idx: usize) -> Option<TickId>

Current tick ID of a specific world.

Auto Trait Implementations§

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, 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.