Skip to main content

ObsPlanCache

Struct ObsPlanCache 

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

Cached observation plan with space-topology-based invalidation.

Holds an ObsSpec and an optional compiled ObsPlan. On each call to execute, checks whether the cached plan was compiled for the same space (by SpaceInstanceId and cell count). On mismatch, the plan is recompiled transparently.

§Example

let mut cache = ObsPlanCache::new(spec);
// First call compiles the plan:
let meta = cache.execute(&space, &snapshot, None, &mut output, &mut mask)?;
// Subsequent calls reuse it (same space):
let meta = cache.execute(&space, &snapshot, None, &mut output, &mut mask)?;

§Invalidation

The plan is recompiled when:

  • No plan has been compiled yet.
  • A different space instance is passed (different SpaceInstanceId).
  • The same space object’s cell_count() has changed (topology mutation).
  • invalidate is called explicitly.

The plan is not recompiled when:

  • The snapshot’s WorldGenerationId changes (that is per-tick churn, not a topology change).

Implementations§

Source§

impl ObsPlanCache

Source

pub fn new(spec: ObsSpec) -> Self

Create a new cache for the given observation spec.

The plan is not compiled until the first call to execute or get_or_compile.

Source

pub fn get_or_compile( &mut self, space: &dyn Space, ) -> Result<&ObsPlan, ObsError>

Get the cached plan, recompiling if needed.

Returns the cached plan if one exists and was compiled for the same space (by SpaceInstanceId and cell count). Otherwise recompiles from the stored ObsSpec.

Source

pub fn execute( &mut self, space: &dyn Space, snapshot: &dyn SnapshotAccess, engine_tick: Option<TickId>, output: &mut [f32], mask: &mut [u8], ) -> Result<ObsMetadata, ObsError>

Execute the observation plan against a snapshot, recompiling if the space has changed.

This is the primary convenience method. It calls get_or_compile then ObsPlan::execute.

engine_tick is the current engine tick for computing ObsMetadata::age_ticks. Pass None in Lockstep mode (age is always 0).

Source

pub fn execute_agents( &mut self, space: &dyn Space, snapshot: &dyn SnapshotAccess, agent_centers: &[Coord], engine_tick: Option<TickId>, output: &mut [f32], mask: &mut [u8], ) -> Result<Vec<ObsMetadata>, ObsError>

Execute the Standard plan for N agents, recompiling if the space has changed.

Convenience wrapper over get_or_compile

Source

pub fn output_len(&self) -> Option<usize>

Output length of the currently cached plan, or None if no plan has been compiled yet.

Source

pub fn mask_len(&self) -> Option<usize>

Mask length of the currently cached plan.

Source

pub fn entry_shapes(&self) -> Option<&[Vec<usize>]>

Entry shapes of the currently cached plan.

Source

pub fn is_compiled(&self) -> bool

Whether a compiled plan is currently cached.

Source

pub fn invalidate(&mut self)

Invalidate the cached plan, forcing recompilation on next use.

Trait Implementations§

Source§

impl Debug for ObsPlanCache

Source§

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

Formats the value using the given formatter. 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.