forked from openai/baselines
-
Notifications
You must be signed in to change notification settings - Fork 728
Open
Labels
enhancementNew feature or requestNew feature or request
Description
Describe the bug
TypeError: 'int' object is not subscriptable
Ran a couple time into this bug, and found it really hard to debug within stable baselines.
To spare others (as well as my future self) much frustration I would suggest to add a type check to wrapper envs like dummyEnv (or only check_env?) before using the action to make sure it's an iterable, before continuing with the code.
The following example assertion will give a developer friendly error message that's easy to understand and offers an immediate solution, saving much frustration.
Code example
obs, reward, done, info = env.step(action)
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/stable_baselines/common/vec_env/base_vec_env.py", line 134, in step
return self.step_wait()
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/stable_baselines/common/vec_env/vec_check_nan.py", line 35, in step_wait
observations, rewards, news, infos = self.venv.step_wait()
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/stable_baselines/common/vec_env/dummy_vec_env.py", line 41, in step_wait
self.envs[env_idx].step(self.actions[env_idx])
Proposed Solution
self.actions = actions
try:
iterator = iter(self.actions)
except TypeError:
# not iterable
raise Exception( "Action must be of type iterable. Try wrapping your action variable in a list [ ] to fix this issue." )
stefanbschneider and xavhl
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request