ObservationSpec

class sorrel.observation.observation_spec.ObservationSpec(entity_list: list[str], full_view: bool, vision_radius: int | None = None, env_dims: Sequence[int] | None = None)

An abstract class of an object that contains the observation specifications for Sorrel agents.

entity_map

A mapping of the kinds of entities in the world totheir appearances.

Type:

dict[str, T]

vision_radius

The radius of the agent’s vision if full_view is False, 0 if full_view is True.

Type:

int

full_view

A boolean that determines whether the agent can see the entire environment.

Type:

bool

input_size

An int or sequence of ints that indicates the size of the observation.

Type:

Sequence[int]

Methods

Abstract Methods

ObservationSpec.__init__(entity_list: list[str], full_view: bool, vision_radius: int | None = None, env_dims: Sequence[int] | None = None)

Initialize the ObservationSpec object. This function uses generate_map() to create an entity map for the ObservationSpec based on entity_list.

Parameters:
  • entity_list – A list of the kinds of entities that appear in the environment.

  • full_view – Whether the agent can see the entire environment.

  • vision_radius – The radius of the agent’s vision. Must be provided if full_view is False.

  • env_dims – The dimensions of the environment. Must be provided if full_view is True.

abstractmethod ObservationSpec.generate_map(entity_list: list[str]) dict[str, T]

Given a list of entity kinds, return a dictionary of appearance values for the agent’s observation function.

This method is used when initializing the ObservationSpec object.

Parameters:

entity_list – A list of the kinds of entities that appears in the environment.

Returns:

A dictionary object matching each entity kind to an appearance.

abstractmethod ObservationSpec.observe(world: Gridworld, location: tuple | None = None) ndarray

Basic environment observation function.

Parameters:
  • world – The world toobserve.

  • location – The location of the observer. Must be provided if full_view is False.

  • True (If full_view is)

  • ignored. (this parameter is)

Returns:

The observation.

Non-Abstract Methods

ObservationSpec.override_entity_map(entity_map: dict[str, T]) None

Override the automatically generated entity map from generate_map() with a provided custom one.

Can be useful if multiple classes should have the same appearance.

Parameters:

entity_map – The new entity map to use.

OneHotObservationSpec

class sorrel.observation.observation_spec.OneHotObservationSpec(entity_list: list[str], full_view: bool, vision_radius: int | None = None, env_dims: Sequence[int] | None = None)

A subclass of ObservationSpec for Sorrel agents whose observations take the form of one-hot encodings.

entity_map

A mapping of the kinds of entities in the world totheir appearances.

Type:

dict[str, T]

vision_radius

The radius of the agent’s vision if full_view is False, 0 if full_view is True.

Type:

int

full_view

A boolean that determines whether the agent can see the entire environment.

Type:

bool

input_size

An int or sequence of ints that indicates the size of the observation.

Type:

Sequence[int]

Methods

OneHotObservationSpec.generate_map(entity_list: list[str]) dict[str, ndarray]

Generate a default entity map by automatically creating one-hot encodings for the entitity kinds in entity_list.

The EmptyEntity kind will receive an all-zero appearance.

This method is used when initializing the OneHotObservationSpec object. Overrides ObservationSpec.generate_map().

Parameters:

entity_list – A list of entities that appears in the environment.

Returns:

A dictionary object matching each entity to an appearance.

OneHotObservationSpec.observe(world: Gridworld, location: tuple | None = None) ndarray

Observes the environment using visual_field().

Overrides ObservationSpec.observe().

Parameters:
  • world – The world toobserve.

  • location – The location of the observer. Must be provided if full_view is False.

  • True (If full_view is)

  • ignored. (this parameter is)

Returns:

The one-hot coded observation, in the shape of (number of channels, 2 * vision + 1, 2 * vision + 1). If full_view is True, the shape will be (number of channels, env.width, env.layers).

AsciiObservationSpec

class sorrel.observation.observation_spec.AsciiObservationSpec(entity_list: list[str], full_view: bool, vision_radius: int | None = None, env_dims: Sequence[int] | None = None)

A subclass of ObservationSpec for Sorrel agents whose observations take the form of ascii representations.

entity_map

A mapping of the kinds of entities in the world totheir appearances.

Type:

dict[str, T]

vision_radius

The radius of the agent’s vision if full_view is False, 0 if full_view is True.

Type:

int

full_view

A boolean that determines whether the agent can see the entire environment.

Type:

bool

input_size

An int or sequence of ints that indicates the size of the observation.

Type:

Sequence[int]

Methods

AsciiObservationSpec.generate_map(entity_list: list[str]) dict[str, str]

Generate a default entity map by automatically creating ascii character representations for the entity kinds in entity_list through the following process:

  1. if the entity kind is “EmptyEntity” (see EmptyEntity), it will be represented by “.”

  2. all other entities are represented by the first character in their kind that is not already used.

  3. if the above procedure fails, the entity will be represented by an ascii character that has not been used, starting from the character “0” (48) and going up to “~” (126).

This method is used when initializing the AsciiObservationSpec object. Overrides ObservationSpec.generate_map().

Parameters:

entity_list – A list of entities that appears in the environment.

Returns:

A dictionary object matching each entity kind to an ascii appearance.

AsciiObservationSpec.observe(world: Gridworld, location: tuple | None = None) ndarray

Observes the environment using visual_field_ascii().

Overrides ObservationSpec.observe().

Parameters:
  • world – The world toobserve.

  • location – The location of the observer. Must be provided if full_view is False.

  • True (If full_view is)

  • ignored. (this parameter is)

Returns:

The ascii-coded observation, in the shape of (2 * vision + 1, 2 * vision + 1). If full_view is True, the shape will be (env.width, env.layers).