https://github.com/sail-sg/envpool

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

https://github.com/sail-sg/envpool

Science Score: 33.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
  • DOI references
  • Academic publication links
    Links to: arxiv.org
  • Committers with academic emails
    2 of 17 committers (11.8%) from academic institutions
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (10.5%) to scientific vocabulary

Keywords

atari-games box2d cpp17 dm-control dm-env gym high-performance-computing lock-free-queue mujoco parallel-processing pybind11 reinforcement-learning reinforcement-learning-environments robotics threadpool vizdoom

Keywords from Contributors

rl jax
Last synced: 5 months ago · JSON representation

Repository

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

Basic Info
Statistics
  • Stars: 1,152
  • Watchers: 22
  • Forks: 108
  • Open Issues: 75
  • Releases: 23
Topics
atari-games box2d cpp17 dm-control dm-env gym high-performance-computing lock-free-queue mujoco parallel-processing pybind11 reinforcement-learning reinforcement-learning-environments robotics threadpool vizdoom
Created over 4 years ago · Last pushed over 1 year ago
Metadata Files
Readme Contributing License Code of conduct

README.md


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:

bash $ pip install envpool

After installation, open a Python console and type

python 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

```python import envpool import numpy as np

make gym env

env = envpool.make("Pong-v5", envtype="gym", numenvs=100)

or use envpool.make_gym(...)

obs = env.reset() # should be (100, 4, 84, 84) act = np.zeros(100, dtype=int) obs, rew, term, trunc, 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.

python 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.

python 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

```python import envpool import numpy as np

make asynchronous

numenvs = 64 batchsize = 16 env = envpool.make("Pong-v5", envtype="gym", numenvs=numenvs, batchsize=batchsize) actionnum = env.actionspace.n env.asyncreset() # send the initial reset signal to all envs while True: obs, rew, term, trunc, info = env.recv() envid = info["envid"] action = np.random.randint(actionnum, size=batchsize) 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).

python 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.

python 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.

python 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.

latex @inproceedings{weng2022envpool, 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}, booktitle = {Advances in Neural Information Processing Systems}, editor = {S. Koyejo and S. Mohamed and A. Agarwal and D. Belgrave and K. Cho and A. Oh}, pages = {22409--22421}, publisher = {Curran Associates, Inc.}, title = {Env{P}ool: A Highly Parallel Reinforcement Learning Environment Execution Engine}, url = {https://proceedings.neurips.cc/paper_files/paper/2022/file/8caaf08e49ddbad6694fae067442ee21-Paper-Datasets_and_Benchmarks.pdf}, volume = {35}, year = {2022} }

Disclaimer

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

Owner

  • Name: Sea AI Lab
  • Login: sail-sg
  • Kind: organization
  • Location: Singapore

GitHub Events

Total
  • Issues event: 3
  • Watch event: 102
  • Issue comment event: 17
  • Pull request event: 1
  • Fork event: 13
Last Year
  • Issues event: 3
  • Watch event: 102
  • Issue comment event: 17
  • Pull request event: 1
  • Fork event: 13

Committers

Last synced: 10 months ago

All Time
  • Total Commits: 182
  • Total Committers: 17
  • Avg Commits per committer: 10.706
  • Development Distribution Score (DDS): 0.346
Past Year
  • Commits: 0
  • Committers: 0
  • Avg Commits per committer: 0.0
  • Development Distribution Score (DDS): 0.0
Top Committers
Name Email Commits
Jiayi Weng t****7@g****m 119
Bo Liu b****s@g****m 18
mavenlin l****n@s****m 12
Yufan Song 3****g 8
Costa Huang c****g@o****m 5
Siping Wang 4****7 5
alicia 3****9 4
Markus Krimmel m****l@g****m 2
Antonin RAFFIN a****n@e****g 1
Hankson Bradley h****g@b****n 1
Lenini 1****h 1
Peilin Rao p****m@g****m 1
Rujikorn Charakorn r****h@g****m 1
Yicheng Luo e****c@g****m 1
Yukun J y****j@a****u 1
quangr q****r@1****m 1
zclzc 3****c 1
Committer Domains (Top 20 + Academic)

Issues and Pull Requests

Last synced: 6 months ago

All Time
  • Total issues: 96
  • Total pull requests: 63
  • Average time to close issues: 3 months
  • Average time to close pull requests: 19 days
  • Total issue authors: 69
  • Total pull request authors: 18
  • Average comments per issue: 2.77
  • Average comments per pull request: 0.78
  • Merged pull requests: 47
  • Bot issues: 0
  • Bot pull requests: 0
Past Year
  • Issues: 6
  • Pull requests: 2
  • Average time to close issues: N/A
  • Average time to close pull requests: N/A
  • Issue authors: 6
  • Pull request authors: 1
  • Average comments per issue: 1.17
  • Average comments per pull request: 0.5
  • Merged pull requests: 0
  • Bot issues: 0
  • Bot pull requests: 0
Top Authors
Issue Authors
  • vwxyzjn (9)
  • Trinkle23897 (6)
  • baixianger (3)
  • ikamensh (2)
  • Benjamin-eecs (2)
  • AsadJeewa (2)
  • araffin (2)
  • jbuckman (2)
  • im-Kitsch (2)
  • mavenlin (2)
  • AcademicWaste (2)
  • hilanzy (2)
  • xiezhipeng-git (2)
  • frasermince (1)
  • befelix (1)
Pull Request Authors
  • Trinkle23897 (22)
  • Benjamin-eecs (8)
  • wangsiping97 (6)
  • vwxyzjn (5)
  • pseudo-rnd-thoughts (4)
  • Alicia1529 (4)
  • taufeeque9 (3)
  • mavenlin (2)
  • renos (2)
  • Markus28 (2)
  • YukunJ (2)
  • cyprienc (2)
  • hilanzy (2)
  • 51616 (1)
  • leninilyich (1)
Top Labels
Issue Labels
question (19) enhancement (18) bug (13) duplicate (2) documentation (2) help wanted (1) discussion (1)
Pull Request Labels
help wanted (1)

Packages

  • Total packages: 2
  • Total downloads:
    • pypi 1,533 last-month
  • Total docker downloads: 369
  • Total dependent packages: 11
    (may contain duplicates)
  • Total dependent repositories: 22
    (may contain duplicates)
  • Total versions: 54
  • Total maintainers: 2
pypi.org: envpool

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

  • Versions: 30
  • Dependent Packages: 11
  • Dependent Repositories: 22
  • Downloads: 1,533 Last month
  • Docker Downloads: 369
Rankings
Dependent packages count: 0.9%
Stargazers count: 2.1%
Dependent repos count: 3.1%
Average: 3.4%
Docker downloads count: 4.1%
Forks count: 4.8%
Downloads: 5.4%
Maintainers (2)
Last synced: 6 months ago
proxy.golang.org: github.com/sail-sg/envpool
  • Versions: 24
  • Dependent Packages: 0
  • Dependent Repositories: 0
Rankings
Dependent packages count: 6.5%
Average: 6.7%
Dependent repos count: 6.9%
Last synced: 6 months ago

Dependencies

.github/workflows/lint.yml actions
  • actions/checkout v3 composite
  • actions/setup-go v3 composite
  • actions/setup-python v4 composite
  • styfle/cancel-workflow-action 0.11.0 composite
.github/workflows/release.yml actions
  • actions/checkout v3 composite
  • actions/download-artifact v3 composite
  • actions/upload-artifact main composite
  • pypa/gh-action-pypi-publish release/v1 composite
.github/workflows/test.yml actions
  • actions/checkout v3 composite
  • styfle/cancel-workflow-action 0.11.0 composite
benchmark/requirements.txt pypi
  • ale-py ==0.7.5
  • dm_control ==1.0.3.post1
  • envpool ==0.6.1.post1
  • gym ==0.23.1
  • mujoco ==2.2.0
  • mujoco_py ==2.1.2.14
  • opencv-python-headless *
  • packaging *
  • sample-factory ==1.123.0
  • tqdm *
examples/acme_examples/requirements.txt pypi
  • jax ==0.3.6
  • jaxlib ==0.3.5
  • libtpu-nightly ==0.1.dev20220412
  • wandb ==0.12.17
third_party/pip_requirements/requirements-dev.txt pypi
  • absl-py * development
  • box2d-py * development
  • dm-control >=1.0.5 development
  • dm-env * development
  • gym >=0.26 development
  • gymnasium >=0.26, development
  • jax * development
  • minigrid * development
  • mujoco >=2.2.1,<2.3 development
  • mujoco_py >=2.1.2.14 development
  • numpy * development
  • opencv-python-headless * development
  • packaging * development
  • protobuf <=4.20.0 development
  • pygame * development
  • setuptools * development
  • tianshou >=0.4.10 development
  • torch * development
  • tqdm * development
  • treevalue >=1.4 development
  • wheel * development
third_party/pip_requirements/requirements-release.txt pypi
  • dm-env *
  • gym >=0.26
  • gymnasium >=0.26,
  • jax *
  • numpy *
  • setuptools *
  • treevalue >=1.4
  • wheel *