import gymnasium as gym
import numpy as np
env = gym.make('racetrack-v0')
env.reset()
env.step([np.nan])
throws the error:
Traceback (most recent call last):
File "", line 1, in
File "/home/trevor/anaconda3/envs/rl_course/lib/python3.7/site-packages/gymnasium/wrappers/order_enforcing.py", line 56, in step
return self.env.step(action)
File "/home/trevor/anaconda3/envs/rl_course/lib/python3.7/site-packages/gymnasium/wrappers/env_checker.py", line 47, in step
return env_step_passive_checker(self.env, action)
File "/home/trevor/anaconda3/envs/rl_course/lib/python3.7/site-packages/gymnasium/utils/passive_env_checker.py", line 237, in env_step_passive_checker
result = env.step(action)
File "/home/trevor/.local/lib/python3.7/site-packages/highway_env/envs/common/abstract.py", line 237, in step
self._simulate(action)
File "/home/trevor/.local/lib/python3.7/site-packages/highway_env/envs/common/abstract.py", line 269, in _simulate
self.road.step(1 / self.config["simulation_frequency"])
File "/home/trevor/.local/lib/python3.7/site-packages/highway_env/road/road.py", line 474, in step
vehicle.handle_collisions(other, dt)
File "/home/trevor/.local/lib/python3.7/site-packages/highway_env/vehicle/objects.py", line 100, in handle_collisions
intersecting, will_intersect, transition = self._is_colliding(other, dt)
File "/home/trevor/.local/lib/python3.7/site-packages/highway_env/vehicle/objects.py", line 134, in _is_colliding
self.polygon(), other.polygon(), self.velocity dt, other.velocity dt
File "/home/trevor/.local/lib/python3.7/site-packages/highway_env/utils.py", line 237, in are_polygons_intersecting
translation = min_distance translation_axis
TypeError: unsupported operand type(s) for : 'float' and 'NoneType'
because translation_axis is None.
This occurs because the input polygon a is filled with nan as a direct result of the action [np.nan]. Here is what a looks like during this error, as printed at the top of function are_polygons_intersecting defined in highway_env/utils.py:
This is contrary to how other environments handle such incorrect action-inputs. For example, with CartPole:
import gymnasium as gym
import numpy as np
env = gym.make('CartPole-v0')
env.reset()
env.step([np.nan])
throws the error
Traceback (most recent call last):
File "", line 1, in
File "/home/trevor/anaconda3/envs/rl_course/lib/python3.7/site-packages/gymnasium/wrappers/time_limit.py", line 57, in step
observation, reward, terminated, truncated, info = self.env.step(action)
File "/home/trevor/anaconda3/envs/rl_course/lib/python3.7/site-packages/gymnasium/wrappers/order_enforcing.py", line 56, in step
return self.env.step(action)
File "/home/trevor/anaconda3/envs/rl_course/lib/python3.7/site-packages/gymnasium/wrappers/env_checker.py", line 47, in step
return env_step_passive_checker(self.env, action)
File "/home/trevor/anaconda3/envs/rl_course/lib/python3.7/site-packages/gymnasium/utils/passive_env_checker.py", line 237, in env_step_passive_checker
result = env.step(action)
File "/home/trevor/anaconda3/envs/rl_course/lib/python3.7/site-packages/gymnasium/envs/classic_control/cartpole.py", line 135, in step
), f"{action!r} ({type(action)}) invalid"
AssertionError: [nan] (<class 'list'>) invalid
which is much more descriptive and reveals the issue immediately. This issue happened to me when a NN I was training "exploded" and started outputting many nans.
For reproduction:
throws the error:
because
translation_axis
is None.This occurs because the input polygon
a
is filled withnan
as a direct result of the action[np.nan]
. Here is whata
looks like during this error, as printed at the top of functionare_polygons_intersecting
defined inhighway_env/utils.py
:This is contrary to how other environments handle such incorrect action-inputs. For example, with CartPole:
throws the error
which is much more descriptive and reveals the issue immediately. This issue happened to me when a NN I was training "exploded" and started outputting many
nan
s.