Skip to content

Done func base


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.


DoneFuncBase (EnvFuncBase) ¤

Base implementation for done functors

Source code in corl/dones/done_func_base.py
class DoneFuncBase(EnvFuncBase):
    """Base implementation for done functors
    """
    _ALL = "__all__"

    def __init__(self, **kwargs) -> None:
        self.config: DoneFuncBaseValidator = self.get_validator(**kwargs)
        self.config.name = self.config.name if self.config.name else type(self).__name__

    @property
    def get_validator(self) -> typing.Type[DoneFuncBaseValidator]:
        """
        get validator for this Done Functor

        Returns:
            DoneFuncBaseValidator -- validator the done functor will use to generate a configuration
        """
        return DoneFuncBaseValidator

    @property
    def agent(self) -> str:
        """The agent to which this done is applied"""
        return self.config.agent_name

    @property
    def platform(self) -> str:
        """The platform to which this done is applied"""
        return self.config.platform_name

    @property
    def name(self) -> str:
        return self.config.name

    def _set_all_done(self, done):
        done[DoneFuncBase._ALL] = False
        if np.any(list(done.values())) and self.config.early_stop:
            done[DoneFuncBase._ALL] = True
            done = done.fromkeys(done, True)
        return done

    @staticmethod
    def _get_platform_time(platform):
        sensor = [s for s in platform.sensors if isinstance(s, BaseTimeSensor)]

        if not sensor:
            raise ValueError("Did not find time sensor type (BaseTimeSensor)")

        update_time = sensor[0].get_measurement()[0]

        return update_time

    @abc.abstractmethod
    def __call__(
        self,
        observation: OrderedDict,
        action: OrderedDict,
        next_observation: OrderedDict,
        next_state: StateDict,
        observation_space: StateDict,
        observation_units: StateDict,
    ) -> DoneDict:
        ...

agent: str property readonly ¤

The agent to which this done is applied

get_validator: Type[corl.dones.done_func_base.DoneFuncBaseValidator] property readonly ¤

get validator for this Done Functor

Returns:

Type Description
Type[corl.dones.done_func_base.DoneFuncBaseValidator]

DoneFuncBaseValidator -- validator the done functor will use to generate a configuration

name: str property readonly ¤

gets the name fo the functor

Returns¤

str The name of the functor

platform: str property readonly ¤

The platform to which this done is applied

DoneFuncBaseValidator (BaseModel) pydantic-model ¤

Initialize the done condition

All done conditions have three common parameters, with any others being handled by subclass validators

Parameters¤

name : str A name applied to this done condition, by default the name of the class. agent_name : str Name of the agent to which this done condition applies platform_name : str Name of the platform to which this done condition applies early_stop : bool, optional If True, set the done condition on "all" once any done condition is True. This is by default False.

Source code in corl/dones/done_func_base.py
class DoneFuncBaseValidator(BaseModel):
    """Initialize the done condition

    All done conditions have three common parameters, with any others being handled by subclass validators

    Parameters
    ----------
    name : str
        A name applied to this done condition, by default the name of the class.
    agent_name : str
        Name of the agent to which this done condition applies
    platform_name : str
        Name of the platform to which this done condition applies
    early_stop : bool, optional
        If True, set the done condition on "__all__" once any done condition is True.  This is by default False.
    """
    name: str = ""
    agent_name: str
    platform_name: str
    early_stop: bool = False

DoneStatusCodes (Enum) ¤

reward states for the done conditions

Source code in corl/dones/done_func_base.py
class DoneStatusCodes(Enum):
    """reward states for the done conditions
    """
    WIN = 1
    PARTIAL_WIN = 2
    DRAW = 3
    PARTIAL_LOSS = 4
    LOSE = 5

SharedDoneFuncBase (EnvFuncBase) ¤

Base implementation for global done functors

Global done functors are not associated with a single agent, but the environment as a whole. They use a modified call syntax that receives the done dictionary and done info from the per-agent done functors.

Source code in corl/dones/done_func_base.py
class SharedDoneFuncBase(EnvFuncBase):
    """Base implementation for global done functors

    Global done functors are not associated with a single agent, but the environment as a whole.  They use a modified call syntax that
    receives the done dictionary and done info from the per-agent done functors.
    """

    def __init__(self, **kwargs) -> None:
        self.config: SharedDoneFuncBaseValidator = self.get_validator(**kwargs)
        self.config.name = self.config.name if self.config.name else type(self).__name__

    @property
    def get_validator(self) -> typing.Type[SharedDoneFuncBaseValidator]:
        """
        gets the validator for this SharedDoneFuncBase

        Returns:
            SharedDoneFuncBaseValidator -- validator for this class
        """
        return SharedDoneFuncBaseValidator

    @property
    def name(self) -> str:
        return self.config.name

    @abc.abstractmethod
    def __call__(
        self,
        observation: OrderedDict,
        action: OrderedDict,
        next_observation: OrderedDict,
        next_state: StateDict,
        observation_space: StateDict,
        observation_units: StateDict,
        local_dones: DoneDict,
        local_done_info: OrderedDict
    ) -> DoneDict:
        ...

get_validator: Type[corl.dones.done_func_base.SharedDoneFuncBaseValidator] property readonly ¤

gets the validator for this SharedDoneFuncBase

Returns:

Type Description
Type[corl.dones.done_func_base.SharedDoneFuncBaseValidator]

SharedDoneFuncBaseValidator -- validator for this class

name: str property readonly ¤

gets the name fo the functor

Returns¤

str The name of the functor

SharedDoneFuncBaseValidator (BaseModel) pydantic-model ¤

name : str The name of this done condition

Source code in corl/dones/done_func_base.py
class SharedDoneFuncBaseValidator(BaseModel):
    """
    name : str
        The name of this done condition
    """
    name: str = ""