Light environment
Goal
lightsim2grid.lightEnv.LightEnv is a (very) limited grid2op environment written
entirely in C++: the loop reset / step / protections / cooldowns / observation runs
without going back to python, and without grid2op’s bookkeeping around it. It is meant for
the workloads where the environment itself is the bottleneck: training an agent that only
acts on the topology, or a search (tree search, beam search, …) that evaluates many
candidate actions one step ahead.
It is not a replacement of grid2op. It models one thing – a grid replaying a time series of injections, on which an agent changes the topology – and it follows grid2op’s semantics for that one thing, so an agent can be trained or searched on the light environment and run on grid2op afterwards. See What it does not model for what it leaves out.
On l2rpn_case14_sandbox a step is 25 to 50 times faster than a grid2op step with
lightsim2grid.LightSimBackend, and evaluating a candidate action is about 20 times
faster than obs.simulate (see Benchmark).
Note
The light environment is new and its interface may still change. It is also usable from
C++ with no python at all: it is header-only, in src/core/light_env/ (installed with
the core library, see Using lightsim2grid as a C++ library).
Quick start
The easiest way to build one is from a grid2op environment using
lightsim2grid.LightSimBackend: the grid of its backend is the initial state of every
episode, and the thermal limits, the protections and the cooldowns are taken from its
parameters. This is the setup used by the benchmark (benchmarks/light_env.py):
import numpy as np
import grid2op
from lightsim2grid import LightSimBackend
from lightsim2grid.lightEnv import LightEnv, Protections
env = grid2op.make("l2rpn_case14_sandbox", backend=LightSimBackend())
env.reset()
# the grid the episode starts from (the topology is restored at every reset)
light_env = LightEnv(env.backend._grid)
# the injections: one row per step, one column per element, NaN meaning "unchanged"
# (a quantity left out, or None, keeps the value of the initial grid)
data = env.chronics_handler.real_data.data
light_env.assign_time_series(
load_p=data.load_p,
load_q=data.load_q,
gen_p=data.prod_p,
gen_v=data.prod_v / env.backend.prod_pu_to_kv, # in pu, not kV
)
# the protections: thermal limits in kA (grid2op uses A), on both sides of each line
th_lim_ka = env.get_thermal_limit() * 1e-3
protections = Protections()
protections.set_thermal_limit_or(th_lim_ka)
protections.set_thermal_limit_ex(th_lim_ka * env.backend.lines_or_pu_to_kv / env.backend.lines_ex_pu_to_kv)
# or, for grid2op's rho (origin side only): protections.set_thermal_limit_ex(np.full(env.n_line, np.nan))
protections.set_max_line_time_step_overflow(
np.full(env.n_line, env.parameters.NB_TIMESTEP_OVERFLOW_ALLOWED, dtype=np.int32))
light_env.protections = protections
# the cooldowns (grid2op parameters of the same name)
light_env.nb_timestep_cooldown_sub = env.parameters.NB_TIMESTEP_COOLDOWN_SUB
light_env.nb_timestep_cooldown_line = env.parameters.NB_TIMESTEP_COOLDOWN_LINE
light_env.nb_timestep_reconnection = env.parameters.NB_TIMESTEP_RECONNECTION
# the actions the agent can take: step(i) plays actions[i]
actions = [env.action_space()] + list(env.action_space.get_all_unitary_topologies_set(env.action_space))
light_env.init_actions(actions)
obs, info = light_env.reset()
done = False
while not done:
act_id = 0 # your agent here
obs, reward, done, truncated, info = light_env.step(act_id)
Setting it up
The grid. LightEnv(grid) takes an lightsim2grid.network.LSGrid and copies it:
this copy is the state every episode starts from (reset restores its topology). A grid
loaded by lightsim2grid.LightSimBackend also carries the position of every element in
grid2op’s topology vector, which obs.topo_vect needs; a grid loaded directly (eg with
init_from_pandapower) works, but has no topo_vect.
The time series (assign_time_series). Nine matrices, one row per step, one column per
element: load_p, load_q, gen_p (MW / MVAr), gen_v (pu), storage_p,
shunt_p, shunt_q, sgen_p, sgen_q. A NaN leaves the value of the grid unchanged,
and a matrix left out (None, the default) is all NaN: that quantity keeps the value of the
initial grid, eg gen_v=None for an environment without a prod_v time series. At least
one matrix is needed. They must all have the same number of rows, which becomes max_step; the sizes are checked
at the next reset. For now only load_p, load_q, gen_p and gen_v are
applied, the other five are only checked.
The protections (lightsim2grid.lightEnv.Protections). The thermal limits, in kA,
on both sides of every line (grid2op numbering: powerlines then transformers, the “or” side
of a transformer being its hv side), and for each line the number of steps it can stay in
overflow. rho is the max over both sides of current / thermal limit; a NaN (or infinite)
limit leaves its side out, and a line with no limit on either side has a rho of 0 and never
trips. grid2op only looks at the origin side (rho = a_or / limit): a NaN on every extremity
side reproduces it, whereas both sides read higher on lines whose current differs a lot from
one end to the other (high charging), and can trip lines grid2op keeps. A line whose overflow counter exceeds that number is disconnected, the powerflow is
run again, and so on until no more line trips (a cascade, within one step). This is grid2op’s
“soft” overflow protection (NB_TIMESTEP_OVERFLOW_ALLOWED).
The cooldowns. nb_timestep_cooldown_sub, nb_timestep_cooldown_line and
nb_timestep_reconnection behave as the grid2op parameters of the same name: after an
action touches a substation (resp. changes the status of a line) that substation (resp. line)
cannot be acted on for that many steps, and a line disconnected by the protections cannot be
reconnected before nb_timestep_reconnection steps.
The actions (init_actions). A list of grid2op actions or of
lightsim2grid.lightEnv.TopoAction, mixing both is fine. Only set_bus and
set_line_status are modelled; a grid2op action using anything else that affects the grid
(change_bus, redispatch, curtail, storage…) is refused. Every action is checked
against the initial grid (the element exists, the busbar exists, no contradiction) and an
invalid one raises a ValueError naming it; nothing is registered in that case. Without
any action registered, step(0) (do nothing) is the only valid call.
A lightsim2grid.lightEnv.TopoAction can also be built by hand, with grid2op semantics:
from lightsim2grid.lightEnv import TopoAction, ElementType
act = TopoAction()
act.add_element(ElementType.load, 0, 2) # set_bus: load 0 on busbar 2 of its substation
act.add_element(ElementType.line_or, 2, 2) # origin side of line 2 on busbar 2
act.set_line_status(3, -1) # set_line_status: disconnect line 3
Playing an episode
reset() restores the initial topology, the overflow counters and the cooldowns, applies
the first row of the time series, runs a powerflow and returns (obs, info). It must be
called before the first step, and again after assign_time_series or a change of the
protections. If that powerflow diverges there is no episode to play: reset raises a
RuntimeError and the env cannot be stepped.
step(act_id) returns (obs, reward, done, truncated, info):
the action
act_idis played, unless it touches a substation or a line still in cooldown: it is then replaced by “do nothing” andinfo["is_illegal"]is"true";the next row of the time series is applied, and the powerflow is run with the protections (the cascade described above);
rewardis the fraction of the episode survived so far,current_step / max_step;doneisTrueat the end of the time series (info["success"] == "true", reward 1) or when the powerflow diverges (info["failure"] == "true", reward 0,truncatedisTrue).info["survival_time"]is then the fraction of the episode survived.
The values in info are strings.
The observation
obs is a lightsim2grid.lightEnv.LightEnvObservation, a view on the state of
the environment: every attribute is a read-only numpy array on the environment’s memory,
nothing is copied. reset and every step return the same object, whose values follow
the environment. Use np.array(obs.p_or) to keep a snapshot.
attribute |
meaning |
|---|---|
|
max over both sides of current / limit, per line (see above) |
|
flows at the origin side (MW, MVAr, kA), per line |
|
flows at the extremity side (MW, MVAr, kA), per line |
|
active power of the loads / generators (MW) |
|
grid2op topology vector (local busbar, -1 if disconnected) |
|
steps before the status of each line can change again |
|
steps before each substation can be acted on again |
|
step of the environment (0 at reset) |
Lines follow grid2op numbering. Currents are in kA, where grid2op uses A.
A view is valid until the next reset, or a step ending the episode by a divergence (the
grid then drops its results); once done is True the values are not meaningful.
Copying: lookahead and search
A lightsim2grid.lightEnv.LightEnv can be copied (env.copy(), copy.copy,
copy.deepcopy, or LightEnv(env), all the same). The copy is an independent environment
at the same point of the same episode, with its own observation. What does not change during
an episode – the initial grid, the time series and the registered actions – is shared
read-only between the copies, so a copy is cheap: it costs less than a step. The first step of
a copy is slower than a step of the original: a copied grid starts with a cold solver (no
cached Ybus nor factorisation) and rebuilds it. This is the light environment’s
counterpart of grid2op’s obs.simulate:
def best_action(light_env, candidates):
"""the candidate that leaves the lowest max(rho) one step ahead"""
best, best_rho = 0, np.inf
for act_id in candidates:
sim = light_env.copy()
obs, reward, done, truncated, info = sim.step(act_id)
if done or info["is_illegal"] == "true":
continue
if obs.rho.max() < best_rho:
best, best_rho = act_id, obs.rho.max()
return best
Unlike obs.simulate, the copy steps on the actual next row of the time series, not on a
forecast: it looks at the future the environment will really see.
What it does not model
Compared with a grid2op environment:
the only actions are
set_busandset_line_status: nochange_bus/change_line_status, no redispatching, curtailment, storage, or setpoint change;only
load_p,load_q,gen_pandgen_vare replayed: storage units, shunts and static generators keep the values of the initial grid;no maintenance, no opponent, no forecasts, no alarms / alerts;
no limit on the number of substations or lines an action touches (
MAX_SUB_CHANGED,MAX_LINE_STATUS_CHANGED), only the cooldowns;only the “soft” overflow protection: no instantaneous disconnection above
HARD_OVERFLOW_THRESHOLD, and a line is in overflow whenrho >= 1(grid2op: aboveSOFT_OVERFLOW_THRESHOLD, 1 by default);a single reward, the fraction of the episode survived;
every powerflow starts from a flat DC initialisation, rather than from the previous state.
Within these limits it follows grid2op step by step: lightsim2grid/tests/test_LightEnv.py
plays the same actions on both and compares the flows, the topology and the cooldowns at every
step.
Benchmark
benchmarks/light_env.py plays the same chronics of l2rpn_case14_sandbox on a grid2op
environment with lightsim2grid.LightSimBackend and on a light environment built as
in the quick start, with the same thermal limits and protections. Its thermal limits are on the
origin side only, as grid2op’s rho (--rho_both_sides limits both sides). grid2op’s
HARD_OVERFLOW_THRESHOLD is raised out of reach, so both sides model the same thing (see
above). Three workloads:
do nothing:
env.step(do_nothing)vslight_env.step(0);topology: every 10 steps a random unitary
set_busaction (the same sequence of actions on both sides), do nothing otherwise. Such an agent ends its episode quickly, so 50 episodes are played;lookahead: at every step, 10 candidate actions are evaluated one step ahead (
obs.simulate(act)vslight_env.copy().step(act_id)), then the episode goes on with do nothing. Only the evaluation is timed.
To run it (cd into the benchmarks folder, grid2op installed):
python light_env.py # the test chronics shipped with grid2op (3 x 575 steps)
python light_env.py --no_test # the full dataset, downloaded by grid2op
The results below were obtained on the test chronics, on a shared cloud machine (Intel Xeon
@ 2.10GHz, python 3.11, grid2op 1.12.5, lightsim2grid 1.0.1rc0 with KLU, compiled without
-O3 / -march=native). Timings vary by up to a factor 2 from one run to the next on such
a machine; the ratio between the two columns is what matters.
“ms / step (in env)” is the time the environment accounts for itself (grid2op
env._time_step, the light env step_time) and “powerflow” the time spent in the
powerflows, protections included (grid2op env._time_powerflow, the light env
protections.powerflow_time, which also counts the powerflow of reset). Both sides play
the same number of steps and end the same episodes: they agree on the physics.
Do nothing:
steps |
game over |
steps / s |
ms / step |
ms / step (in env) |
ms / step (powerflow) |
|
|---|---|---|---|---|---|---|
grid2op + LightSimBackend |
1725 |
0 |
1153 |
0.868 |
0.790 |
0.187 |
LightEnv |
1725 |
0 |
54503 |
0.018 |
0.017 |
0.015 |
Topology (a random unitary set_bus action every 10 steps, 50 episodes):
steps |
game over |
steps / s |
ms / step |
ms / step (in env) |
ms / step (powerflow) |
|
|---|---|---|---|---|---|---|
grid2op + LightSimBackend |
1246 |
50 |
1294 |
0.773 |
0.706 |
0.176 |
LightEnv |
1246 |
50 |
31620 |
0.032 |
0.029 |
0.030 |
Lookahead (10 candidate actions per step, one step ahead):
steps |
game over |
steps / s |
ms / step |
|
|---|---|---|---|---|
grid2op |
17220 |
0 |
634 |
1.577 |
LightEnv copy + step |
17220 |
0 |
12160 |
0.082 |
In short, over three runs: a step is 25 to 50 times faster, and a one-step lookahead about 20 times faster. Most of a grid2op step is spent outside the powerflow (compare the last two columns): applying the action, the rules, building the observation. The light environment spends almost all of its time in the powerflow, and the python binding adds little per step (the gap between “ms / step” and “ms / step (in env)”). A step with a topological change is slower than a do nothing one, as the admittance matrix has to be rebuilt, and the lookahead is dominated by the first step of each copy, which starts from a cold solver (see Copying: lookahead and search).
Detailed usage
Python side of the light environment: a LightEnv whose actions can be given
as grid2op actions.
Classes:
This enum controls the topology action in the light environment of lightsim2grid |
|
The light environment, see the c++ documentation. |
|
Observation of a LightEnv: a read-only view on the current state of its environment, nothing is copied. |
|
Limited protection used for the light environment |
|
Limited topological action used for the light environment, with grid2op semantics: add_element is grid2op set_bus (local busbar id: -1 disconnect, 0 nothing, 1..n_busbar_per_sub), set_line_status is grid2op set_line_status (-1, 0, +1). |
Functions:
|
Convert a grid2op action into a (not yet checked) |
- class lightsim2grid.lightEnv.ElementType
This enum controls the topology action in the light environment of lightsim2grid
Members:
load : denotes a load
gen : denotes a gen
line_or : denotes a line (origin side)
line_ex : denotes a line (ext side)
storage : denotes a storage unit
trafo_hv : denotes a trafo (hv side)
trafo_lv : denotes a trafo (lv side)
shunt : denotes a shunt
static_gen : denotes a static generator
dc_line_or : denotes a dc powerline (or side)
dc_line_ex : denotes a dc powerline (ex side)
Attributes:
- property name
- class lightsim2grid.lightEnv.LightEnv[source]
The light environment, see the c++ documentation. On top of it,
LightEnv.init_actions()also accepts grid2op actions.It can be copied (
env.copy(),copy.copy(env),copy.deepcopy(env)orLightEnv(env), all the same): the copy is an independent env at the same point of the same episode, with its own observation. The initial grid, the time series and the registered actions, which do not change during an episode, are shared read-only.Methods:
assign_time_series([load_p, load_q, gen_p, ...])Give the injections replayed by the episode: one matrix per quantity, one row per step and one column per element (MW, MVAr,
gen_vin pu).copy()An independent copy of this env, at the same step (see the class documentation).
init_actions(actions)Register the actions the agent can take:
step(i)playsactions[i].- assign_time_series(load_p: ndarray | None = None, load_q: ndarray | None = None, gen_p: ndarray | None = None, gen_v: ndarray | None = None, storage_p: ndarray | None = None, shunt_p: ndarray | None = None, shunt_q: ndarray | None = None, sgen_p: ndarray | None = None, sgen_q: ndarray | None = None) None[source]
Give the injections replayed by the episode: one matrix per quantity, one row per step and one column per element (MW, MVAr,
gen_vin pu).A NaN leaves the value of the grid unchanged, and a matrix left to
Noneis a matrix of NaN: that quantity keeps the value of the initial grid for the whole episode (eggen_v=Nonefor an environment without aprod_vtime series). At least one matrix must be given, the number of steps is taken from it.
- copy() LightEnv[source]
An independent copy of this env, at the same step (see the class documentation).
- init_actions(actions: Iterable) None[source]
Register the actions the agent can take:
step(i)playsactions[i].actionsis a list of grid2op actions (set_busandset_line_statusonly, seetopo_action_from_grid2op()) or ofTopoAction, mixing both is fine. Every action is checked against the initial grid: an element that does not exist, a busbar that does not exist (eg-2, or3on a grid with 2 busbars per substation), an unsupported modification or a contradiction raises aValueErrornaming the action, and nothing is registered.
- class lightsim2grid.lightEnv.LightEnvObservation
Observation of a LightEnv: a read-only view on the current state of its environment, nothing is copied. Every attribute is a read-only numpy array on the environment’s memory, so it follows the environment as it steps (it is not a snapshot: use np.array(obs.p_or) to keep one). An array is valid until the next reset of the environment or a step ending the episode by a divergence; once done is True the values are not meaningful. Lines use grid2op numbering (powerlines then transformers, ‘or’ being a transformer’s hv side), powers are in MW / MVAr, currents in kA (like the thermal limits of Protections).
Attributes:
Current flow (kA) at the extremity side of each line
Current flow (kA) at the origin side of each line
Step of the environment (0 at reset)
Active power (MW) produced by each generator
Active power (MW) consumed by each load
Active power flow (MW) at the extremity side of each line
Active power flow (MW) at the origin side of each line
Reactive power flow (MVAr) at the extremity side of each line
Reactive power flow (MVAr) at the origin side of each line
For each line, the max over its two sides of current / thermal limit (a side whose limit is NaN or infinite left out, 0 if both are)
For each line, number of steps before its status can be changed again
For each substation, number of steps before it can be acted on again
the local busbar (1..n_busbar_per_sub, -1 if disconnected) of every element, at its grid2op position.
- property a_ex
Current flow (kA) at the extremity side of each line
- property a_or
Current flow (kA) at the origin side of each line
- property current_step
Step of the environment (0 at reset)
- property gen_p
Active power (MW) produced by each generator
- property load_p
Active power (MW) consumed by each load
- property p_ex
Active power flow (MW) at the extremity side of each line
- property p_or
Active power flow (MW) at the origin side of each line
- property q_ex
Reactive power flow (MVAr) at the extremity side of each line
- property q_or
Reactive power flow (MVAr) at the origin side of each line
- property rho
For each line, the max over its two sides of current / thermal limit (a side whose limit is NaN or infinite left out, 0 if both are)
- property time_before_cooldown_line
For each line, number of steps before its status can be changed again
- property time_before_cooldown_sub
For each substation, number of steps before it can be acted on again
- property topo_vect
the local busbar (1..n_busbar_per_sub, -1 if disconnected) of every element, at its grid2op position. Raises if the grid carries no position in the topology vector (they are set by LightSimBackend).
- Type:
grid2op topology vector
- class lightsim2grid.lightEnv.Protections
Limited protection used for the light environment
Methods:
For each line, the number of steps it can stay in overflow: it is disconnected once its overflow counter exceeds this value (grid2op NB_TIMESTEP_OVERFLOW_ALLOWED)
get_thermal_limit_ex(self)Thermal limit (kA) of each line on its extremity side (lv side for a trafo), grid2op numbering (powerlines then transformers)
get_thermal_limit_or(self)Thermal limit (kA) of each line on its origin side (hv side for a trafo), grid2op numbering (powerlines then transformers)
Lines (grid2op numbering) disconnected by the protections during the last step, all iterations together
set_max_line_time_step_overflow(self, ...)Set, for each line (powerlines then transformers), the number of steps it can stay in overflow before the protections disconnect it (int32 vector)
set_thermal_limit_ex(self, thermal_limit_ex)Set the thermal limits (kA) on the extremity side, one per line (powerlines then transformers).
set_thermal_limit_or(self, thermal_limit_or)Set the thermal limits (kA) on the origin side, one per line (powerlines then transformers).
Attributes:
Information on line / trafo disconnected
For how long each line has been on overflow
Number of 'iterations' used to perform the 'next_grid_state' (number of powerflow run) for the last call to 'next_grid_state' only
Total time spent to check the overflow, cumulated over an episode
Total time spent to perform the powerflow (init DC + AC), cumulated over an episode
Last computed 'rho' values.
Total time spent in the 'next_grid_state' function, cumulated over an episode
Total time spent to update the value of rho, cumulated over an episode
Complex voltage used to initialize the last AC powerflow (result of a DC powerflow)
Complex voltage used to initialize the last DC powerflow
Complex voltage at the end of the last powerflow
- get_max_line_time_step_overflow(self: lightsim2grid.lightsim2grid_cpp.Protections) Annotated[numpy.typing.NDArray[numpy.int32], '[m, 1]']
For each line, the number of steps it can stay in overflow: it is disconnected once its overflow counter exceeds this value (grid2op NB_TIMESTEP_OVERFLOW_ALLOWED)
- get_thermal_limit_ex(self: lightsim2grid.lightsim2grid_cpp.Protections) Annotated[numpy.typing.NDArray[numpy.float64], '[m, 1]']
Thermal limit (kA) of each line on its extremity side (lv side for a trafo), grid2op numbering (powerlines then transformers)
- get_thermal_limit_or(self: lightsim2grid.lightsim2grid_cpp.Protections) Annotated[numpy.typing.NDArray[numpy.float64], '[m, 1]']
Thermal limit (kA) of each line on its origin side (hv side for a trafo), grid2op numbering (powerlines then transformers)
- property line_disconnected
Information on line / trafo disconnected
- property line_time_step_overflow
For how long each line has been on overflow
- lines_disconnected_this_step(self: lightsim2grid.lightsim2grid_cpp.Protections) list[int]
Lines (grid2op numbering) disconnected by the protections during the last step, all iterations together
- property nb_iter
Number of ‘iterations’ used to perform the ‘next_grid_state’ (number of powerflow run) for the last call to ‘next_grid_state’ only
- property overflow_time
Total time spent to check the overflow, cumulated over an episode
- property powerflow_time
Total time spent to perform the powerflow (init DC + AC), cumulated over an episode
- property rho
Last computed ‘rho’ values.
- set_max_line_time_step_overflow(self: lightsim2grid.lightsim2grid_cpp.Protections, max_line_time_step_overflow: Annotated[numpy.typing.NDArray[numpy.int32], '[m, 1]']) None
Set, for each line (powerlines then transformers), the number of steps it can stay in overflow before the protections disconnect it (int32 vector)
- set_thermal_limit_ex(self: lightsim2grid.lightsim2grid_cpp.Protections, thermal_limit_ex: Annotated[numpy.typing.NDArray[numpy.float64], '[m, 1]']) None
Set the thermal limits (kA) on the extremity side, one per line (powerlines then transformers). rho is the max over both sides of current / thermal limit; a NaN or infinite limit leaves that side out (eg NaN on every extremity side for grid2op’s rho = a_or / limit).
- set_thermal_limit_or(self: lightsim2grid.lightsim2grid_cpp.Protections, thermal_limit_or: Annotated[numpy.typing.NDArray[numpy.float64], '[m, 1]']) None
Set the thermal limits (kA) on the origin side, one per line (powerlines then transformers). rho is the max over both sides of current / thermal limit; a NaN or infinite limit leaves that side out (eg NaN on every extremity side for grid2op’s rho = a_or / limit).
- property total_time
Total time spent in the ‘next_grid_state’ function, cumulated over an episode
- property update_rho_time
Total time spent to update the value of rho, cumulated over an episode
- property v_init_ac
Complex voltage used to initialize the last AC powerflow (result of a DC powerflow)
- property v_init_dc
Complex voltage used to initialize the last DC powerflow
- property v_res_ac
Complex voltage at the end of the last powerflow
- class lightsim2grid.lightEnv.TopoAction
Limited topological action used for the light environment, with grid2op semantics: add_element is grid2op set_bus (local busbar id: -1 disconnect, 0 nothing, 1..n_busbar_per_sub), set_line_status is grid2op set_line_status (-1, 0, +1). Line ids follow grid2op numbering (powerlines then transformers). check_validity(grid) validates the action and must be called before it can be applied (LightEnv.init_actions does it).
Methods:
add_element(self, el_type, el_id, local_bus_id)grid2op set_bus on one element: add_element(ElementType el_type, int el_id, int local_bus_id) with local_bus_id -1 (disconnect), 0 (nothing) or 1..n_busbar_per_sub.
apply_to_gridmodel(self, grid)Play the (checked) action on a grid: disconnect / reconnect / move its elements.
check_validity(self, grid)Check the action against a grid (element exists, busbar exists, no contradiction) and resolve the busbars.
has_been_checked(self)True if check_validity was called since the last modification
is_do_nothing(self)True if the action does not modify anything
set_line_status(self, line_id, status)grid2op set_line_status on one line (grid2op numbering): -1 disconnect, 0 nothing, +1 reconnect.
Attributes:
Number of (resolved) set_bus entries, after check_validity
Number of (resolved) set_line_status entries, after check_validity
- add_element(self: lightsim2grid.lightsim2grid_cpp.TopoAction, el_type: lightsim2grid.lightsim2grid_cpp.ElementType, el_id: SupportsInt | SupportsIndex, local_bus_id: SupportsInt | SupportsIndex) None
grid2op set_bus on one element: add_element(ElementType el_type, int el_id, int local_bus_id) with local_bus_id -1 (disconnect), 0 (nothing) or 1..n_busbar_per_sub.
- apply_to_gridmodel(self: lightsim2grid.lightsim2grid_cpp.TopoAction, grid: lightsim2grid.lightsim2grid_cpp.LSGrid) None
Play the (checked) action on a grid: disconnect / reconnect / move its elements. The grid should be the one it was checked against, or a copy of it.
- check_validity(self: lightsim2grid.lightsim2grid_cpp.TopoAction, grid: lightsim2grid.lightsim2grid_cpp.LSGrid) None
Check the action against a grid (element exists, busbar exists, no contradiction) and resolve the busbars. Raises ValueError / IndexError on an invalid action.
- has_been_checked(self: lightsim2grid.lightsim2grid_cpp.TopoAction) bool
True if check_validity was called since the last modification
- is_do_nothing(self: lightsim2grid.lightsim2grid_cpp.TopoAction) bool
True if the action does not modify anything
- property nb_set_bus
Number of (resolved) set_bus entries, after check_validity
- property nb_set_line_status
Number of (resolved) set_line_status entries, after check_validity
- set_line_status(self: lightsim2grid.lightsim2grid_cpp.TopoAction, line_id: SupportsInt | SupportsIndex, status: SupportsInt | SupportsIndex) None
grid2op set_line_status on one line (grid2op numbering): -1 disconnect, 0 nothing, +1 reconnect.
- lightsim2grid.lightEnv.topo_action_from_grid2op(action: BaseAction) TopoAction[source]
Convert a grid2op action into a (not yet checked)
TopoAction.Only
set_busandset_line_statusare modelled by the light environment. An action using anything else that affects the grid (change_bus,change_line_status,redispatch,curtail, storage, injections, shunts, detachment) raises aValueError. Alarms and alerts are ignored, they do not affect the grid.The values are copied as they are: the check that every element exists and every busbar exists is done against the grid by
TopoAction.check_validity(), whichLightEnv.init_actions()calls.