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 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:

  • PyPI wheels do not require a separate Qt installation at runtime.
  • Windows Procgen wheels bundle the required Qt runtime DLLs (Qt5Core.dll and Qt5Gui.dll) next to the extension module.
  • 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.

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.

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.0.1-cp314-cp314-win_amd64.whl (61.2 MB view details)

Uploaded CPython 3.14Windows x86-64

envpool-1.0.1-cp314-cp314-manylinux_2_28_x86_64.whl (89.1 MB view details)

Uploaded CPython 3.14manylinux: glibc 2.28+ x86-64

envpool-1.0.1-cp314-cp314-manylinux_2_28_aarch64.whl (88.4 MB view details)

Uploaded CPython 3.14manylinux: glibc 2.28+ ARM64

envpool-1.0.1-cp314-cp314-macosx_11_0_arm64.whl (55.5 MB view details)

Uploaded CPython 3.14macOS 11.0+ ARM64

envpool-1.0.1-cp313-cp313-win_amd64.whl (59.9 MB view details)

Uploaded CPython 3.13Windows x86-64

envpool-1.0.1-cp313-cp313-manylinux_2_28_x86_64.whl (89.1 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.28+ x86-64

envpool-1.0.1-cp313-cp313-manylinux_2_28_aarch64.whl (88.4 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.28+ ARM64

envpool-1.0.1-cp313-cp313-macosx_11_0_arm64.whl (55.5 MB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

envpool-1.0.1-cp312-cp312-win_amd64.whl (59.9 MB view details)

Uploaded CPython 3.12Windows x86-64

envpool-1.0.1-cp312-cp312-manylinux_2_28_x86_64.whl (89.1 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.28+ x86-64

envpool-1.0.1-cp312-cp312-manylinux_2_28_aarch64.whl (88.4 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.28+ ARM64

envpool-1.0.1-cp312-cp312-macosx_11_0_arm64.whl (55.5 MB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

envpool-1.0.1-cp311-cp311-win_amd64.whl (59.9 MB view details)

Uploaded CPython 3.11Windows x86-64

envpool-1.0.1-cp311-cp311-manylinux_2_28_x86_64.whl (89.1 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.28+ x86-64

envpool-1.0.1-cp311-cp311-manylinux_2_28_aarch64.whl (88.4 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.28+ ARM64

envpool-1.0.1-cp311-cp311-macosx_11_0_arm64.whl (55.5 MB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

File details

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

File metadata

  • Download URL: envpool-1.0.1-cp314-cp314-win_amd64.whl
  • Upload date:
  • Size: 61.2 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.0.1-cp314-cp314-win_amd64.whl
Algorithm Hash digest
SHA256 256ba767c5b22ea4e9ec69de1a414eba3468fe5e5946c0a2ab517e062cfef40e
MD5 9e080c0ee0f30b867ddea38e76164af3
BLAKE2b-256 362556dc32b5142d3d95db09b3876765e41cdde97092307c010014265ff58893

See more details on using hashes here.

File details

Details for the file envpool-1.0.1-cp314-cp314-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for envpool-1.0.1-cp314-cp314-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 87bbb3d38fd7e95220d6332b2e61f979e8712a4aa7c3f85f74b5d0ac32f41f44
MD5 017c145ee492519b1e7551672f44cd3a
BLAKE2b-256 941d28dca97f119f7ecace1972fcda305a27d88c25181ed85e3bdbe557e50b66

See more details on using hashes here.

File details

Details for the file envpool-1.0.1-cp314-cp314-manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for envpool-1.0.1-cp314-cp314-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 1d9e17793878abacda3fd08fbbb89891a550646495e6351f61ec36f142dd36fb
MD5 d15f67ce771043dbe464dc252a2dcc20
BLAKE2b-256 c853aadb08f03fd79fa890486c9a298862d4cc40b3533967bccea70c56537eec

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for envpool-1.0.1-cp314-cp314-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 1163124bd6049cbe7983ae9273862fc13dbf39d0cb578a5de83b63dc416acdd4
MD5 bcabeb92d1592573dc555568c77ae2a2
BLAKE2b-256 d99ad627c6cae5606e776b69cf8434ab910c7b51a63e9edfebb63d593ea60735

See more details on using hashes here.

File details

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

File metadata

  • Download URL: envpool-1.0.1-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 59.9 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.0.1-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 fd053579764411b2b3b693ece080f6418fd0f641ab42bfe161bcf8e714c0414b
MD5 77a35cc88dba26b818b3a3dad16a3386
BLAKE2b-256 933c5845b7221e740c3c63da1a30a40a02aab80b223ea3e2fc47fded77b339b7

See more details on using hashes here.

File details

Details for the file envpool-1.0.1-cp313-cp313-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for envpool-1.0.1-cp313-cp313-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 0614b791044b0ee375b159336b12a5295c3ec0c494a3fd39c5061bba73a2de11
MD5 90e5541bfb7dd565dedb851d6c5e01c8
BLAKE2b-256 185c08dda84a3a12fc622aa8bb0287bc4fe1752dad40495a319de4ac4b4cc445

See more details on using hashes here.

File details

Details for the file envpool-1.0.1-cp313-cp313-manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for envpool-1.0.1-cp313-cp313-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 7cad7c9da0f72fc35095f9fd553f04c5e494815be02aae1a84c3cc691006f190
MD5 ae636cfcee3f45b368d70c9c38308107
BLAKE2b-256 f3d9f4d172d33caf51b75ccb7af2d5366418760870cb3c90b18ca39a667b5804

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for envpool-1.0.1-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 16abaa84bb2a9fb6b6483b12e0609fdf8019ddfb59051b8b526de263538d75f8
MD5 eecce373464ce06d5dc24facc224caa8
BLAKE2b-256 72efd8051535738ac0082d6ade54c7823764f36730b98ebca1a84312432b8c14

See more details on using hashes here.

File details

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

File metadata

  • Download URL: envpool-1.0.1-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 59.9 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.0.1-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 23a9cd50d11978a8619ecc548a1c1031ab5ec856b2c83a72fd286b345eb3604f
MD5 bbd943f4a44f3025d3cab55fed7ffd9e
BLAKE2b-256 864fbd2896d1078bcabcb75cf575b13c195a8e84b2ec785193f9d8d529872904

See more details on using hashes here.

File details

Details for the file envpool-1.0.1-cp312-cp312-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for envpool-1.0.1-cp312-cp312-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 883114e9cea93b861472a8fcd999004346f1f6e2a13213637d2b980b725f3086
MD5 1bc4dbdf115bacf0e731ad4c7a256a7f
BLAKE2b-256 a16ea1782c994f34b0b82523b02bfb2ce5433950579eeb2cf770a7eadc65e3b5

See more details on using hashes here.

File details

Details for the file envpool-1.0.1-cp312-cp312-manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for envpool-1.0.1-cp312-cp312-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 928adc4f7d0006263aca937caa6e69ea96e1d07c5beb4c7fb927e64b858e6f88
MD5 360d1fcd2a55e3cdd52cbeb45cbc536b
BLAKE2b-256 905377686d39863353c1b3ae031de257bd041edbd9fb77d51046dd7d0e196686

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for envpool-1.0.1-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 ffd5df4bfcf62653ee9f4e8858852009f00d43cae301e1640ce80a92b66b4fca
MD5 e20819689433c50d18bc0c6712dd1f70
BLAKE2b-256 aa17967031db2c4a8fd97e4e232909b6d95a99b4211b80a89de741d8984dbd9f

See more details on using hashes here.

File details

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

File metadata

  • Download URL: envpool-1.0.1-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 59.9 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.0.1-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 c2e756f0c21e95cf53bc19d845f094dbeb45da804d2c022e2857132edf1a46f5
MD5 2c5009e298587d5b51d515e3417222e8
BLAKE2b-256 e6e85048f72d90debfcdb6481b06d746b5aed6de2ca9a3435b671013c31b91a9

See more details on using hashes here.

File details

Details for the file envpool-1.0.1-cp311-cp311-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for envpool-1.0.1-cp311-cp311-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 6f267bac55a410578845e12953293a0635e3d54f7ddbb452980e4ce0f914bd76
MD5 42d679a3628060c69d233dbd843d9e44
BLAKE2b-256 d42512ebe94332f5b4a3a3c2b1f5622c43dc810da56c53fca082cf8cfa906496

See more details on using hashes here.

File details

Details for the file envpool-1.0.1-cp311-cp311-manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for envpool-1.0.1-cp311-cp311-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 2ad0db66bed200fdd35bd3f4e4db92d26cb006b9419bf5f0a4e062673fa17b76
MD5 1b040e3092aa6ef4b4557c14a0101d98
BLAKE2b-256 9a81050a6fbad01e3506d584bca64ceb1271723c655dcb668b6ea065c810f612

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for envpool-1.0.1-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 6bcff2aeba57b0debc6dfd4458d8f5abd20ff37636ceae71b30d3e72bb3ea65f
MD5 559f7ca2e0a2b1c9007392c315f6cad9
BLAKE2b-256 39bba1b3fa6b247f20daad5bd7aa2f4f01b2e7180843fb63b63dd418f3c8cda5

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