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[EnvType, ObservationType]

ObservationBuilder base class.

get(handle: int = 0) ObservationType[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, ObservationType][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: EnvType)[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.

Parameters#

envEnvType

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 = None, sigma: ndarray | None = 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