Skip to content

Commit

Permalink
adressing issue #66, now reproduced
Browse files Browse the repository at this point in the history
  • Loading branch information
BDonnot committed Oct 19, 2023
1 parent eb44108 commit b3c9ab2
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
8 changes: 6 additions & 2 deletions lightsim2grid/lightSimBackend.py
Original file line number Diff line number Diff line change
Expand Up @@ -820,8 +820,12 @@ def apply_action(self, backendAction):
raise BackendError(f"{exc_}")

if self.__has_storage:
self._grid.update_storages_p(backendAction.storage_power.changed,
backendAction.storage_power.values)
try:
self._grid.update_storages_p(backendAction.storage_power.changed,
backendAction.storage_power.values)
except RuntimeError as exc_:
# modification of power of disconnected storage has no effect in lightsim2grid
pass

# handle shunts
if type(self).shunts_data_available:
Expand Down
2 changes: 1 addition & 1 deletion lightsim2grid/tests/test_dist_slack_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def test_after_runner(self):
runner_ds = Runner(**self.env_ds.get_params_for_runner())
res_ss = runner_ss.run(nb_episode=1, max_iter=self.max_iter_real, add_detailed_output=True)
res_ds = runner_ds.run(nb_episode=1, max_iter=self.max_iter_real, add_detailed_output=True)
assert res_ss[0][3] == res_ds[0][3] # same number of steps survived
assert res_ss[0][3] == res_ds[0][3], f"{res_ss[0][3]} vs {res_ds[0][3]}" # same number of steps survived
assert res_ss[0][2] != res_ds[0][2] # not the same reward
ep_ss = res_ss[0][-1]
ep_ds = res_ds[0][-1]
Expand Down
18 changes: 17 additions & 1 deletion lightsim2grid/tests/test_issue_66.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,16 @@
import unittest
import warnings
from lightsim2grid import LightSimBackend
from grid2op.Action import PlayableAction
import grid2op

class Issue66Tester(unittest.TestCase):
"""issue is still not replicated and these tests pass"""
def setUp(self) -> None:
with warnings.catch_warnings():
warnings.filterwarnings("ignore")
self.env = grid2op.make("l2rpn_case14_sandbox", test=True, backend=LightSimBackend())
self.env = grid2op.make("educ_case14_storage", test=True, backend=LightSimBackend(),
action_class=PlayableAction)
return super().setUp()

def tearDown(self) -> None:
Expand Down Expand Up @@ -67,6 +69,20 @@ def test_change_bus_gen(self):
obs, reward, done, info = self.env.step(act)
assert done

def test_disco_storage(self):
"""test i can disconnect a storage unit"""
obs = self.env.reset()
act = self.env.action_space({"set_bus": {"storages_id": [(0, -1)]}})
obs, reward, done, info = self.env.step(act)
assert not done
# should not raise any RuntimeError

act = self.env.action_space({"storage_p": [(0, -1)]})
obs, reward, done, info = self.env.step(act)
assert not done
# should not raise any RuntimeError


if __name__ == "__main__":
unittest.main()

0 comments on commit b3c9ab2

Please sign in to comment.