|
17 | 17 |
|
18 | 18 | import pandapower as pp |
19 | 19 | import scipy |
| 20 | +# check that pandapower does not introduce some |
| 21 | +from packaging import version |
20 | 22 |
|
21 | 23 | import grid2op |
22 | 24 | from grid2op.dtypes import dt_int, dt_float, dt_bool |
23 | 25 | from grid2op.Action import BaseAction |
24 | 26 | from grid2op.Exceptions import BackendError |
25 | 27 | from grid2op.Backend.backend import Backend |
26 | 28 |
|
| 29 | +MIN_LS_VERSION_VM_PU = version.parse("0.6.0") |
| 30 | + |
27 | 31 | try: |
28 | 32 | import numba |
29 | 33 | NUMBA_ = True |
@@ -544,6 +548,23 @@ def load_grid(self, |
544 | 548 | self._in_service_storage_cold_id = int((self._grid.storage.columns == "in_service").nonzero()[0][0]) |
545 | 549 | self.comp_time = 0. |
546 | 550 |
|
| 551 | + # hack for backward compat with oldest lightsim2grid version |
| 552 | + try: |
| 553 | + import lightsim2grid |
| 554 | + if version.parse(lightsim2grid.__version__) < MIN_LS_VERSION_VM_PU: |
| 555 | + warnings.warn("You are using a really old version of lightsim2grid. Consider upgrading.") |
| 556 | + if "_options" in self._grid and "init_vm_pu" in self._grid["_options"]: |
| 557 | + try: |
| 558 | + float(self._grid["_options"]["init_vm_pu"]) |
| 559 | + except ValueError as exc_: |
| 560 | + # we delete it because lightsim2grid uses it |
| 561 | + # to init its internal "GridModel" and did not check that |
| 562 | + # this is a float until MIN_LS_VERSION_VM_PU |
| 563 | + del self._grid["_options"]["init_vm_pu"] |
| 564 | + except ImportError: |
| 565 | + # lightsim2grid is not installed, so no risk to contaminate it |
| 566 | + pass |
| 567 | + |
547 | 568 | def _aux_run_pf_init(self): |
548 | 569 | """run a powerflow when the file is being loaded. This is called three times for each call to "load_grid" """ |
549 | 570 | with warnings.catch_warnings(): |
|
0 commit comments