From abddf01b65c2c4ee59f68dcdbfde6a3a1f79352a Mon Sep 17 00:00:00 2001 From: EBoguslawski Date: Fri, 29 Nov 2024 18:47:44 +0100 Subject: [PATCH 1/3] Fix bug in the MultifolderWithCache.seed method and add a test Signed-off-by: EBoguslawski --- grid2op/Chronics/multifolderWithCache.py | 2 +- .../tests/test_MultifolderWithCache_seed.py | 42 +++++++++++++++++++ 2 files changed, 43 insertions(+), 1 deletion(-) create mode 100644 grid2op/tests/test_MultifolderWithCache_seed.py diff --git a/grid2op/Chronics/multifolderWithCache.py b/grid2op/Chronics/multifolderWithCache.py index 43684284..ed4217d2 100644 --- a/grid2op/Chronics/multifolderWithCache.py +++ b/grid2op/Chronics/multifolderWithCache.py @@ -291,7 +291,7 @@ def seed(self, seed : int): """ res = super().seed(seed) max_int = np.iinfo(dt_int).max - self._cached_seeds = np.empty(shape=self._order.shape, dtype=dt_int) + self._cached_seeds = np.empty(len(shape=self._cached_data), dtype=dt_int) for i in self._order: data = self._cached_data[i] seed_ts = self.space_prng.randint(max_int) diff --git a/grid2op/tests/test_MultifolderWithCache_seed.py b/grid2op/tests/test_MultifolderWithCache_seed.py new file mode 100644 index 00000000..e59e91ca --- /dev/null +++ b/grid2op/tests/test_MultifolderWithCache_seed.py @@ -0,0 +1,42 @@ +# Copyright (c) 2023, 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. + +# %% +import os +import grid2op +from grid2op.Chronics import MultifolderWithCache +import unittest +import warnings + +module_name = MultifolderWithCache.__module__ +module = __import__(module_name) +file_path = module.__file__ +print(f"Library path: \n{file_path}") + +class TestMultifolderWithCacheSeed(unittest.TestCase): + def test_box_action_space(self): + + with warnings.catch_warnings(): + warnings.filterwarnings("ignore") + env = grid2op.make("l2rpn_case14_sandbox", test=True, _add_to_name=type(self).__name__, + chronics_class=MultifolderWithCache) + + # I take the last chronics on purpose so that its index is larger than the number of selected chronics (only one here) + env.chronics_handler.real_data.set_filter(lambda x: os.path.basename(x) == "0002") + env.chronics_handler.reset() + + try: + env.reset(seed=0) + except Exception as e: + self.fail(f"{type(self).__name__} raised an exception: {e}") + + + +# %% +if __name__ == "__main__": + unittest.main() \ No newline at end of file From 8dfe10c4f980b090900b36e58284f02e95d03963 Mon Sep 17 00:00:00 2001 From: EBoguslawski Date: Fri, 29 Nov 2024 20:02:10 +0100 Subject: [PATCH 2/3] fix typing error Signed-off-by: EBoguslawski --- grid2op/Chronics/multifolderWithCache.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/grid2op/Chronics/multifolderWithCache.py b/grid2op/Chronics/multifolderWithCache.py index ed4217d2..a2b04c80 100644 --- a/grid2op/Chronics/multifolderWithCache.py +++ b/grid2op/Chronics/multifolderWithCache.py @@ -291,7 +291,7 @@ def seed(self, seed : int): """ res = super().seed(seed) max_int = np.iinfo(dt_int).max - self._cached_seeds = np.empty(len(shape=self._cached_data), dtype=dt_int) + self._cached_seeds = np.empty(len(self._cached_data), dtype=dt_int) for i in self._order: data = self._cached_data[i] seed_ts = self.space_prng.randint(max_int) From 6e596569859583ca3de7cdfeace94e2690755edd Mon Sep 17 00:00:00 2001 From: EBoguslawski Date: Fri, 29 Nov 2024 20:27:51 +0100 Subject: [PATCH 3/3] remove useless code Signed-off-by: EBoguslawski --- grid2op/tests/test_MultifolderWithCache_seed.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/grid2op/tests/test_MultifolderWithCache_seed.py b/grid2op/tests/test_MultifolderWithCache_seed.py index e59e91ca..6602c2e3 100644 --- a/grid2op/tests/test_MultifolderWithCache_seed.py +++ b/grid2op/tests/test_MultifolderWithCache_seed.py @@ -13,10 +13,6 @@ import unittest import warnings -module_name = MultifolderWithCache.__module__ -module = __import__(module_name) -file_path = module.__file__ -print(f"Library path: \n{file_path}") class TestMultifolderWithCacheSeed(unittest.TestCase): def test_box_action_space(self):