def __init__(self, gridobj, subtype=object): """ subtype: ``type`` Type of action used to build :attr:`SerializableActionSpace._template_act`. This type should derive from :class:`grid2op.BaseAction.BaseAction` or :class:`grid2op.BaseObservation.BaseObservation` . """ if not isinstance(subtype, type): raise Grid2OpException( "Parameter \"subtype\" used to build the Space should be a type (a class) and not an object " "(an instance of a class). It is currently \"{}\"".format( type(subtype))) GridObjects.__init__(self) RandomObject.__init__(self) self.init_grid(gridobj) self.subtype = subtype self._template_obj = self.subtype(gridobj=self) self.n = self._template_obj.size() self.global_vars = None self.shape = self._template_obj.shape() self.dtype = self._template_obj.dtype()
def __init__(self, gridobj, subtype=object, _init_grid=True): """ subtype: ``type`` Type of action used to build :attr:`SerializableActionSpace._template_act`. This type should derive from :class:`grid2op.BaseAction.BaseAction` or :class:`grid2op.BaseObservation.BaseObservation` . _init_grid: ``bool`` Whether or not to call 'init_grid' in the subtype (to initialize the class). Do not modify unless you are certain of what you want to do """ if not isinstance(subtype, type): raise Grid2OpException( "Parameter \"subtype\" used to build the Space should be a type (a class) and not an object " "(an instance of a class). It is currently \"{}\"".format( type(subtype))) GridObjects.__init__(self) RandomObject.__init__(self) self._init_subtype = subtype # do not use, use to save restore only !!! if _init_grid: self.subtype = subtype.init_grid(gridobj) from grid2op.Action import BaseAction # lazy loading to prevent circular reference if issubclass(self.subtype, BaseAction): # add the shunt data if needed by the action only self.subtype._add_shunt_data() # compute the class attribute "attr_list_set" from "attr_list_vect" self.subtype._update_value_set() else: self.subtype = subtype from grid2op.Action import BaseAction # lazy import to avoid circular reference from grid2op.Observation import BaseObservation # lazy import to avoid circular reference if not issubclass(subtype, (BaseAction, BaseObservation)): raise RuntimeError( f"\"subtype\" should inherit either BaseAction or BaseObservation. Currently it " f"is \"{subtype}\"") self._template_obj = self.subtype() self.n = self._template_obj.size() self.global_vars = None self.shape = self._template_obj.shape() self.dtype = self._template_obj.dtype() self.attr_list_vect = copy.deepcopy(self._template_obj.attr_list_vect) self._to_extract_vect = { } # key: attr name, value: tuple: (beg_, end_, dtype) beg_ = 0 end_ = 0 for attr, size, dtype_ in zip(self.attr_list_vect, self.shape, self.dtype): end_ += size self._to_extract_vect[attr] = (beg_, end_, dtype_) beg_ += size
def __init__(self, gridobj, subtype=object, _init_grid=True): """ subtype: ``type`` Type of action used to build :attr:`SerializableActionSpace._template_act`. This type should derive from :class:`grid2op.BaseAction.BaseAction` or :class:`grid2op.BaseObservation.BaseObservation` . _init_grid: ``bool`` Whether or not to call 'init_grid' in the subtype (to initialize the class). Do not modify unless you are certain of what you want to do """ if not isinstance(subtype, type): raise Grid2OpException( "Parameter \"subtype\" used to build the Space should be a type (a class) and not an object " "(an instance of a class). It is currently \"{}\"".format( type(subtype))) GridObjects.__init__(self) RandomObject.__init__(self) self.init_grid(gridobj) self._init_subtype = subtype # do not use, use to save restore only !!! # print(f"gridobj : {gridobj}") if _init_grid: self.subtype = subtype.init_grid(gridobj) else: self.subtype = subtype # print(f"subtype : {self.subtype}") self._template_obj = self.subtype() self.n = self._template_obj.size() self.global_vars = None self.shape = self._template_obj.shape() self.dtype = self._template_obj.dtype() self.attr_list_vect = self._template_obj.attr_list_vect self._to_extract_vect = { } # key: attr name, value: tuple: (beg_, end_, dtype) beg_ = 0 end_ = 0 for attr, size, dtype_ in zip(self._template_obj.attr_list_vect, self.shape, self.dtype): end_ += size self._to_extract_vect[attr] = (beg_, end_, dtype_) beg_ += size
def __init__(self, gridobj, subtype=object): """ subtype: ``type`` Type of action used to build :attr:`SerializableActionSpace._template_act`. This type should derive from :class:`grid2op.BaseAction.BaseAction` or :class:`grid2op.BaseObservation.BaseObservation` . """ if not isinstance(subtype, type): raise Grid2OpException( "Parameter \"subtype\" used to build the Space should be a type (a class) and not an object " "(an instance of a class). It is currently \"{}\"".format( type(subtype))) GridObjects.__init__(self) RandomObject.__init__(self) self.init_grid(gridobj) self._init_subtype = subtype # do not use, use to save restore only !!! self.subtype = subtype.init_grid(gridobj) self._template_obj = self.subtype() self.n = self._template_obj.size() self.global_vars = None self.shape = self._template_obj.shape() self.dtype = self._template_obj.dtype() self.attr_list_vect = self._template_obj.attr_list_vect self._to_extract_vect = { } # key: attr name, value: tuple: (beg_, end_, dtype) beg_ = 0 end_ = 0 for attr, size, dtype_ in zip(self._template_obj.attr_list_vect, self.shape, self.dtype): end_ += size self._to_extract_vect[attr] = (beg_, end_, dtype_) beg_ += size