Rules of the Game

This page is organized as follow:

Objectives

The Rules module define what is “Legal” and what is not. For example, it can be usefull, at the beginning of the training of an grid2op.Agent.BaseAgent to loosen the rules in order to ease the learning process, and have the agent focusing more on the physics. When the agent is performing well enough, it is then possible to make the rules more and more complex up to the target complexity.

Rules includes:

  • checking the number of powerline that can be connected / disconnected at a given time step

  • checking the number of substations for which the topology can be reconfigured at a given timestep

If an action “break the rules” it is replaced by a do nothing. Note that the Rules of the game is different from the concept of Ambiguous Action.

Detailed Documentation by class

Classes:

AlwaysLegal()

This subclass doesn't implement any rules regarding the legality of the actions.

BaseRules()

This class is a base class that determines whether or not an action is legal in certain environment.

DefaultRules()

This subclass combine both LookParam and PreventReconnection.

LookParam()

This subclass only check that the number of powerlines reconnected / disconnected by the agent.

PreventDiscoStorageModif()

This subclass only check that the action do not modify the storage power (charge / discharge) of a disconnected storage unit.

PreventReconnection()

A subclass is used to check that an action will not attempt to reconnect a powerlines disconnected because of an overflow, or to check that 2 actions acting on the same powerline are distant from the right number of timesteps (see grid2op.Parameters.Parameters.NB_TIMESTEP_LINE_STATUS_REMODIF) or if two topological modification of the same substation are too close in time (see grid2op.Parameters.Parameters.NB_TIMESTEP_TOPOLOGY_REMODIF)

RulesChecker([legalActClass])

Class that define the rules of the game.

class grid2op.Rules.AlwaysLegal[source]

This subclass doesn’t implement any rules regarding the legality of the actions. All actions are legal.

Methods:

__call__(action, env)[source]

All actions being legal, this returns always true. See BaseRules.__call__() for a definition of the parameters of this function.

class grid2op.Rules.BaseRules[source]

This class is a base class that determines whether or not an action is legal in certain environment. See the definition of BaseRules.__call__() for more information.

Basically, this is an empty class with an overload of the __call__ operator that should return True or False depending on the legality of the action.

In grid2op.Environment, only action of the users are checked for legality.

Methods:

abstractmethod __call__(action, env)[source]

As opposed to “ambiguous action”, “illegal action” are not illegal per se. They are legal or not on a certain environment. For example, disconnecting a powerline that has been cut off for maintenance is illegal. Saying to action to both disconnect a powerline and assign it to bus 2 on it’s origin end is ambiguous, and not tolerated in Grid2Op.

Parameters
  • action (grid2op.Action.Action) – The action of which the legality is tested.

  • env (grid2op.Environment.Environment) – The environment on which the action is performed.

Returns

  • is_legal (bool) – Whether the action is legal or not

  • reason – The cause of the illegal part of the action (should be a grid2op exception)

class grid2op.Rules.DefaultRules[source]

This subclass combine both LookParam and PreventReconnection. An action is declared legal if and only if:

  • It doesn’t disconnect / reconnect more power lines than what stated in the actual game _parameters grid2op.Parameters

  • It doesn’t attempt to act on more substations that what is stated in the actual game _parameters grid2op.Parameters

  • It doesn’t attempt to modify the power produce by a turned off storage unit

Methods:

__call__(action, env)[source]

See BaseRules.__call__() for a definition of the _parameters of this function.

class grid2op.Rules.LookParam[source]

This subclass only check that the number of powerlines reconnected / disconnected by the agent.

This class doesn’t require any environment information. The “env” argument is only used to look for the game rules implemented in grid2op.Parameters.

See BaseRules.__call__() for a definition of the parameters of this function.

Methods:

__call__(action, env)[source]

See BaseRules.__call__() for a definition of the parameters of this function.

class grid2op.Rules.PreventDiscoStorageModif[source]

This subclass only check that the action do not modify the storage power (charge / discharge) of a disconnected storage unit.

See BaseRules.__call__() for a definition of the parameters of this function.

Methods:

__call__(action, env)[source]

See BaseRules.__call__() for a definition of the parameters of this function.

class grid2op.Rules.PreventReconnection[source]

A subclass is used to check that an action will not attempt to reconnect a powerlines disconnected because of an overflow, or to check that 2 actions acting on the same powerline are distant from the right number of timesteps (see grid2op.Parameters.Parameters.NB_TIMESTEP_LINE_STATUS_REMODIF) or if two topological modification of the same substation are too close in time (see grid2op.Parameters.Parameters.NB_TIMESTEP_TOPOLOGY_REMODIF)

Methods:

__call__(action, env)[source]

This function check only that the action doesn’t attempt to reconnect a powerline that has been disconnected due to an overflow.

See BaseRules.__call__() for a definition of the parameters of this function.

class grid2op.Rules.RulesChecker(legalActClass=<class 'grid2op.Rules.AlwaysLegal.AlwaysLegal'>)[source]

Class that define the rules of the game.

Methods:

__init__

Initialize self.

Attributes:

__call__(action, env)[source]

Says if an action is legal or not.

Parameters
Returns

  • is_legal (bool) – Assess if the given action is legal or not. True: the action is legal, False otherwise

  • reason – A grid2op IllegalException given the reason for which the action is illegal

__init__(legalActClass=<class 'grid2op.Rules.AlwaysLegal.AlwaysLegal'>)[source]
Parameters

legalActClass (type) – The class that will be used to tell if the actions are legal or not. The class must be given, and not an object of this class. It should derived from BaseRules.

__weakref__

list of weak references to the object (if defined)

If you still can’t find what you’re looking for, try in one of the following pages:

Still trouble finding the information ? Do not hesitate to send a github issue about the documentation at this link: Documentation issue template