Grid2op/l2rpn-baselines

Can't reset a GymEnvWithHeuristics env if I set a seed

Closed this issue · 0 comments

Environment

  • Python version: 3.12
  • Grid2op version: 1.10.5
  • l2rpn-baselines version: 0.8.0
  • System: ubuntu

Bug description

Hello
I created a gym environment with the GymEnvWithHeuristics class. I can't reset it if I add seed=0 as an argument. I obtained the error message shown bellow. However, if I just use the GymEnv (the parent class), it works.

How to reproduce

import grid2op
from l2rpn_baselines.utils import GymEnvWithHeuristics
from grid2op.gym_compat import GymEnv

env = grid2op.make("l2rpn_idf_2023")

gym_env = GymEnv(env)
gym_env_heur = GymEnvWithHeuristics(env)

_ = gym_env.reset(seed=0)
print("I can reset gym_env with the seed 0")

_ = gym_env_heur.reset(seed=0)
print("I can't reset gym_env_heur with the seed 0 but if you see this line in your terminal, you succeeded")

Current output

I can reset gym_env with the seed 0

{
	"name": "AttributeError",
	"message": "'super' object has no attribute 'seed'",
	"stack": "---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
File /home/boguslawskieva/env_with_setpoint_new_implementation/test.py:14
     11 _ = gym_env.reset(seed=0)
     12 print(\"I can reset gym_env with the seed 0\")
---> 14 _ = gym_env_heur.reset(seed=0)
     15 print(\"I can't reset gym_env_heur with the seed 0 but if you see this line in your terminal, you succeeded\")

File /data/boguslawskieva/virtual_environments/venv_multi_agent/lib/python3.12/site-packages/l2rpn_baselines/utils/gymenv_custom.py:270, in GymEnvWithHeuristics.reset(self, seed, return_info, options)
    268 info = {}  # no extra information provided !
    269 while done:
--> 270     super()._aux_reset(seed, return_info, options)  # reset the scenario
    271     g2op_obs = self.init_env.get_obs()  # retrieve the observation
    272     reward = self.init_env.reward_range[0]  # the reward at first step is always minimal

File /data/boguslawskieva/virtual_environments/venv_multi_agent/lib/python3.12/site-packages/grid2op/gym_compat/gymenv.py:167, in __AuxGymEnv._aux_reset(self, seed, return_info, options)
    164     self.init_env.chronics_handler.sample_next_chronics()
    166 if seed is not None:
--> 167     seed_, next_seed, underlying_env_seeds = self._aux_seed(seed)
    169 g2op_obs = self.init_env.reset(options=options)
    170 gym_obs = self.observation_space.to_gym(g2op_obs)

File /data/boguslawskieva/virtual_environments/venv_multi_agent/lib/python3.12/site-packages/grid2op/gym_compat/gymenv.py:247, in __AuxGymEnv._aux_seed(self, seed)
    243 def _aux_seed(self, seed: Optional[int]=None):
    244     # deprecated in gym >=0.26
    245     if seed is not None:
    246         # seed the gym env
--> 247         super().seed(seed)
    248         self._np_random.seed(seed)
    249         self._aux_seed_spaces()

AttributeError: 'super' object has no attribute 'seed'"
}

Expected output

I can reset gym_env with the seed 0
I can't reset gym_env_heur with the seed 0 but if you see this line in your terminal, you succeeded # No error message