openai / gym

A toolkit for developing and comparing reinforcement learning algorithms.
https://www.gymlibrary.dev
Other
34.2k stars 8.58k forks source link

[Question] Custom dtype in observation space #3263

Closed dicksimon closed 3 months ago

dicksimon commented 3 months ago

How to make use of custom data types in observation spaces?

Hey there I am quite new to Reinforcement Learning.

I defined a custom numpy data type like this: dtype_page = np.dtype([ ('in_use', np.bool_)])

I want to use a box space with this custom type to define my observation space: self.observation_space = spaces.Dict({ 'pages': spaces.Box(low=0, high=1, shape=(57,), dtype=dtype_page), ... })

However, when I run my environment the following errors occur

File "/../.venv/lib/python3.11/site-packages/gymnasium/envs/registration.py", line 802, in make env = env_creator(**env_spec_kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/../gym_yos/envs/yos_env.py", line 75, in init 'pages': spaces.Box(low=0, high=1, shape=(57,), dtype=dtype_page), ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/../.venv/lib/python3.11/site-packages/gymnasium/spaces/box.py", line 125, in init if np.any(low > high): ^^^^^^^^^^ numpy.core._exceptions._UFuncNoLoopError: ufunc 'greater' did not contain a loop with signature matching types (<class 'numpy.dtypes.VoidDType'>, <class 'numpy.dtypes.VoidDType'>) -> None During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/../gym_yos/env_handler.py", line 10, in env = gym.make('YOS-v0'); ^^^^^^^^^^^^^^^^^^ File "/../.venv/lib/python3.11/site-packages/gymnasium/envs/registration.py", line 814, in make raise type(e)( ^^^^^^^^ TypeError: _UFuncNoLoopError.init() missing 1 required positional argument: 'dtypes'

Can I use custom data types like this or am I missing something other essential? Any hint is highly appreciated.