Skip to content

Commit

Permalink
fix some small bug in the Backend
Browse files Browse the repository at this point in the history
  • Loading branch information
BDonnot committed Oct 16, 2023
1 parent 13590b4 commit 618ffc7
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -269,3 +269,8 @@ test_issue_58.py
test_issue_58_old.py
lightsim2grid/gridmodel/pypowsybl.ipynb
lightsim2grid/tests/test.mat
output_test.txt
req_test.txt
test.txt
test_output.txt
test_pypower_fdpf.py
7 changes: 7 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@ Change Log
- maybe have a look at suitesparse "sliplu" tools ?
- easier building (get rid of the "make" part)

[0.7.6] 2023-xx-yy
--------------------
- [FIXED] now voltage is properly set to 0. when shunts are disconnected
- [FIXED] now voltage is properly set to 0. when storage units are disconnected
- [FIXED] a bug where non connected grid were not spotted in DC
- [IMPROVED] now making the new grid2op `create_test_suite`

[0.7.5] 2023-10-05
--------------------
- [FIXED] a bug in DC powerflow when asking for computation time: it was not reset to 0. when
Expand Down
7 changes: 6 additions & 1 deletion lightsim2grid/lightSimBackend.py
Original file line number Diff line number Diff line change
Expand Up @@ -814,6 +814,8 @@ def runpf(self, is_dc=False):
self.prod_p[:], self.prod_q[:], self.prod_v[:] = self._grid.get_gen_res()
if self.__has_storage:
self.storage_p[:], self.storage_q[:], self.storage_v[:] = self._grid.get_storages_res()
self.storage_v[self.storage_v == -1.] = 0. # voltage is 0. for disconnected elements in grid2op

self.next_prod_p[:] = self.prod_p

if np.any(~np.isfinite(self.load_v)) or np.any(self.load_v <= 0.):
Expand All @@ -825,14 +827,16 @@ def runpf(self, is_dc=False):
disco = (~np.isfinite(self.prod_v)) | (self.prod_v <= 0.)
gen_disco = np.where(disco)[0]
self._timer_postproc += time.perf_counter() - beg_postroc
raise DivergingPowerFlow(f"At least one generator is disconnected (check loads {gen_disco})")
raise DivergingPowerFlow(f"At least one generator is disconnected (check gen {gen_disco})")
# TODO storage case of divergence !

if self.shunts_data_available:
self._set_shunt_info()

self._fill_theta()

if (self.line_or_theta >= 1e6).any() or (self.line_ex_theta >= 1e6).any():
raise DivergingPowerFlow(f"Some theta are above 1e6 which should not be happening !")
res = True
self._grid.unset_topo_changed()
self._timer_postproc += time.perf_counter() - beg_postroc
Expand Down Expand Up @@ -1039,6 +1043,7 @@ def _set_shunt_info(self):
res_bus[shunt_bus >= self.__nb_bus_before] = 2 # except the one that are connected to bus 2
res_bus[shunt_bus == -1] = -1 # or the one that are disconnected
self.sh_bus[:] = res_bus
self.sh_v[self.sh_v == -1.] = 0. # in grid2op disco element have voltage of 0. and -1.

def _disconnect_line(self, id_):
self.topo_vect[self.line_ex_pos_topo_vect[id_]] = -1
Expand Down
37 changes: 37 additions & 0 deletions lightsim2grid/tests/test_basic_backend_api.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Copyright (c) 2020, 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 LightSim2grid, LightSim2grid a implements a c++ backend targeting the Grid2Op platform.

import unittest

try:
from grid2op._create_test_suite import create_test_suite
CAN_PERFORM_THESE = True
except ImportError as exc_:
CAN_PERFORM_THESE = False

from lightsim2grid import LightSimBackend

if CAN_PERFORM_THESE:
def this_make_backend(self, detailed_infos_for_cascading_failures=False):
return LightSimBackend(
detailed_infos_for_cascading_failures=detailed_infos_for_cascading_failures
)
add_name_cls = "test_LightSimBackend"

res = create_test_suite(make_backend_fun=this_make_backend,
add_name_cls=add_name_cls,
add_to_module=__name__,
extended_test=False, # for now keep `extended_test=False` until all problems are solved
)
else:
import warnings
warnings.warn("Have you installed grid2op in dev / editable mode ? We cannot make the `create_test_suite` :-(")

# and run it with `python -m unittest gridcal_backend_tests.py`
if __name__ == "__main__":
unittest.main()

0 comments on commit 618ffc7

Please sign in to comment.