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

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, 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="gym", 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.1.1-cp314-cp314-win_amd64.whl (75.5 MB view details)

Uploaded CPython 3.14Windows x86-64

envpool-1.1.1-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (80.1 MB view details)

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

envpool-1.1.1-cp314-cp314-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl (79.5 MB view details)

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

envpool-1.1.1-cp314-cp314-macosx_11_0_arm64.whl (68.7 MB view details)

Uploaded CPython 3.14macOS 11.0+ ARM64

envpool-1.1.1-cp313-cp313-win_amd64.whl (74.3 MB view details)

Uploaded CPython 3.13Windows x86-64

envpool-1.1.1-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (80.1 MB view details)

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

envpool-1.1.1-cp313-cp313-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl (79.5 MB view details)

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

envpool-1.1.1-cp313-cp313-macosx_11_0_arm64.whl (68.7 MB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

envpool-1.1.1-cp312-cp312-win_amd64.whl (74.3 MB view details)

Uploaded CPython 3.12Windows x86-64

envpool-1.1.1-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (80.1 MB view details)

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

envpool-1.1.1-cp312-cp312-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl (79.5 MB view details)

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

envpool-1.1.1-cp312-cp312-macosx_11_0_arm64.whl (68.7 MB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

envpool-1.1.1-cp311-cp311-win_amd64.whl (74.3 MB view details)

Uploaded CPython 3.11Windows x86-64

envpool-1.1.1-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (80.1 MB view details)

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

envpool-1.1.1-cp311-cp311-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl (79.5 MB view details)

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

envpool-1.1.1-cp311-cp311-macosx_11_0_arm64.whl (68.7 MB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

File details

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

File metadata

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

File hashes

Hashes for envpool-1.1.1-cp314-cp314-win_amd64.whl
Algorithm Hash digest
SHA256 1b16efcb4a6ccbb437dac4ce0ecf1c497b00beb6808ac4379957e8057af391f9
MD5 3ee20b3d1107f4b750a364d1f1c19cdf
BLAKE2b-256 463f725813f7b538b4e3c158ba046a6f77529d55352d46a0914960a5cb46244d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for envpool-1.1.1-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 ae042c78e9c3c9f66a9c35e60c728254f7bfe33492224668380b53eeed9033a1
MD5 6e23bc7018cefc0380395b6319ab221a
BLAKE2b-256 a768733f228a09d6ef5dfaaa957bf3881ae37e00ee087ffe4d448d11e6f0d634

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for envpool-1.1.1-cp314-cp314-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 caac1f677696cd35ddb6c5f2b9e7c470b059b5a21b59084aceb16e7ce399e647
MD5 3556cc0c9a2c718f4caa01c69fa36655
BLAKE2b-256 cbd9e72efec672a59b76f9fa172ea08a69cb4af6a818197f5a658b3b40528dce

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for envpool-1.1.1-cp314-cp314-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 a56a00ff36424cac5b14b1baa0863b5c357175be2a15cd0a8e3136d0a27997fc
MD5 2c68bbec0b8f04a0478eb492adf851a2
BLAKE2b-256 c08504a14e865b919246fdf2695090e3885a451f0f17cebea76f9916521697b0

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for envpool-1.1.1-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 9bc46e1e62733d61044f3281dbaa2dddcc1b72979ea56362c07b05cfc2e08c32
MD5 acb2a7544d8e8919f539f902b3d8295b
BLAKE2b-256 4f5e266642c4ee253c98674e99391c5779a72dee3eec915bd8a539b60e8cf341

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for envpool-1.1.1-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 4d5d57f3e1e09d29fef0ed69de35c790ae8271663dcec9b39a772b7689063006
MD5 f1db36f0e31e7c94f8b9f130bab0ad19
BLAKE2b-256 dfa1c6b0141bd26a9867799a514993466804e9111c99f543a26c1f2e25edb716

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for envpool-1.1.1-cp313-cp313-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 88cae13c03043c6955bb0769b5c3be4a4fe9430f92d586da2ba0e935a01d3c8d
MD5 cd9fc116bbb105411b08495e2b4bc025
BLAKE2b-256 e7eb86a087c5affc3c04c60126dc5f7f756f85fe41de5fb1ecedf0e304174ad7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for envpool-1.1.1-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 d7cc78a82b0aa5b631510d56b48c45738d8504d27f39d19c3f48e1550631ebc3
MD5 4c8357ff32c155ead75131d1aaa0bb35
BLAKE2b-256 e5ad13fe5a4dfd4d795576ad2562e8b437b681c88101001627ba8b4ca9cda62f

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for envpool-1.1.1-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 c5272f3389191f061fecf7d2d4d55db7c6c8b95773547a3eab15744e325014a4
MD5 4614e6d81034c31bb56926aa6f5d0e05
BLAKE2b-256 1350a1fdc0158a6f3f87b7e46624da29d8713ea99cc93dc43a8ad0d466d714e2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for envpool-1.1.1-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 124be439d2a97ca6e6120ab8aaf424d4edc3e859eb648da54d7a5d031bc44e8c
MD5 5217f39b8e320cc22f1f6b65058b7106
BLAKE2b-256 be42be9917be49e59e3bd4c8107e0de7c0b41aef51882da397defd9b309a58cd

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for envpool-1.1.1-cp312-cp312-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 9621f5ca3e89c377233ad67ce55ae0d04d2dedc6d13ee35826cee1efa292356c
MD5 a4478a30c0371d3cd7584a76e947249e
BLAKE2b-256 70c11e226cddc5c55b676f85bbf6b6f9548e38101b17f192d5339bf9369becb7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for envpool-1.1.1-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 2cbfde510e671491390e24e3c83e715e22ea8810bfe3c1438897bcbc5e9fc228
MD5 0ddaffb71519fc163752c8c73f677876
BLAKE2b-256 e25eba9bfc3bc70887bd9ec8387e22a2f54d2eb2a5de1d5d75e8829113fb1b5d

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for envpool-1.1.1-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 1d138585bc858ce799b3a08680703ee7ae9a2b59c17f8b12e29c51db42108512
MD5 d068fb8b907a80dc81a63fe9f697e95d
BLAKE2b-256 b661bed8d6948369503aa331ef8496a737dc228ec599ed93545807c73d45e551

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for envpool-1.1.1-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 0dbde139aee39dece18eb5708b6be3e925cc90f4867acbfc08a61fbb939b2d5a
MD5 7d65e0b33fe46375db3a676bda53e67c
BLAKE2b-256 293fef4ef9c66fab1f32b2b769486e6a6d6a9b4d7a7c80e0f05b822f19a43a7c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for envpool-1.1.1-cp311-cp311-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 b25f03a29f0202c5ca8328845070aebc544b67c558e2cd4bb2568d8a0df7dc9c
MD5 7a258d29355cb25613a0397f772d18b8
BLAKE2b-256 9dd215a5a41fef673927eae434d3e3126eddd0eccc24ee4bde6a91378d9072b0

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for envpool-1.1.1-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 17a07cdac089409c88d5b8c7edea451862234705bc378c177b779d45c4d2cbdd
MD5 ae1d026b4a26b86bcd9fca2cd7beea0a
BLAKE2b-256 bd058542b002412500c47ef4f6fe7d0bc2be6b5a659c7a797cb459ce30aca208

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