Module ai.environments
Module containing the abstract definition of an environment, as well as implementations of it.
Expand source code
"""Module containing the abstract definition of an environment, as well as
implementations of it."""
from . import action_spaces
from ._base import Base
from ._factory import Factory
from ._simulator_wrapper import SimulatorWrapper
from ._gym_wrapper import GymWrapper
__all__ = ["Base", "SimulatorWrapper", "action_spaces", "Factory", "GymWrapper"]
Sub-modules
ai.environments.action_spaces
-
Action spaces for environments.
Classes
class Base
-
Environment base class.
An environment is a stateful environment upon which action may be executed. It has an internal state that is modified by the action and (potentially only partially) observable from the outside.
Ancestors
- abc.ABC
Subclasses
Static methods
def get_factory(*args, **kwargs) ‑> Factory
-
Creates and returns a factory object that spawns simulators when called.
Args and kwargs are passed along to the class constructor. However, if other behavior is required, feel free to override this method and return a factory class of your choice.
Expand source code
@classmethod def get_factory(cls, *args, **kwargs) -> "environments.Factory": """Creates and returns a factory object that spawns simulators when called. Args and kwargs are passed along to the class constructor. However, if other behavior is required, feel free to override this method and return a factory class of your choice.""" return environments.Factory(cls, *args, **kwargs)
Instance variables
var action_space : Base
-
The action space instance used by the environment instance.
Expand source code
@property @abstractmethod def action_space(self) -> environments.action_spaces.Base: """The action space instance used by the environment instance.""" raise NotImplementedError
Methods
def close(self)
-
Disposes resources used by the environment.
Expand source code
@abstractmethod def close(self): """Disposes resources used by the environment.""" raise NotImplementedError
def render(self)
-
Renders the environment in its current state.
Expand source code
@abstractmethod def render(self): """Renders the environment in its current state.""" raise NotImplementedError
def reset(self) ‑> numpy.ndarray
-
Resets the environment to a new initial state.
Returns
np.ndarray
- Initial state.
Expand source code
@abstractmethod def reset(self) -> np.ndarray: """Resets the environment to a new initial state. Returns: np.ndarray: Initial state. """ raise NotImplementedError
def step(self, action: int) ‑> Tuple[numpy.ndarray, float, bool, Dict]
-
Executes an action in the environment.
Args
action
:int
- Action index
Returns
Tuple[np.ndarray, float, bool, Dict]
- Tuple of next state, reward, terminal
flag, and debugging dictionary.
Expand source code
@abstractmethod def step(self, action: int) -> Tuple[np.ndarray, float, bool, Dict]: """Executes an action in the environment. Args: action (int): Action index Returns: Tuple[np.ndarray, float, bool, Dict]: Tuple of next state, reward, terminal flag, and debugging dictionary. """ raise NotImplementedError
class Factory (cls: Type[Base], *args, **kwargs)
-
Factories are callable objects that spawn environment instances.
Args
cls
:Type[environments.Base]
- Environment class.
*args, **kwargs
: arguments and key-word arguments passed to the environment__init__
method.Subclasses
- ai.environments._simulator_wrapper.SimulatorWrapper.Factory
class GymWrapper (env: Union[gym.core.Env, str])
-
Environment wrapper for openAI gym environments.
Args
env
:Union[gym.Env, str]
- Environment instance to wrap, or the gym environment identifier..
Ancestors
- Base
- abc.ABC
Class variables
var ActionSpace
-
Discrete action space that wraps a discrete openAI Gym action space.
Inherited members
class SimulatorWrapper (simulator: Base)
-
Environment that wraps a simulator, exposing it as an environment.
Args
simulator
:simulators.Base
- Simulator class to wrap into an environment.
Ancestors
- Base
- abc.ABC
Class variables
var Factory
-
Factories are callable objects that spawn environment instances.
Static methods
def get_factory(factory: Factory) ‑> ai.environments._simulator_wrapper.SimulatorWrapper.Factory
-
Wraps a simulator factory into an environment factory.
Expand source code
@classmethod def get_factory(cls, factory: simulators.Factory) -> "SimulatorWrapper.Factory": """Wraps a simulator factory into an environment factory.""" return SimulatorWrapper.Factory(factory)
Inherited members