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 Coverage 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 Gymnasium 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 supports Python 3.11-3.14 on Linux, macOS, and Windows.

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.

Platform notes:

  • Linux Procgen wheels intentionally do not vendor Qt. If making a Procgen environment reports missing libQt5Core.so.5 or libQt5Gui.so.5, install the system Qt 5 runtime, for example with apt install qtbase5-dev or dnf install qt5-qtbase.
  • Windows Procgen wheels bundle the required Qt runtime DLLs (Qt5Core.dll and Qt5Gui.dll) next to the extension module.
  • Windows source/release CI validates MuJoCo rendering with Mesa software OpenGL. To reproduce that setup locally, point ENVPOOL_DLL_DIR at a Mesa DLL directory and set GALLIUM_DRIVER=llvmpipe plus MESA_GL_VERSION_OVERRIDE=4.5COMPAT.
  • Building from source still requires platform-local build dependencies, including Qt 5. The full per-platform setup is documented in Build From Source.

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

The historical benchmark tables below were produced 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. The current scripts under benchmark/ use Gymnasium's ALE/Pong-v5 and Ant-v5. 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 Gymnasium env
env = envpool.make("Pong-v5", env_type="gymnasium", num_envs=100)
# or use envpool.make_gymnasium(...)
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 Gymnasium and 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="gymnasium", 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="gymnasium", 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, term, trunc, 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="gymnasium", num_envs=64, batch_size=16)

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

Rendering

EnvPool exposes rendering through the Python wrapper. Create the env with render_mode="rgb_array" to get batched RGB output, or render_mode="human" to display a single env through OpenCV.

import envpool

env = envpool.make(
    "Ant-v5",
    env_type="gymnasium",
    num_envs=4,
    render_mode="rgb_array",
    render_width=480,
    render_height=480,
)
env.reset()
frames = env.render(env_ids=[0, 2])
assert frames.shape == (2, 480, 480, 3)

render() is batch-first, so even a single render keeps the batch dimension: env.render().shape == (1, H, W, 3). If env_ids is omitted, EnvPool renders render_env_id (default 0). camera_id can be overridden per call, while the output size is fixed at env creation time via render_width and render_height.

The repo test suite also exercises rendering. make bazel-test runs repeated render checks for every render-capable env family, and make release-test includes a wheel smoke that calls render() after reset(). On Windows, the MuJoCo render tests use the same ENVPOOL_DLL_DIR Mesa preload hook described above when you want software OpenGL instead of the system driver.

viewer = envpool.make(
    "WalkerWalk-v1",
    env_type="gymnasium",
    num_envs=1,
    render_mode="human",
    render_env_id=0,
)
viewer.reset()
viewer.render()

render_mode="human" returns None and currently supports a single env id per call. It also requires opencv-python to be installed.

Pixel Observations

For MuJoCo tasks, pixel observations can also be exposed directly through the regular observation API by passing from_pixels=True. This path is produced natively in C++, without routing through Python-side render().

pixels = envpool.make(
    "WalkerWalk-v1",
    env_type="gymnasium",
    num_envs=2,
    from_pixels=True,
    frame_stack=3,
    render_width=84,
    render_height=84,
)
obs, info = pixels.reset()
assert obs.shape == (2, 9, 84, 84)

Pixel observations use channel-first layout. With frame_stack=1, each environment returns (3, H, W); with frame_stack=3, EnvPool stacks frames on the channel dimension and returns (9, H, W). This matches the usual PyTorch BCHW convention directly. If render_width / render_height are omitted, EnvPool defaults them to 84.

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.

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

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

If you're not sure about the file name format, learn more about wheel file names.

envpool-1.2.0-cp314-cp314-win_amd64.whl (94.2 MB view details)

Uploaded CPython 3.14Windows x86-64

envpool-1.2.0-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (99.7 MB view details)

Uploaded CPython 3.14manylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

envpool-1.2.0-cp314-cp314-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl (98.9 MB view details)

Uploaded CPython 3.14manylinux: glibc 2.27+ ARM64manylinux: glibc 2.28+ ARM64

envpool-1.2.0-cp314-cp314-macosx_11_0_arm64.whl (86.7 MB view details)

Uploaded CPython 3.14macOS 11.0+ ARM64

envpool-1.2.0-cp313-cp313-win_amd64.whl (92.8 MB view details)

Uploaded CPython 3.13Windows x86-64

envpool-1.2.0-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (99.7 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

envpool-1.2.0-cp313-cp313-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl (98.9 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.27+ ARM64manylinux: glibc 2.28+ ARM64

envpool-1.2.0-cp313-cp313-macosx_11_0_arm64.whl (86.7 MB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

envpool-1.2.0-cp312-cp312-win_amd64.whl (92.8 MB view details)

Uploaded CPython 3.12Windows x86-64

envpool-1.2.0-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (99.7 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

envpool-1.2.0-cp312-cp312-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl (98.9 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.27+ ARM64manylinux: glibc 2.28+ ARM64

envpool-1.2.0-cp312-cp312-macosx_11_0_arm64.whl (86.7 MB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

envpool-1.2.0-cp311-cp311-win_amd64.whl (92.7 MB view details)

Uploaded CPython 3.11Windows x86-64

envpool-1.2.0-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (99.7 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

envpool-1.2.0-cp311-cp311-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl (98.9 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.27+ ARM64manylinux: glibc 2.28+ ARM64

envpool-1.2.0-cp311-cp311-macosx_11_0_arm64.whl (86.7 MB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

File details

Details for the file envpool-1.2.0-cp314-cp314-win_amd64.whl.

File metadata

  • Download URL: envpool-1.2.0-cp314-cp314-win_amd64.whl
  • Upload date:
  • Size: 94.2 MB
  • Tags: CPython 3.14, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for envpool-1.2.0-cp314-cp314-win_amd64.whl
Algorithm Hash digest
SHA256 8bb176e28f24cfc090979056acc72e6552e8b001508ad899e77d128f988bed55
MD5 6e6c5812705e33e219ce54adf373d65a
BLAKE2b-256 ced3e1b606ebfe2934dea56d63ba9b7fa50f241a4badcba69675a674f71fbfde

See more details on using hashes here.

File details

Details for the file envpool-1.2.0-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for envpool-1.2.0-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 a0fd3dd5c170a96907567e2131bea0c29cab7c96eaa009acdb4aa3e54137ce03
MD5 a93198d0be8e12bc8370d91119bc51be
BLAKE2b-256 4a0bf39f846d5ffee40dd2e2d8e19fab501b709896426dd45560af16959964de

See more details on using hashes here.

File details

Details for the file envpool-1.2.0-cp314-cp314-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for envpool-1.2.0-cp314-cp314-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 ce2ab65378268f1ac5af1a74731e79a151a345b81e6e870b3410b3fa4a902da1
MD5 7e84640b415203e3bf6a8c4a16abd726
BLAKE2b-256 cccdee67aa102231c902efad64f7678105ec5cccc35d187389c019295709ab6f

See more details on using hashes here.

File details

Details for the file envpool-1.2.0-cp314-cp314-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for envpool-1.2.0-cp314-cp314-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 899bb14c5344ac94e271c9d131a64e008b4a08c8e21f0c90dae74a0973704c81
MD5 b4f28a12728ee5ce068101c0665f3cba
BLAKE2b-256 5a0785fd97a21428cedb86fc3b39a275818b73d4d4204db76226f0246165e647

See more details on using hashes here.

File details

Details for the file envpool-1.2.0-cp313-cp313-win_amd64.whl.

File metadata

  • Download URL: envpool-1.2.0-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 92.8 MB
  • Tags: CPython 3.13, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for envpool-1.2.0-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 b739fa668b335a08359aab81e12ad3330fd861780d3fce6cb1d1a53957b2e307
MD5 332efa5d765951b1521beb7d86831d45
BLAKE2b-256 4b012348d8f5a00d42c39a21cb6d07817f02a68d4ee8063f444bf50b41b0fc51

See more details on using hashes here.

File details

Details for the file envpool-1.2.0-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for envpool-1.2.0-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 dfbc814217beec0247fcc92a2cd081d2488e8c6b7895b362db52e703c4c44b0d
MD5 d7e7be5dc585fd03e99e7e85012785b9
BLAKE2b-256 d69c756e8e69eea8f0c3baaf9ac268dc9dc68adeab6dc0f55616363a8ac0a8f0

See more details on using hashes here.

File details

Details for the file envpool-1.2.0-cp313-cp313-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for envpool-1.2.0-cp313-cp313-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 1b6c2315f438d8b069eeb76c3eec1a73fd8e04af5f573fd18a53a0047f3303d9
MD5 b3b72e75df8fe161664e477531001b1c
BLAKE2b-256 5e39e3f720dd9045c13102838e078d96c65bd19315343f352237e8e4e2497274

See more details on using hashes here.

File details

Details for the file envpool-1.2.0-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for envpool-1.2.0-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 316668363a40f1b541a86e39db8752e33ef05c332577d827554e31d1c8caab39
MD5 627f83684a9d24d056e5103cf7787124
BLAKE2b-256 a331e486fd264d3e32b1f7878d8e4e2e9175e2b6561456924e62599bca3468f7

See more details on using hashes here.

File details

Details for the file envpool-1.2.0-cp312-cp312-win_amd64.whl.

File metadata

  • Download URL: envpool-1.2.0-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 92.8 MB
  • Tags: CPython 3.12, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for envpool-1.2.0-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 31d0fcc5b485fbd52236ad87dbafe54a562d66d1fd83c6103dbd8ad25e34ac61
MD5 42452876f6ccbecb4757454034f8f616
BLAKE2b-256 d73f3231cce4a275bbb234238d892859f3768beba8423e7569dedcf8a297b6d0

See more details on using hashes here.

File details

Details for the file envpool-1.2.0-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for envpool-1.2.0-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 1d0aaf0d34f73da30d9d4577c15d0f0d20891746be5a5cacbdb83ecedf7e3717
MD5 1625ff680865ed3f1629ca5af3f1b423
BLAKE2b-256 8276e11dfb35c52c7c4f36cad47297ee297be6a166190e69e518efa499e4239f

See more details on using hashes here.

File details

Details for the file envpool-1.2.0-cp312-cp312-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for envpool-1.2.0-cp312-cp312-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 a2b19014f8ea93c2db12c67159788207024334eebaddfda44e4097d8da5637e0
MD5 9eca3c2574652ce274cd5d0c91c324d7
BLAKE2b-256 d2991a6bf7bb44a4593576c9cf1e5cc92d4b210944ef2795ccc3a7f84fd8d982

See more details on using hashes here.

File details

Details for the file envpool-1.2.0-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for envpool-1.2.0-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 38a528a5571165d610a83766fe6905a7f172df12105f8ad0cabf9f5dd05e24eb
MD5 571ac34732561574716b061547a7918e
BLAKE2b-256 4480ef204c9dc55944a747d8c77349b5e9571e9f12c06648bd5cfa03d6af4270

See more details on using hashes here.

File details

Details for the file envpool-1.2.0-cp311-cp311-win_amd64.whl.

File metadata

  • Download URL: envpool-1.2.0-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 92.7 MB
  • Tags: CPython 3.11, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for envpool-1.2.0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 f201def1199b9988d43b0ab1e4d1d340ceb73a49f626653f449f9948c338e323
MD5 0b6087969c8770025571285cc3dc27c4
BLAKE2b-256 af7b0fcb530d9390f4c2e3d4f04cf03de8cc230d85dd69918f876acab962d4e8

See more details on using hashes here.

File details

Details for the file envpool-1.2.0-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for envpool-1.2.0-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 7626801d35e97da70b5d2f1f4f1e9815e3a8e89455e5b9eb5e0cb345ac628ed0
MD5 e9d1d9b2c759d8892ba0257e3c131644
BLAKE2b-256 b696445a06225f9d1ab8549380317da9ee03bc87f3a8ede184f7a7f4bad90422

See more details on using hashes here.

File details

Details for the file envpool-1.2.0-cp311-cp311-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for envpool-1.2.0-cp311-cp311-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 f4def40c9fffa963f99002566d03c29036716d4ff518dee8a69b95e2faca413b
MD5 d471771d1151f5b672022ff767688a14
BLAKE2b-256 ceca35ebf227f80e5762d1d976f975f164f916cc5a790eed2d1f1636a60973e0

See more details on using hashes here.

File details

Details for the file envpool-1.2.0-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for envpool-1.2.0-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 05f2d484909b4f520e04810f9b7b1efa7c4bc6b877d70de2fc8b2e05ef3584cb
MD5 51e682ca29d5df653b8d89c8d2e1e2c4
BLAKE2b-256 194e3af8c885c0b9e426e87b3e32c67af7da9a8c49b391ab553de4bb085bbfbf

See more details on using hashes here.

Supported by

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