Skip to content

Commit

Permalink
Merge pull request #438 from BDonnot/bd_dev
Browse files Browse the repository at this point in the history
improve "env.generate_data" function
  • Loading branch information
BDonnot committed Apr 13, 2023
2 parents da27927 + c080cec commit 5954303
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,9 @@ Change Log
env backend and the obs backend.
- [IMPROVED] the environment now called the "chronics_handler.forecast" function at most once per step.
- [IMPROVED] make it easier to create an environment without `MultiFolder` or `MultifolderWithCache`

- [IMPROVED] add the possibility to forward kwargs to chronix2grid function when calling `env.generate_data`
- [IMPROVED] when calling `env.generate_data` an extra file (json) will be read to set default values
passed to `chronix2grid.add_data`

[1.8.1] - 2023-01-11
---------------------
Expand Down
1 change: 0 additions & 1 deletion grid2op/Environment/BaseEnv.py
Original file line number Diff line number Diff line change
Expand Up @@ -2967,7 +2967,6 @@ def step(self, action: BaseAction) -> Tuple[BaseObservation, float, bool, dict]:

except StopIteration:
# episode is over
print("I got a StopIteration")
is_done = True

self._backend_action.reset()
Expand Down
18 changes: 16 additions & 2 deletions grid2op/Environment/Environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -1714,7 +1714,7 @@ def get_params_for_runner(self):
res["_is_test"] = self._is_test # TODO not implemented !!
return res

def generate_data(self, nb_year=1, nb_core=1, seed=None):
def generate_data(self, nb_year=1, nb_core=1, seed=None, **kwargs):
"""This function uses the chronix2grid package to generate more data that will then
be available locally. You need to install it independently (see https://github.com/BDonnot/ChroniX2Grid#installation
for more information)
Expand Down Expand Up @@ -1762,6 +1762,8 @@ def generate_data(self, nb_year=1, nb_core=1, seed=None):
number of computer cores to use, by default 1.
seed: int, optional
If the same seed is given, then the same data will be generated.
**kwargs:
key word arguments passed to `add_data` function of `chronix2grid.grid2op_utils` module
"""
try:
from chronix2grid.grid2op_utils import add_data
Expand All @@ -1771,6 +1773,18 @@ def generate_data(self, nb_year=1, nb_core=1, seed=None):
f"Please visit https://github.com/bdonnot/chronix2grid#installation "
f"for further install instructions."
) from exc_
pot_file = None
if self.get_path_env() is not None:
pot_file = os.path.join(self.get_path_env(), "chronix2grid_adddata_kwargs.json")
if os.path.exists(pot_file) and os.path.isfile(pot_file):
import json
with open(pot_file, "r", encoding="utf-8") as f:
kwargs_default = json.load(f)
for el in kwargs_default:
if not el in kwargs:
kwargs[el] = kwargs_default[el]
# TODO logger here for the kwargs used (including seed=seed, nb_scenario=nb_year, nb_core=nb_core)
add_data(
env=self, seed=seed, nb_scenario=nb_year, nb_core=nb_core, with_loss=True
env=self, seed=seed, nb_scenario=nb_year, nb_core=nb_core,
**kwargs
)

0 comments on commit 5954303

Please sign in to comment.