Skip to content

allenact.base_abstractions.sensor#

[view_source]

Sensor#

class Sensor(Generic[EnvType, SubTaskType])

[view_source]

Represents a sensor that provides data from the environment to agent. The user of this class needs to implement the get_observation method and the user is also required to set the below attributes:

Attributes

  • uuid: universally unique id.
  • observation_space: gym.Space object corresponding to observation of sensor.

Sensor.get_observation#

 | get_observation(env: EnvType, task: Optional[SubTaskType], *args: Any, **kwargs: Any) -> Any

[view_source]

Returns observations from the environment (or task).

Parameters

  • env : The environment the sensor is used upon.
  • task : (Optionally) a Task from which the sensor should get data.

Returns

Current observation for Sensor.

SensorSuite#

class SensorSuite(Generic[EnvType])

[view_source]

Represents a set of sensors, with each sensor being identified through a unique id.

Attributes

  • sensors: list containing sensors for the environment, uuid of each sensor must be unique.

SensorSuite.__init__#

 | __init__(sensors: Sequence[Sensor]) -> None

[view_source]

Initializer.

Parameters

  • param sensors: the sensors that will be included in the suite.

SensorSuite.get#

 | get(uuid: str) -> Sensor

[view_source]

Return sensor with the given uuid.

Parameters

  • uuid : The unique id of the sensor

Returns

The sensor with unique id uuid.

SensorSuite.get_observations#

 | get_observations(env: EnvType, task: Optional[SubTaskType], **kwargs: Any) -> Dict[str, Any]

[view_source]

Get all observations corresponding to the sensors in the suite.

Parameters

  • env : The environment from which to get the observation.
  • task : (Optionally) the task from which to get the observation.

Returns

Data from all sensors packaged inside a Dict.

AbstractExpertSensor#

class AbstractExpertSensor(Sensor[EnvType, SubTaskType],  abc.ABC)

[view_source]

Base class for sensors that obtain the expert action for a given task (if available).

AbstractExpertSensor.__init__#

 | __init__(action_space: Optional[Union[gym.Space, int]] = None, uuid: str = "expert_sensor_type_uuid", expert_args: Optional[Dict[str, Any]] = None, nactions: Optional[int] = None, use_dict_as_groups: bool = True, **kwargs: Any, ,) -> None

[view_source]

Initialize an ExpertSensor.

Parameters

  • action_space : The action space of the agent. This is necessary in order for this sensor to know what its output observation space is.
  • uuid : A string specifying the unique ID of this sensor.
  • expert_args : This sensor obtains an expert action from the task by calling the query_expert method of the task. expert_args are any keyword arguments that should be passed to the query_expert method when called.
  • nactions : [DEPRECATED] The number of actions available to the agent, corresponds to an action_space of gym.spaces.Discrete(nactions).
  • use_dict_as_groups : Whether to use the top-level action_space of type gym.spaces.Dict as action groups.

AbstractExpertSensor.flagged_group_space#

 | @classmethod
 | @abc.abstractmethod
 | flagged_group_space(cls, group_space: gym.spaces.Space) -> gym.spaces.Dict

[view_source]

gym space resulting from wrapping the given action space (or a derived space, as in AbstractExpertPolicySensor) together with a binary action space corresponding to an expert success flag, in a Dict space.

Parameters

  • group_space : The source action space to be (optionally used to derive a policy space,) flagged and wrapped

AbstractExpertSensor.flagged_space#

 | @classmethod
 | flagged_space(cls, action_space: gym.spaces.Space, use_dict_as_groups: bool = True) -> gym.spaces.Dict

[view_source]

gym space resulting from wrapping the given action space (or every highest-level entry in a Dict action space), together with binary action space corresponding to an expert success flag, in a Dict space.

Parameters

  • action_space : The agent's action space (to be flagged and wrapped)
  • use_dict_as_groups : Flag enabling every highest-level entry in a Dict action space to be independently flagged.

AbstractExpertSensor.query_expert#

 | @abc.abstractmethod
 | query_expert(task: SubTaskType, expert_sensor_group_name: Optional[str]) -> Tuple[Any, bool]

[view_source]

Query the expert for the given task (and optional group name).

Returns

A tuple (x, y) where x is the expert action or policy and y is False \ if the expert could not determine the optimal action (otherwise True). Here y \ is used for masking. Even when y is False, x should still lie in the space of \ possible values (e.g. if x is the expert policy then x should be the correct length, \ sum to 1, and have non-negative entries).

AbstractExpertActionSensor#

class AbstractExpertActionSensor(AbstractExpertSensor,  abc.ABC)

[view_source]

AbstractExpertActionSensor.flagged_group_space#

 | @classmethod
 | flagged_group_space(cls, group_space: gym.spaces.Space) -> gym.spaces.Dict

[view_source]

gym space resulting from wrapping the given action space, together with a binary action space corresponding to an expert success flag, in a Dict space.

Parameters

  • group_space : The action space to be flagged and wrapped

ExpertActionSensor#

class ExpertActionSensor(AbstractExpertActionSensor)

[view_source]

(Deprecated) A sensor that obtains the expert action from a given task (if available).

AbstractExpertPolicySensor#

class AbstractExpertPolicySensor(AbstractExpertSensor,  abc.ABC)

[view_source]

AbstractExpertPolicySensor.flagged_group_space#

 | @classmethod
 | flagged_group_space(cls, group_space: gym.spaces.Space) -> gym.spaces.Dict

[view_source]

gym space resulting from wrapping the policy space corresponding to allenact.utils.spaces_utils.policy_space(group_space) together with a binary action space corresponding to an expert success flag, in a Dict space.

Parameters

  • group_space : The source action space to be used to derive a policy space, flagged and wrapped

ExpertPolicySensor#

class ExpertPolicySensor(AbstractExpertPolicySensor)

[view_source]

(Deprecated) A sensor that obtains the expert policy from a given task (if available).