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
impl BatchedEngine
Sourcepub fn new(
configs: Vec<WorldConfig>,
obs_spec: Option<&ObsSpec>,
) -> Result<Self, BatchError>
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.
Sourcepub fn step_and_observe(
&mut self,
commands: &[Vec<Command>],
output: &mut [f32],
mask: &mut [u8],
) -> Result<BatchResult, BatchError>
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.
Sourcepub fn step_all(
&mut self,
commands: &[Vec<Command>],
) -> Result<BatchResult, BatchError>
pub fn step_all( &mut self, commands: &[Vec<Command>], ) -> Result<BatchResult, BatchError>
Step all worlds without observation extraction.
Sourcepub fn observe_all(
&self,
output: &mut [f32],
mask: &mut [u8],
) -> Result<Vec<ObsMetadata>, BatchError>
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.
Sourcepub fn reset_world(&mut self, idx: usize, seed: u64) -> Result<(), BatchError>
pub fn reset_world(&mut self, idx: usize, seed: u64) -> Result<(), BatchError>
Reset a single world by index.
Sourcepub fn reset_all(&mut self, seeds: &[u64]) -> Result<(), BatchError>
pub fn reset_all(&mut self, seeds: &[u64]) -> Result<(), BatchError>
Reset all worlds with per-world seeds.
Sourcepub fn num_worlds(&self) -> usize
pub fn num_worlds(&self) -> usize
Number of worlds in the batch.
Sourcepub fn obs_output_len(&self) -> usize
pub fn obs_output_len(&self) -> usize
Per-world observation output length (f32 elements).
Sourcepub fn obs_mask_len(&self) -> usize
pub fn obs_mask_len(&self) -> usize
Per-world observation mask length (bytes).
Sourcepub fn world_tick(&self, idx: usize) -> Option<TickId>
pub fn world_tick(&self, idx: usize) -> Option<TickId>
Current tick ID of a specific world.