Skip to main content

RealtimeAsyncWorld

Struct RealtimeAsyncWorld 

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

Realtime asynchronous simulation world.

Runs the tick engine on a background thread and serves observations from a pool of egress workers. This is the primary API for RL training environments.

Implementations§

Source§

impl RealtimeAsyncWorld

Source

pub fn new( config: WorldConfig, async_config: AsyncConfig, ) -> Result<Self, ConfigError>

Create a new realtime async world and spawn all threads.

The WorldConfig is consumed: the TickEngine is moved into the tick thread. The space is shared via Arc for egress workers that need it for agent-relative observations.

Source

pub fn submit_commands( &self, commands: Vec<Command>, ) -> Result<Vec<Receipt>, SubmitError>

Submit commands to be processed in the next tick.

Non-blocking: sends the batch via channel and blocks only for the receipt reply (which arrives within one tick period).

Source

pub fn observe( &self, plan: &Arc<ObsPlan>, output: &mut [f32], mask: &mut [u8], ) -> Result<ObsMetadata, ObsError>

Extract an observation from the latest snapshot.

Blocking: dispatches to an egress worker and waits for the result. The output and mask buffers must be pre-allocated.

Source

pub fn observe_agents( &self, plan: &Arc<ObsPlan>, space: &Arc<dyn Space>, agent_centers: &[Coord], output: &mut [f32], mask: &mut [u8], ) -> Result<Vec<ObsMetadata>, ObsError>

Extract agent-relative observations from the latest snapshot.

Each agent gets output_len / n_agents elements in the output buffer.

Source

pub fn latest_snapshot(&self) -> Option<Arc<OwnedSnapshot>>

Get the latest snapshot directly from the ring.

Source

pub fn current_epoch(&self) -> u64

Current epoch (lock-free read).

Source

pub fn shutdown(&mut self) -> ShutdownReport

Shutdown the world with the 4-state machine.

  1. Running → Draining (≤33ms): Set shutdown flag, wait for tick stop.
  2. Draining → Quiescing (≤200ms): Cancel workers, drop obs channel.
  3. Quiescing → Dropped (≤10ms): Join all threads.
Source

pub fn reset(&mut self, seed: u64) -> Result<(), ConfigError>

Reset the world: stop all threads, reset engine state, restart.

This is the RL episode-boundary operation. The engine is recovered from the tick thread, reset in-place, then respawned with fresh channels and worker threads.

Source

pub fn space(&self) -> &dyn Space

The shared space used for agent-relative observations.

Trait Implementations§

Source§

impl Drop for RealtimeAsyncWorld

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

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.