-
Notifications
You must be signed in to change notification settings - Fork 117
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #658 from BDonnot/bd_dev
Some few additions
- Loading branch information
Showing
10 changed files
with
215 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
# Copyright (c) 2019-2024, RTE (https://www.rte-france.com) | ||
# See AUTHORS.txt | ||
# This Source Code Form is subject to the terms of the Mozilla Public License, version 2.0. | ||
# If a copy of the Mozilla Public License, version 2.0 was not distributed with this file, | ||
# you can obtain one at http://mozilla.org/MPL/2.0/. | ||
# SPDX-License-Identifier: MPL-2.0 | ||
# This file is part of Grid2Op, Grid2Op a testbed platform to model sequential decision making in power systems. | ||
|
||
from typing import Dict, Union, Literal | ||
|
||
import grid2op | ||
from grid2op.Exceptions import EnvError, ChronicsError | ||
from grid2op.Chronics import ChangeNothing | ||
|
||
|
||
class _ObsCH(ChangeNothing): | ||
""" | ||
INTERNAL | ||
.. warning:: /!\\\\ Internal, do not use unless you know what you are doing /!\\\\ | ||
This class is reserved to internal use. Do not attempt to do anything with it. | ||
""" | ||
|
||
# properties that should not be accessed | ||
@property | ||
def chronicsClass(self): | ||
raise EnvError("There are no time series in the observation from `obs.simulate`, so no `chronicsClass`") | ||
|
||
@property | ||
def path(self): | ||
raise EnvError("There are no time series in the observation from `obs.simulate`, so no `path`") | ||
|
||
@property | ||
def _real_data(self): | ||
raise EnvError("There are no time series in the observation from `obs.simulate`, so no `_real_data`") | ||
|
||
@property | ||
def kwargs(self): | ||
return {} | ||
|
||
@kwargs.setter | ||
def kwargs(self, new_value): | ||
raise ChronicsError('Impossible to set the "kwargs" attribute') | ||
|
||
@property | ||
def _kwargs(self): | ||
return {} | ||
|
||
# functions overriden from the ChronicsHandler class | ||
def forecasts(self): | ||
return [] | ||
|
||
def get_name(self): | ||
return "" | ||
|
||
def next_time_step(self): | ||
raise EnvError("There are no time series in the observation from `obs.simulate`, so no `next_time_step`") | ||
|
||
def max_episode_duration(self): | ||
return 0 | ||
|
||
def seed(self, seed): | ||
""".. warning:: This function is part of the public API of ChronicsHandler but should not do anything here""" | ||
pass | ||
|
||
def cleanup_action_space(self): | ||
""".. warning:: This function is part of the public API of ChronicsHandler but should not do anything here""" | ||
pass | ||
|
||
# methods overriden from the ChronicsHandler class (__getattr__) so forwarded to the Chronics class | ||
@property | ||
def gridvalueClass(self): | ||
raise EnvError("There are no time series in the observation from `obs.simulate`, so no `gridvalueClass`") | ||
|
||
@property | ||
def data(self): | ||
raise EnvError("There are no time series in the observation from `obs.simulate`, so no `data`") | ||
|
||
@property | ||
def sep(self): | ||
raise EnvError("There are no time series in the observation from `obs.simulate`, so no `sep`") | ||
|
||
@property | ||
def subpaths(self): | ||
raise EnvError("There are no time series in the observation from `obs.simulate`, so no `subpaths`") | ||
|
||
@property | ||
def _order(self): | ||
raise EnvError("There are no time series in the observation from `obs.simulate`, so no `_order`") | ||
|
||
@property | ||
def chunk_size(self): | ||
raise EnvError("There are no time series in the observation from `obs.simulate`, so no `chunk_size`") | ||
|
||
@property | ||
def _order_backend_loads(self): | ||
raise EnvError("There are no time series in the observation from `obs.simulate`, so no `_order_backend_loads`") | ||
|
||
@property | ||
def _order_backend_prods(self): | ||
raise EnvError("There are no time series in the observation from `obs.simulate`, so no `_order_backend_prods`") | ||
|
||
@property | ||
def _order_backend_lines(self): | ||
raise EnvError("There are no time series in the observation from `obs.simulate`, so no `_order_backend_lines`") | ||
|
||
@property | ||
def _order_backend_subs(self): | ||
raise EnvError("There are no time series in the observation from `obs.simulate`, so no `_order_backend_subs`") | ||
|
||
@property | ||
def _names_chronics_to_backend(self): | ||
raise EnvError("There are no time series in the observation from `obs.simulate`, so no `_names_chronics_to_backend`") | ||
|
||
@property | ||
def _filter(self): | ||
raise EnvError("There are no time series in the observation from `obs.simulate`, so no `_filter`") | ||
|
||
@property | ||
def _prev_cache_id(self): | ||
raise EnvError("There are no time series in the observation from `obs.simulate`, so no `_prev_cache_id`") | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
# Copyright (c) 2024, RTE (https://www.rte-france.com) | ||
# See AUTHORS.txt and https://github.com/Grid2Op/grid2op/pull/319 | ||
# This Source Code Form is subject to the terms of the Mozilla Public License, version 2.0. | ||
# If a copy of the Mozilla Public License, version 2.0 was not distributed with this file, | ||
# you can obtain one at http://mozilla.org/MPL/2.0/. | ||
# SPDX-License-Identifier: MPL-2.0 | ||
# This file is part of Grid2Op, Grid2Op a testbed platform to model sequential decision making in power systems. | ||
|
||
from logging import Logger | ||
import unittest | ||
import warnings | ||
|
||
|
||
from helper_path_test import PATH_DATA_TEST | ||
import grid2op | ||
from grid2op.Exceptions import ChronicsError, EnvError | ||
from grid2op.Action import BaseAction | ||
from grid2op.Environment import BaseEnv | ||
from grid2op.Reward import BaseReward | ||
|
||
|
||
class WeirdReward(BaseReward): | ||
def __init__(self, logger: Logger = None): | ||
super().__init__(logger) | ||
|
||
def __call__(self, action: BaseAction, env:BaseEnv, has_error: bool, is_done: bool, is_illegal: bool, is_ambiguous: bool) -> float: | ||
return len(env.chronics_handler.get_name()) | ||
|
||
|
||
class Issue657Tester(unittest.TestCase): | ||
def setUp(self): | ||
self.env_name = "l2rpn_case14_sandbox" | ||
# create first env | ||
with warnings.catch_warnings(): | ||
warnings.filterwarnings("ignore") | ||
self.env = grid2op.make("l2rpn_case14_sandbox", test=True, reward_class=WeirdReward) | ||
|
||
def tearDown(self) -> None: | ||
self.env.close() | ||
return super().tearDown() | ||
|
||
def test_issue_657(self): | ||
obs = self.env.reset() | ||
obs.simulate(self.env.action_space()) | ||
self.env.step(self.env.action_space()) | ||
|
||
def test_broader_names(self): | ||
obs = self.env.reset() | ||
obs_ch = obs._obs_env.chronics_handler | ||
for attr_nm in self.env.chronics_handler.__dict__: | ||
try: | ||
getattr(obs_ch, attr_nm) | ||
except (EnvError, ChronicsError) as exc_: | ||
# access to some attributes / function might return these type of errors | ||
pass | ||
except AttributeError as exc_: | ||
raise TypeError(f"No know attribute {attr_nm} for obs_chronics_handler") from exc_ | ||
|
||
for attr_nm in self.env.chronics_handler.real_data.__dict__: | ||
try: | ||
getattr(obs_ch, attr_nm) | ||
except (EnvError, ChronicsError) as exc_: | ||
# access to some attributes / function might return these type of errors | ||
pass | ||
except AttributeError as exc_: | ||
raise TypeError(f"No know attribute {attr_nm} (from real_data / GridValue) for obs_chronics_handler") from exc_ | ||
|
||
|
||
if __name__ == "__main__": | ||
unittest.main() |