Converters¶
-
class
grid2op.Converter.
Converter
(action_space)[source]¶ This Base class should be use to implement any converter. If for some reasons
-
convert_act
(encoded_act)[source]¶ This function will transform the action, encoded somehow (for example identified by an id, represented by an integer) to a valid actions that can be processed by the environment.
- Parameters
encoded_act (
object
) – Representation of an action, as a vector or an integer etc.- Returns
regular_act – The action corresponding to the encoded_action above converted into a format that can be processed by the environment.
- Return type
-
convert_obs
(obs)[source]¶ This function is used to convert an observation into something that is easier to manipulate.
- Parameters
obs (
grid2op.Observation.Observation
) – The input observation.- Returns
transformed_obs – An different representation of the input observation, typically represented as a 1d vector that can be processed by a neural networks.
- Return type
object
-
-
class
grid2op.Converter.
IdToAct
(action_space)[source]¶ This type of converter allows to represent action with unique id. Instead of manipulating complex objects, it allows to manipulate only positive integer.
The list of all actions can either be the list of all possible unary actions (see below for a complete description) or by a given pre computed list.
A “unary action” is an action that consists only in acting on one “concept” it includes:
disconnecting a single powerline
reconnecting a single powerline and connect it to bus xxx on its origin end and yyy on its extremity end
changing the topology of a single substation
Examples of non unary actions include: - disconnection / reconnection of 2 or more powerlines - change of the configuration of 2 or more substations - disconnection / reconnection of a single powerline and change of the configration of a single substation
NB All the actions created automatically are unary. For the L2RPN 2019, agent could be allowed to act with non unary actions, for example by disconnecting a powerline and reconfiguring a substation. This class would not allow to do such action at one time step.
NB The actions that are initialized by default uses the “set” way and not the “change” way (see the description of
grid2op.BaseAction.BaseAction
for more information).For each powerline, 5 different actions will be computed:
disconnect it
reconnect it and connect it to bus 1 on “origin” end ann bus 1 on “extremity” end
reconnect it and connect it to bus 1 on “origin” end ann bus 2 on “extremity” end
reconnect it and connect it to bus 2 on “origin” end ann bus 1 on “extremity” end
reconnect it and connect it to bus 2 on “origin” end ann bus 2 on “extremity” end
Actions corresponding to all topologies are also used by default. See
grid2op.BaseAction.ActionSpace.get_all_unitary_topologies_set()
for more information.In this converter:
encoded_act are positive integer, representing the index of the actions.
transformed_obs are regular observations.
-
convert_act
(encoded_act)[source]¶ In this converter, we suppose that “encoded_act” is an id of an action stored in the
IdToAct.all_actions
list.Converting an id of an action (here called “act”) into a valid action is then easy: we just need to take the “act”-th element of
IdToAct.all_actions
.- Parameters
encoded_act (
int
) – The id of the action- Returns
action – The action corresponding to id “act”
- Return type
-
init_converter
(all_actions=None, **kwargs)[source]¶ This function is used to initialized the converter. When the converter is created, this method should be called otherwise the converter might be in an unstable state.
- Parameters
all_actions (
list
) – The (ordered) list of all actions that the agent will be able to perform. If given a numberi
the converter will return actionall_actions[i]
. In the “pacman” game, this vector could be [“up”, “down”, “left”, “right”], in this case “up” would be encode by 0, “down” by 1, “left” by 2 and “right” by 3. If nothing is provided, the converter will output all the unary actions possible for the environment. Be careful, computing all these actions might take some time.kwargs – other keyword arguments
-
class
grid2op.Converter.
ToVect
(action_space)[source]¶ This converters allows to manipulate the vector representation of the actions and observations.
In this converter:
encoded_act are numpy ndarray
transformed_obs are numpy ndarray
-
convert_act
(encoded_act)[source]¶ In this converter encoded_act is a numpy ndarray. This function transforms it back to a valid action.
- Parameters
encoded_act (
numpy.ndarray
) – The action, representated as a vector- Returns
regular_act – The corresponding action transformed with the
grid2op.BaseAction.BaseAction.from_vect()
.- Return type
-
convert_obs
(obs)[source]¶ This converter will match the observation to a vector, using the
grid2op.BaseObservation.BaseObservation.to_vect()
function.- Parameters
obs (
grid2op.Observation.Observation
) – The observation, that will be processed into a numpy ndarray vector.- Returns
transformed_obs – The vector representation of the action.
- Return type
numpy.ndarray
If you still can’t find what you’re looking for, try in one of the following pages: