worker_base#


class EnvWorker(env_fn: Callable[[], Env])[source]#

Bases: ABC

An abstract worker for an environment.

abstract get_env_attr(key: str) Any[source]#
abstract set_env_attr(key: str, value: Any) None[source]#
abstract send(action: ndarray | None) None[source]#

Send action signal to low-level worker.

When action is None, it indicates sending “reset” signal; otherwise it indicates “step” signal. The paired return value from “recv” function is determined by such kind of different signal.

recv() tuple[ndarray, ndarray, ndarray, ndarray, ndarray] | tuple[ndarray, dict][source]#

Receive result from low-level worker.

If the last “send” function sends a NULL action, it only returns a single observation; otherwise it returns a tuple of (obs, rew, done, info) or (obs, rew, terminated, truncated, info), based on whether the environment is using the old step API or the new one.

abstract reset(**kwargs: Any) tuple[ndarray, dict][source]#
step(action: ndarray) tuple[ndarray, ndarray, ndarray, ndarray, ndarray][source]#

Perform one timestep of the environment’s dynamic.

“send” and “recv” are coupled in sync simulation, so users only call “step” function. But they can be called separately in async simulation, i.e. someone calls “send” first, and calls “recv” later.

static wait(workers: list[EnvWorker], wait_num: int, timeout: float | None = None) list[EnvWorker][source]#

Given a list of workers, return those ready ones.

seed(seed: int | None = None) list[int] | None[source]#

Seeds the environment’s action space sampler. NOTE: This does not seed the environment itself.

Parameters:

seed – the random seed

Returns:

a list containing the resulting seed used

abstract render(**kwargs: Any) Any[source]#

Render the environment.

abstract close_env() None[source]#
close() None[source]#