Skip to content

Gym sensors


Air Force Research Laboratory (AFRL) Autonomous Capabilities Team (ACT3) Reinforcement Learning (RL) Core.

This is a US Government Work not subject to copyright protection in the US.

The use, dissemination or disclosure of data in this file is subject to limitation or restriction. See accompanying README and LICENSE for details.


Sensors for OpenAIGymSimulator

OpenAiGymRepeatedStateSensor (BaseSensor) ¤

Sensor that reports the observation of a given platform gym environment

Source code in corl/simulators/openai_gym/gym_sensors.py
class OpenAiGymRepeatedStateSensor(BaseSensor):
    """
    Sensor that reports the observation of a given platform gym environment
    """

    def __init__(self, parent_platform, config=None):

        obs_space = parent_platform.observation_space

        class GymSensorProp(BoxProp):
            """
            GymSensorProp can be updated via config and valdidate by pydantic
            """
            name: str = "GymStateSensor"
            low: typing.List[float] = obs_space.low.tolist()
            high: typing.List[float] = obs_space.high.tolist()
            unit: typing.List[str] = ["None"] * len(obs_space.low)
            description: str = "Gym Space"

        class GymSensorRepeatedProp(RepeatedProp):
            """
            GymSensorProp can be updated via config and valdidate by pydantic
            """
            name: str = "GymStateRepeatedSensor"
            max_len: int = 10
            child_space: typing.Dict[str, GymSensorProp] = {"GymState": GymSensorProp()}  # type: ignore
            description: str = "Gym Space Repeated"

        super().__init__(config=config, parent_platform=parent_platform, property_class=GymSensorRepeatedProp)

        self.obs_buffer = RingBuffer(capacity=self.measurement_properties.max_len, dtype=np.ndarray)

    @property
    def exclusiveness(self) -> typing.Set[str]:
        """Return exclusiveness"""
        return {"state_sensor"}

    def _calculate_measurement(self, state):
        self.obs_buffer.append(state.obs[self.parent_platform.name])
        ret = map(lambda x: {"GymState": x}, self.obs_buffer)
        return list(ret)

exclusiveness: Set[str] property readonly ¤

Return exclusiveness

OpenAiGymStateSensor (BaseSensor) ¤

Sensor that reports the observation of a given platform gym environment

Source code in corl/simulators/openai_gym/gym_sensors.py
class OpenAiGymStateSensor(BaseSensor):
    """
    Sensor that reports the observation of a given platform gym environment
    """

    def __init__(self, parent_platform, config=None):

        obs_space = parent_platform.observation_space

        class GymSensorProp(BoxProp):
            """
            GymSensorProp can be updated via config and valdidate by pydantic
            """
            name: str = "GymStateSensor"
            low: typing.List[float] = obs_space.low.tolist()
            high: typing.List[float] = obs_space.high.tolist()
            unit: typing.List[str] = ["None"] * len(obs_space.low)
            description: str = "Gym Space"

        super().__init__(parent_platform=parent_platform, config=config, property_class=GymSensorProp)

    @property
    def exclusiveness(self) -> typing.Set[str]:
        """Return exclusiveness"""
        return {"state_sensor"}

    def _calculate_measurement(self, state):
        return state.obs[self.parent_platform.name]

exclusiveness: Set[str] property readonly ¤

Return exclusiveness