예제 #1
0
    def __init__(
        self,
        grid2op_action_space,
        attr_to_keep=ALL_ATTR,
        nb_bins=None,
    ):

        if not isinstance(grid2op_action_space, ActionSpace):
            raise RuntimeError(
                f"Impossible to create a BoxGymActSpace without providing a "
                f"grid2op action_space. You provided {type(grid2op_action_space)}"
                f"as the \"grid2op_action_space\" attribute.")

        if nb_bins is None:
            nb_bins = {"redispatch": 7, "set_storage": 7, "curtail": 7}

        act_sp = grid2op_action_space
        self.action_space = copy.deepcopy(act_sp)

        if attr_to_keep == ALL_ATTR:
            # by default, i remove all the attributes that are not supported by the action type
            # i do not do that if the user specified specific attributes to keep. This is his responsibility in
            # in this case
            attr_to_keep = {
                el
                for el in attr_to_keep
                if grid2op_action_space.supports_type(el)
            }

        for el in attr_to_keep:
            if el not in ATTR_DISCRETE:
                warnings.warn(
                    f"The class \"DiscreteActSpace\" should mainly be used to consider only discrete "
                    f"actions (eg. set_line_status, set_bus or change_bus). Though it is possible to use "
                    f"\"{el}\" when building it, be aware that this continuous action will be treated "
                    f"as discrete by splitting it into bins. "
                    f"Consider using the \"BoxGymActSpace\" for these attributes."
                )

        self._attr_to_keep = sorted(attr_to_keep)
        self._nb_bins = nb_bins

        self.dict_properties = {
            "set_line_status": act_sp.get_all_unitary_line_set,
            "change_line_status": act_sp.get_all_unitary_line_change,
            "set_bus": act_sp.get_all_unitary_topologies_set,
            "change_bus": act_sp.get_all_unitary_topologies_change,
            "redispatch": act_sp.get_all_unitary_redispatch,
            "set_storage": act_sp.get_all_unitary_storage,
            "curtail": act_sp.get_all_unitary_curtail,
            "curtail_mw": act_sp.get_all_unitary_curtail
        }

        self.converter = None
        n_act = self._get_info()

        # initialize the base container
        Discrete.__init__(self, n=n_act)
예제 #2
0
 def __init__(self, action_mapper):
     self.action_mapper = action_mapper
     self.bprogram = None
     Discrete.__init__(self, len(action_mapper))