araffin / rl-baselines-zoo

A collection of 100+ pre-trained RL agents using Stable Baselines, training and hyperparameter optimization included.
https://stable-baselines.readthedocs.io/
MIT License
1.12k stars 208 forks source link

Default value for hyperparams raises AttributeError #54

Closed laurelkeys closed 4 years ago

laurelkeys commented 4 years ago

Describe the bug The current default value form hyperparams raises an AttributeError in utils.create_test_env.

Code example

# use default value for `hyperparams`
_env = create_test_env("BreakoutNoFrameskip-v4", n_envs=1, seed=0, 
                       is_atari=True, log_dir='.', should_render=False)

Traceback:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-35-05121958d8f1> in <module>()
----> 1 _env = create_test_env("BreakoutNoFrameskip-v4", n_envs=1, seed=0, is_atari=True, log_dir='.', should_render=False)

/content/rl-baselines-zoo/utils/utils.py in create_test_env(env_id, n_envs, is_atari, stats_path, seed, log_dir, should_render, hyperparams)
    160 
    161     # Create the environment and wrap it if necessary
--> 162     env_wrapper = get_wrapper_class(hyperparams)
    163     if 'env_wrapper' in hyperparams.keys():
    164         del hyperparams['env_wrapper']

/content/rl-baselines-zoo/utils/utils.py in get_wrapper_class(hyperparams)
     93         return wrapper_name.split('.')[-1]
     94 
---> 95     if 'env_wrapper' in hyperparams.keys():
     96         wrapper_name = hyperparams.get('env_wrapper')
     97         wrapper_module = importlib.import_module(get_module_name(wrapper_name))

AttributeError: 'NoneType' object has no attribute 'keys'

System Info Running on Colab, with version 2.9.0a0 of Stable Baselines, and using the code after cloning the repository as:

!git clone https://github.com/araffin/rl-baselines-zoo.git cd rl-baselines-zoo/ from utils import create_test_env cd .. _env = create_test_env("BreakoutNoFrameskip-v4", n_envs=1, seed=0, is_atari=True, log_dir='.', should_render=False)

(where each line is a code cell).

Additional context In the create_test_env function, hyperparams=None by default: https://github.com/araffin/rl-baselines-zoo/blob/da52f568282de8e3b0a7435eb64c752d00568ca3/utils/utils.py#L136-L138

However, this raises an AttributeError ('NoneType' object has no attribute 'keys') when trying to call hyperparams.keys(): https://github.com/araffin/rl-baselines-zoo/blob/da52f568282de8e3b0a7435eb64c752d00568ca3/utils/utils.py#L163

Shouldn't hyperparams={} by default? Or keep it None, but add a check for it in the line above?

araffin commented 4 years ago

Hello, Could be please fill the issue template completely?

laurelkeys commented 4 years ago

Done.

araffin commented 4 years ago

Ok, you are not using the script from the zoo, that explains why you have errors... This is definitely not recommended.

Anyway, I understand the concern, I would appreciate if you submit a PR that set hyperparams={} if None is passed.