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

Issue getting the ALARM_WINDOW_SIZE parameter right when using the runner #224

Closed
marota opened this issue Jun 8, 2021 · 2 comments
Closed
Labels
bug Something isn't working

Comments

@marota
Copy link
Contributor

marota commented Jun 8, 2021

Environment

  • Grid2op version: 1.6.0.rc1
  • System: osx
  • Additional system information

Bug description

The window_size alarm parameter is properly set to the desired value when creating an env.
But this value is apparently not the one used by the runner then, which is always window_size=1

How to reproduce

Command line

# command line used if any 

Code snippet

import grid2op
print(grid2op.__version__)

# Backend class to use
try:
    from lightsim2grid.LightSimBackend import LightSimBackend
    BACKEND = LightSimBackend
except ModuleNotFoundError:
    from grid2op.Backend import PandaPowerBackend
    BACKEND = PandaPowerBackend

from grid2op.Exceptions import Grid2OpException
from grid2op.Reward.BaseReward import BaseReward
from grid2op.dtypes import dt_float
from grid2op.Runner import Runner
from grid2op.Parameters import Parameters

class AlarmReward_test(BaseReward):

    def __init__(self):
        BaseReward.__init__(self)
        # required if you want to design a custom reward taking into account the
        # alarm feature
        self.reward_no_game_over = dt_float(0.)

        self.window_size = None
        self.best_time = None


    def initialize(self, env):
        if not env._has_attention_budget:
            raise Grid2OpException("Impossible to use the \"AlarmReward\" with an environment for which this feature "
                                   "is disabled. Please make sure \"env._has_attention_budget\" is set to ``True`` or "
                                   "change the reward class with `grid2op.make(..., reward_class=AnyOtherReward)`")
        self.reset(env)

    def reset(self, env):
        self.window_size = env.parameters.ALARM_WINDOW_SIZE#ALARM_BEST_TIME
        self.best_time = env.parameters.ALARM_BEST_TIME
        print("window value")
        print(self.window_size)
        print("best_time value")
        print(self.best_time)

    def __call__(self, action, env, has_error, is_done, is_illegal, is_ambiguous):
        if is_done:
            return 1
        else:
            res = self.reward_no_game_over
        return res

####Input environment path here
env_path='YourPath/l2rpn_neurips_2020_track1_with_alert'
######

param = Parameters()
#param.init_from_dict({'ALARM_BEST_TIME':6,'ALARM_WINDOW_SIZE':6})

env = grid2op.make(env_path,backend=BACKEND()
                   ,param=param,reward_class=AlarmReward_test)

runner = Runner(**env.get_params_for_runner()
                )

nb_episode=1
res = runner.run(nb_episode=nb_episode,max_iter=1,
                 nb_process=1)

Current output

window_size=1 once running the runner whatever env.parameters.ALARM_WINDOW_SIZE is

Expected output

window_size_runner= env.parameters.ALARM_WINDOW_SIZE
@marota marota added the bug Something isn't working label Jun 8, 2021
@marota marota changed the title Issue getting the best_time alarm parameter right when using the runner Issue getting the ALARM_WINDOW_SIZE parameter right when using the runner Jun 8, 2021
BDonnot referenced this issue in BDonnot/Grid2Op Jun 9, 2021
@BDonnot
Copy link
Collaborator

BDonnot commented Jun 9, 2021

Issue is fixed, new changes can be obtained by intalling the dev version of grid2op:
pip install git+git://github.com/rte-france/grid2op.git@dev_1.6.0

@BDonnot
Copy link
Collaborator

BDonnot commented Jun 22, 2021

Fixed and merged in version 1.6.0, now available on pypi

@BDonnot BDonnot closed this as completed Jun 22, 2021
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

No branches or pull requests

2 participants