Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug in the MultifolderWithCache.seed method #670

Merged
merged 3 commits into from
Dec 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()