Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

check_env function of gym is giving some assertion errors after converting environment using GymEnv #379

Closed
AvisP opened this issue Nov 30, 2022 · 2 comments · Fixed by #383
Labels
bug Something isn't working

Comments

@AvisP
Copy link

AvisP commented Nov 30, 2022

Environment

  • Grid2op version: 1.7.2
  • System: macos 12.6.1

Bug description

The check_env() function of gym is failing after converting the environment using the GymEnv class. The check_env function calls

  • check_reset_return_type() gives the output
200 result = env.reset()
--> 201 assert isinstance(
    202     result, tuple
    203 ), f"The result returned by `env.reset()` was not a tuple of the form `(obs, info)`, where `obs` is a observation and `info` is a dictionary containing additional information. Actual type: `{type(result)}`"
    204 assert (
    205     len(result) == 2
    206 ), f"Calling the reset method did not return a 2-tuple, actual length: {len(result)}"
    208 obs, info = result

AssertionError: The result returned by `env.reset()` was not a tuple of the form `(obs, info)`, where `obs` is a observation and `info` is a dictionary containing additional information. Actual type: `<class 'collections.OrderedDict'>``
    299 check_reset_options(env) 

-check_reset_seed() gives

ValueError                                Traceback (most recent call last)
Cell In [5], line 1
----> 1 check_reset_seed(gym_env)

File ~/........../L2PRN/lib/python3.10/site-packages/gym/utils/env_checker.py:78, in check_reset_seed(env)
     73 if "seed" in signature.parameters or (
     74     "kwargs" in signature.parameters
     75     and signature.parameters["kwargs"].kind is inspect.Parameter.VAR_KEYWORD
     76 ):
     77     try:
---> 78         obs_1, info = env.reset(seed=123)
     79         assert (
     80             obs_1 in env.observation_space
     81         ), "The observation returned by `env.reset(seed=123)` is not within the observation space."
     82         assert (
     83             env.unwrapped._np_random  # pyright: ignore [reportPrivateUsage]
     84             is not None
     85         ), "Expects the random number generator to have been generated given a seed was passed to reset. Mostly likely the environment reset function does not call `super().reset(seed=seed)`."

ValueError: too many values to unpack (expected 2)

How to reproduce

from grid2op.gym_compat import GymEnv
import grid2op
from gym import Env
from gym.utils.env_checker import check_env, check_reset_return_type, check_reset_options, check_reset_seed

from grid2op.Backend import PandaPowerBackend
bk_cls = PandaPowerBackend
    
env_name = "l2rpn_case14_sandbox"
training_env = grid2op.make(env_name, test=True, backend=bk_cls())  
gym_env = GymEnv(training_env)

check_reset_return_type(gym_env)

check_reset_seed(gym_env)

Temporary Solution

By Navigating to /......../L2PRN/lib/python3.10/site-packages/grid2op/gym_compat/gymenv.pyI temporarily fixed it by setting return_info=True and adding super().reset(seed=seed) in the reset function

def reset(self, seed=None, return_info=False, options=None):

@AvisP AvisP added the bug Something isn't working label Nov 30, 2022
@BDonnot
Copy link
Collaborator

BDonnot commented Nov 30, 2022

Hi again

You are facing this issue because grid2op is not totally compatible with recent gym versions.

I'm currently (did that this afternoon) working toward it but it takes a bit of time as gym changed a lot recently.

For now I guess using gum 0.21 is probably the best thing to do. In gym 0.26 they enforce their new api for reset, seed etc which I had no time to work on (it's just simple glue code but it should be done regardless)

Thanks for the script provided, I will add it in the tests tomorrow or the day after when i will have time to finish the integration.

Thanks

@AvisP
Copy link
Author

AvisP commented Nov 30, 2022

Hi again!

Yeah the gym environment has changed a lot and is causing issues specially with more values being returned.

This is a minor issue. I just wanted to mention it but may need fixing eventually.

Thanks

@BDonnot BDonnot linked a pull request Dec 12, 2022 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants