envpool icon indicating copy to clipboard operation
envpool copied to clipboard

[BUG] Blank output for numpy 2.0.0

Open jsonmona opened this issue 1 year ago • 4 comments

Describe the bug

Atari environment produces blank output when having numpy>=2 installed.

Installing numpy<2 (which resolves to numpy-1.26.4-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl) fixes the issue.

Here, blank output means RGB (0, 0, 0) for Breakout-v5. Pong-v5 produces RGB (89, 89, 89) instead.

To Reproduce

pip install -U envpool opencv-python

# To fix the issue:
pip install -U 'numpy<2'

# To reproduce the issue:
pip install -U 'numpy>=2'
import numpy as np
import envpool
import cv2

env_id = "Pong-v5"

# gray_scale does not affect this issue
env = envpool.make_gymnasium(
    env_id,
    num_envs=16,
    max_episode_steps=3600,
    stack_num=1,
    gray_scale=False,
    episodic_life=True,
    repeat_action_probability=0.25,
    use_fire_reset=True,
)

for _ in range(1000):
    next_obs, reward, terminations, truncations, infos = env.step(np.zeros(args.num_envs, dtype="int32"))
    cv2.imshow("img", np.moveaxis(next_obs[0], 0, -1))
    cv2.waitKey(10)

Expected behavior

Either work with numpy 2 or declare to not support numpy>2.

System info

Describe the characteristic of your environment:

  • Installed via pip inside venv
  • Using python 3.10.12
  • Working inside WSL 2 (Windows Subsystem Linux)
import envpool, numpy, sys
print(envpool.__version__, numpy.__version__, sys.version, sys.platform)
# 0.8.4 1.26.4 3.10.12 (main, Nov  6 2024, 20:22:13) [GCC 11.4.0] linux

Reason and Possible fixes

This project declares support for any numpy version. That is broken by design as numpy bumping its major version can cause issue at any time. It is extra confusing as things work perfectly for people who have not upgraded numpy yet.

While this issue should be fixed at some point, I think adding numpy<2 is good for now. With that being said, I propose to add version constraint like <2 to prevent upgrading major version for every dependency that is not alpha (e.g. 0.1.2).

If you plan to tackle on the root cause of this issue, this article from numpy documentation might be helpful.

Checklist

  • [x] I have checked that there is no similar issue in the repo (required)
  • [x] I have read the documentation (required)
  • [x] I have provided a minimal working example to reproduce the bug (required)

jsonmona avatar Dec 15 '24 04:12 jsonmona

having same issue here

anthony0727 avatar Jan 07 '25 13:01 anthony0727

I believe that pybind11 will need to updated

pseudo-rnd-thoughts avatar Jan 17 '25 16:01 pseudo-rnd-thoughts

Having same issue

y4umeng avatar Mar 13 '25 21:03 y4umeng

For those having the issue, downgrade to Numpy 1.x

pseudo-rnd-thoughts avatar Mar 14 '25 08:03 pseudo-rnd-thoughts