From 2562878b714850c67bf078beddfce37e5ac46b5c Mon Sep 17 00:00:00 2001 From: DONNOT Benjamin Date: Fri, 20 Sep 2024 16:54:59 +0200 Subject: [PATCH] fix a bug due to shunt when all shunts are disconnected --- grid2op/Space/detailed_topo_description.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/grid2op/Space/detailed_topo_description.py b/grid2op/Space/detailed_topo_description.py index d91755bd..91a55ceb 100644 --- a/grid2op/Space/detailed_topo_description.py +++ b/grid2op/Space/detailed_topo_description.py @@ -571,9 +571,12 @@ def compute_switches_position(self, if topo_vect[topo_vect != -1].min() < 1: raise Grid2OpException("In grid2op buses are labelled starting from 1 and not 0 " "(check your `topo_vect` input)") - if shunt_bus is not None and shunt_bus[shunt_bus != -1].min() < 1: - raise Grid2OpException("In grid2op buses are labelled starting from 1 and not 0 " - "(check your `shunt_bus` input)") + if self._n_shunt > 0 and shunt_bus is not None: + conn_shunt = shunt_bus[shunt_bus != -1] + if conn_shunt.shape[0]: + if conn_shunt.min() < 1: + raise Grid2OpException("In grid2op buses are labelled starting from 1 and not 0 " + "(check your `shunt_bus` input)") if np.unique(topo_vect).shape[0] > self.busbar_section_to_subid.shape[0]: raise ImpossibleTopology("You ask for more independant buses than there are " "busbar section on this substation") @@ -617,7 +620,7 @@ def _aux_compute_switches_position_one_sub(self, conn_node_to_bus_id = np.zeros(nb_conn_node, dtype=dt_int) all_pos = ((self.conn_node_to_topovect_id != -1) & (self.conn_node_to_subid == sub_id)).nonzero()[0] - if shunt_bus is not None: + if self._n_shunt > 0 and shunt_bus is not None: # add the shunts all_pos = np.concatenate((all_pos, ((self.conn_node_to_shunt_id != -1) & (self.conn_node_to_subid == sub_id)).nonzero()[0]))