Module pearl.api.environment
Expand source code
from __future__ import annotations
from abc import ABC, abstractmethod
from typing import Optional, Tuple
from pearl.api.action import Action
from pearl.api.action_result import ActionResult
from pearl.api.action_space import ActionSpace
from pearl.api.observation import Observation
class Environment(ABC):
"""An abstract interface for environments. An `Environment` is an object
that the agent interacts with and provides the agent with observations in
the form of an `ActionResult` object. This interface follows the design of
environments in Gymnasium.
"""
@property
@abstractmethod
def action_space(self) -> ActionSpace:
"""Returns the action space of the environment."""
pass
# FIXME: add this and in implement in all concrete subclasses
# @property
# @abstractmethod
# def observation_space(self) -> Space:
# """Returns the observation space of the environment."""
# pass
@abstractmethod
def reset(self, seed: Optional[int] = None) -> Tuple[Observation, ActionSpace]:
"""Resets the environment and returns the initial observation and
initial available action space."""
pass
@abstractmethod
def step(self, action: Action) -> ActionResult:
"""Takes one step in the environment given the agent's action. Returns an
`ActionResult` object containing the next observation, reward, and done flag."""
pass
def render(self) -> None:
"""Renders the environment. Default implementation does nothing."""
return None
def close(self) -> None:
"""
Closes environment, taking care of any cleanup needed.
Default implementation does nothing.
"""
return None
Classes
class Environment
-
An abstract interface for environments. An
Environment
is an object that the agent interacts with and provides the agent with observations in the form of anActionResult
object. This interface follows the design of environments in Gymnasium.Expand source code
class Environment(ABC): """An abstract interface for environments. An `Environment` is an object that the agent interacts with and provides the agent with observations in the form of an `ActionResult` object. This interface follows the design of environments in Gymnasium. """ @property @abstractmethod def action_space(self) -> ActionSpace: """Returns the action space of the environment.""" pass # FIXME: add this and in implement in all concrete subclasses # @property # @abstractmethod # def observation_space(self) -> Space: # """Returns the observation space of the environment.""" # pass @abstractmethod def reset(self, seed: Optional[int] = None) -> Tuple[Observation, ActionSpace]: """Resets the environment and returns the initial observation and initial available action space.""" pass @abstractmethod def step(self, action: Action) -> ActionResult: """Takes one step in the environment given the agent's action. Returns an `ActionResult` object containing the next observation, reward, and done flag.""" pass def render(self) -> None: """Renders the environment. Default implementation does nothing.""" return None def close(self) -> None: """ Closes environment, taking care of any cleanup needed. Default implementation does nothing. """ return None
Ancestors
- abc.ABC
Subclasses
- ContextualBanditEnvironment
- BoxObservationsEnvironmentBase
- FixedNumberOfStepsEnvironment
- GymEnvironment
- SparseRewardEnvironment
Instance variables
var action_space : ActionSpace
-
Returns the action space of the environment.
Expand source code
@property @abstractmethod def action_space(self) -> ActionSpace: """Returns the action space of the environment.""" pass
Methods
def close(self) ‑> None
-
Closes environment, taking care of any cleanup needed. Default implementation does nothing.
Expand source code
def close(self) -> None: """ Closes environment, taking care of any cleanup needed. Default implementation does nothing. """ return None
def render(self) ‑> None
-
Renders the environment. Default implementation does nothing.
Expand source code
def render(self) -> None: """Renders the environment. Default implementation does nothing.""" return None
def reset(self, seed: Optional[int] = None) ‑> Tuple[object, ActionSpace]
-
Resets the environment and returns the initial observation and initial available action space.
Expand source code
@abstractmethod def reset(self, seed: Optional[int] = None) -> Tuple[Observation, ActionSpace]: """Resets the environment and returns the initial observation and initial available action space.""" pass
def step(self, action: Action) ‑> ActionResult
-
Takes one step in the environment given the agent's action. Returns an
ActionResult
object containing the next observation, reward, and done flag.Expand source code
@abstractmethod def step(self, action: Action) -> ActionResult: """Takes one step in the environment given the agent's action. Returns an `ActionResult` object containing the next observation, reward, and done flag.""" pass