From 1accc804d5610d184279386f7f5eac2094de359b Mon Sep 17 00:00:00 2001 From: DONNOT Benjamin Date: Thu, 25 Jul 2024 08:59:33 +0200 Subject: [PATCH] clean the way to init lightsim2grid --- lightsim2grid/_utils/__init__.py | 1 - lightsim2grid/gridmodel/__init__.py | 19 +- .../gridmodel/from_pandapower/__init__.py | 11 + .../{ => from_pandapower}/_aux_add_dc_line.py | 0 .../{ => from_pandapower}/_aux_add_gen.py | 0 .../{ => from_pandapower}/_aux_add_line.py | 0 .../{ => from_pandapower}/_aux_add_load.py | 0 .../{ => from_pandapower}/_aux_add_sgen.py | 0 .../{ => from_pandapower}/_aux_add_shunt.py | 0 .../{ => from_pandapower}/_aux_add_slack.py | 0 .../{ => from_pandapower}/_aux_add_storage.py | 0 .../{ => from_pandapower}/_aux_add_trafo.py | 0 .../{ => from_pandapower}/_aux_check_legit.py | 0 .../_pp_bus_to_ls_bus.py | 0 .../{ => from_pandapower}/initGridModel.py | 24 +- .../gridmodel/from_pypowsybl/__init__.py | 11 + .../_from_pypowsybl.py} | 0 .../gridmodel/from_pypowsybl/pypowsybl.ipynb | 2398 +++++++++++++++++ lightsim2grid/lightSimBackend.py | 4 +- .../convert_from_grid2op.py | 12 +- lightsim2grid/tests/test_Deactivatedbus.py | 4 +- lightsim2grid/tests/test_GridModel.py | 4 +- lightsim2grid/tests/test_backend_pypowsybl.py | 4 +- lightsim2grid/tests/test_case118.py | 8 +- lightsim2grid/tests/test_dcline.py | 8 +- lightsim2grid/tests/test_fdpf.py | 4 +- .../tests/test_init_from_pypowsybl.py | 42 +- lightsim2grid/tests/test_lodf.py | 4 +- lightsim2grid/tests/test_multi_slack.py | 4 +- lightsim2grid/tests/test_multiple_slack.py | 12 +- lightsim2grid/tests/test_nr_case300.py | 4 +- lightsim2grid/tests/test_ptdf.py | 4 +- 32 files changed, 2512 insertions(+), 70 deletions(-) create mode 100644 lightsim2grid/gridmodel/from_pandapower/__init__.py rename lightsim2grid/gridmodel/{ => from_pandapower}/_aux_add_dc_line.py (100%) rename lightsim2grid/gridmodel/{ => from_pandapower}/_aux_add_gen.py (100%) rename lightsim2grid/gridmodel/{ => from_pandapower}/_aux_add_line.py (100%) rename lightsim2grid/gridmodel/{ => from_pandapower}/_aux_add_load.py (100%) rename lightsim2grid/gridmodel/{ => from_pandapower}/_aux_add_sgen.py (100%) rename lightsim2grid/gridmodel/{ => from_pandapower}/_aux_add_shunt.py (100%) rename lightsim2grid/gridmodel/{ => from_pandapower}/_aux_add_slack.py (100%) rename lightsim2grid/gridmodel/{ => from_pandapower}/_aux_add_storage.py (100%) rename lightsim2grid/gridmodel/{ => from_pandapower}/_aux_add_trafo.py (100%) rename lightsim2grid/gridmodel/{ => from_pandapower}/_aux_check_legit.py (100%) rename lightsim2grid/gridmodel/{ => from_pandapower}/_pp_bus_to_ls_bus.py (100%) rename lightsim2grid/gridmodel/{ => from_pandapower}/initGridModel.py (85%) create mode 100644 lightsim2grid/gridmodel/from_pypowsybl/__init__.py rename lightsim2grid/gridmodel/{from_pypowsybl.py => from_pypowsybl/_from_pypowsybl.py} (100%) create mode 100644 lightsim2grid/gridmodel/from_pypowsybl/pypowsybl.ipynb diff --git a/lightsim2grid/_utils/__init__.py b/lightsim2grid/_utils/__init__.py index fa8866b1..85b3a6cb 100644 --- a/lightsim2grid/_utils/__init__.py +++ b/lightsim2grid/_utils/__init__.py @@ -131,7 +131,6 @@ def f(cls): setattr(_DoNotUseAnywherePandaPowerBackend, "_clear_grid_dependant_class_attributes", classmethod(f)) - except ImportError as exc_: # grid2op is not installed, we do not use it. pass diff --git a/lightsim2grid/gridmodel/__init__.py b/lightsim2grid/gridmodel/__init__.py index e6900e80..15e84e1a 100644 --- a/lightsim2grid/gridmodel/__init__.py +++ b/lightsim2grid/gridmodel/__init__.py @@ -6,6 +6,21 @@ # SPDX-License-Identifier: MPL-2.0 # This file is part of LightSim2grid, LightSim2grid implements a c++ backend targeting the Grid2Op platform. -__all__ = ["init", "GridModel"] +__all__ = ["GridModel"] + +from lightsim2grid_cpp import GridModel + +try: + from lightsim2grid.gridmodel.from_pandapower import init as init_from_pandapower + __all__.append("init_from_pandapower") +except ImportError: + # pandapower is not installed + pass + +try: + from lightsim2grid.gridmodel.from_pypowsybl import init as init_from_pypowsybl + __all__.append("init_from_pypowsybl") +except ImportError: + # pandapower is not installed + pass -from lightsim2grid.gridmodel.initGridModel import init, GridModel diff --git a/lightsim2grid/gridmodel/from_pandapower/__init__.py b/lightsim2grid/gridmodel/from_pandapower/__init__.py new file mode 100644 index 00000000..39788afc --- /dev/null +++ b/lightsim2grid/gridmodel/from_pandapower/__init__.py @@ -0,0 +1,11 @@ +# Copyright (c) 2024, 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 implements a c++ backend targeting the Grid2Op platform. + +__all__ = ["init"] + +from lightsim2grid.gridmodel.from_pandapower.initGridModel import init diff --git a/lightsim2grid/gridmodel/_aux_add_dc_line.py b/lightsim2grid/gridmodel/from_pandapower/_aux_add_dc_line.py similarity index 100% rename from lightsim2grid/gridmodel/_aux_add_dc_line.py rename to lightsim2grid/gridmodel/from_pandapower/_aux_add_dc_line.py diff --git a/lightsim2grid/gridmodel/_aux_add_gen.py b/lightsim2grid/gridmodel/from_pandapower/_aux_add_gen.py similarity index 100% rename from lightsim2grid/gridmodel/_aux_add_gen.py rename to lightsim2grid/gridmodel/from_pandapower/_aux_add_gen.py diff --git a/lightsim2grid/gridmodel/_aux_add_line.py b/lightsim2grid/gridmodel/from_pandapower/_aux_add_line.py similarity index 100% rename from lightsim2grid/gridmodel/_aux_add_line.py rename to lightsim2grid/gridmodel/from_pandapower/_aux_add_line.py diff --git a/lightsim2grid/gridmodel/_aux_add_load.py b/lightsim2grid/gridmodel/from_pandapower/_aux_add_load.py similarity index 100% rename from lightsim2grid/gridmodel/_aux_add_load.py rename to lightsim2grid/gridmodel/from_pandapower/_aux_add_load.py diff --git a/lightsim2grid/gridmodel/_aux_add_sgen.py b/lightsim2grid/gridmodel/from_pandapower/_aux_add_sgen.py similarity index 100% rename from lightsim2grid/gridmodel/_aux_add_sgen.py rename to lightsim2grid/gridmodel/from_pandapower/_aux_add_sgen.py diff --git a/lightsim2grid/gridmodel/_aux_add_shunt.py b/lightsim2grid/gridmodel/from_pandapower/_aux_add_shunt.py similarity index 100% rename from lightsim2grid/gridmodel/_aux_add_shunt.py rename to lightsim2grid/gridmodel/from_pandapower/_aux_add_shunt.py diff --git a/lightsim2grid/gridmodel/_aux_add_slack.py b/lightsim2grid/gridmodel/from_pandapower/_aux_add_slack.py similarity index 100% rename from lightsim2grid/gridmodel/_aux_add_slack.py rename to lightsim2grid/gridmodel/from_pandapower/_aux_add_slack.py diff --git a/lightsim2grid/gridmodel/_aux_add_storage.py b/lightsim2grid/gridmodel/from_pandapower/_aux_add_storage.py similarity index 100% rename from lightsim2grid/gridmodel/_aux_add_storage.py rename to lightsim2grid/gridmodel/from_pandapower/_aux_add_storage.py diff --git a/lightsim2grid/gridmodel/_aux_add_trafo.py b/lightsim2grid/gridmodel/from_pandapower/_aux_add_trafo.py similarity index 100% rename from lightsim2grid/gridmodel/_aux_add_trafo.py rename to lightsim2grid/gridmodel/from_pandapower/_aux_add_trafo.py diff --git a/lightsim2grid/gridmodel/_aux_check_legit.py b/lightsim2grid/gridmodel/from_pandapower/_aux_check_legit.py similarity index 100% rename from lightsim2grid/gridmodel/_aux_check_legit.py rename to lightsim2grid/gridmodel/from_pandapower/_aux_check_legit.py diff --git a/lightsim2grid/gridmodel/_pp_bus_to_ls_bus.py b/lightsim2grid/gridmodel/from_pandapower/_pp_bus_to_ls_bus.py similarity index 100% rename from lightsim2grid/gridmodel/_pp_bus_to_ls_bus.py rename to lightsim2grid/gridmodel/from_pandapower/_pp_bus_to_ls_bus.py diff --git a/lightsim2grid/gridmodel/initGridModel.py b/lightsim2grid/gridmodel/from_pandapower/initGridModel.py similarity index 85% rename from lightsim2grid/gridmodel/initGridModel.py rename to lightsim2grid/gridmodel/from_pandapower/initGridModel.py index 220f4e11..a47f5084 100644 --- a/lightsim2grid/gridmodel/initGridModel.py +++ b/lightsim2grid/gridmodel/from_pandapower/initGridModel.py @@ -10,25 +10,21 @@ Use the pandapower converter to properly initialize a GridModel c++ object. """ -__all__ = ["init", "GridModel"] - import numpy as np from numbers import Number -import warnings import pandapower -import lightsim2grid from lightsim2grid_cpp import GridModel, PandaPowerConverter -from lightsim2grid.gridmodel._aux_add_sgen import _aux_add_sgen -from lightsim2grid.gridmodel._aux_add_load import _aux_add_load -from lightsim2grid.gridmodel._aux_add_trafo import _aux_add_trafo -from lightsim2grid.gridmodel._aux_add_line import _aux_add_line -from lightsim2grid.gridmodel._aux_add_gen import _aux_add_gen -from lightsim2grid.gridmodel._aux_add_shunt import _aux_add_shunt -from lightsim2grid.gridmodel._aux_check_legit import _aux_check_legit -from lightsim2grid.gridmodel._aux_add_slack import _aux_add_slack -from lightsim2grid.gridmodel._aux_add_storage import _aux_add_storage -from lightsim2grid.gridmodel._aux_add_dc_line import _aux_add_dc_line +from ._aux_add_sgen import _aux_add_sgen +from ._aux_add_load import _aux_add_load +from ._aux_add_trafo import _aux_add_trafo +from ._aux_add_line import _aux_add_line +from ._aux_add_gen import _aux_add_gen +from ._aux_add_shunt import _aux_add_shunt +from ._aux_check_legit import _aux_check_legit +from ._aux_add_slack import _aux_add_slack +from ._aux_add_storage import _aux_add_storage +from ._aux_add_dc_line import _aux_add_dc_line def init(pp_net: "pandapower.auxiliary.pandapowerNet") -> GridModel: diff --git a/lightsim2grid/gridmodel/from_pypowsybl/__init__.py b/lightsim2grid/gridmodel/from_pypowsybl/__init__.py new file mode 100644 index 00000000..c62313ab --- /dev/null +++ b/lightsim2grid/gridmodel/from_pypowsybl/__init__.py @@ -0,0 +1,11 @@ +# Copyright (c) 2024, 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 implements a c++ backend targeting the Grid2Op platform. + +__all__ = ["init"] + +from ._from_pypowsybl import init diff --git a/lightsim2grid/gridmodel/from_pypowsybl.py b/lightsim2grid/gridmodel/from_pypowsybl/_from_pypowsybl.py similarity index 100% rename from lightsim2grid/gridmodel/from_pypowsybl.py rename to lightsim2grid/gridmodel/from_pypowsybl/_from_pypowsybl.py diff --git a/lightsim2grid/gridmodel/from_pypowsybl/pypowsybl.ipynb b/lightsim2grid/gridmodel/from_pypowsybl/pypowsybl.ipynb new file mode 100644 index 00000000..cc2e15c8 --- /dev/null +++ b/lightsim2grid/gridmodel/from_pypowsybl/pypowsybl.ipynb @@ -0,0 +1,2398 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [], + "source": [ + "import pypowsybl as pp\n", + "import numpy as np\n", + "network = pp.network.create_ieee14()\n", + "net = network" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "network.set" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [], + "source": [ + "df_gen = network.get_generators() " + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
nameenergy_sourcetarget_pmin_pmax_pmin_qmax_qrated_sreactive_limits_kindtarget_vtarget_qvoltage_regulator_onregulated_element_idpqivoltage_level_idbus_idconnected
id
B1-GOTHER232.4-9999.09999.0-1.797693e+3081.797693e+308NaNMIN_MAX143.100-16.9TrueNaNNaNNaNVL1VL1_0True
B2-GOTHER40.0-9999.09999.0-4.000000e+015.000000e+01NaNMIN_MAX141.07542.4TrueNaNNaNNaNVL2VL2_0True
B3-GOTHER0.0-9999.09999.00.000000e+004.000000e+01NaNMIN_MAX136.35023.4TrueNaNNaNNaNVL3VL3_0True
B6-GOTHER0.0-9999.09999.0-6.000000e+002.400000e+01NaNMIN_MAX12.84012.2TrueNaNNaNNaNVL6VL6_0True
B8-GOTHER0.0-9999.09999.0-6.000000e+002.400000e+01NaNMIN_MAX21.80017.4TrueNaNNaNNaNVL8VL8_0True
\n", + "
" + ], + "text/plain": [ + " name energy_source target_p min_p max_p min_q \\\n", + "id \n", + "B1-G OTHER 232.4 -9999.0 9999.0 -1.797693e+308 \n", + "B2-G OTHER 40.0 -9999.0 9999.0 -4.000000e+01 \n", + "B3-G OTHER 0.0 -9999.0 9999.0 0.000000e+00 \n", + "B6-G OTHER 0.0 -9999.0 9999.0 -6.000000e+00 \n", + "B8-G OTHER 0.0 -9999.0 9999.0 -6.000000e+00 \n", + "\n", + " max_q rated_s reactive_limits_kind target_v target_q \\\n", + "id \n", + "B1-G 1.797693e+308 NaN MIN_MAX 143.100 -16.9 \n", + "B2-G 5.000000e+01 NaN MIN_MAX 141.075 42.4 \n", + "B3-G 4.000000e+01 NaN MIN_MAX 136.350 23.4 \n", + "B6-G 2.400000e+01 NaN MIN_MAX 12.840 12.2 \n", + "B8-G 2.400000e+01 NaN MIN_MAX 21.800 17.4 \n", + "\n", + " voltage_regulator_on regulated_element_id p q i voltage_level_id \\\n", + "id \n", + "B1-G True NaN NaN NaN VL1 \n", + "B2-G True NaN NaN NaN VL2 \n", + "B3-G True NaN NaN NaN VL3 \n", + "B6-G True NaN NaN NaN VL6 \n", + "B8-G True NaN NaN NaN VL8 \n", + "\n", + " bus_id connected \n", + "id \n", + "B1-G VL1_0 True \n", + "B2-G VL2_0 True \n", + "B3-G VL3_0 True \n", + "B6-G VL6_0 True \n", + "B8-G VL8_0 True " + ] + }, + "execution_count": 12, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "df_gen" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "array([135., 135., 135., 12., 20.])" + ] + }, + "execution_count": 11, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "net.get_voltage_levels().loc[df_gen[\"voltage_level_id\"].values][\"nominal_v\"].values" + ] + }, + { + "cell_type": "code", + "execution_count": 17, + "metadata": {}, + "outputs": [], + "source": [ + "bus_df = net.get_buses()\n", + "bus_df[\"bus_id\"] = np.arange(bus_df.shape[0])" + ] + }, + { + "cell_type": "code", + "execution_count": 19, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "array([0, 1, 2, 5, 7])" + ] + }, + "execution_count": 19, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "bus_df.loc[df_gen[\"bus_id\"]][\"bus_id\"].values" + ] + }, + { + "cell_type": "code", + "execution_count": 44, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
namev_magv_angleconnected_componentsynchronous_componentvoltage_level_idbus_id
id
VL1_0143.1000.0000VL10
VL2_0141.075-4.9800VL21
VL3_0136.350-12.7200VL32
VL4_0137.565-10.3300VL43
VL5_0137.700-8.7800VL54
VL6_012.840-14.2200VL65
VL7_014.868-13.3700VL76
VL8_021.800-13.3600VL87
VL9_012.672-14.9400VL98
VL10_012.612-15.1000VL109
VL11_012.684-14.7900VL1110
VL12_012.660-15.0700VL1211
VL13_012.600-15.1600VL1312
VL14_012.432-16.0400VL1413
\n", + "
" + ], + "text/plain": [ + " name v_mag v_angle connected_component synchronous_component \\\n", + "id \n", + "VL1_0 143.100 0.00 0 0 \n", + "VL2_0 141.075 -4.98 0 0 \n", + "VL3_0 136.350 -12.72 0 0 \n", + "VL4_0 137.565 -10.33 0 0 \n", + "VL5_0 137.700 -8.78 0 0 \n", + "VL6_0 12.840 -14.22 0 0 \n", + "VL7_0 14.868 -13.37 0 0 \n", + "VL8_0 21.800 -13.36 0 0 \n", + "VL9_0 12.672 -14.94 0 0 \n", + "VL10_0 12.612 -15.10 0 0 \n", + "VL11_0 12.684 -14.79 0 0 \n", + "VL12_0 12.660 -15.07 0 0 \n", + "VL13_0 12.600 -15.16 0 0 \n", + "VL14_0 12.432 -16.04 0 0 \n", + "\n", + " voltage_level_id bus_id \n", + "id \n", + "VL1_0 VL1 0 \n", + "VL2_0 VL2 1 \n", + "VL3_0 VL3 2 \n", + "VL4_0 VL4 3 \n", + "VL5_0 VL5 4 \n", + "VL6_0 VL6 5 \n", + "VL7_0 VL7 6 \n", + "VL8_0 VL8 7 \n", + "VL9_0 VL9 8 \n", + "VL10_0 VL10 9 \n", + "VL11_0 VL11 10 \n", + "VL12_0 VL12 11 \n", + "VL13_0 VL13 12 \n", + "VL14_0 VL14 13 " + ] + }, + "execution_count": 44, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "bus_df" + ] + }, + { + "cell_type": "code", + "execution_count": 20, + "metadata": {}, + "outputs": [], + "source": [ + "\n", + "df_load = net.get_loads()" + ] + }, + { + "cell_type": "code", + "execution_count": 21, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
nametypep0q0pqivoltage_level_idbus_idconnected
id
B2-LUNDEFINED21.712.7NaNNaNNaNVL2VL2_0True
B3-LUNDEFINED94.219.0NaNNaNNaNVL3VL3_0True
B4-LUNDEFINED47.8-3.9NaNNaNNaNVL4VL4_0True
B5-LUNDEFINED7.61.6NaNNaNNaNVL5VL5_0True
B6-LUNDEFINED11.27.5NaNNaNNaNVL6VL6_0True
B9-LUNDEFINED29.516.6NaNNaNNaNVL9VL9_0True
B10-LUNDEFINED9.05.8NaNNaNNaNVL10VL10_0True
B11-LUNDEFINED3.51.8NaNNaNNaNVL11VL11_0True
B12-LUNDEFINED6.11.6NaNNaNNaNVL12VL12_0True
B13-LUNDEFINED13.55.8NaNNaNNaNVL13VL13_0True
B14-LUNDEFINED14.95.0NaNNaNNaNVL14VL14_0True
\n", + "
" + ], + "text/plain": [ + " name type p0 q0 p q i voltage_level_id bus_id \\\n", + "id \n", + "B2-L UNDEFINED 21.7 12.7 NaN NaN NaN VL2 VL2_0 \n", + "B3-L UNDEFINED 94.2 19.0 NaN NaN NaN VL3 VL3_0 \n", + "B4-L UNDEFINED 47.8 -3.9 NaN NaN NaN VL4 VL4_0 \n", + "B5-L UNDEFINED 7.6 1.6 NaN NaN NaN VL5 VL5_0 \n", + "B6-L UNDEFINED 11.2 7.5 NaN NaN NaN VL6 VL6_0 \n", + "B9-L UNDEFINED 29.5 16.6 NaN NaN NaN VL9 VL9_0 \n", + "B10-L UNDEFINED 9.0 5.8 NaN NaN NaN VL10 VL10_0 \n", + "B11-L UNDEFINED 3.5 1.8 NaN NaN NaN VL11 VL11_0 \n", + "B12-L UNDEFINED 6.1 1.6 NaN NaN NaN VL12 VL12_0 \n", + "B13-L UNDEFINED 13.5 5.8 NaN NaN NaN VL13 VL13_0 \n", + "B14-L UNDEFINED 14.9 5.0 NaN NaN NaN VL14 VL14_0 \n", + "\n", + " connected \n", + "id \n", + "B2-L True \n", + "B3-L True \n", + "B4-L True \n", + "B5-L True \n", + "B6-L True \n", + "B9-L True \n", + "B10-L True \n", + "B11-L True \n", + "B12-L True \n", + "B13-L True \n", + "B14-L True " + ] + }, + "execution_count": 21, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "df_load" + ] + }, + { + "cell_type": "code", + "execution_count": 23, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "272.4" + ] + }, + "execution_count": 23, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "df_gen[\"target_p\"].sum()" + ] + }, + { + "cell_type": "code", + "execution_count": 24, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "259.0" + ] + }, + "execution_count": 24, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "df_load[\"p0\"].sum()" + ] + }, + { + "cell_type": "code", + "execution_count": 27, + "metadata": {}, + "outputs": [], + "source": [ + "df_line = net.get_lines()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": 30, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "array([ 0, 0, 1, 1, 1, 2, 3, 5, 5, 5, 6, 6, 8, 8, 9, 11, 12])" + ] + }, + "execution_count": 30, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "bus_df.loc[df_line[\"bus1_id\"].values][\"bus_id\"].values" + ] + }, + { + "cell_type": "code", + "execution_count": 29, + "metadata": {}, + "outputs": [], + "source": [ + "line_h = 0.5 * (df_line[\"g1\"].values + 1j*df_line[\"b1\"] + df_line[\"g2\"].values + 1j*df_line[\"b2\"])" + ] + }, + { + "cell_type": "code", + "execution_count": 31, + "metadata": {}, + "outputs": [], + "source": [ + "df_trafo = net.get_2_windings_transformers()" + ] + }, + { + "cell_type": "code", + "execution_count": 35, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "array([0.+0.j, 0.+0.j, 0.+0.j])" + ] + }, + "execution_count": 35, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "df_trafo[\"g\"].values + 1j*df_trafo[\"b\"].values" + ] + }, + { + "cell_type": "code", + "execution_count": 36, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
namerxgbrated_u1rated_u2rated_sp1q1i1p2q2i2voltage_level1_idvoltage_level2_idbus1_idbus2_idconnected1connected2
id
T4-7-10.00.4098750.00.0132.03014.0NaNNaNNaNNaNNaNNaNNaNVL4VL7VL4_0VL7_0TrueTrue
T4-9-10.00.8008990.00.0130.81512.0NaNNaNNaNNaNNaNNaNNaNVL4VL9VL4_0VL9_0TrueTrue
T5-6-10.00.3629090.00.0125.82012.0NaNNaNNaNNaNNaNNaNNaNVL5VL6VL5_0VL6_0TrueTrue
\n", + "
" + ], + "text/plain": [ + " name r x g b rated_u1 rated_u2 rated_s p1 q1 i1 \\\n", + "id \n", + "T4-7-1 0.0 0.409875 0.0 0.0 132.030 14.0 NaN NaN NaN NaN \n", + "T4-9-1 0.0 0.800899 0.0 0.0 130.815 12.0 NaN NaN NaN NaN \n", + "T5-6-1 0.0 0.362909 0.0 0.0 125.820 12.0 NaN NaN NaN NaN \n", + "\n", + " p2 q2 i2 voltage_level1_id voltage_level2_id bus1_id bus2_id \\\n", + "id \n", + "T4-7-1 NaN NaN NaN VL4 VL7 VL4_0 VL7_0 \n", + "T4-9-1 NaN NaN NaN VL4 VL9 VL4_0 VL9_0 \n", + "T5-6-1 NaN NaN NaN VL5 VL6 VL5_0 VL6_0 \n", + "\n", + " connected1 connected2 \n", + "id \n", + "T4-7-1 True True \n", + "T4-9-1 True True \n", + "T5-6-1 True True " + ] + }, + "execution_count": 36, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "df_trafo" + ] + }, + { + "cell_type": "code", + "execution_count": 40, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
namegbmodel_typemax_section_countsection_countvoltage_regulation_ontarget_vtarget_deadbandregulating_bus_idpqivoltage_level_idbus_idconnected
id
B9-SH0.00.131944LINEAR11FalseNaNNaNVL9_00.0-21.184844965.267236VL9VL9_0True
\n", + "
" + ], + "text/plain": [ + " name g b model_type max_section_count section_count \\\n", + "id \n", + "B9-SH 0.0 0.131944 LINEAR 1 1 \n", + "\n", + " voltage_regulation_on target_v target_deadband regulating_bus_id \\\n", + "id \n", + "B9-SH False NaN NaN VL9_0 \n", + "\n", + " p q i voltage_level_id bus_id connected \n", + "id \n", + "B9-SH 0.0 -21.184844 965.267236 VL9 VL9_0 True " + ] + }, + "execution_count": 40, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "net.get_shunt_compensators()" + ] + }, + { + "cell_type": "code", + "execution_count": 42, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
namegbmodel_typemax_section_countsection_countvoltage_regulation_ontarget_vtarget_deadbandregulating_bus_idpqivoltage_level_idbus_idconnected
id
B9-SH0.00.131944LINEAR11FalseNaNNaNVL9_0NaNNaNNaNVL9VL9_0True
\n", + "
" + ], + "text/plain": [ + " name g b model_type max_section_count section_count \\\n", + "id \n", + "B9-SH 0.0 0.131944 LINEAR 1 1 \n", + "\n", + " voltage_regulation_on target_v target_deadband regulating_bus_id p \\\n", + "id \n", + "B9-SH False NaN NaN VL9_0 NaN \n", + "\n", + " q i voltage_level_id bus_id connected \n", + "id \n", + "B9-SH NaN NaN VL9 VL9_0 True " + ] + }, + "execution_count": 42, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "net.get_shunt_compensators()" + ] + }, + { + "cell_type": "code", + "execution_count": 38, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "['DynaFlow', 'OpenLoadFlow']" + ] + }, + "execution_count": 38, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "import pypowsybl.loadflow as lf\n", + "lf.get_provider_names()" + ] + }, + { + "cell_type": "code", + "execution_count": 55, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[ComponentResult(connected_component_num=0, synchronous_component_num=0, status=CONVERGED, iteration_count=0, slack_bus_id='VL1_0', slack_bus_active_power_mismatch=-13.399999999999942, distributed_active_power=nan)]" + ] + }, + "execution_count": 55, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "lf.run_dc(net)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": 57, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
namev_magv_angleconnected_componentsynchronous_componentvoltage_level_id
id
VL1_0NaN0.00000000VL1
VL2_0NaN-5.01201100VL2
VL3_0NaN-12.95366300VL3
VL4_0NaN-10.58366700VL4
VL5_0NaN-9.09389400VL5
VL6_0NaN-14.85207900VL6
VL7_0NaN-13.90705500VL7
VL8_0NaN-13.90705500VL8
VL9_0NaN-15.69468900VL9
VL10_0NaN-15.97412300VL10
VL11_0NaN-15.61885000VL11
VL12_0NaN-15.96707700VL12
VL13_0NaN-16.13970400VL13
VL14_0NaN-17.18828800VL14
\n", + "
" + ], + "text/plain": [ + " name v_mag v_angle connected_component synchronous_component \\\n", + "id \n", + "VL1_0 NaN 0.000000 0 0 \n", + "VL2_0 NaN -5.012011 0 0 \n", + "VL3_0 NaN -12.953663 0 0 \n", + "VL4_0 NaN -10.583667 0 0 \n", + "VL5_0 NaN -9.093894 0 0 \n", + "VL6_0 NaN -14.852079 0 0 \n", + "VL7_0 NaN -13.907055 0 0 \n", + "VL8_0 NaN -13.907055 0 0 \n", + "VL9_0 NaN -15.694689 0 0 \n", + "VL10_0 NaN -15.974123 0 0 \n", + "VL11_0 NaN -15.618850 0 0 \n", + "VL12_0 NaN -15.967077 0 0 \n", + "VL13_0 NaN -16.139704 0 0 \n", + "VL14_0 NaN -17.188288 0 0 \n", + "\n", + " voltage_level_id \n", + "id \n", + "VL1_0 VL1 \n", + "VL2_0 VL2 \n", + "VL3_0 VL3 \n", + "VL4_0 VL4 \n", + "VL5_0 VL5 \n", + "VL6_0 VL6 \n", + "VL7_0 VL7 \n", + "VL8_0 VL8 \n", + "VL9_0 VL9 \n", + "VL10_0 VL10 \n", + "VL11_0 VL11 \n", + "VL12_0 VL12 \n", + "VL13_0 VL13 \n", + "VL14_0 VL14 " + ] + }, + "execution_count": 57, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "net.get_buses()" + ] + }, + { + "cell_type": "code", + "execution_count": 46, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
nameenergy_sourcetarget_pmin_pmax_pmin_qmax_qrated_sreactive_limits_kindtarget_vtarget_qvoltage_regulator_onregulated_element_idpqivoltage_level_idbus_idconnected
id
B1-GOTHER232.4-9999.09999.0-1.797693e+3081.797693e+308NaNMIN_MAX143.100-16.9TrueNaNNaNNaNVL1VL1_0True
B2-GOTHER40.0-9999.09999.0-4.000000e+015.000000e+01NaNMIN_MAX141.07542.4TrueNaNNaNNaNVL2VL2_0True
B3-GOTHER0.0-9999.09999.00.000000e+004.000000e+01NaNMIN_MAX136.35023.4TrueNaNNaNNaNVL3VL3_0True
B6-GOTHER0.0-9999.09999.0-6.000000e+002.400000e+01NaNMIN_MAX12.84012.2TrueNaNNaNNaNVL6VL6_0True
B8-GOTHER0.0-9999.09999.0-6.000000e+002.400000e+01NaNMIN_MAX21.80017.4TrueNaNNaNNaNVL8VL8_0True
\n", + "
" + ], + "text/plain": [ + " name energy_source target_p min_p max_p min_q \\\n", + "id \n", + "B1-G OTHER 232.4 -9999.0 9999.0 -1.797693e+308 \n", + "B2-G OTHER 40.0 -9999.0 9999.0 -4.000000e+01 \n", + "B3-G OTHER 0.0 -9999.0 9999.0 0.000000e+00 \n", + "B6-G OTHER 0.0 -9999.0 9999.0 -6.000000e+00 \n", + "B8-G OTHER 0.0 -9999.0 9999.0 -6.000000e+00 \n", + "\n", + " max_q rated_s reactive_limits_kind target_v target_q \\\n", + "id \n", + "B1-G 1.797693e+308 NaN MIN_MAX 143.100 -16.9 \n", + "B2-G 5.000000e+01 NaN MIN_MAX 141.075 42.4 \n", + "B3-G 4.000000e+01 NaN MIN_MAX 136.350 23.4 \n", + "B6-G 2.400000e+01 NaN MIN_MAX 12.840 12.2 \n", + "B8-G 2.400000e+01 NaN MIN_MAX 21.800 17.4 \n", + "\n", + " voltage_regulator_on regulated_element_id p q i voltage_level_id \\\n", + "id \n", + "B1-G True NaN NaN NaN VL1 \n", + "B2-G True NaN NaN NaN VL2 \n", + "B3-G True NaN NaN NaN VL3 \n", + "B6-G True NaN NaN NaN VL6 \n", + "B8-G True NaN NaN NaN VL8 \n", + "\n", + " bus_id connected \n", + "id \n", + "B1-G VL1_0 True \n", + "B2-G VL2_0 True \n", + "B3-G VL3_0 True \n", + "B6-G VL6_0 True \n", + "B8-G VL8_0 True " + ] + }, + "execution_count": 46, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "df_gen" + ] + }, + { + "cell_type": "code", + "execution_count": 52, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "-272.4" + ] + }, + "execution_count": 52, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "net.get_generators()[\"p\"].sum()" + ] + }, + { + "cell_type": "code", + "execution_count": 53, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "259.0" + ] + }, + "execution_count": 53, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "net.get_loads()[\"p\"].sum()" + ] + }, + { + "cell_type": "code", + "execution_count": 59, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
namerxg1b1g2b2p1q1i1p2q2i2voltage_level1_idvoltage_level2_idbus1_idbus2_idconnected1connected2
id
L1-2-13.53200510.7837320.00.0001450.00.000145NaNNaNNaNNaNNaNNaNVL1VL2VL1_0VL2_0TrueTrue
L1-5-19.84696740.6490400.00.0001350.00.000135NaNNaNNaNNaNNaNNaNVL1VL5VL1_0VL5_0TrueTrue
L2-3-18.56392736.0800330.00.0001200.00.000120NaNNaNNaNNaNNaNNaNVL2VL3VL2_0VL3_0TrueTrue
L2-4-110.59054732.1343200.00.0000930.00.000093NaNNaNNaNNaNNaNNaNVL2VL4VL2_0VL4_0TrueTrue
L2-5-110.37913731.6896300.00.0000950.00.000095NaNNaNNaNNaNNaNNaNVL2VL5VL2_0VL5_0TrueTrue
L3-4-112.21257331.1702170.00.0000350.00.000035NaNNaNNaNNaNNaNNaNVL3VL4VL3_0VL4_0TrueTrue
L4-5-12.4330387.6745480.00.0000000.00.000000NaNNaNNaNNaNNaNNaNVL4VL5VL4_0VL5_0TrueTrue
L6-11-10.1367710.2864160.00.0000000.00.000000NaNNaNNaNNaNNaNNaNVL6VL11VL6_0VL11_0TrueTrue
L6-12-10.1769900.3683660.00.0000000.00.000000NaNNaNNaNNaNNaNNaNVL6VL12VL6_0VL12_0TrueTrue
L6-13-10.0952560.1875890.00.0000000.00.000000NaNNaNNaNNaNNaNNaNVL6VL13VL6_0VL13_0TrueTrue
L7-8-10.0000000.4932200.0-0.8689250.00.608248NaNNaNNaNNaNNaNNaNVL7VL8VL7_0VL8_0TrueTrue
L7-9-10.0000000.1848170.00.7729660.0-0.901794NaNNaNNaNNaNNaNNaNVL7VL9VL7_0VL9_0TrueTrue
L9-10-10.0458060.1216800.00.0000000.00.000000NaNNaNNaNNaNNaNNaNVL9VL10VL9_0VL10_0TrueTrue
L9-14-10.1830380.3893470.00.0000000.00.000000NaNNaNNaNNaNNaNNaNVL9VL14VL9_0VL14_0TrueTrue
L10-11-10.1181520.2765810.00.0000000.00.000000NaNNaNNaNNaNNaNNaNVL10VL11VL10_0VL11_0TrueTrue
L12-13-10.3181250.2878270.00.0000000.00.000000NaNNaNNaNNaNNaNNaNVL12VL13VL12_0VL13_0TrueTrue
L13-14-10.2461390.5011490.00.0000000.00.000000NaNNaNNaNNaNNaNNaNVL13VL14VL13_0VL14_0TrueTrue
\n", + "
" + ], + "text/plain": [ + " name r x g1 b1 g2 b2 p1 q1 i1 \\\n", + "id \n", + "L1-2-1 3.532005 10.783732 0.0 0.000145 0.0 0.000145 NaN NaN NaN \n", + "L1-5-1 9.846967 40.649040 0.0 0.000135 0.0 0.000135 NaN NaN NaN \n", + "L2-3-1 8.563927 36.080033 0.0 0.000120 0.0 0.000120 NaN NaN NaN \n", + "L2-4-1 10.590547 32.134320 0.0 0.000093 0.0 0.000093 NaN NaN NaN \n", + "L2-5-1 10.379137 31.689630 0.0 0.000095 0.0 0.000095 NaN NaN NaN \n", + "L3-4-1 12.212573 31.170217 0.0 0.000035 0.0 0.000035 NaN NaN NaN \n", + "L4-5-1 2.433038 7.674548 0.0 0.000000 0.0 0.000000 NaN NaN NaN \n", + "L6-11-1 0.136771 0.286416 0.0 0.000000 0.0 0.000000 NaN NaN NaN \n", + "L6-12-1 0.176990 0.368366 0.0 0.000000 0.0 0.000000 NaN NaN NaN \n", + "L6-13-1 0.095256 0.187589 0.0 0.000000 0.0 0.000000 NaN NaN NaN \n", + "L7-8-1 0.000000 0.493220 0.0 -0.868925 0.0 0.608248 NaN NaN NaN \n", + "L7-9-1 0.000000 0.184817 0.0 0.772966 0.0 -0.901794 NaN NaN NaN \n", + "L9-10-1 0.045806 0.121680 0.0 0.000000 0.0 0.000000 NaN NaN NaN \n", + "L9-14-1 0.183038 0.389347 0.0 0.000000 0.0 0.000000 NaN NaN NaN \n", + "L10-11-1 0.118152 0.276581 0.0 0.000000 0.0 0.000000 NaN NaN NaN \n", + "L12-13-1 0.318125 0.287827 0.0 0.000000 0.0 0.000000 NaN NaN NaN \n", + "L13-14-1 0.246139 0.501149 0.0 0.000000 0.0 0.000000 NaN NaN NaN \n", + "\n", + " p2 q2 i2 voltage_level1_id voltage_level2_id bus1_id bus2_id \\\n", + "id \n", + "L1-2-1 NaN NaN NaN VL1 VL2 VL1_0 VL2_0 \n", + "L1-5-1 NaN NaN NaN VL1 VL5 VL1_0 VL5_0 \n", + "L2-3-1 NaN NaN NaN VL2 VL3 VL2_0 VL3_0 \n", + "L2-4-1 NaN NaN NaN VL2 VL4 VL2_0 VL4_0 \n", + "L2-5-1 NaN NaN NaN VL2 VL5 VL2_0 VL5_0 \n", + "L3-4-1 NaN NaN NaN VL3 VL4 VL3_0 VL4_0 \n", + "L4-5-1 NaN NaN NaN VL4 VL5 VL4_0 VL5_0 \n", + "L6-11-1 NaN NaN NaN VL6 VL11 VL6_0 VL11_0 \n", + "L6-12-1 NaN NaN NaN VL6 VL12 VL6_0 VL12_0 \n", + "L6-13-1 NaN NaN NaN VL6 VL13 VL6_0 VL13_0 \n", + "L7-8-1 NaN NaN NaN VL7 VL8 VL7_0 VL8_0 \n", + "L7-9-1 NaN NaN NaN VL7 VL9 VL7_0 VL9_0 \n", + "L9-10-1 NaN NaN NaN VL9 VL10 VL9_0 VL10_0 \n", + "L9-14-1 NaN NaN NaN VL9 VL14 VL9_0 VL14_0 \n", + "L10-11-1 NaN NaN NaN VL10 VL11 VL10_0 VL11_0 \n", + "L12-13-1 NaN NaN NaN VL12 VL13 VL12_0 VL13_0 \n", + "L13-14-1 NaN NaN NaN VL13 VL14 VL13_0 VL14_0 \n", + "\n", + " connected1 connected2 \n", + "id \n", + "L1-2-1 True True \n", + "L1-5-1 True True \n", + "L2-3-1 True True \n", + "L2-4-1 True True \n", + "L2-5-1 True True \n", + "L3-4-1 True True \n", + "L4-5-1 True True \n", + "L6-11-1 True True \n", + "L6-12-1 True True \n", + "L6-13-1 True True \n", + "L7-8-1 True True \n", + "L7-9-1 True True \n", + "L9-10-1 True True \n", + "L9-14-1 True True \n", + "L10-11-1 True True \n", + "L12-13-1 True True \n", + "L13-14-1 True True " + ] + }, + "execution_count": 59, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "net.get_lines()" + ] + }, + { + "cell_type": "code", + "execution_count": 62, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "100" + ] + }, + "execution_count": 62, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "import pandapower.networks as pn\n", + "pn.case14().sn_mva" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.8.10" + }, + "orig_nbformat": 4 + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/lightsim2grid/lightSimBackend.py b/lightsim2grid/lightSimBackend.py index 45327221..8c296652 100644 --- a/lightsim2grid/lightSimBackend.py +++ b/lightsim2grid/lightSimBackend.py @@ -41,7 +41,6 @@ except ImportError: from typing_extensions import Literal -from lightsim2grid.gridmodel import init from lightsim2grid.solver import SolverType @@ -740,7 +739,8 @@ def _load_grid_pandapower(self, path=None, filename=None): def _aux_init_pandapower(self): self.can_output_theta = True # i can compute the "theta" and output it to grid2op - self._grid = init(self.init_pp_backend._grid) + from lightsim2grid.gridmodel import init_from_pandapower + self._grid = init_from_pandapower(self.init_pp_backend._grid) self.__nb_bus_before = self.init_pp_backend.get_nb_active_bus() self._aux_setup_right_after_grid_init() diff --git a/lightsim2grid/tests/case_14_storage_iidm/convert_from_grid2op.py b/lightsim2grid/tests/case_14_storage_iidm/convert_from_grid2op.py index 47e14243..ea7d582b 100644 --- a/lightsim2grid/tests/case_14_storage_iidm/convert_from_grid2op.py +++ b/lightsim2grid/tests/case_14_storage_iidm/convert_from_grid2op.py @@ -13,8 +13,8 @@ import pypowsybl.network as pypo_n import grid2op -from lightsim2grid.gridmodel import init as init_from_pp -from lightsim2grid.gridmodel.from_pypowsybl import init as init_from_pypo +from lightsim2grid.gridmodel import init_from_pandapower +from lightsim2grid.gridmodel import init_from_pypowsybl @@ -229,10 +229,10 @@ def get_bus_id(el, nb_dig_bus): # check that grid are equals -ls_grid_pp = init_from_pp(pp_grid) -ls_grid_pypo = init_from_pypo(pypo_grid, - gen_slack_id=np.where(pp_grid.gen["slack"])[0], - sn_mva=1.) +ls_grid_pp = init_from_pandapower(pp_grid) +ls_grid_pypo = init_from_pypowsybl(pypo_grid, + gen_slack_id=np.where(pp_grid.gen["slack"])[0], + sn_mva=1.) # check the elements are consistent for i, (el_pp, el_pypo) in enumerate(zip(ls_grid_pp.get_buses(), ls_grid_pypo.get_buses())): diff --git a/lightsim2grid/tests/test_Deactivatedbus.py b/lightsim2grid/tests/test_Deactivatedbus.py index 0dee8d9e..26a3cc90 100644 --- a/lightsim2grid/tests/test_Deactivatedbus.py +++ b/lightsim2grid/tests/test_Deactivatedbus.py @@ -31,7 +31,7 @@ def setUp(self): with warnings.catch_warnings(): warnings.filterwarnings("ignore") - self.model = init(self.net) + self.model = init_from_pandapower(self.net) self.model.deactivate_bus(self.last_real_bus) @@ -65,7 +65,7 @@ def setUp(self): self.n_bus = self.net.bus.shape[0] with warnings.catch_warnings(): warnings.filterwarnings("ignore") - self.model = init(self.net) + self.model = init_from_pandapower(self.net) self.model.deactivate_bus(self.last_real_bus) self.max_it = 10 diff --git a/lightsim2grid/tests/test_GridModel.py b/lightsim2grid/tests/test_GridModel.py index 03a7f575..eafaaaa6 100644 --- a/lightsim2grid/tests/test_GridModel.py +++ b/lightsim2grid/tests/test_GridModel.py @@ -11,7 +11,7 @@ import pandapower.networks as pn import pandapower as pp -from lightsim2grid.gridmodel import init +from lightsim2grid.gridmodel import init_from_pandapower import warnings import pdb @@ -36,7 +36,7 @@ def setUp(self): # initialize and use converters with warnings.catch_warnings(): warnings.filterwarnings("ignore") - self.model = init(self.net_datamodel) + self.model = init_from_pandapower(self.net_datamodel) def assert_equal(self, tmp, ref, error=""): assert np.all(tmp.shape == ref.shape), "vector does not have the same shape" diff --git a/lightsim2grid/tests/test_backend_pypowsybl.py b/lightsim2grid/tests/test_backend_pypowsybl.py index 1390698d..e52033fa 100644 --- a/lightsim2grid/tests/test_backend_pypowsybl.py +++ b/lightsim2grid/tests/test_backend_pypowsybl.py @@ -11,7 +11,7 @@ import os import numpy as np from lightsim2grid import LightSimBackend -from lightsim2grid.gridmodel.from_pypowsybl import init as init_pypow +from lightsim2grid.gridmodel import init_from_pypowsybl import grid2op from grid2op.Runner import Runner import pypowsybl.network as pypow_net @@ -88,7 +88,7 @@ def setUp(self) -> None: def test_init(self): grid_tmp = pypow_net.load(os.path.join(self.path, self.file_name)) - grid = init_pypow(grid_tmp, gen_slack_id=5, sort_index=True) + grid = init_from_pypowsybl(grid_tmp, gen_slack_id=5, sort_index=True) grid.ac_pf(np.ones(14, dtype=np.complex128), 10, 1e-6) def test_runpf(self): diff --git a/lightsim2grid/tests/test_case118.py b/lightsim2grid/tests/test_case118.py index 95b5d875..42232a63 100644 --- a/lightsim2grid/tests/test_case118.py +++ b/lightsim2grid/tests/test_case118.py @@ -16,7 +16,7 @@ import tempfile import unittest from lightsim2grid import LightSimBackend -from lightsim2grid.gridmodel import init +from lightsim2grid.gridmodel import init_from_pandapower from grid2op.Chronics import GridStateFromFileWithForecastsWithoutMaintenance as GridStateFromFile @@ -130,7 +130,7 @@ def test_neurips_track2(self): pp.runpp(self.pp_net, distributed_slack=True, init_vm_pu="flat", init_va_degree="flat") with warnings.catch_warnings(): warnings.filterwarnings("ignore") - ls_grid = init(self.pp_net) + ls_grid = init_from_pandapower(self.pp_net) ls_grid.tell_solver_need_reset() V = np.ones(2 * self.nb_bus_total, dtype=np.complex_) V = ls_grid.ac_pf(V, self.max_it, self.tol) @@ -194,7 +194,7 @@ def test_single_slack(self): init_va_degree="flat") with warnings.catch_warnings(): warnings.filterwarnings("ignore") - ls_grid_single = init(self.net) + ls_grid_single = init_from_pandapower(self.net) V = np.ones(self.nb_bus_total, dtype=np.complex_) V = ls_grid_single.ac_pf(V, self.max_it, self.tol) self.check_results(V, ls_grid_single, self.net) @@ -221,7 +221,7 @@ def test_two_slacks_diff_bus(self): init_va_degree="flat") with warnings.catch_warnings(): warnings.filterwarnings("ignore") - ls_grid = init(self.net) + ls_grid = init_from_pandapower(self.net) V = np.ones(self.nb_bus_total, dtype=np.complex_) V = ls_grid.ac_pf(V, self.max_it, self.tol) self.check_results(V, ls_grid, self.net) diff --git a/lightsim2grid/tests/test_dcline.py b/lightsim2grid/tests/test_dcline.py index 5837c7a1..450f2d43 100644 --- a/lightsim2grid/tests/test_dcline.py +++ b/lightsim2grid/tests/test_dcline.py @@ -8,7 +8,7 @@ import lightsim2grid -from lightsim2grid.gridmodel import init +from lightsim2grid.gridmodel import init_from_pandapower import pandapower as pp import pandapower.networks as pn import unittest @@ -27,7 +27,7 @@ def test_init(self): with warnings.catch_warnings(): warnings.filterwarnings("ignore") - model = init(self.net) + model = init_from_pandapower(self.net) # different convention in pandapower and lightsim for now assert model.get_dclines()[0].target_p_or_mw == -100. @@ -35,7 +35,7 @@ def _aux_test_dc(self): # init ls with warnings.catch_warnings(): warnings.filterwarnings("ignore") - model = init(self.net) + model = init_from_pandapower(self.net) assert model.get_dclines()[0].target_p_or_mw == -self.net.dcline["p_mw"].values # run the dc powerflow for the reference @@ -64,7 +64,7 @@ def _aux_test_ac(self, max_iteration=10, tolerance_mva=1e-08): # init ls with warnings.catch_warnings(): warnings.filterwarnings("ignore") - model = init(self.net) + model = init_from_pandapower(self.net) assert model.get_dclines()[0].target_p_or_mw == -self.net.dcline["p_mw"].values # run the dc powerflow for the reference diff --git a/lightsim2grid/tests/test_fdpf.py b/lightsim2grid/tests/test_fdpf.py index 8e7971a2..2120f829 100644 --- a/lightsim2grid/tests/test_fdpf.py +++ b/lightsim2grid/tests/test_fdpf.py @@ -11,7 +11,7 @@ from scipy.sparse import csc_matrix from lightsim2grid_cpp import FDPFMethod -from lightsim2grid.gridmodel import init +from lightsim2grid.gridmodel import init_from_pandapower from lightsim2grid.solver import SolverType import pandapower.networks as pn @@ -59,7 +59,7 @@ def setUp(self) -> None: self.net = self.get_network() with warnings.catch_warnings(): warnings.filterwarnings("ignore") - self.gridmodel = init(self.net) + self.gridmodel = init_from_pandapower(self.net) self.tol = 1e-7 self.tol_solver = 1e-8 diff --git a/lightsim2grid/tests/test_init_from_pypowsybl.py b/lightsim2grid/tests/test_init_from_pypowsybl.py index c05123d0..a9667194 100644 --- a/lightsim2grid/tests/test_init_from_pypowsybl.py +++ b/lightsim2grid/tests/test_init_from_pypowsybl.py @@ -12,11 +12,16 @@ import unittest import warnings -from lightsim2grid.gridmodel.from_pypowsybl import init +from lightsim2grid.gridmodel import init_from_pypowsybl -import pandapower.networks as pn -import pandapower as pdp -from lightsim2grid.gridmodel import init as init_from_pp +try: + import pandapower.networks as pn + import pandapower as pdp + from lightsim2grid.gridmodel import init_from_pandapower + PDP_AVAIL = True +except ImportError: + # pandapower not available, eg if testing with numpy 2 + PDP_AVAIL = False class AuxInitFromPyPowSyBl: @@ -35,18 +40,22 @@ def get_tol_eq(self): def compare_pp(self): """will this test suite compare pypowsybl and pandapower (cannot be used for ieee57 or ieee118)""" - return True + return PDP_AVAIL def setUp(self) -> None: self.network_ref = self.get_pypo_grid() # init equivalent pandapower grid (if any) - tmp = self.get_equiv_pdp_grid() + if PDP_AVAIL: + tmp = self.get_equiv_pdp_grid() + else: + tmp = None + if tmp is not None: self.pp_samecase = tmp with warnings.catch_warnings(): warnings.filterwarnings("ignore") - self.ref_samecase = init_from_pp(self.pp_samecase) + self.ref_samecase = init_from_pandapower(self.pp_samecase) self.can_pp = True else: # TODO will crash later if no equiv grid @@ -55,11 +64,11 @@ def setUp(self) -> None: self.ref_samecase = None # init lightsim2grid model - self.gridmodel = init(self.network_ref, slack_bus_id=self.get_slackbus_id()) + self.gridmodel = init_from_pypowsybl(self.network_ref, slack_bus_id=self.get_slackbus_id()) # use some data self.nb_bus_total = self.network_ref.get_buses().shape[0] - self.V_init_dc = np.ones(self.nb_bus_total, dtype=np.complex_) + self.V_init_dc = np.ones(self.nb_bus_total, dtype=np.complex128) self.V_init_ac = 1.04 * self.V_init_dc self.tol = 1e-7 # for the solver self.tol_eq = self.get_tol_eq() @@ -82,7 +91,9 @@ def test_compare_pp(self): # check the SBus and Ybus in DC (i need to run powerflow for that) v_ls = self.gridmodel.dc_pf(1.0 * self.V_init_dc, 2, self.tol) - v_ls_ref = self.ref_samecase.dc_pf(1.0 * self.V_init_dc, 2, self.tol) + v_ls_ref = None + if self.ref_samecase is not None: + v_ls_ref = self.ref_samecase.dc_pf(1.0 * self.V_init_dc, 2, self.tol) slack_id = self.get_slackbus_id() reorder = self.gridmodel._orig_to_ls.reshape(1, -1) @@ -117,8 +128,9 @@ def test_compare_pp(self): # # self.pp_samecase["_ppc"]["internal"]["Bbus"] # self.pp_samecase["_ppc"]["internal"]["Ybus"][64,67] # self.pp_samecase["_ppc"]["internal"]["bus"] - max_ = np.abs(v_ls[reorder] - v_ls_ref).max() - # assert max_ <= self.tol_eq, f"error for vresults for dc: {max_:.2e}" + if v_ls_ref is not None: + max_ = np.abs(v_ls[reorder] - v_ls_ref).max() + assert max_ <= self.tol_eq, f"error for vresults for dc: {max_:.2e}" tmp_ = self.gridmodel.get_dcYbus_solver()[reorder.T, reorder].todense() - self.ref_samecase.get_dcYbus_solver().todense() max_ = np.abs(tmp_).max() mat_ls = self.gridmodel.get_dcYbus_solver()[reorder.T, reorder].todense() @@ -253,7 +265,7 @@ def get_equiv_pdp_grid(self): return pn.case57() def compare_pp(self): - return False + return super().compare_pp() and False def get_tol_eq(self): return 1e-4 # otherwise vangle from pypowsybl and pandapower does not match @@ -276,7 +288,7 @@ def get_tol_eq(self): return 3e-5 # otherwise vangle from pypowsybl and pandapower does not match def compare_pp(self): - return False + return super().compare_pp() and False class TestCase300FromPypo(AuxInitFromPyPowSyBl): @@ -297,7 +309,7 @@ def get_tol_eq(self): return 3e-5 # otherwise vangle from pypowsybl and pandapower does not match def compare_pp(self): - return False + return super().compare_pp() and False def get_slackbus_id(self): # does not work with PP, probably bus not ordered the same diff --git a/lightsim2grid/tests/test_lodf.py b/lightsim2grid/tests/test_lodf.py index 059cd7be..c0037307 100644 --- a/lightsim2grid/tests/test_lodf.py +++ b/lightsim2grid/tests/test_lodf.py @@ -14,7 +14,7 @@ import warnings from pandapower.pypower.makeLODF import update_LODF_diag -from lightsim2grid.gridmodel import init +from lightsim2grid.gridmodel import init_from_pandapower from lightsim2grid.solver import SolverType import pdb @@ -31,7 +31,7 @@ def setUp(self) -> None: self.case = self.make_grid() with warnings.catch_warnings(): warnings.filterwarnings("ignore") - self.gridmodel = init(self.case) + self.gridmodel = init_from_pandapower(self.case) self.V_init = 1. * self.gridmodel.get_bus_vn_kv() solver_type = self.get_solver_type() if solver_type not in self.gridmodel.available_solvers(): diff --git a/lightsim2grid/tests/test_multi_slack.py b/lightsim2grid/tests/test_multi_slack.py index 279db8a7..4dbed3b3 100644 --- a/lightsim2grid/tests/test_multi_slack.py +++ b/lightsim2grid/tests/test_multi_slack.py @@ -21,7 +21,7 @@ import unittest -from lightsim2grid.gridmodel import init +from lightsim2grid.gridmodel import init_from_pandapower from lightsim2grid.solver import SolverType @@ -69,7 +69,7 @@ def setUp(self) -> None: self.net = self.get_network() with warnings.catch_warnings(): warnings.filterwarnings("ignore") - self.gridmodel = init(self.net) + self.gridmodel = init_from_pandapower(self.net) self.tol = 1e-7 self.tol_solver = 1e-8 diff --git a/lightsim2grid/tests/test_multiple_slack.py b/lightsim2grid/tests/test_multiple_slack.py index eeac5210..b1a8806f 100644 --- a/lightsim2grid/tests/test_multiple_slack.py +++ b/lightsim2grid/tests/test_multiple_slack.py @@ -12,7 +12,7 @@ import numpy as np import pandapower.networks as pn import unittest -from lightsim2grid.gridmodel import init +from lightsim2grid.gridmodel import init_from_pandapower from functools import reduce @@ -170,7 +170,7 @@ def test_single_slack(self): with warnings.catch_warnings(): warnings.filterwarnings("ignore") - ls_grid_single = init(self.net) + ls_grid_single = init_from_pandapower(self.net) V = np.ones(self.nb_bus_total, dtype=np.complex_) V = ls_grid_single.ac_pf(V, self.max_it, self.tol) self.check_results(V, ls_grid_single, self.net) @@ -202,7 +202,7 @@ def test_two_slacks_diff_bus(self): lightsim2grid=False) with warnings.catch_warnings(): warnings.filterwarnings("ignore") - ls_grid = init(self.net) + ls_grid = init_from_pandapower(self.net) V = np.ones(self.nb_bus_total, dtype=np.complex_) V = ls_grid.ac_pf(V, self.max_it, self.tol) self.check_results(V, ls_grid, self.net) @@ -228,7 +228,7 @@ def test_two_slacks_diff_bus_diff_weights(self): init_va_degree="flat") with warnings.catch_warnings(): warnings.filterwarnings("ignore") - ls_grid = init(self.net) + ls_grid = init_from_pandapower(self.net) V = np.ones(self.nb_bus_total, dtype=np.complex_) V = ls_grid.ac_pf(V, self.max_it, self.tol) self.check_results(V, ls_grid, self.net) @@ -260,7 +260,7 @@ def test_multiple_slack_same_bus(self): init_va_degree="flat") with warnings.catch_warnings(): warnings.filterwarnings("ignore") - ls_grid = init(self.net) + ls_grid = init_from_pandapower(self.net) V = np.ones(self.nb_bus_total, dtype=np.complex_) V = ls_grid.ac_pf(V, self.max_it, self.tol) @@ -307,7 +307,7 @@ def test_multiple_slack_one_gen_not_slack(self): with warnings.catch_warnings(): warnings.filterwarnings("ignore") - ls_grid = init(self.net) + ls_grid = init_from_pandapower(self.net) V = np.ones(self.nb_bus_total, dtype=np.complex_) V = ls_grid.ac_pf(V, self.max_it, self.tol) diff --git a/lightsim2grid/tests/test_nr_case300.py b/lightsim2grid/tests/test_nr_case300.py index 14297127..e0f7d6a6 100644 --- a/lightsim2grid/tests/test_nr_case300.py +++ b/lightsim2grid/tests/test_nr_case300.py @@ -10,7 +10,7 @@ import numpy as np from scipy.sparse import csc_matrix -from lightsim2grid.gridmodel import init +from lightsim2grid.gridmodel import init_from_pandapower from lightsim2grid.solver import SolverType import pandapower.networks as pn @@ -65,7 +65,7 @@ def setUp(self) -> None: self.net = self.get_network() with warnings.catch_warnings(): warnings.filterwarnings("ignore") - self.gridmodel = init(self.net) + self.gridmodel = init_from_pandapower(self.net) self.tol = 1e-7 self.tol_solver = 1e-8 diff --git a/lightsim2grid/tests/test_ptdf.py b/lightsim2grid/tests/test_ptdf.py index 8b4d40b2..acfad137 100644 --- a/lightsim2grid/tests/test_ptdf.py +++ b/lightsim2grid/tests/test_ptdf.py @@ -13,7 +13,7 @@ import warnings from scipy.sparse.linalg import spsolve -from lightsim2grid.gridmodel import init +from lightsim2grid.gridmodel import init_from_pandapower from lightsim2grid.solver import SolverType import pdb @@ -30,7 +30,7 @@ def setUp(self) -> None: self.case = self.make_grid() with warnings.catch_warnings(): warnings.filterwarnings("ignore") - self.gridmodel = init(self.case) + self.gridmodel = init_from_pandapower(self.case) self.V_init = 1. * self.gridmodel.get_bus_vn_kv() solver_type = self.get_solver_type() if solver_type not in self.gridmodel.available_solvers():