sail-sg / envpool

C++-based high-performance parallel environment execution engine (vectorized env) for general RL environments.
https://envpool.readthedocs.io
Apache License 2.0
1.09k stars 100 forks source link

[BUG] Repeated `step` causes segmentation fault for CartPole-v0 #236

Closed sgrigory closed 1 year ago

sgrigory commented 1 year ago

Describe the bug

The snippet below with repeated env.step causes a segmentation fault. A single env.step works fine.

To Reproduce

import numpy as np
import envpool

env = envpool.make(task_id="CartPole-v0", env_type="gym", num_envs=1)
env.step(np.array(1))
env.step(np.array(1))
$ python reproduce.py 
/home/grigorysizov/anaconda3/envs/torch_rl/lib/python3.9/site-packages/gymnasium/envs/registration.py:313: UserWarning: WARN: No module named 'glfw'
  logger.warn(str(e))
Segmentation fault (core dumped)

Expected behavior

The code doesn't crash, or, if this operation is invalid, gives a user-friendly error message

System info

Envpool 0.8.1 is installed through pip in a conda environment:

import envpool, numpy, sys
print(envpool.__version__, numpy.__version__, sys.version, sys.platform)
-----------
0.8.1 1.23.5 3.9.15 (main, Nov 24 2022, 14:31:59) 
[GCC 11.2.0] linux

Additional context

This came up when working on https://github.com/pytorch/rl/pull/734 - integrating EnvPool into TorchRL

Checklist

Trinkle23897 commented 1 year ago

You need to use np.array([1]) instead of np.array(1), the first one is a 1d array while the second one is a 0d array.

sgrigory commented 1 year ago

Thank you!