pokaxpoka/sunrise

UnboundLocalError: local variable 'env' referenced before assignment

sweetice opened this issue · 3 comments

Error:

Traceback (most recent call last):
  File "/home/mirror/PycharmProjects/sunrise/OpenAIGym_SAC/examples/sunrise.py", line 197, in <module>
    experiment(variant)
  File "/home/mirror/PycharmProjects/sunrise/OpenAIGym_SAC/examples/sunrise.py", line 50, in experiment
    expl_env = NormalizedBoxEnv(get_env(variant['env'], variant['seed']))
  File "/home/mirror/PycharmProjects/sunrise/OpenAIGym_SAC/examples/sunrise.py", line 46, in get_env
    env = env(env_name=env_name, rand_seed=seed, misc_info={'reset_type': 'gym'})
UnboundLocalError: local variable 'env' referenced before assignment

Seems that the error comes from this line

def get_env(env_name, seed):
    if env_name in ['gym_walker2d', 'gym_hopper',
                    'gym_cheetah', 'gym_ant']:
        from mbbl.env.gym_env.walker import env
    env = env(env_name=env_name, rand_seed=seed, misc_info={'reset_type': 'gym'})
    return env

The env was used but not be defined.
I don't know how to fix this bug due to the complexity of the codebase. Would you mind fixing this bug in this repo?

hm, hard to understand the problem at glance. Could you elaborate more? what was the env_name you used?

Well, I use pubullet envs. Specifically, I use "HopperBulletEnv-v0" env. . And then the error described occurs. Seems that the error is due to the program don't process the env (Because "HopperBulletEnv-v0" is not in ['gym_walker2d', 'gym_hopper',
'gym_cheetah', 'gym_ant'])

I want to apply your code on another env.

Thanks for your reply! I have solved the issue! :)