Skip to main content

"C++-based high-performance parallel environment execution engine (vectorized env) for general RL environments."

Project description


PyPI Downloads arXiv Read the Docs Unittest GitHub issues GitHub stars GitHub forks GitHub license

EnvPool is a C++-based batched environment pool with pybind11 and thread pool. It has high performance (~1M raw FPS with Atari games, ~3M raw FPS with Mujoco simulator on DGX-A100) and compatible APIs (supports both gym and dm_env, both sync and async, both single and multi player environment). Currently it supports:

Here are EnvPool's several highlights:

Check out our arXiv paper for more details!

Installation

PyPI

EnvPool is currently hosted on PyPI. It requires Python >= 3.7.

You can simply install EnvPool with the following command:

$ pip install envpool

After installation, open a Python console and type

import envpool
print(envpool.__version__)

If no error occurs, you have successfully installed EnvPool.

From Source

Please refer to the guideline.

Documentation

The tutorials and API documentation are hosted on envpool.readthedocs.io.

The example scripts are under examples/ folder; benchmark scripts are under benchmark/ folder.

Benchmark Results

We perform our benchmarks with ALE Atari environment PongNoFrameskip-v4 (with environment wrappers from OpenAI Baselines) and Mujoco environment Ant-v3 on different hardware setups, including a TPUv3-8 virtual machine (VM) of 96 CPU cores and 2 NUMA nodes, and an NVIDIA DGX-A100 of 256 CPU cores with 8 NUMA nodes. Baselines include 1) naive Python for-loop; 2) the most popular RL environment parallelization execution by Python subprocess, e.g., gym.vector_env; 3) to our knowledge, the fastest RL environment executor Sample Factory before EnvPool.

We report EnvPool performance with sync mode, async mode, and NUMA + async mode, compared with the baselines on different number of workers (i.e., number of CPU cores). As we can see from the results, EnvPool achieves significant improvements over the baselines on all settings. On the high-end setup, EnvPool achieves 1 Million frames per second with Atari and 3 Million frames per second with Mujoco on 256 CPU cores, which is 14.9x / 19.6x of the gym.vector_env baseline. On a typical PC setup with 12 CPU cores, EnvPool's throughput is 3.1x / 2.9x of gym.vector_env.

Atari Highest FPS Laptop (12) Workstation (32) TPU-VM (96) DGX-A100 (256)
For-loop 4,893 7,914 3,993 4,640
Subprocess 15,863 47,699 46,910 71,943
Sample-Factory 28,216 138,847 222,327 707,494
EnvPool (sync) 37,396 133,824 170,380 427,851
EnvPool (async) 49,439 200,428 359,559 891,286
EnvPool (numa+async) / / 373,169 1,069,922
Mujoco Highest FPS Laptop (12) Workstation (32) TPU-VM (96) DGX-A100 (256)
For-loop 12,861 20,298 10,474 11,569
Subprocess 36,586 105,432 87,403 163,656
Sample-Factory 62,510 309,264 461,515 1,573,262
EnvPool (sync) 66,622 380,950 296,681 949,787
EnvPool (async) 105,126 582,446 887,540 2,363,864
EnvPool (numa+async) / / 896,830 3,134,287

Please refer to the benchmark page for more details.

API Usage

The following content shows both synchronous and asynchronous API usage of EnvPool. You can also run the full script at examples/env_step.py

Synchronous API

import envpool
import numpy as np

# make gym env
env = envpool.make("Pong-v5", env_type="gym", num_envs=100)
# or use envpool.make_gym(...)
obs = env.reset()  # should be (100, 4, 84, 84)
act = np.zeros(100, dtype=int)
obs, rew, done, info = env.step(act)

Under the synchronous mode, envpool closely resembles openai-gym/dm-env. It has the reset and step functions with the same meaning. However, there is one exception in envpool: batch interaction is the default. Therefore, during the creation of the envpool, there is a num_envs argument that denotes how many envs you like to run in parallel.

env = envpool.make("Pong-v5", env_type="gym", num_envs=100)

The first dimension of action passed to the step function should equal num_envs.

act = np.zeros(100, dtype=int)

You don't need to manually reset one environment when any of done is true; instead, all envs in envpool have enabled auto-reset by default.

Asynchronous API

import envpool
import numpy as np

# make asynchronous
num_envs = 64
batch_size = 16
env = envpool.make("Pong-v5", env_type="gym", num_envs=num_envs, batch_size=batch_size)
action_num = env.action_space.n
env.async_reset()  # send the initial reset signal to all envs
while True:
    obs, rew, done, info = env.recv()
    env_id = info["env_id"]
    action = np.random.randint(action_num, size=batch_size)
    env.send(action, env_id)

In the asynchronous mode, the step function is split into two parts: the send/recv functions. send takes two arguments, a batch of action, and the corresponding env_id that each action should be sent to. Unlike step, send does not wait for the envs to execute and return the next state, it returns immediately after the actions are fed to the envs. (The reason why it is called async mode).

env.send(action, env_id)

To get the "next states", we need to call the recv function. However, recv does not guarantee that you will get back the "next states" of the envs you just called send on. Instead, whatever envs finishes execution gets recved first.

state = env.recv()

Besides num_envs, there is one more argument batch_size. While num_envs defines how many envs in total are managed by the envpool, batch_size specifies the number of envs involved each time we interact with envpool. e.g. There are 64 envs executing in the envpool, send and recv each time interacts with a batch of 16 envs.

envpool.make("Pong-v5", env_type="gym", num_envs=64, batch_size=16)

There are other configurable arguments with envpool.make; please check out EnvPool Python interface introduction.

Contributing

EnvPool is still under development. More environments will be added, and we always welcome contributions to help EnvPool better. If you would like to contribute, please check out our contribution guideline.

License

EnvPool is under Apache2 license.

Other third-party source-code and data are under their corresponding licenses.

We do not include their source code and data in this repo.

Citing EnvPool

If you find EnvPool useful, please cite it in your publications.

@article{envpool,
  title={Env{P}ool: A Highly Parallel Reinforcement Learning Environment Execution Engine},
  author={Weng, Jiayi and Lin, Min and Huang, Shengyi and Liu, Bo and Makoviichuk, Denys and Makoviychuk, Viktor and Liu, Zichen and Song, Yufan and Luo, Ting and Jiang, Yukun and Xu, Zhongwen and Yan, Shuicheng},
  journal={arXiv preprint arXiv:2206.10558},
  year={2022}
}

Disclaimer

This is not an official Sea Limited or Garena Online Private Limited product.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

envpool-0.8.0-cp311-cp311-manylinux_2_24_x86_64.whl (74.7 MB view details)

Uploaded CPython 3.11 manylinux: glibc 2.24+ x86-64

envpool-0.8.0-cp310-cp310-manylinux_2_24_x86_64.whl (74.7 MB view details)

Uploaded CPython 3.10 manylinux: glibc 2.24+ x86-64

envpool-0.8.0-cp39-cp39-manylinux_2_24_x86_64.whl (74.7 MB view details)

Uploaded CPython 3.9 manylinux: glibc 2.24+ x86-64

envpool-0.8.0-cp38-cp38-manylinux_2_24_x86_64.whl (74.7 MB view details)

Uploaded CPython 3.8 manylinux: glibc 2.24+ x86-64

envpool-0.8.0-cp37-cp37m-manylinux_2_24_x86_64.whl (74.7 MB view details)

Uploaded CPython 3.7m manylinux: glibc 2.24+ x86-64

File details

Details for the file envpool-0.8.0-cp311-cp311-manylinux_2_24_x86_64.whl.

File metadata

  • Download URL: envpool-0.8.0-cp311-cp311-manylinux_2_24_x86_64.whl
  • Upload date:
  • Size: 74.7 MB
  • Tags: CPython 3.11, manylinux: glibc 2.24+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.11.1 pkginfo/1.7.0 requests/2.22.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.10

File hashes

Hashes for envpool-0.8.0-cp311-cp311-manylinux_2_24_x86_64.whl
Algorithm Hash digest
SHA256 b7b90ec83e9397e7914a4f983f2f8eeebc92284a25d3d6f79dcfccd22d8e4378
MD5 5d75da234e906840833f53507d2ffca7
BLAKE2b-256 3ca29af4aed78680b4faf57a2a31060a8a5e110bea2da1634ccd1eda38bc5b6e

See more details on using hashes here.

File details

Details for the file envpool-0.8.0-cp310-cp310-manylinux_2_24_x86_64.whl.

File metadata

  • Download URL: envpool-0.8.0-cp310-cp310-manylinux_2_24_x86_64.whl
  • Upload date:
  • Size: 74.7 MB
  • Tags: CPython 3.10, manylinux: glibc 2.24+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.11.1 pkginfo/1.7.0 requests/2.22.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.10

File hashes

Hashes for envpool-0.8.0-cp310-cp310-manylinux_2_24_x86_64.whl
Algorithm Hash digest
SHA256 3ddb476c948e25c6ac992bb64c20a107db460aef7e76899240f5e6750f17be99
MD5 8b47b86a79025412996111c46635d31c
BLAKE2b-256 e5ebc80564d7080d1d6882e3e3b47e074c3837666099f3537f1c643c7cbe8b9d

See more details on using hashes here.

File details

Details for the file envpool-0.8.0-cp39-cp39-manylinux_2_24_x86_64.whl.

File metadata

  • Download URL: envpool-0.8.0-cp39-cp39-manylinux_2_24_x86_64.whl
  • Upload date:
  • Size: 74.7 MB
  • Tags: CPython 3.9, manylinux: glibc 2.24+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.11.1 pkginfo/1.7.0 requests/2.22.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.10

File hashes

Hashes for envpool-0.8.0-cp39-cp39-manylinux_2_24_x86_64.whl
Algorithm Hash digest
SHA256 1b10b2e7e79997f7a5329f8a1ff03bd9a4822047e4a1f13edd163179e6a07ba4
MD5 530fcf187c94d367902f5df33fbbf8cb
BLAKE2b-256 59e0746125903038ca450ef483e0149d42365e2bed89b23e4ad4299773d56196

See more details on using hashes here.

File details

Details for the file envpool-0.8.0-cp38-cp38-manylinux_2_24_x86_64.whl.

File metadata

  • Download URL: envpool-0.8.0-cp38-cp38-manylinux_2_24_x86_64.whl
  • Upload date:
  • Size: 74.7 MB
  • Tags: CPython 3.8, manylinux: glibc 2.24+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.11.1 pkginfo/1.7.0 requests/2.22.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.10

File hashes

Hashes for envpool-0.8.0-cp38-cp38-manylinux_2_24_x86_64.whl
Algorithm Hash digest
SHA256 4c34c428dcc72973c7467284c6fd9cdf3c9c3787d1204658913940d79ee348d3
MD5 74d1d9a71381318a469f3179a5efc4dd
BLAKE2b-256 3bb2972c1316fed9d464683edbc9b9f62a625b8daf864c3fea8843603b1b55f5

See more details on using hashes here.

File details

Details for the file envpool-0.8.0-cp37-cp37m-manylinux_2_24_x86_64.whl.

File metadata

  • Download URL: envpool-0.8.0-cp37-cp37m-manylinux_2_24_x86_64.whl
  • Upload date:
  • Size: 74.7 MB
  • Tags: CPython 3.7m, manylinux: glibc 2.24+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.11.1 pkginfo/1.7.0 requests/2.22.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.10

File hashes

Hashes for envpool-0.8.0-cp37-cp37m-manylinux_2_24_x86_64.whl
Algorithm Hash digest
SHA256 31b81342d58f8454d0b2dc5155756d9284e365ddf964f2b5e25e9342817f252d
MD5 183d16bb1f06673852eb01b686d14e6c
BLAKE2b-256 b04d74ac55cec50717c1529ac9e036d82d0bc44356decbe11a1b7921a182dcbe

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page