Skip to content

Commit

Permalink
trying to fix CI yet again
Browse files Browse the repository at this point in the history
  • Loading branch information
BDonnot committed Mar 8, 2024
1 parent 6fa83dd commit 85852a1
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 22 deletions.
5 changes: 2 additions & 3 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand Down Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions lightsim2grid/gridmodel/_aux_add_slack.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
22 changes: 14 additions & 8 deletions lightsim2grid/lightSimBackend.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
30 changes: 21 additions & 9 deletions lightsim2grid/tests/test_init_from_pypowsybl.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 85852a1

Please sign in to comment.