Skip to content

Commit

Permalink
Add: Backend-Agnostic Detachment Check
Browse files Browse the repository at this point in the history
Signed-off-by: Xavier Weiss <[email protected]>
  • Loading branch information
DEUCE1957 committed Nov 6, 2024
1 parent 189b33b commit 6fbe606
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 11 deletions.
32 changes: 30 additions & 2 deletions getting_started/13_DetachmentOfLoadsAndGenerators.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"### Shedding\n",
"In emergency conditions, it may be possible / necessary for a grid operator to disconnect certain loads, generators, or other components in order to prevent a larger blackout. This notebook explores how this can be achieved in Grid2OP. \n",
"### Detachment of Loads and Generators\n",
"In emergency conditions, it may be possible / necessary for a grid operator to detach certain loads, generators, or other components in order to prevent a larger blackout. This notebook explores how this can be achieved in Grid2OP. \n",
"\n",
"By default shedding is disabled in all environments, to provide the keyword argument allow_detachment when initializing the environment."
]
Expand Down Expand Up @@ -71,6 +71,34 @@
")\n",
"display(network.res_line.loc[:, [\"p_from_mw\", \"p_to_mw\", \"q_from_mvar\", \"q_to_mvar\"]])"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"env.backend.loads_info()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"env.backend.generators_info()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"topo_vect = env.backend.get_topo_vect()\n",
"topo_vect[env.backend.load_pos_topo_vect]"
]
}
],
"metadata": {
Expand Down
23 changes: 14 additions & 9 deletions grid2op/Backend/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -1080,16 +1080,21 @@ def _runpf_with_diverging_exception(self, is_dc : bool) -> Optional[Exception]:
conv = False
exc_me = None

# if not self.allow_detachment and (~self._grid.load["in_service"]).any():
# # TODO see if there is a better way here -> do not handle this here, but rather in Backend._next_grid_state
# raise pp.powerflow.LoadflowNotConverged("Disconnected load: for now grid2op cannot handle properly"
# " disconnected load. If you want to disconnect one, say it"
# " consumes 0. instead. Please check loads: "
# f"{(~self._grid.load['in_service'].values).nonzero()[0]}"
# )
try:
# load_p, load_q, load_v = self.loads_info()
# prod_p, prod_q, prod_v = self.generators_info()
# Check if loads/gens have been detached and if this is allowed, otherwise raise an error
# .. versionadded:: 1.11.0
topo_vect = self.get_topo_vect()

load_buses = topo_vect[self.load_pos_topo_vect]
if not self.allow_detachment and (load_buses == -1).any():
raise Grid2OpException(f"One or more loads were detached before powerflow in Backend {type(self).__name__}"
"but this is not allowed or not supported (Game Over)")

gen_buses = topo_vect[self.gen_pos_topo_vect]
if not self.allow_detachment and (gen_buses == -1).any():
raise Grid2OpException(f"One or more generators were detached before powerflow in Backend {type(self).__name__}"
"but this is not allowed or not supported (Game Over)")

conv, exc_me = self.runpf(is_dc=is_dc) # run powerflow
except Grid2OpException as exc_:
exc_me = exc_
Expand Down
1 change: 1 addition & 0 deletions grid2op/Backend/pandaPowerBackend.py
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,7 @@ def load_grid(self,
"""
self.can_handle_more_than_2_busbar()
self.can_handle_detachment()
full_path = self.make_complete_path(path, filename)

with warnings.catch_warnings():
Expand Down

0 comments on commit 6fbe606

Please sign in to comment.