flatland.core.env_observation_builder module#

ObservationBuilder objects are objects that can be passed to environments designed for customizability. The ObservationBuilder-derived custom classes implement 2 functions, reset(env) and get() or get(handle).

  • reset(env) is called after each environment reset, to allow for pre-computing relevant data. It receives the (possibly newly generated) env instance, so any instantiations depending on env parameters (e.g. width, height) should be done here rather than in __init__.

  • get() is called whenever an observation has to be computed, potentially for each agent independently in case of multi-agent environments.

class flatland.core.env_observation_builder.DummyObservationBuilder[source]#

Bases: ObservationBuilder[Environment, bool]

DummyObservationBuilder class which returns dummy observations This is used in the evaluation service

get(handle: int = 0) → bool[source]#

Called whenever an observation has to be computed for the env environment, possibly for each agent independently (agent id handle).

Parameters#

handleint, optional

Handle of the agent for which to compute the observation vector.

Returns#

function

An observation structure, specific to the corresponding environment.

class flatland.core.env_observation_builder.ObservationBuilder[source]#

Bases: Generic[EnvT, ObservationT]

ObservationBuilder base class.

get(handle: int = 0) → ObservationT[source]#

Called whenever an observation has to be computed for the env environment, possibly for each agent independently (agent id handle).

Parameters#

handleint, optional

Handle of the agent for which to compute the observation vector.

Returns#

function

An observation structure, specific to the corresponding environment.

get_many(handles: List[int] | None = None) → Dict[int, ObservationT][source]#

Called whenever an observation has to be computed for the env environment, for each agent with handle in the handles list.

Parameters#

handleslist of handles, optional

List with the handles of the agents for which to compute the observation vector.

Returns#

function

A dictionary of observation structures, specific to the corresponding environment, with handles from handles as keys.

reset(env: EnvT)[source]#

Called after each environment reset, to allow for pre-computing relevant data. Receives the (possibly newly generated) env instance, so any instantiations depending on env parameters (e.g. width, height) should be made here rather than in __init__.

Subclasses that need to pre-compute env-dependent data should override this method and call super().reset(env) first to keep self.env up to date.

Randomness per episode: an observation builder that keeps random state across steps (e.g. a perturbation with its own malfunction generator) starts it over here. env.reset(random_seed=s) reseeds only env.np_random; an observation builder doesn’t seed itself, and one that draws from a RandomState its caller passes in is reproducible only if the caller reseeds that RandomState before env.reset().

Parameters#

envEnvT

the (possibly newly generated) environment instance

flatland.core.env_observation_builder.gauss_perturbation_observation_builder_wrapper(builder: ObservationBuilder[Environment, ndarray], np_random: RandomState, mu: ndarray = None, sigma: ndarray = None) → ObservationBuilder[Environment, ndarray][source]#

Perturb a numpy array based observation with Gaussian noise.

Parameters#

builder : ObservationBuilder[np.ndarray] np_random : RandomState mu : np.ndarray

mean of appropriate size, defaults to 0

sigmanp.ndarray

sigma of appropriate size, defaults to 1

Returns#

observation with Gaussian noise added

The noise is drawn from np_random, which env.reset(random_seed=…) doesn’t reseed: to reproduce it, reseed np_random before env.reset().