From 85852a1ea41093a9d7d7fb987dfca9ad8b000caf Mon Sep 17 00:00:00 2001 From: DONNOT Benjamin Date: Fri, 8 Mar 2024 16:46:27 +0100 Subject: [PATCH] trying to fix CI yet again --- .circleci/config.yml | 5 ++-- CHANGELOG.rst | 2 ++ lightsim2grid/gridmodel/_aux_add_slack.py | 4 +-- lightsim2grid/lightSimBackend.py | 22 +++++++++----- .../tests/test_init_from_pypowsybl.py | 30 +++++++++++++------ 5 files changed, 41 insertions(+), 22 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 542bd2d..a476e0b 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -318,8 +318,7 @@ jobs: resource_class: small steps: - checkout - - run: apt-get update && apt-get install python3-pip python3-full git -y - - run: python3 -m pip install virtualenv + - run: apt-get update && apt-get install python3-full python3-dev python3-pip python3-virtualenv git -y - run: python3 -m virtualenv venv_test - run: command: | @@ -368,7 +367,7 @@ jobs: size: medium # ("medium" "large" "xlarge" "2xlarge") steps: - checkout - - run: choco install python --version=3.10 + - run: choco install python --version=3.10 --force - run: py --version - run: py -m pip install --upgrade pip setuptools wheel - run: py -m pip install virtualenv diff --git a/CHANGELOG.rst b/CHANGELOG.rst index a02c84e..bfa3cd8 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -42,6 +42,8 @@ Change Log - [FIXED] a bug when reading a grid initialize from pypowsybl (trafo names where put in place of shunt names) - [FIXED] read the docs was broken +- [FIXED] a bug when reading a grid from pandapower for multiple slacks when slack + are given by the "ext_grid" information. - [ADDED] sets of methods to extract the main component of a grid and perform powerflow only on this one. - [ADDED] possibility to set / retrieve the names of each elements of the grid. diff --git a/lightsim2grid/gridmodel/_aux_add_slack.py b/lightsim2grid/gridmodel/_aux_add_slack.py index 17b9c83..cfa66f0 100644 --- a/lightsim2grid/gridmodel/_aux_add_slack.py +++ b/lightsim2grid/gridmodel/_aux_add_slack.py @@ -103,8 +103,8 @@ def _aux_add_slack(model, pp_net, pp_to_ls): gen_p = np.concatenate((pp_net.gen["p_mw"].values, slack_contrib)) gen_v = np.concatenate((pp_net.gen["vm_pu"].values, vm_pu)) gen_bus = np.concatenate((pp_bus_to_ls(pp_net.gen["bus"].values, pp_to_ls), slack_bus_ids)) - gen_min_q = np.concatenate((pp_net.gen["min_q_mvar"].values, [-999999.])) - gen_max_q = np.concatenate((pp_net.gen["max_q_mvar"].values, [+99999.])) + gen_min_q = np.concatenate((pp_net.gen["min_q_mvar"].values, [-999999. for _ in range(nb_slack)])) + gen_max_q = np.concatenate((pp_net.gen["max_q_mvar"].values, [+99999. for _ in range(nb_slack)])) model.init_generators(gen_p, gen_v, gen_min_q, gen_max_q, gen_bus) # handle the possible distributed slack bus diff --git a/lightsim2grid/lightSimBackend.py b/lightsim2grid/lightSimBackend.py index f91d869..cd38e07 100644 --- a/lightsim2grid/lightSimBackend.py +++ b/lightsim2grid/lightSimBackend.py @@ -462,8 +462,12 @@ def _aux_pypowsybl_init_substations(self, loader_kwargs): orig_to_ls = np.array(self._grid._orig_to_ls) bus_doubled = np.concatenate([bus_init for _ in range(self.n_busbar_per_sub)]) self._grid.init_bus(bus_doubled, 0, 0) - for i in range(self.__nb_bus_before): - self._grid.deactivate_bus(i + self.__nb_bus_before) + if hasattr(type(self), "can_handle_more_than_2_busbar"): + for i in range(self.__nb_bus_before * (self.n_busbar_per_sub - 1)): + self._grid.deactivate_bus(i + self.__nb_bus_before) + else: + for i in range(self.__nb_bus_before): + self._grid.deactivate_bus(i + self.__nb_bus_before) new_orig_to_ls = np.concatenate([orig_to_ls + i * self.__nb_bus_before for i in range(self.n_busbar_per_sub)] ) @@ -622,7 +626,14 @@ def _load_grid_pandapower(self, path=None, filename=None): self._grid = init(self.init_pp_backend._grid) self.__nb_bus_before = self.init_pp_backend.get_nb_active_bus() - self._aux_setup_right_after_grid_init() + self._aux_setup_right_after_grid_init() + + # deactive the buses that have been added + for bus_id, bus_status in enumerate(self.init_pp_backend._grid.bus["in_service"].values): + if bus_status: + self._grid.reactivate_bus(bus_id) + else: + self._grid.deactivate_bus(bus_id) self.n_line = self.init_pp_backend.n_line self.n_gen = self.init_pp_backend.n_gen @@ -670,11 +681,6 @@ def _load_grid_pandapower(self, path=None, filename=None): self.thermal_limit_a = copy.deepcopy(self.init_pp_backend.thermal_limit_a) - # deactive the buses that have been added - nb_bus_init = self.init_pp_backend._grid.bus.shape[0] // 2 - for i in range(nb_bus_init): - self._grid.deactivate_bus(i + nb_bus_init) - self.__nb_powerline = self.init_pp_backend._grid.line.shape[0] self.__nb_bus_before = self.init_pp_backend.get_nb_active_bus() self._init_bus_load = 1.0 * self.init_pp_backend._grid.load["bus"].values diff --git a/lightsim2grid/tests/test_init_from_pypowsybl.py b/lightsim2grid/tests/test_init_from_pypowsybl.py index 7e008be..6621ed6 100644 --- a/lightsim2grid/tests/test_init_from_pypowsybl.py +++ b/lightsim2grid/tests/test_init_from_pypowsybl.py @@ -175,15 +175,27 @@ def test_ac_pf(self): v_ls_ref = self.ref_samecase.ac_pf(1.0 * self.V_init_ac, 10, self.tol) assert np.abs(v_ls[reorder] - v_ls_ref).max() <= self.tol_eq, f"error for vresults for ac: {np.abs(v_ls[reorder] - v_ls_ref).max():.2e}" - param = lf.Parameters(voltage_init_mode=pp._pypowsybl.VoltageInitMode.UNIFORM_VALUES, - transformer_voltage_control_on=False, - no_generator_reactive_limits=True, - phase_shifter_regulation_on=False, - simul_shunt=False, - distributed_slack=False, - provider_parameters={"slackBusSelectionMode": "NAME", - "slackBusesIds": self.network_ref.get_buses().iloc[self.get_slackbus_id()].name} - ) + try: + param = lf.Parameters(voltage_init_mode=pp._pypowsybl.VoltageInitMode.UNIFORM_VALUES, + transformer_voltage_control_on=False, + no_generator_reactive_limits=True, + phase_shifter_regulation_on=False, + simul_shunt=False, + distributed_slack=False, + provider_parameters={"slackBusSelectionMode": "NAME", + "slackBusesIds": self.network_ref.get_buses().iloc[self.get_slackbus_id()].name} + ) + except TypeError: + param = lf.Parameters(voltage_init_mode=pp._pypowsybl.VoltageInitMode.UNIFORM_VALUES, + transformer_voltage_control_on=False, + # no_generator_reactive_limits=True, # documented in the doc but apparently fails + phase_shifter_regulation_on=False, + simul_shunt=False, + distributed_slack=False, + provider_parameters={"slackBusSelectionMode": "NAME", + "slackBusesIds": self.network_ref.get_buses().iloc[self.get_slackbus_id()].name} + ) + res_pypow = lf.run_ac(self.network_ref, parameters=param) bus_ref_kv = self.network_ref.get_voltage_levels().loc[self.network_ref.get_buses()["voltage_level_id"].values]["nominal_v"].values v_mag_pypo = self.network_ref.get_buses()["v_mag"].values / bus_ref_kv