Skip to main content

CompiledEnv

Trait CompiledEnv 

Source
pub trait CompiledEnv: Send + Sync {
    type State: Clone + Send + Sync + Debug;
    type Obs: Clone + Send + Sync + Debug;
    type Action: CompiledAction;

Show 14 methods // Required methods fn name(&self) -> &'static str; fn action_space(&self) -> ActionSpace; fn obs_len(&self) -> usize; fn reset(&self, key: [u32; 2]) -> (Self::Obs, Self::State); fn step( &self, key: [u32; 2], state: &Self::State, action: Self::Action, ) -> CompiledStep<Self::Obs, Self::State>; fn step_in_place( &self, key: [u32; 2], state: &mut Self::State, action: Self::Action, obs: &mut Self::Obs, ) -> StepInfo; fn step_in_place_with_final( &self, key: [u32; 2], state: &mut Self::State, action: Self::Action, obs: &mut Self::Obs, final_obs: &mut Self::Obs, ) -> StepInfo; fn obs_shape(&self) -> Vec<usize>; fn obs_into(&self, obs: &Self::Obs, out: &mut [f32]); fn state_leaves(&self, state: &Self::State) -> Vec<HostArray>; fn obs_leaves(&self, obs: &Self::Obs) -> Vec<HostArray>; fn state_from_leaves(&self, leaves: &[HostArray]) -> Self::State; // Provided methods fn num_actions(&self) -> usize { ... } fn legal_action_mask(&self, state: &Self::State, out: &mut [bool]) -> bool { ... }
}
Expand description

An environment compiled by generate: reset and step (with the automatic reset of Environment::step) with the parameters fixed at generation, on states of fixed-size arrays. Keys are the two words of a JAX key (see key and split_key).

Required Associated Types§

Source

type State: Clone + Send + Sync + Debug

The state: a tuple struct of the state’s leaves.

Source

type Obs: Clone + Send + Sync + Debug

The observation: a tuple struct of the observation’s leaves.

Source

type Action: CompiledAction

An action: i32 (discrete), f32 (one element), or [f32; N].

Required Methods§

Source

fn name(&self) -> &'static str

The environment’s name (Environment::name).

Source

fn action_space(&self) -> ActionSpace

Source

fn obs_len(&self) -> usize

The number of elements of an observation.

Source

fn reset(&self, key: [u32; 2]) -> (Self::Obs, Self::State)

A new episode.

Source

fn step( &self, key: [u32; 2], state: &Self::State, action: Self::Action, ) -> CompiledStep<Self::Obs, Self::State>

One step, with the automatic reset.

Source

fn step_in_place( &self, key: [u32; 2], state: &mut Self::State, action: Self::Action, obs: &mut Self::Obs, ) -> StepInfo

One step, with the automatic reset, in place: the state is updated and the observation written to obs (without the final observation, which CompiledEnv::step also gives).

Source

fn step_in_place_with_final( &self, key: [u32; 2], state: &mut Self::State, action: Self::Action, obs: &mut Self::Obs, final_obs: &mut Self::Obs, ) -> StepInfo

CompiledEnv::step_in_place that also writes the observation reached by the step, before any reset, to final_obs.

Source

fn obs_shape(&self) -> Vec<usize>

The shape of an observation (of its only leaf, or [obs_len] for several leaves).

Source

fn obs_into(&self, obs: &Self::Obs, out: &mut [f32])

Writes the observation’s elements (converted to f32) to out.

Source

fn state_leaves(&self, state: &Self::State) -> Vec<HostArray>

The leaves of a state (those of the environment’s state pytree).

Source

fn obs_leaves(&self, obs: &Self::Obs) -> Vec<HostArray>

The leaves of an observation.

Source

fn state_from_leaves(&self, leaves: &[HostArray]) -> Self::State

A state from its leaves.

Provided Methods§

Source

fn num_actions(&self) -> usize

The number of discrete actions (0 for continuous actions).

Source

fn legal_action_mask(&self, state: &Self::State, out: &mut [bool]) -> bool

Writes the legal action mask of state (over the joint actions, Environment::legal_action_mask) to out and returns true, or returns false if the environment has none.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§