@@ -813,7 +813,10 @@ def _aux_copy(self, other : Self) -> None:
813813 setattr (other , attr_nm , copy .deepcopy (getattr (self , attr_nm )))
814814
815815 for attr_nm in cls .attr_vect_cpy :
816- getattr (other , attr_nm )[:] = getattr (self , attr_nm )
816+ if hasattr (self , attr_nm ):
817+ # for old code (eg lightsim2grid legacy)
818+ # some attribute did not exist
819+ getattr (other , attr_nm )[:] = getattr (self , attr_nm )
817820
818821 def change_reward (self , reward_func : "grid2op.Reward.BaseReward" ):
819822 """Allow to change the reward used when calling :func:`BaseObservation.simulate`
@@ -1211,19 +1214,27 @@ def state_of(
12111214
12121215 @classmethod
12131216 def process_shunt_static_data (cls ) -> None :
1217+ shunts_attr = ["_shunt_p" , "_shunt_q" , "_shunt_v" , "_shunt_bus" ]
12141218 if not cls .shunts_data_available :
1219+ # shunts are not available
12151220 # this is really important, otherwise things from grid2op base types will be affected
12161221 cls .attr_list_vect = copy .deepcopy (cls .attr_list_vect )
12171222 cls .attr_list_set = copy .deepcopy (cls .attr_list_set )
12181223 # remove the shunts from the list to vector
1219- for el in [ "_shunt_p" , "_shunt_q" , "_shunt_v" , "_shunt_bus" ] :
1224+ for el in shunts_attr :
12201225 if el in cls .attr_list_vect :
12211226 try :
12221227 cls .attr_list_vect .remove (el )
12231228 except ValueError :
12241229 pass
12251230 cls .attr_list_set = set (cls .attr_list_vect )
1226- cls .attr_vect_cpy += ["_shunt_bus" , "_shunt_v" , "_shunt_q" , "_shunt_p" ]
1231+ else :
1232+ # shunts are available
1233+ cls .attr_vect_cpy = copy .deepcopy (cls .attr_vect_cpy )
1234+ for el in shunts_attr :
1235+ if el not in cls .attr_vect_cpy :
1236+ cls .attr_vect_cpy .append (el )
1237+
12271238 return super ().process_shunt_static_data ()
12281239
12291240 @classmethod
0 commit comments