Skip to content

Commit

Permalink
still debug windows CI
Browse files Browse the repository at this point in the history
  • Loading branch information
BDonnot committed Jul 23, 2024
1 parent 303ee7f commit ec800de
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
4 changes: 3 additions & 1 deletion lightsim2grid/lightSimBackend.py
Original file line number Diff line number Diff line change
Expand Up @@ -1129,7 +1129,9 @@ def runpf(self, is_dc : bool=False) -> Tuple[bool, Union[Exception, None]]:
self._debug_Vdc = self._grid.dc_pf(copy.deepcopy(self.V), self.max_it, self.tol)
self._grid.reactivate_result_computation()
if self._debug_Vdc.shape[0] == 0:
raise BackendError(f"Divergence of DC powerflow (non connected grid) at the initialization of AC powerflow. Detailed error: {self._grid.get_dc_solver().get_error()}")
raise BackendError(f"Divergence of DC powerflow (non connected grid) at the "
f"initialization of AC powerflow. Detailed error: "
f"{self._grid.get_dc_solver().get_error()}")
V_init = 1. * self._debug_Vdc
else:
V_init = copy.deepcopy(self.V)
Expand Down
7 changes: 5 additions & 2 deletions lightsim2grid/tests/test_n1contingencyrewards.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,17 +122,20 @@ def _aux_test_reward(self, obs, reward):
obs._obs_env.backend._grid = grid_cpy
obs._obs_env.backend._reset_res_pointers()
obs._obs_env.backend._grid.tell_solver_need_reset()
Vinit = np.ones(grid_cpy.total_bus(), dtype=complex)
V = grid_cpy.dc_pf(Vinit, 1, 1e-5)
print(f"{V.shape[0] = }, {V[0]:.3f}, {V[1]:.3f}")
print(f"Obs env {obs._obs_env.backend._grid.get_solver_type()}")
print(f"Obs env {obs._obs_env.backend._grid.get_dc_solver_type()}")
sim_obs, sim_r, sim_d, sim_i = obs.simulate(self.env.action_space(), time_step=0)
print(f"without contingency: {sim_d = }, {sim_i['exception']}")
# print(f"without contingency: {sim_d = }, {sim_i['exception']}")
print(f"without contingency: {sim_d = }, {sim_i}")
# print("test:")
for l_id in self.my_ids:
sim_obs, sim_r, sim_d, sim_i = obs.simulate(self.env.action_space({"set_line_status": [(l_id, -1)]}),
time_step=0)
if not self.is_dc():
print(f"for {l_id}: {sim_d = }, {sim_i['exception']}, {(sim_obs.a_or / obs._thermal_limit).max()}")
# print(f"for {l_id}: {sim_d = }, {sim_i['exception']}, {(sim_obs.a_or / obs._thermal_limit).max()}")
if np.any(sim_obs.a_or > obs._thermal_limit * self.threshold_margin()) or sim_d:
unsafe_cont += 1
else:
Expand Down

0 comments on commit ec800de

Please sign in to comment.