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

Bug in BoxGymActSpace when some action types cannot be done in grid2op #283

Closed
BDonnot opened this issue Jan 25, 2022 · 0 comments · Fixed by #309
Closed

Bug in BoxGymActSpace when some action types cannot be done in grid2op #283

BDonnot opened this issue Jan 25, 2022 · 0 comments · Fixed by #309
Labels
bug Something isn't working good first issue Good for newcomers

Comments

@BDonnot
Copy link
Collaborator

BDonnot commented Jan 25, 2022

Environment

  • Grid2op version: 1.6.5
  • System: all
  • Additional system information

Bug description

When trying to use the BxGymActSpace on environment where not all actions are possible it raises an error (all actions
are illegal)

How to reproduce

Just run the code below:

import unittest
import warnings

import grid2op
from grid2op.Rules.AlwaysLegal import AlwaysLegal
from grid2op.gym_compat import GymEnv
from grid2op.gym_compat import BoxGymActSpace


class Issue283Tester(unittest.TestCase):
    def setUp(self):
        with warnings.catch_warnings():
            warnings.filterwarnings("ignore")
            self.env = grid2op.make("educ_case14_storage", test=True, gamerules_class=AlwaysLegal)
            self.env_gym = GymEnv(self.env)
    
        self.env_gym.action_space.close()
        self.env_gym.action_space = BoxGymActSpace(self.env.action_space)
        self.env_gym.seed(0)

    def tearDown(self):
        self.env.close()
        self.env_gym.close()

    def test_can_make(self):
        """test that the opponent state is correctly copied"""
        gym_act = self.env_gym.action_space.sample()
        gym_act[:self.env.n_line] = 0.  # do not change line status ! (otherwise it diverges)
        act = self.env_gym.action_space.from_gym(gym_act)
        obs, reward, done, info = self.env.step(act)
        assert len(info["exception"]) == 0, f"{info['exception'] = }"

Current output

grid2op.Exceptions.IllegalActionExceptions.IllegalAction: Grid2OpException IllegalAction "Impossible to perform curtailment action with this action type."

----------------------------------------------------------------------
Ran 1 test in 7.780s

FAILED (errors=1)

Expected output

.
----------------------------------------------------------------------
Ran 1 test in 5.254s

OK

@BDonnot BDonnot added the bug Something isn't working label Jan 25, 2022
BDonnot added a commit to BDonnot/Grid2Op that referenced this issue Jan 25, 2022
@BDonnot BDonnot added the good first issue Good for newcomers label Jan 25, 2022
@BDonnot BDonnot mentioned this issue Jan 27, 2022
@BDonnot BDonnot linked a pull request Apr 29, 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 good first issue Good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant