BaseAction¶
-
class
grid2op.Action.
Action
(*args, **kwargs)[source]¶ -
__init__
(*args, **kwargs)[source]¶ This is used to create an BaseAction instance. Preferably,
BaseAction
should be created withActionSpace
.It is NOT recommended to create an action with this method. Please use
ActionSpace.__call__()
orActionSpace.sample()
to create a valid action.- Parameters
gridobj (
grid2op.Space.GridObjects
) – Representation of the objects present in the powergrid
-
-
class
grid2op.Action.
ActionSpace
(gridobj, legal_action, actionClass=<class 'grid2op.Action.BaseAction.BaseAction'>)[source]¶ ActionSpace
should be created by angrid2op.Environment.Environment
with its parameters coming from a properly set upgrid2op.Backend.Backend
(ie a Backend instance with a loaded powergrid. Seegrid2op.Backend.Backend.load_grid()
for more information).It will allow, thanks to its
ActionSpace.__call__()
method to create validBaseAction
. It is the the preferred way to create an object of classBaseAction
in this package.On the contrary to the
BaseAction
, it is NOT recommended to overload this helper. If more flexibility is needed on the type ofBaseAction
created, it is recommended to pass a different “actionClass” argument when it’s built. Note that it’s mandatory that the class used in the “actionClass” argument derived from theBaseAction
.-
game_rules
¶ Class specifying the rules of the game used to check the legality of the actions.
- Type
grid2op.RulesChecker.RulesChecker
-
__call__
(dict_=None, check_legal=False, env=None)[source]¶ This utility allows you to build a valid action, with the proper sizes if you provide it with a valid dictionnary.
More information about this dictionnary can be found in the
Action.update()
help. This dictionnary is not changed in this method.NB This is the only recommended way to make a valid, with proper dimension
Action
object:Examples
Here is a short example on how to make a action. For more detailed examples see
Action.update()
import grid2op # create a simple environment env = grid2op.make() act = env.action_space({}) # act is now the "do nothing" action, that doesn't modify the grid.
- Parameters
dict (
dict
) – seeAction.__call__()
documentation for an extensive help about this parametercheck_legal (
bool
) – is there a test performed on the legality of the action. NB When an object of classAction
is used, it is automatically tested for ambiguity. If this parameter is set toTrue
then a legality test is performed. An action can be illegal if the environment doesn’t allow it, for example if an agent tries to reconnect a powerline during a maintenance.env (
grid2op.Environment
, optional) – An environment used to perform a legality check.
- Returns
res – An action that is valid and corresponds to what the agent want to do with the formalism defined in see
Action.udpate()
.- Return type
-
__init__
(gridobj, legal_action, actionClass=<class 'grid2op.Action.BaseAction.BaseAction'>)[source]¶ All parameters (name_gen, name_load, name_line, sub_info, etc.) are used to fill the attributes having the same name. See
ActionSpace
for more information.- Parameters
gridobj (
grid2op.Space.GridObjects
) – The representation of the powergrid.actionClass (
type
) – Note that this parameter expected a class and not an object of the class. It is used to return the appropriate action type.legal_action (
grid2op.RulesChecker.BaseRules
) – Class specifying the rules of the game used to check the legality of the actions.
-
-
class
grid2op.Action.
BaseAction
(gridobj)[source]¶ This is a base class for each
BaseAction
objects. As stated above, an action represents conveniently the modifications that will affect a powergrid.It is not recommended to instantiate an action from scratch. The recommended way to get an action is either by modifying an existing one using the method
BaseAction.update()
or to call andActionSpace
object that has been properly set up by angrid2op.Environment
.BaseAction can be fully converted to and back from a numpy array with a fixed size.
An action can modify the grid in multiple ways. It can change :
the production and voltage setpoint of the generator units
the amount of power consumed (for both active and reactive part) for load
disconnect powerlines
change the topology of the _grid.
To be valid, an action should be convertible to a tuple of 5 elements:
- the first element is the “injections” vector: representing the way generator units and loads are modified
It is, in turn, a dictionary with the following keys (optional)
“load_p” a vector of the same size of the load, giving the modification of the loads active consumption
“load_q” a vector of the same size of the load, giving the modification of the loads reactive consumption
“prod_p” a vector of the same size of the generators, giving the modification of the productions active setpoint production
“prod_v” a vector of the same size of the generators, giving the modification of the productions voltage setpoint
the second element is made of force line status. It is made of a vector of size
BaseAction._n_lines
(the number of lines in the powergrid) and is interpreted as:-1 force line disconnection
+1 force line reconnection
0 do nothing to this line
the third element is the switch line status vector. It is made of a vector of size
BaseAction._n_lines
and is interpreted as:True
: change the line statusFalse
: don’t do anything
the fourth element set the buses to which the object is connected. It’s a vector of integers with the following interpretation:
0 -> don’t change
1 -> connect to bus 1
2 -> connect to bus 2
-1 -> disconnect the object.
- the fifth element changes the buses to which the object is connected. It’s a boolean vector interpreted as:
False
: nothing is doneTrue
: change the bus eg connect it to bus 1 if it was connected to bus 2 or connect it to bus 2 if it was connected to bus 1. NB this is only active if the system has only 2 buses per substation (that’s the case for the L2RPN challenge).
the sixth element is a vector, representing the redispatching. Component of this vector is added to the generators active setpoint value (if set) of the first elements.
NB the difference between
BaseAction._set_topo_vect
andBaseAction._change_bus_vect
is the following:If a component of
BaseAction._set_topo_vect
is 1, then the object (load, generator or powerline) will be moved to bus 1 of the substation to which it is connected. If it is already to bus 1 nothing will be done. If it’s on another bus it will connect it to bus 1. It’s disconnected, it will reconnect it and connect it to bus 1.If a component of
BaseAction._change_bus_vect
is True, then the object will be moved from one bus to another. If the object were on bus 1 it will be moved on bus 2, and if it were on bus 2, it will be moved on bus 1. If the object were disconnected, then this does nothing.
The conversion to the action into an understandable format by the backend is performed by the “update” method, that takes into account a dictionary and is responsible to convert it into this format. It is possible to overload this class as long as the overloaded
BaseAction.__call__()
operator returns the specified format, and theBaseAction.__init__()
method has the same signature.This format is then digested by the backend and the powergrid is modified accordingly.
-
_set_line_status
¶ For each powerline, it gives the effect of the action on the status of it. It should be understood as:
-1: disconnect the powerline
0: don’t affect the powerline
+1: reconnect the powerline
- Type
numpy.ndarray
, dtype:int
-
_switch_line_status
¶ For each powerline, it informs whether the action will switch the status of a powerline of not. It should be understood as followed:
False
: the action doesn’t affect the powerlineTrue
: the action affects the powerline. If it was connected, it will disconnect it. If it was disconnected, it will reconnect it.
- Type
numpy.ndarray
, dtype:bool
-
_dict_inj
¶ Represents the modification of the injection (productions and loads) of the power _grid. This dictionary can have the optional keys:
“load_p” to set the active load values (this is a numpy array with the same size as the number of load in the power _grid with Nan: don’t change anything, else set the value
“load_q”: same as above but for the load reactive values
“prod_p”: same as above but for the generator active setpoint values. It has the size corresponding to the number of generators in the test case.
“prod_v”: same as above but set the voltage setpoint of generator units.
- Type
dict
-
_set_topo_vect
¶ Similar to
BaseAction._set_line_status
but instead of affecting the status of powerlines, it affects the bus connectivity at a substation. It has the same size as the full topological vector (BaseAction._dim_topo
) and for each element it should be understood as:0: nothing is changed for this element
+1: this element is affected to bus 1
-1: this element is affected to bus 2
- Type
numpy.ndarray
, dtype:int
-
_change_bus_vect
¶ Similar to
BaseAction._switch_line_status
but it affects the topology at substations instead of the status of the powerline. It has the same size as the full topological vector (BaseAction._dim_topo
) and each component should mean:False
: the object is not affectedTrue
: the object will be moved to another bus. If it was on bus 1 it will be moved on bus 2, and if it was on bus 2 it will be moved on bus 1.
- Type
numpy.ndarray
, dtype:bool
The set indicating which keys the actions can understand when calling
BaseAction.update()
- Type
set
-
_subs_impacted
¶ This attributes is either not initialized (set to
None
) or it tells, for each substation, if it is impacted by the action (in this caseBaseAction._subs_impacted
[sub_id] isTrue
) or not (in this caseBaseAction._subs_impacted
[sub_id] isFalse
)- Type
numpy.ndarray
, dtype:bool
-
_lines_impacted
¶ This attributes is either not initialized (set to
None
) or it tells, for each powerline, if it is impacted by the action (in this caseBaseAction._lines_impacted
[line_id] isTrue
) or not (in this caseBaseAction._subs_impacted
[line_id] isFalse
)- Type
numpy.ndarray
, dtype:bool
-
vars_action
¶ The authorized key that are processed by
BaseAction.__call__()
to modify the injections- Type
list
, static
-
vars_action_set
¶ The authorized key that is processed by
BaseAction.__call__()
to modify the injections- Type
set
, static
-
_redispatch
¶ Amount of redispatching that this action will perform. Redispatching will increase the generator’s active setpoint value. This will be added to the value of the generators. The Environment will make sure that every physical constraint is met. This means that the agent provides a setpoint, but there is no guarantee that the setpoint will be achievable. Redispatching action is cumulative, this means that if at a given timestep you ask +10 MW on a generator, and on another you ask +10 MW then the total setpoint for this generator that the environment will try to implement is +20MW.
- Type
numpy.ndarray
, dtype:float
-
__call__
()[source]¶ This method is used to return the effect of the current action in a format understandable by the backend. This format is detailed below.
This function must also integrate the redispatching strategy for the BaseAction.
It also performs a check of whether or not an action is “Ambiguous”, eg an action that reconnect a powerline but doesn’t specify on which bus to reconnect it is said to be ambiguous.
If this
BaseAction.__call__()
is overloaded, the call ofBaseAction._check_for_ambiguity()
must be ensured by this the derived class.- Returns
dict_injection (
dict
) – This dictionnary isBaseAction._dict_inj
set_line_status (
numpy.array
, dtype:int) – This array isBaseAction._set_line_status
switch_line_status (
numpy.array
, dtype:bool) – This array isBaseAction._switch_line_status
set_topo_vect (
numpy.array
, dtype:int) – This array isBaseAction._set_topo_vect
change_bus_vect (
numpy.array
, dtype:bool) – This array isBaseAction._change_bus_vect
redispatch (
numpy.ndarray
, dtype:float) – This array, that has the same size as the number of generators indicates for each generator the amount of redispatching performed by the action.shunts (
dict
) – A dictionnary containing the shunts data, with keys: “shunt_p”, “shunt_q” and “shunt_bus” and the convention, for “shun_p” and “shunt_q” that Nan means “don’t change” and for shunt_bus: -1 => disconnect 0 don’t change, and 1 / 2 connect to bus 1 / 2
- Raises
grid2op.Exceptions.AmbiguousAction – Or one of its derivate class.
-
__eq__
(other) → bool[source]¶ Test the equality of two actions.
2 actions are said to be identical if they have the same impact on the powergrid. This is unrelated to their respective class. For example, if an Action is of class
Action
and doesn’t act on the injection, it can be equal to an Action of the derived classTopologyAction
(if the topological modifications are the same of course).This implies that the attributes
Action.authorized_keys
is not checked in this method.Note that if 2 actions don’t act on the same powergrid, or on the same backend (eg number of loads, or generators are not the same in self and other, or they are not in the same order) then action will be declared as different.
Known issue if two backends are different, but the description of the _grid are identical (ie all n_gen, n_load, n_line, sub_info, dim_topo, all vectors *_to_subid, and *_pos_topo_vect are identical) then this method will not detect the backend are different, and the action could be declared as identical. For now, this is only a theoretical behavior: if everything is the same, then probably, up to the naming convention, then the power grids are identical too.
- Parameters
other (
BaseAction
) – An instance of class Action to which “self” will be compared.- Returns
res – Whether the actions are equal or not.
- Return type
bool
-
__iadd__
(other)[source]¶ Add an action to this one. Adding an action to myself is equivalent to perform myself, and then perform other.
Add will have the following properties:
it erase the previous changes to injections
- Parameters
other (
BaseAction
) –
-
__init__
(gridobj)[source]¶ This is used to create an BaseAction instance. Preferably,
BaseAction
should be created withActionSpace
.It is NOT recommended to create an action with this method. Please use
ActionSpace.__call__()
orActionSpace.sample()
to create a valid action.- Parameters
gridobj (
grid2op.Space.GridObjects
) – Representation of the objects present in the powergrid
-
__str__
()[source]¶ This utility allows printing in a human-readable format what objects will be impacted by the action.
- Returns
str – The string representation of an
BaseAction
in a human-readable format.- Return type
str
-
_assign_attr_from_name
(attr_nm, vect)[source]¶ Assign the proper attributes with name ‘attr_nm’ with the value of the vector vect
If this function is overloaded, then the _get_array_from_attr_name must be too.
- Parameters
attr_nm –
vect –
- Returns
- Return type
None
-
_check_for_ambiguity
()[source]¶ This method checks if an action is ambiguous or not. If the instance is ambiguous, an
grid2op.Exceptions.AmbiguousAction
is raised.An action can be ambiguous in the following context:
It incorrectly affects the injections:
self._dict_inj["load_p"]
doesn’t have the same size as the number of loads on the _grid.self._dict_inj["load_q"]
doesn’t have the same size as the number of loads on the _grid.self._dict_inj["prod_p"]
doesn’t have the same size as the number of loads on the _grid.self._dict_inj["prod_v"]
doesn’t have the same size as the number of loads on the _grid.
It affects the powerline in an incorrect manner:
self._switch_line_status
has not the same size as the number of powerlinesself._set_line_status
has not the same size as the number of powerlinessomes lines are reconnected (
self._switch_line_status[i] == True
for some powerline i but it is not specified on which bus to connect it ( the element corresponding to powerline i inself._set_topo_vect
is set to 0)the status of some powerline is both changed (
self._switch_line_status[i] == True
for some i) and set (self._set_line_status[i]
for the same i is not 0)
It has an ambiguous behavior concerning the topology of some substations
the state of some bus for some element is both changed (
self._change_bus_vect[i] = True
for some i) and set (self._set_topo_vect[i]
for the same i is not 0)self._set_topo_vect
has not the same dimension as the number of elements on the powergridself._change_bus_vect
has not the same dimension as the number of elements on the powergrid
For redispatching, Ambiguous actions can come from:
Some redispatching action is active, yet
grid2op.Space.GridObjects.redispatching_unit_commitment_availble
is set toFalse
the length of the redispatching vector
BaseAction._redispatching
is not compatible with the number of generators.some redispatching are above the maximum ramp up
grid2op.Space.GridObjects.gen_max_ramp_up
some redispatching are below the maximum ramp down
grid2op.Space.GridObjects.gen_max_ramp_down
the redispatching action affect non dispatchable generators
the redispatching and the production setpoint, if added, are above pmax for at least a generator
the redispatching and the production setpoint, if added, are below pmin for at least a generator
In case of need to overload this method, it is advise to still call this one from the base
BaseAction
with “super()._check_for_ambiguity()
” or “BaseAction._check_for_ambiguity(self)
”.- Raises
grid2op.Exceptions.AmbiguousAction – Or any of its more precise subclasses, depending on which assumption is not met.
-
_get_array_from_attr_name
(attr_name)[source]¶ This function returns the proper attribute vector that can be inspected in the
GridObject.shape()
,GridObject.size()
,GridObject.dtype()
,GridObject.from_vect()
andGridObject.to_vect()
method.If this function is overloaded, then the _assign_attr_from_name must be too.
- Parameters
attr_name (
str
) – Name of the attribute to inspect or set- Returns
res – The attribute corresponding the name, flatten as a 1d vector.
- Return type
numpy.ndarray
-
as_dict
()[source]¶ Represent an action “as a” dictionary. This dictionary is useful to further inspect on which elements the actions had an impact. It is not recommended to use it as a way to serialize actions. The “do nothing” action should always be represented by an empty dictionary.
The following keys (all optional) are present in the results:
load_p: if the action modifies the active loads.
load_q: if the action modifies the reactive loads.
prod_p: if the action modifies the active productions of generators.
prod_v: if the action modifies the voltage setpoint of generators.
set_line_status if the action tries to set the status of some powerlines. If present, this is a a dictionary with keys:
nb_connected: number of powerlines that are reconnected
nb_disconnected: number of powerlines that are disconnected
connected_id: the id of the powerlines reconnected
disconnected_id: the ids of the powerlines disconnected
change_line_status: if the action tries to change the status of some powerlines. If present, this is a dictionary with keys:
nb_changed: number of powerlines having their status changed
changed_id: the ids of the powerlines that are changed
change_bus_vect: if the action tries to change the topology of some substations. If present, this is a dictionary with keys:
nb_modif_subs: number of substations impacted by the action
modif_subs_id: ids of the substations impacted by the action
change_bus_vect: details the objects that are modified. It is itself a dictionary that represents for each impacted substations (keys) the modification of the objects connected to it.
set_bus_vect: if the action tries to set the topology of some substations. If present, this is a dictionary with keys:
nb_modif_subs: number of substations impacted by the action
modif_subs_id: the ids of the substations impacted by the action
set_bus_vect: details the objects that are modified. It is also a dictionary that represents for each impacted substations (keys) how the elements connected to it are impacted (their “new” bus)
hazards if the action is composed of some hazards. In this case, it’s simply the index of the powerlines that are disconnected because of them.
nb_hazards the number of hazards the “action” implemented (eg number of powerlines disconnected because of hazards.
maintenance if the action is composed of some maintenance. In this case, it’s simply the index of the powerlines that are affected by maintenance operation at this time step. that are disconnected because of them.
nb_maintenance the number of maintenance the “action” implemented eg the number of powerlines disconnected because of maintenance operations.
redispatch the redispatching action (if any). It gives, for each generator (all generator, not just the dispatchable one) the amount of power redispatched in this action.
- Returns
res – The action represented as a dictionary. See above for a description of it.
- Return type
dict
-
check_space_legit
()[source]¶ This method allows to check if this method is ambiguous per se (defined more formally as: whatever the observation at time t, and the changes that can occur between t and t+1, this action will be ambiguous).
For example, an action that try to assign something to busbar 3 will be ambiguous per se. An action that tries to dispatch a non dispatchable generator will be also ambiguous per se.
However, an action that “switch” (change) the status (connected / disconnected) of a powerline can be ambiguous and it will not be detected here. This is because the ambiguity depends on the current state of the powerline:
if the powerline is disconnected, changing its status means reconnecting it. And we cannot reconnect a powerline without specifying on which bus.
on the contrary if the powerline is connected, changing its status means disconnecting it, which is always feasible.
In case of “switch” as we see here, the action can be ambiguous, but not ambiguous per se. This method will never throw any error in this case.
-
effect_on
(_sentinel=None, load_id=None, gen_id=None, line_id=None, substation_id=None)[source]¶ Return the effect of this action on a unique given load, generator unit, powerline or substation. Only one of load, gen, line or substation should be filled.
The query of these objects can only be done by id here (ie by giving the integer of the object in the backed). The
ActionSpace
has some utilities to access them by name too.- Parameters
_sentinel (
None
) – Used to prevent positional parameters. Internal, do not use.load_id (
int
) – The ID of the load we want to inspectgen_id (
int
) – The ID of the generator we want to inspectline_id (
int
) – The ID of the powerline we want to inspectsubstation_id (
int
) – The ID of the substation we want to inspect
- Returns
res (
dict
) – A dictionary with keys and value depending on which object needs to be inspected:if a load is inspected, then the keys are:
”new_p” the new load active value (or NaN if it doesn’t change),
”new_q” the new load reactive value (or Nan if nothing has changed from this point of view)
”set_bus” the new bus where the load will be moved (int: id of the bus, 0 no change, -1 disconnected)
”change_bus” whether or not this load will be moved from one bus to another (for example is an action asked it to go from bus 1 to bus 2)
if a generator is inspected, then the keys are:
”new_p” the new generator active setpoint value (or NaN if it doesn’t change),
”new_v” the new generator voltage setpoint value (or Nan if nothing has changed from this point of view)
”set_bus” the new bus where the load will be moved (int: id of the bus, 0 no change, -1 disconnected)
”change_bus” whether or not this load will be moved from one bus to another (for example is an action asked it to go from bus 1 to bus 2)
”redispatch” the amount of power redispatched for this generator.
if a powerline is inspected then the keys are:
”change_bus_or”: whether or not the origin end will be moved from one bus to another
”change_bus_ex”: whether or not the extremity end will be moved from one bus to another
”set_bus_or”: the new bus where the origin will be moved
”set_bus_ex”: the new bus where the extremity will be moved
”set_line_status”: the new status of the power line
”change_line_status”: whether or not to switch the status of the powerline
if a substation is inspected, it returns the topology to this substation in a dictionary with keys:
”change_bus”
”set_bus”
NB the difference between “set_bus” and “change_bus” is the following –
If “set_bus” is 1, then the object (load, generator or powerline) will be moved to bus 1 of the substation to which it is connected. If it is already to bus 1 nothing will be done. If it’s on another bus it will connect it to bus 1. It’s disconnected, it will reconnect it and connect it to bus 1.
If “change_bus” is True, then the object will be moved from one bus to another. If the object were on bus 1 then it will be moved on bus 2, and if it were on bus 2, it will be moved on bus 1. If the object were disconnected, then it will be connected to the affected bus.
- Raises
grid2op.Exception.Grid2OpException – If _sentinel is modified, or if none of the arguments are set or alternatively if 2 or more of the parameters are being set.
-
get_change_line_status_vect
()[source]¶ Computes and returns a vector that can be used in the
BaseAction.__call__()
with the keyword “set_status” if building anBaseAction
.NB this vector is not the internal vector of this action but corresponds to “do nothing” action.
- Returns
res – A vector that doesn’t affect the grid, but can be used in
BaseAction.__call__()
with the keyword “set_status” if building anBaseAction
.- Return type
numpy.array
, dtype:np.bool
-
get_set_line_status_vect
()[source]¶ Computes and returns a vector that can be used in the
BaseAction.__call__()
with the keyword “set_status” if building anBaseAction
.NB this vector is not the internal vector of this action but corresponds to “do nothing” action.
- Returns
res – A vector that doesn’t affect the grid, but can be used in
BaseAction.__call__()
with the keyword “set_status” if building anBaseAction
.- Return type
numpy.array
, dtype:np.int
-
get_topological_impact
(powerline_status=None)[source]¶ Gives information about the element being impacted by this action.
NB The impacted elements can be used by
grid2op.BaseRules
to determine whether or not an action is legal or not.NB The impacted are the elements that can potentially be impacted by the action. This does not mean they will be impacted. For examples:
If an action from an
grid2op.BaseAgent
reconnect a powerline, but this powerline is being disconnected by a hazard at the same time step, then this action will not be implemented on the grid. However, it this powerline couldn’t be reconnected for some reason (for example it was already out of order) the action will still be declared illegal, even if it has NOT impacted the powergrid.If an action tries to disconnect a powerline already disconnected, it will “impact” this powergrid. This means that even if the action will do nothing, it disconnecting this powerline is against the rules, then the action will be illegal.
If an action tries to change the topology of a substation, but this substation is already at the target topology, the same mechanism applies. The action will “impact” the substation, even if, in the end, it consists of doing nothing.
Any such “change” that would be illegal is declared as “illegal” regardless of the real impact of this action on the powergrid.
- Returns
lines_impacted (
numpy.array
, dtype:np.bool) – A vector with the same size as the number of powerlines in the grid (BaseAction.n_line
) with for each componentTrue
if the line STATUS is impacted by the action, andFalse
otherwise. SeeBaseAction._lines_impacted
for more information.subs_impacted (
numpy.array
, dtype:np.bool) – A vector with the same size as the number of substations in the grid with for each componentTrue
if the substation is impacted by the action, andFalse
otherwise. SeeBaseAction._subs_impacted
for more information.
-
impact_on_objects
()[source]¶ This will return a dictionary which contains details on objects that will be impacted by the action.
- Returns
dict – The dictionary representation of an action impact on objects
- Return type
dict
-
is_ambiguous
()[source]¶ Says if the action, as defined is ambiguous per se or not.
See definition of
BaseAction.check_space_legit()
for more details about ambiguity per se.- Returns
res (
True
if the action is ambiguous,False
otherwise.)info (
dict
or not) – More information about the error. If the action is not ambiguous, it values toNone
-
sample
(space_prng)[source]¶ This method is used to sample action.
A generic sampling of action can be really tedious. Uniform sampling is almost impossible. The actual implementation gives absolutely no warranty toward any of these concerns.
It is not implemented yet. TODO
By calling
Action.sample()
, the action isAction.reset()
to a “do nothing” state.- Parameters
space_prng –
- Returns
self – The action sampled among the action space.
- Return type
-
update
(dict_)[source]¶ Update the action with a comprehensible format specified by a dictionary.
Preferably, if a key of the argument dict_ is not found in
Action.authorized_keys
it should throw a warning. This argument will be completely ignored.This method also reset the attributes
Action._vectorized
Action._lines_impacted
andAction._subs_impacted
toNone
regardless of the argument in input.If an action consists of “reconnecting” a powerline, and this same powerline is affected by maintenance or a hazard, it will be erased without any warning. “hazards” and “maintenance” have the priority. This is a requirement for all proper
Action
subclass.- Parameters
dict (
dict
) –If it’s
None
or empty it does nothing. Otherwise, it can contain the following (optional) keys:”injection” if the action will modify the injections (generator setpoint/load value - active or reactive) of the powergrid. It has optionally one of the following keys:
”load_p”: to set the active load values (this is a numpy array with the same size as the number of load in the power _grid with Nan: don’t change anything, else set the value
”load_q”: same as above but for the load reactive values
”prod_p”: same as above but for the generator active setpoint values. It has the size corresponding to the number of generators in the test case.
”prod_v”: same as above but set the voltage setpoint of generator units.
”hazards”: represents the hazards that the line might suffer (boolean vector) False: no hazard, nothing is done, True: a hazard, the powerline is disconnected
”maintenance”: represents the maintenance operation performed on each powerline (boolean vector) False: no maintenance, nothing is done, True: a maintenance is scheduled, the powerline is disconnected
”set_line_status”: a vector (int or float) to set the status of the powerline status (connected / disconnected) with the following interpretation:
0: nothing is changed,
-1: disconnect the powerline,
+1: reconnect the powerline. If an action consists in “reconnecting” a powerline, and this same powerline is affected by a maintenance or a hazard, it will be erased without any warning. “hazards” and “maintenance” have the priority.
”change_line_status”: a vector (bool) to change the status of the powerline. This vector should be interpreted as:
False
: do nothingTrue
: change the status of the powerline: disconnect it if it was connected, connect it if it was disconnected
”set_bus”: (numpy int vector or dictionary) will set the buses to which the objects are connected. It follows a similar interpretation than the line status vector:
0 -> don’t change anything
+1 -> set to bus 1,
+2 -> set to bus 2, etc.
-1: You can use this method to disconnect an object by setting the value to -1.
”change_bus”: (numpy bool vector or dictionary) will change the bus to which the object is connected. True will change it (eg switch it from bus 1 to bus 2 or from bus 2 to bus 1). NB this is only active if the system has only 2 buses per substation.
”redispatch” TODO
NB the difference between “set_bus” and “change_bus” is the following:
If “set_bus” is 1, then the object (load, generator or powerline) will be moved to bus 1 of the substation to which it is connected. If it is already to bus 1 nothing will be done. If it’s on another bus it will connect it to bus 1. It’s disconnected, it will reconnect it and connect it to bus 1.
If “change_bus” is True, then objects will be moved from one bus to another. If the object were on bus 1 then it will be moved on bus 2, and if it were on bus 2, it will be moved on bus 1. If the object is disconnected then the action is ambiguous, and calling it will throw an AmbiguousAction exception.
NB: if a powerline is reconnected, it should be specified on the “set_bus” action at which buses it should be reconnected. Otherwise, action cannot be used. Trying to apply the action to the grid will lead to an “AmbiguousAction” exception.
NB: if for a given powerline, both switch_line_status and set_line_status is set, the action will not be usable. This will lead to an
grid2op.Exception.AmbiguousAction
exception.NB: The length of vectors provided here is NOT check in this function. This method can be “chained” and only on the final action, when used, eg. in the Backend, is checked.
NB: If a powerline is disconnected, on maintenance, or suffer an outage, the associated “set_bus” will be ignored. Disconnection has the priority on anything. This priority is given because, in case of hazard, the hazard has the priority over the possible actions.
Examples
Here are short examples on how to update an action eg. how to create a valid
Action
object that be used to modify agrid2op.Backend.Backend
.In all the following examples, we suppose that a valid grid2op environment is created, for example with: .. code-block:: python
import grid2op # create a simple environment # and make sure every type of action can be used. env = grid2op.make(action_class=grid2op.Action.Action)
Example 1: modify the load active values to set them all to 1. You can replace “load_p” by “load_q”, “prod_p” or “prod_v” to change the load reactive value, the generator active setpoint or the generator voltage magnitude setpoint.
new_load = np.ones(env.action_space.n_load) modify_load_active_value = env.action_space({"injection": {"load_p": new_load}}) print(modify_load_active_value)
Example 2: disconnect the powerline of id 1:
disconnect_powerline = env.action_space({"set_line_status": [(1, -1)]}) print(disconnect_powerline) # there is a shortcut to do that: disconnect_powerline2 = env.disconnect_powerline(line_id=1)
Example 3: force the reconnection of the powerline of id 5 by connected it to bus 1 on its origin end and bus 2 on its extremity end. Note that this is mandatory to specify on which bus to reconnect each extremity of the powerline. Otherwise it’s an ambiguous action.
reconnect_powerline = env.action_space({"set_line_status": [(5, 1)], "set_bus": {"lines_or_id": [(5, 1)]}, "set_bus": {"lines_ex_id": [(5, 2)]} }) print(reconnect_powerline) # and the shorter method: reconnect_powerline = env.action.space.reconnect_powerline(line_id=5, bus_or=1, bus_ex=2)
Example 4: change the bus to which load 4 is connected:
change_load_bus = env.action_space({"set_bus": {"loads_id": [(4, 1)]} }) print(change_load_bus)
Example 5: reconfigure completely substation 5, and connect the first 3 elements to bus 1 and the last 3 elements to bus 2
sub_id = 5 target_topology = np.ones(env.sub_info[sub_id], dtype=np.int) target_topology[3:] = 2 reconfig_sub = env.action_space({"set_bus": {"substations_id": [(sub_id, target_topology)] } }) print(reconfig_sub)
- Returns
self – Return the modified instance. This is handy to chain modifications if needed.
- Return type
-
grid2op.Action.
CompleteAction
¶ alias of
grid2op.Action.BaseAction.BaseAction
-
class
grid2op.Action.
DontAct
(gridobj)[source]¶ This class is model the action where you force someone to do absolutely nothing.
-
__init__
(gridobj)[source]¶ See the definition of
BaseAction.__init__()
and ofBaseAction
for more information. Nothing more is done in this constructor.
-
sample
(space_prng)[source]¶ This method is used to sample action.
A generic sampling of action can be really tedious. Uniform sampling is almost impossible. The actual implementation gives absolutely no warranty toward any of these concerns.
It is not implemented yet. TODO
By calling
Action.sample()
, the action isAction.reset()
to a “do nothing” state.- Parameters
space_prng –
- Returns
self – The action sampled among the action space.
- Return type
-
update
(dict_)[source]¶ Update the action with a comprehensible format specified by a dictionary.
Preferably, if a key of the argument dict_ is not found in
Action.authorized_keys
it should throw a warning. This argument will be completely ignored.This method also reset the attributes
Action._vectorized
Action._lines_impacted
andAction._subs_impacted
toNone
regardless of the argument in input.If an action consists of “reconnecting” a powerline, and this same powerline is affected by maintenance or a hazard, it will be erased without any warning. “hazards” and “maintenance” have the priority. This is a requirement for all proper
Action
subclass.- Parameters
dict (
dict
) –If it’s
None
or empty it does nothing. Otherwise, it can contain the following (optional) keys:”injection” if the action will modify the injections (generator setpoint/load value - active or reactive) of the powergrid. It has optionally one of the following keys:
”load_p”: to set the active load values (this is a numpy array with the same size as the number of load in the power _grid with Nan: don’t change anything, else set the value
”load_q”: same as above but for the load reactive values
”prod_p”: same as above but for the generator active setpoint values. It has the size corresponding to the number of generators in the test case.
”prod_v”: same as above but set the voltage setpoint of generator units.
”hazards”: represents the hazards that the line might suffer (boolean vector) False: no hazard, nothing is done, True: a hazard, the powerline is disconnected
”maintenance”: represents the maintenance operation performed on each powerline (boolean vector) False: no maintenance, nothing is done, True: a maintenance is scheduled, the powerline is disconnected
”set_line_status”: a vector (int or float) to set the status of the powerline status (connected / disconnected) with the following interpretation:
0: nothing is changed,
-1: disconnect the powerline,
+1: reconnect the powerline. If an action consists in “reconnecting” a powerline, and this same powerline is affected by a maintenance or a hazard, it will be erased without any warning. “hazards” and “maintenance” have the priority.
”change_line_status”: a vector (bool) to change the status of the powerline. This vector should be interpreted as:
False
: do nothingTrue
: change the status of the powerline: disconnect it if it was connected, connect it if it was disconnected
”set_bus”: (numpy int vector or dictionary) will set the buses to which the objects are connected. It follows a similar interpretation than the line status vector:
0 -> don’t change anything
+1 -> set to bus 1,
+2 -> set to bus 2, etc.
-1: You can use this method to disconnect an object by setting the value to -1.
”change_bus”: (numpy bool vector or dictionary) will change the bus to which the object is connected. True will change it (eg switch it from bus 1 to bus 2 or from bus 2 to bus 1). NB this is only active if the system has only 2 buses per substation.
”redispatch” TODO
NB the difference between “set_bus” and “change_bus” is the following:
If “set_bus” is 1, then the object (load, generator or powerline) will be moved to bus 1 of the substation to which it is connected. If it is already to bus 1 nothing will be done. If it’s on another bus it will connect it to bus 1. It’s disconnected, it will reconnect it and connect it to bus 1.
If “change_bus” is True, then objects will be moved from one bus to another. If the object were on bus 1 then it will be moved on bus 2, and if it were on bus 2, it will be moved on bus 1. If the object is disconnected then the action is ambiguous, and calling it will throw an AmbiguousAction exception.
NB: if a powerline is reconnected, it should be specified on the “set_bus” action at which buses it should be reconnected. Otherwise, action cannot be used. Trying to apply the action to the grid will lead to an “AmbiguousAction” exception.
NB: if for a given powerline, both switch_line_status and set_line_status is set, the action will not be usable. This will lead to an
grid2op.Exception.AmbiguousAction
exception.NB: The length of vectors provided here is NOT check in this function. This method can be “chained” and only on the final action, when used, eg. in the Backend, is checked.
NB: If a powerline is disconnected, on maintenance, or suffer an outage, the associated “set_bus” will be ignored. Disconnection has the priority on anything. This priority is given because, in case of hazard, the hazard has the priority over the possible actions.
Examples
Here are short examples on how to update an action eg. how to create a valid
Action
object that be used to modify agrid2op.Backend.Backend
.In all the following examples, we suppose that a valid grid2op environment is created, for example with: .. code-block:: python
import grid2op # create a simple environment # and make sure every type of action can be used. env = grid2op.make(action_class=grid2op.Action.Action)
Example 1: modify the load active values to set them all to 1. You can replace “load_p” by “load_q”, “prod_p” or “prod_v” to change the load reactive value, the generator active setpoint or the generator voltage magnitude setpoint.
new_load = np.ones(env.action_space.n_load) modify_load_active_value = env.action_space({"injection": {"load_p": new_load}}) print(modify_load_active_value)
Example 2: disconnect the powerline of id 1:
disconnect_powerline = env.action_space({"set_line_status": [(1, -1)]}) print(disconnect_powerline) # there is a shortcut to do that: disconnect_powerline2 = env.disconnect_powerline(line_id=1)
Example 3: force the reconnection of the powerline of id 5 by connected it to bus 1 on its origin end and bus 2 on its extremity end. Note that this is mandatory to specify on which bus to reconnect each extremity of the powerline. Otherwise it’s an ambiguous action.
reconnect_powerline = env.action_space({"set_line_status": [(5, 1)], "set_bus": {"lines_or_id": [(5, 1)]}, "set_bus": {"lines_ex_id": [(5, 2)]} }) print(reconnect_powerline) # and the shorter method: reconnect_powerline = env.action.space.reconnect_powerline(line_id=5, bus_or=1, bus_ex=2)
Example 4: change the bus to which load 4 is connected:
change_load_bus = env.action_space({"set_bus": {"loads_id": [(4, 1)]} }) print(change_load_bus)
Example 5: reconfigure completely substation 5, and connect the first 3 elements to bus 1 and the last 3 elements to bus 2
sub_id = 5 target_topology = np.ones(env.sub_info[sub_id], dtype=np.int) target_topology[3:] = 2 reconfig_sub = env.action_space({"set_bus": {"substations_id": [(sub_id, target_topology)] } }) print(reconfig_sub)
- Returns
self – Return the modified instance. This is handy to chain modifications if needed.
- Return type
-
-
class
grid2op.Action.
HelperAction
(*args, **kwargs)[source]¶ -
__init__
(*args, **kwargs)[source]¶ All parameters (name_gen, name_load, name_line, sub_info, etc.) are used to fill the attributes having the same name. See
ActionSpace
for more information.- Parameters
gridobj (
grid2op.Space.GridObjects
) – The representation of the powergrid.actionClass (
type
) – Note that this parameter expected a class and not an object of the class. It is used to return the appropriate action type.legal_action (
grid2op.RulesChecker.BaseRules
) – Class specifying the rules of the game used to check the legality of the actions.
-
-
class
grid2op.Action.
PowerLineSet
(gridobj)[source]¶ This class is here to model only a subpart of Topological actions, the one consisting of topological switching. It will throw an “AmbiguousAction” error if someone attempts to change injections in any way.
It has the same attributes as its base class
BaseAction
.It is also here to show an example of how to implement a valid class deriving from
BaseAction
.NB This class doesn’t allow to connect an object to other buses than their original bus. In this case, reconnecting a powerline cannot be considered “ambiguous”: all powerlines are reconnected on bus 1 on both of their substations.
-
__call__
()[source]¶ Compare to the ancestor
BaseAction.__call__()
this type of BaseAction doesn’t allow to change the injections. The only difference is in the returned value dict_injection that is always an empty dictionary.- Returns
dict_injection (
dict
) – This dictionary is always emptyset_line_status (
numpy.array
, dtype:int) – This array isBaseAction._set_line_status
switch_line_status (
numpy.array
, dtype:bool) – This array isBaseAction._switch_line_status
, it is never modifiedset_topo_vect (
numpy.array
, dtype:int) – This array isBaseAction._set_topo_vect
, it is never modifiedchange_bus_vect (
numpy.array
, dtype:bool) – This array isBaseAction._change_bus_vect
, it is never modifiedredispatch (
numpy.ndarray
, dtype:float) – Always 0 for this classshunts (
dict
) – Always empty for this class
-
__init__
(gridobj)[source]¶ See the definition of
BaseAction.__init__()
and ofBaseAction
for more information. Nothing more is done in this constructor.
-
check_space_legit
()[source]¶ This method allows to check if this method is ambiguous per se (defined more formally as: whatever the observation at time t, and the changes that can occur between t and t+1, this action will be ambiguous).
For example, an action that try to assign something to busbar 3 will be ambiguous per se. An action that tries to dispatch a non dispatchable generator will be also ambiguous per se.
However, an action that “switch” (change) the status (connected / disconnected) of a powerline can be ambiguous and it will not be detected here. This is because the ambiguity depends on the current state of the powerline:
if the powerline is disconnected, changing its status means reconnecting it. And we cannot reconnect a powerline without specifying on which bus.
on the contrary if the powerline is connected, changing its status means disconnecting it, which is always feasible.
In case of “switch” as we see here, the action can be ambiguous, but not ambiguous per se. This method will never throw any error in this case.
-
disambiguate_reconnection
()[source]¶ As this class doesn’t allow to perform any topology change, when a powerline is reconnected, it’s necessarily on the first bus of the substation.
So it’s not ambiguous in this case. We have to implement this logic here, and that is what is done in this function.
-
sample
(space_prng)[source]¶ Sample a PowerlineSwitch BaseAction.
By default, this sampling will act on one random powerline, and it will either disconnect it or reconnect it each with equal probability.
- Parameters
space_prng (
numpy.random.RandomState
) – The pseudo random number generator of the BaseAction space used to sample actions.- Returns
res – The sampled action
- Return type
PowerLineSwitch
-
update
(dict_)[source]¶ As its original implementation, this method allows modifying the way a dictionary can be mapped to a valid
BaseAction
.It has only minor modifications compared to the original
BaseAction.update()
implementation, most notably, it doesn’t update theBaseAction._dict_inj
. It raises a warning if attempting to change them.- Parameters
dict (
dict
) – See the help ofBaseAction.update()
for a detailed explanation. NB all the explanations concerning the “injection”, “change bus”, “set bus”, or “change line status” are irrelevant for this subclass.- Returns
self – Return object itself thus allowing multiple calls to “update” to be chained.
- Return type
-
-
class
grid2op.Action.
SerializableActionSpace
(gridobj, actionClass=<class 'grid2op.Action.BaseAction.BaseAction'>)[source]¶ This class allows serializing/ deserializing the action space.
It should not be used inside an
grid2op.Environment.Environment
, as some functions of the action might not be compatible with the serialization, especially the checking of whether or not an action is legal or not.-
actionClass
¶ Type used to build the
SerializableActionSpace.template_act
- Type
type
-
_template_act
¶ An instance of the “actionClass” provided used to provide higher level utilities, such as the size of the action (see
Action.size()
) or to sample a new Action (seegrid2op.Action.Action.sample()
)- Type
-
__init__
(gridobj, actionClass=<class 'grid2op.Action.BaseAction.BaseAction'>)[source]¶ - Parameters
gridobj (
grid2op.Space.GridObjects
) – Representation of the underlying powergrid.actionClass (
type
) – Type of action used to buildSpace.SerializableSpace._template_obj
. It should derived fromBaseAction
.
-
change_bus
(name_element, extremity=None, substation=None, type_element=None, previous_action=None)[source]¶ Utilities to change the bus of a single element if you give its name. NB Changing a bus has the effect to assign the object to bus 1 if it was before that connected to bus 2, and to assign it to bus 2 if it was connected to bus 1. It should not be mixed up with
ActionSpace.set_bus()
.If the parameter “previous_action” is not
None
, then the action given to it is updated (in place) and returned.- Parameters
name_element (
str
) – The name of the element you want to change the busextremity (
str
) – “or” or “ex” for origin or extremity, ignored if an element is not a powerline.substation (
int
, optional) – Its substation ID, if you know it will increase the performance. Otherwise, the method will search for it.type_element (
int
, optional) – Type of the element to look for. It is here to speed up the computation. One of “line”, “gen” or “load”previous_action (
Action
, optional) – The (optional) action to update. It should be of the same type asActionSpace.actionClass
- Returns
res – The action with the modification implemented
- Return type
- Raises
grid2op.Exception.AmbiguousAction – If previous_action has not the same type as
ActionSpace.actionClass
.
-
disconnect_powerline
(line_id, previous_action=None)[source]¶ Utilities to disconnect a powerline more easily.
- Parameters
line_id (
int
) – The powerline to be disconnected.previous_action –
-
staticmethod
from_dict
(dict_)[source]¶ Allows the de-serialization of an object stored as a dictionary (for example in the case of JSON saving).
- Parameters
dict (
dict
) – Representation of an BaseAction Space (aka SerializableActionSpace) as a dictionary.- Returns
res – An instance of an action space matching the dictionary.
- Return type
:class:
SerializableActionSpace
-
staticmethod
get_all_unitary_topologies_change
(action_space)[source]¶ This methods allows to compute and return all the unitary topological changes that can be performed on a powergrid.
The changes will be performed using the “change_bus” method. The “do nothing” action will be counted only once.
- Parameters
action_space (
grid2op.BaseAction.ActionHelper
) – The action space used.- Returns
res – The list of all the topological actions that can be performed.
- Return type
list
-
staticmethod
get_all_unitary_topologies_set
(action_space)[source]¶ This methods allows to compute and return all the unitary topological changes that can be performed on a powergrid.
The changes will be performed using the “set_bus” method. The “do nothing” action will be counted once per substation in the grid.
- Parameters
action_space (
grid2op.BaseAction.ActionHelper
) – The action space used.- Returns
res – The list of all the topological actions that can be performed.
- Return type
list
-
get_change_line_status_vect
()[source]¶ Computes and return a vector that can be used in the “change_line_status” keyword if building an
BaseAction
- Returns
res – A vector that doesn’t affect the grid, but can be used in “change_line_status”
- Return type
numpy.array
, dtype:np.bool
-
get_set_line_status_vect
()[source]¶ Computes and returns a vector that can be used in the “set_status” keyword if building an
BaseAction
- Returns
res – A vector that doesn’t affect the grid, but can be used in “set_line_status”
- Return type
numpy.array
, dtype:np.int
-
reconnect_powerline
(line_id, bus_or, bus_ex, previous_action=None)[source]¶ Utilities to reconnect a powerline more easily.
Note that in case “bus_or” or “bus_ex” are not the current bus to which the powerline is connected, they will be affected by this action.
- Parameters
line_id (
int
) – The powerline to be disconnected.bus_or (
int
) – On which bus to reconnect the powerline at its origin endbus_ex (
int
) – On which bus to reconnect the powerline at its extremity endprevious_action –
-
sample
()[source]¶ A utility used to sample
Action
.This method is under development, use with care (actions are not sampled on the full action space, and are not uniform in general).
- Returns
res – A random action sampled from the
ActionSpace.actionClass
- Return type
-
set_bus
(name_element, new_bus, extremity=None, substation=None, type_element=None, previous_action=None)[source]¶ Utilities to set the bus of a single element if you give its name. NB Setting a bus has the effect to assign the object to this bus. If it was before that connected to bus 1, and you assign it to bus 1 (new_bus = 1) it will stay on bus 1. If it was on bus 2 (and you still assign it to bus 1) it will be moved to bus 2. 1. It should not be mixed up with
ActionSpace.change_bus()
.If the parameter “previous_action” is not
None
, then the action given to it is updated (in place) and returned.- Parameters
name_element (
str
) – The name of the element you want to change the busnew_bus (
int
) – Id of the new bus to connect the object to.extremity (
str
) – “or” or “ext” for origin or extremity, ignored if the element is not a powerline.substation (
int
, optional) – Its substation ID, if you know it will increase the performance. Otherwise, the method will search for it.type_element (
str
, optional) – Type of the element to look for. It is here to speed up the computation. One of “line”, “gen” or “load”previous_action (
Action
, optional) – The (optional) action to update. It should be of the same type asActionSpace.actionClass
- Returns
res – The action with the modification implemented
- Return type
- Raises
AmbiguousAction – If previous_action has not the same type as
ActionSpace.actionClass
.
-
-
class
grid2op.Action.
TopoAndRedispAction
(gridobj)[source]¶ -
__call__
()[source]¶ Compare to the ancestor
BaseAction.__call__()
this type of BaseAction doesn’t allow to change the injections. The only difference is in the returned value dict_injection that is always an empty dictionary.- Returns
dict_injection (
dict
) – This dictionary is always emptyset_line_status (
numpy.ndarray
, dtype:int) – This array isBaseAction._set_line_status
switch_line_status (
numpy.ndarray
, dtype:bool) – This array isBaseAction._switch_line_status
set_topo_vect (
numpy.ndarray
, dtype:int) – This array isBaseAction._set_topo_vect
change_bus_vect (
numpy.ndarray
, dtype:bool) – This array isBaseAction._change_bus_vect
redispatch (
numpy.ndarray
, dtype:float) – Thie array isBaseAction._redispatch
shunts (
dict
) – Always empty for this class
-
__init__
(gridobj)[source]¶ This is used to create an BaseAction instance. Preferably,
BaseAction
should be created withActionSpace
.It is NOT recommended to create an action with this method. Please use
ActionSpace.__call__()
orActionSpace.sample()
to create a valid action.- Parameters
gridobj (
grid2op.Space.GridObjects
) – Representation of the objects present in the powergrid
-
update
(dict_)[source]¶ As its original implementation, this method allows modifying the way a dictionary can be mapped to a valid
BaseAction
.It has only minor modifications compared to the original
BaseAction.update()
implementation, most notably, it doesn’t update theBaseAction._dict_inj
. It raises a warning if attempting to change them.- Parameters
dict (
dict
) – See the help ofBaseAction.update()
for a detailed explanation. NB all the explanations concerning the “injection” part is irrelevant for this subclass.- Returns
self – Return object itself thus allowing multiple calls to “update” to be chained.
- Return type
-
-
class
grid2op.Action.
TopologyAction
(gridobj)[source]¶ This class is model only topological actions. It will throw an “
grid2op.Exception.AmbiguousAction
” error it someone attempt to change injections in any ways.It has the same attributes as its base class
BaseAction
.It is also here to show an example on how to implement a valid class deriving from
BaseAction
.-
__call__
()[source]¶ Compare to the ancestor
BaseAction.__call__()
this type of BaseAction doesn’t allow to change the injections. The only difference is in the returned value dict_injection that is always an empty dictionary.- Returns
dict_injection (
dict
) – This dictionary is always emptyset_line_status (
numpy.ndarray
, dtype:int) – This array isBaseAction._set_line_status
switch_line_status (
numpy.ndarray
, dtype:bool) – This array isBaseAction._switch_line_status
set_topo_vect (
numpy.ndarray
, dtype:int) – This array isBaseAction._set_topo_vect
change_bus_vect (
numpy.ndarray
, dtype:bool) – This array isBaseAction._change_bus_vect
redispatch (
numpy.ndarray
, dtype:float) – Thie array isBaseAction._redispatch
shunts (
dict
) – Always empty for this class
-
__init__
(gridobj)[source]¶ See the definition of
BaseAction.__init__()
and ofBaseAction
for more information. Nothing more is done in this constructor.
-
sample
(space_prng)[source]¶ Sample a Topology action.
This method is not implemented at the moment. TODO
- Parameters
space_prng –
- Returns
res – The current action (useful to chain some calls to methods)
- Return type
-
update
(dict_)[source]¶ As its original implementation, this method allows modifying the way a dictionary can be mapped to a valid
BaseAction
.It has only minor modifications compared to the original
BaseAction.update()
implementation, most notably, it doesn’t update theBaseAction._dict_inj
. It raises a warning if attempting to change them.- Parameters
dict (
dict
) – See the help ofBaseAction.update()
for a detailed explanation. NB all the explanations concerning the “injection” part is irrelevant for this subclass.- Returns
self – Return object itself thus allowing multiple calls to “update” to be chained.
- Return type
-
-
class
grid2op.Action.
VoltageOnlyAction
(gridobj)[source]¶ This class is here to serve as a base class for the controler of the voltages (if any). It allows to perform only modification of the generator voltage set point.
Only action of type “injection” are supported, and only setting “prod_v” keyword.
-
__init__
(gridobj)[source]¶ See the definition of
BaseAction.__init__()
and ofBaseAction
for more information. Nothing more is done in this constructor.
-
update
(dict_)[source]¶ As its original implementation, this method allows modifying the way a dictionary can be mapped to a valid
BaseAction
.It has only minor modifications compared to the original
BaseAction.update()
implementation, most notably, it doesn’t update theBaseAction._dict_inj
. It raises a warning if attempting to change them.- Parameters
dict (
dict
) – See the help ofBaseAction.update()
for a detailed explanation. NB all the explanations concerning the “injection”, “change bus”, “set bus”, or “change line status” are irrelevant for this subclass.- Returns
self – Return object itself thus allowing multiple calls to “update” to be chained.
- Return type
-
If you still can’t find what you’re looking for, try in one of the following pages: