Skip to content

Commit

Permalink
Merge pull request #670 from EBoguslawski/dev_1.11.0_seed_chronics
Browse files Browse the repository at this point in the history
Fix bug in the MultifolderWithCache.seed method
  • Loading branch information
BDonnot authored Dec 1, 2024
2 parents c6754d1 + 6e59656 commit 5a335c0
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
2 changes: 1 addition & 1 deletion grid2op/Chronics/multifolderWithCache.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(self._cached_data), dtype=dt_int)
for i in self._order:
data = self._cached_data[i]
seed_ts = self.space_prng.randint(max_int)
Expand Down
38 changes: 38 additions & 0 deletions grid2op/tests/test_MultifolderWithCache_seed.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# 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


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()

0 comments on commit 5a335c0

Please sign in to comment.