Skip to content

Commit

Permalink
adding a function to initialize runner from then environment
Browse files Browse the repository at this point in the history
  • Loading branch information
BDonnot committed Feb 13, 2020
1 parent 2a88b02 commit 1fb025a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
2 changes: 1 addition & 1 deletion grid2op/Environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -1282,7 +1282,7 @@ def get_kwargs(self):
res["epsilon_poly"] = self._epsilon_poly
return res

def init_runner(self):
def get_params_for_runner(self):
"""
This method is used to initialize a proper :class:`grid2op.Runner.Runner` to use this specific environment.
Expand Down
25 changes: 15 additions & 10 deletions grid2op/MakeEnv.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
from .Exceptions import *
from .Observation import CompleteObservation, Observation
from .Reward import FlatReward, Reward, L2RPNReward, RedispReward
from .GameRules import LegalAction, AllwaysLegal
from .GameRules import LegalAction, AllwaysLegal, DefaultRules

from .Settings_L2RPN2019 import L2RPN2019_CASEFILE, L2RPN2019_DICT_NAMES, ReadPypowNetData, CASE_14_L2RPN2019_LAYOUT
from .Settings_5busExample import EXAMPLE_CHRONICSPATH, EXAMPLE_CASEFILE, CASE_5_GRAPH_LAYOUT
Expand All @@ -50,7 +50,7 @@
from Exceptions import *
from Observation import CompleteObservation, Observation
from Reward import FlatReward, Reward, L2RPNReward, RedispReward
from GameRules import LegalAction, AllwaysLegal
from GameRules import LegalAction, AllwaysLegal, DefaultRules
from Settings_L2RPN2019 import L2RPN2019_CASEFILE, L2RPN2019_DICT_NAMES, ReadPypowNetData, CASE_14_L2RPN2019_LAYOUT
from Settings_5busExample import EXAMPLE_CHRONICSPATH, EXAMPLE_CASEFILE, CASE_5_GRAPH_LAYOUT
from Settings_case14_redisp import case14_redisp_CASEFILE, case14_redisp_CHRONICSPATH, case14_redisp_TH_LIM
Expand Down Expand Up @@ -284,14 +284,6 @@ def make(name_env="case14_fromfile", **kwargs):
msg_error=msg_error,
isclass=True)

## type of rules of the game (mimic the operationnal constraints)
msg_error = "The type of rules of the environment (keyword \"gamerules_class\")"
msg_error += " must be a subclass of grid2op.LegalAction"
gamerules_class = _get_default_aux("gamerules_class", kwargs, defaultClass=AllwaysLegal,
defaultClassApp=LegalAction,
msg_error=msg_error,
isclass=True)

## type of rules of the game (mimic the operationnal constraints)
msg_error = "The path where the data is located (keyword \"chronics_path\") should be a string."
chronics_path = _get_default_aux("chronics_path", kwargs,
Expand All @@ -300,6 +292,7 @@ def make(name_env="case14_fromfile", **kwargs):

# bulid the default parameters for each case file
defaultinstance_chronics_kwargs = {}
gamerules_class = LegalAction
if name_env.lower() == "case14_fromfile":
default_grid_path = CASE_14_FILE
if chronics_path == '':
Expand All @@ -324,6 +317,7 @@ def make(name_env="case14_fromfile", **kwargs):
data_feeding_default_class = ChronicsHandler
default_action_class = TopologyAction
default_reward_class = L2RPNReward
gamerules_class = DefaultRules
elif name_env.lower() == "case5_example":
if chronics_path == '':
chronics_path = EXAMPLE_CHRONICSPATH
Expand All @@ -335,6 +329,7 @@ def make(name_env="case14_fromfile", **kwargs):
data_feeding_default_class = ChronicsHandler
default_action_class = TopologyAction
default_reward_class = L2RPNReward
gamerules_class = DefaultRules
elif name_env.lower() == "case14_test":
if chronics_path == '':
chronics_path = case14_test_CHRONICSPATH
Expand All @@ -348,6 +343,7 @@ def make(name_env="case14_fromfile", **kwargs):
data_feeding_default_class = ChronicsHandler
default_action_class = TopoAndRedispAction
default_reward_class = RedispReward
gamerules_class = DefaultRules
elif name_env.lower() == "case14_redisp":
if chronics_path == '':
chronics_path = case14_redisp_CHRONICSPATH
Expand All @@ -360,11 +356,20 @@ def make(name_env="case14_fromfile", **kwargs):
data_feeding_default_class = ChronicsHandler
default_action_class = TopoAndRedispAction
default_reward_class = RedispReward
gamerules_class = DefaultRules
else:
raise UnknownEnv("Unknown Environment named \"{}\". Current known environments are \"case14_fromfile\" "
"(default), \"case5_example\", \"case14_redisp\" and \"l2rpn_2019\"".format(name_env))

# extract powergrid dependant parameters
## type of rules of the game (mimic the operationnal constraints)
msg_error = "The type of rules of the environment (keyword \"gamerules_class\")"
msg_error += " must be a subclass of grid2op.LegalAction"
gamerules_class = _get_default_aux("gamerules_class", kwargs, defaultClass=gamerules_class,
defaultClassApp=LegalAction,
msg_error=msg_error,
isclass=True)

## type of reward the agent will receive
msg_error = "The type of observation of the environment (keyword \"reward_class\")"
msg_error += " must be a subclass of grid2op.Reward"
Expand Down

0 comments on commit 1fb025a

Please sign in to comment.