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§
Sourcetype Obs: Clone + Send + Sync + Debug
type Obs: Clone + Send + Sync + Debug
The observation: a tuple struct of the observation’s leaves.
Sourcetype Action: CompiledAction
type Action: CompiledAction
An action: i32 (discrete), f32 (one element), or [f32; N].
Required Methods§
Sourcefn name(&self) -> &'static str
fn name(&self) -> &'static str
The environment’s name (Environment::name).
Sourcefn action_space(&self) -> ActionSpace
fn action_space(&self) -> ActionSpace
The actions (Environment::action_space).
Sourcefn step(
&self,
key: [u32; 2],
state: &Self::State,
action: Self::Action,
) -> CompiledStep<Self::Obs, Self::State>
fn step( &self, key: [u32; 2], state: &Self::State, action: Self::Action, ) -> CompiledStep<Self::Obs, Self::State>
One step, with the automatic reset.
Sourcefn step_in_place(
&self,
key: [u32; 2],
state: &mut Self::State,
action: Self::Action,
obs: &mut Self::Obs,
) -> StepInfo
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).
Sourcefn 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 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.
Sourcefn obs_shape(&self) -> Vec<usize>
fn obs_shape(&self) -> Vec<usize>
The shape of an observation (of its only leaf, or [obs_len] for
several leaves).
Sourcefn obs_into(&self, obs: &Self::Obs, out: &mut [f32])
fn obs_into(&self, obs: &Self::Obs, out: &mut [f32])
Writes the observation’s elements (converted to f32) to out.
Sourcefn state_leaves(&self, state: &Self::State) -> Vec<HostArray>
fn state_leaves(&self, state: &Self::State) -> Vec<HostArray>
The leaves of a state (those of the environment’s state pytree).
Sourcefn obs_leaves(&self, obs: &Self::Obs) -> Vec<HostArray>
fn obs_leaves(&self, obs: &Self::Obs) -> Vec<HostArray>
The leaves of an observation.
Sourcefn state_from_leaves(&self, leaves: &[HostArray]) -> Self::State
fn state_from_leaves(&self, leaves: &[HostArray]) -> Self::State
A state from its leaves.
Provided Methods§
Sourcefn num_actions(&self) -> usize
fn num_actions(&self) -> usize
The number of discrete actions (0 for continuous actions).
Sourcefn legal_action_mask(&self, state: &Self::State, out: &mut [bool]) -> bool
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".