diff --git a/lightsim2grid/lightSimBackend.py b/lightsim2grid/lightSimBackend.py index 04fb0c7..bbb7599 100644 --- a/lightsim2grid/lightSimBackend.py +++ b/lightsim2grid/lightSimBackend.py @@ -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) diff --git a/lightsim2grid/tests/test_n1contingencyrewards.py b/lightsim2grid/tests/test_n1contingencyrewards.py index 346c7f4..477e3fe 100644 --- a/lightsim2grid/tests/test_n1contingencyrewards.py +++ b/lightsim2grid/tests/test_n1contingencyrewards.py @@ -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: