env#


class ContinuousEnvironments(env: Env, train_envs: BaseVectorEnv, test_envs: BaseVectorEnv, watch_env: BaseVectorEnv | None = None)[source]#

Represents (vectorized) continuous environments.

static from_factory(factory_fn: Callable[[EnvMode], Env], venv_type: VectorEnvType, num_training_envs: int, num_test_envs: int, create_watch_env: bool = False) ContinuousEnvironments[source]#

Creates an instance from a factory function that creates a single instance.

Parameters:
  • factory_fn – the factory for a single environment instance

  • venv_type – the vector environment type to use for parallelization

  • num_training_envs – the number of training environments to create

  • num_test_envs – the number of test environments to create

  • create_watch_env – whether to create an environment for watching the agent

Returns:

the instance

get_action_shape() Sequence[int] | int | int64[source]#
get_observation_shape() int | Sequence[int][source]#
get_type() EnvType[source]#
info() dict[str, Any][source]#
class DiscreteEnvironments(env: Env, train_envs: BaseVectorEnv, test_envs: BaseVectorEnv, watch_env: BaseVectorEnv | None = None)[source]#

Represents (vectorized) discrete environments.

static from_factory(factory_fn: Callable[[EnvMode], Env], venv_type: VectorEnvType, num_training_envs: int, num_test_envs: int, create_watch_env: bool = False) DiscreteEnvironments[source]#

Creates an instance from a factory function that creates a single instance.

Parameters:
  • factory_fn – the factory for a single environment instance

  • venv_type – the vector environment type to use for parallelization

  • num_training_envs – the number of training environments to create

  • num_test_envs – the number of test environments to create

  • create_watch_env – whether to create an environment for watching the agent

Returns:

the instance

get_action_shape() Sequence[int] | int | int64[source]#
get_observation_shape() int | Sequence[int][source]#
get_type() EnvType[source]#
class EnvFactory(venv_type: VectorEnvType)[source]#

Main interface for the creation of environments (in various forms).

abstract create_env(mode: EnvMode) Env[source]#
create_envs(num_training_envs: int, num_test_envs: int, create_watch_env: bool = False) Environments[source]#

Create environments for learning.

Parameters:
  • num_training_envs – the number of training environments

  • num_test_envs – the number of test environments

  • create_watch_env – whether to create an environment for watching the agent

Returns:

the environments

create_venv(num_envs: int, mode: EnvMode) BaseVectorEnv[source]#

Create vectorized environments.

Parameters:
  • num_envs – the number of environments

  • mode – the mode for which to create. In WATCH mode the resulting venv will always be of type DUMMY with a single env.

Returns:

the vectorized environments

class EnvFactoryRegistered(*, task: str, seed: int, venv_type: VectorEnvType, envpool_factory: EnvPoolFactory | None = None, render_mode_train: str | None = None, render_mode_test: str | None = None, render_mode_watch: str = 'human', **make_kwargs: Any)[source]#

Factory for environments that are registered with gymnasium and thus can be created via gymnasium.make (or via envpool.make_gymnasium).

create_env(mode: EnvMode) Env[source]#

Creates a single environment for the given mode.

Parameters:

mode – the mode

Returns:

an environment

create_venv(num_envs: int, mode: EnvMode) BaseVectorEnv[source]#

Create vectorized environments.

Parameters:
  • num_envs – the number of environments

  • mode – the mode for which to create. In WATCH mode the resulting venv will always be of type DUMMY with a single env.

Returns:

the vectorized environments

class EnvMode(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]#

Indicates the purpose for which an environment is created.

TEST = 'test'#
TRAIN = 'train'#
WATCH = 'watch'#
class EnvPoolFactory[source]#

A factory for the creation of envpool-based vectorized environments, which can be used in conjunction with EnvFactoryRegistered.

create_venv(task: str, num_envs: int, mode: EnvMode, seed: int, kwargs: dict) BaseVectorEnv[source]#
class EnvType(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]#

Enumeration of environment types.

CONTINUOUS = 'continuous'#
DISCRETE = 'discrete'#
assert_continuous(requiring_entity: Any) None[source]#
assert_discrete(requiring_entity: Any) None[source]#
static from_env(env: Env) EnvType[source]#
is_continuous() bool[source]#
is_discrete() bool[source]#
class Environments(env: Env, train_envs: BaseVectorEnv, test_envs: BaseVectorEnv, watch_env: BaseVectorEnv | None = None)[source]#

Represents (vectorized) environments for a learning process.

static from_factory_and_type(factory_fn: Callable[[EnvMode], Env], env_type: EnvType, venv_type: VectorEnvType, num_training_envs: int, num_test_envs: int, create_watch_env: bool = False) Environments[source]#

Creates a suitable subtype instance from a factory function that creates a single instance and the type of environment (continuous/discrete).

Parameters:
  • factory_fn – the factory for a single environment instance

  • env_type – the type of environments created by factory_fn

  • venv_type – the vector environment type to use for parallelization

  • num_training_envs – the number of training environments to create

  • num_test_envs – the number of test environments to create

  • create_watch_env – whether to create an environment for watching the agent

Returns:

the instance

abstract get_action_shape() Sequence[int] | int | int64[source]#
get_action_space() Space[source]#
abstract get_observation_shape() int | Sequence[int][source]#
get_observation_space() Space[source]#
abstract get_type() EnvType[source]#
info() dict[str, Any][source]#
set_persistence(*p: Persistence) None[source]#

Associates the given persistence handlers which may persist and restore environment-specific information.

Parameters:

p – persistence handlers

class VectorEnvType(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]#
DUMMY = 'dummy'#

Vectorized environment without parallelization; environments are processed sequentially

RAY = 'ray'#

Parallelization based on the ray library

SUBPROC = 'subproc'#

Parallelization based on subprocess

SUBPROC_SHARED_MEM = 'shmem'#

Parallelization based on subprocess with shared memory

SUBPROC_SHARED_MEM_FORK_CONTEXT = 'shmem_fork'#

Parallelization based on subprocess with shared memory and fork context (relevant for macOS, which uses spawn by default https://docs.python.org/3/library/multiprocessing.html#contexts-and-start-methods)

create_venv(factories: Sequence[Callable[[], Env]]) BaseVectorEnv[source]#