forked from Grid2op/grid2op
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'deuce1957/dev_shedding' into dev_shedding
- Loading branch information
Showing
21 changed files
with
483 additions
and
114 deletions.
There are no files selected for viewing
125 changes: 125 additions & 0 deletions
125
getting_started/13_DetachmentOfLoadsAndGenerators.ipynb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"### 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." | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"import numpy as np\n", | ||
"import matplotlib.pyplot as plt\n", | ||
"import grid2op\n", | ||
"from lightsim2grid import LightSimBackend\n", | ||
"from grid2op.Parameters import Parameters\n", | ||
"\n", | ||
"from grid2op.PlotGrid import PlotMatplot\n", | ||
"from pathlib import Path\n", | ||
"\n", | ||
"data_path = Path.cwd() / \"grid2op\" / \"data\"\n", | ||
"p = Parameters()\n", | ||
"p.MAX_SUB_CHANGED = 5\n", | ||
"env = grid2op.make(data_path / \"rte_case5_example\", param=p, allow_detachment=True)\n", | ||
"plotter = PlotMatplot(env.observation_space, load_name=True, gen_name=True, dpi=150)\n", | ||
"print(f\"Loads: {env.n_load}, Generators: {env.n_gen}, Storage: {env.n_storage}, Allow Detachment: {env.allow_detachment}\")" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"# Disconnect the load at substation 4\n", | ||
"load_lookup = {name:i for i,name in enumerate(env.name_load)}\n", | ||
"gen_lookup = {name:i for i,name in enumerate(env.name_gen)}\n", | ||
"act = env.action_space({\"set_bus\":[(env.load_pos_topo_vect[load_lookup[\"load_4_2\"]], -1),\n", | ||
" (env.load_pos_topo_vect[load_lookup[\"load_3_1\"]], -1)]})\n", | ||
"# act = env.action_space({\"set_bus\":[(env.gen_pos_topo_vect[gen_lookup[\"gen_0_0\"]], -1)]})\n", | ||
"print(act)\n", | ||
"env.set_id(\"00\")\n", | ||
"init_obs = env.reset()\n", | ||
"obs, reward, done, info = env.step(act)\n", | ||
"plotter.plot_obs(obs, figure=plt.figure(figsize=(8,5)))\n", | ||
"plt.show()" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"import pandapower as pp\n", | ||
"network = env.backend._grid.deepcopy()\n", | ||
"display(network.res_line.loc[:, [\"p_from_mw\", \"p_to_mw\", \"q_from_mvar\", \"q_to_mvar\"]])\n", | ||
"pp.runpp(network,\n", | ||
" check_connectivity=False,\n", | ||
" init=\"dc\",\n", | ||
" lightsim2grid=False,\n", | ||
" max_iteration=10,\n", | ||
" distributed_slack=False,\n", | ||
")\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": { | ||
"kernelspec": { | ||
"display_name": "venv_grid2op", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.12.7" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 2 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.