Skip to content

Commit

Permalink
Test: Add Entry for Allow_Shedding
Browse files Browse the repository at this point in the history
Signed-off-by: Xavier Weiss <[email protected]>
  • Loading branch information
DEUCE1957 committed Nov 5, 2024
1 parent 6882e73 commit 88f8ccf
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 27 deletions.
28 changes: 4 additions & 24 deletions getting_started/13_Shedding.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,7 @@
"### 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",
"\n",
"By default shedding is disabled in all environments, to enable it provide set the environment parameter ALLOW_SHEDDING to True.\n",
"\n",
"Shed load:\n",
"* **Vector** :: $\\text{n\\_load}$\n",
"* **List** :: $[(\\text{load\\_id}, \\text{status})]$\n",
"* **Dictionary** :: $\\text{load\\_name}: \\text{status}$\n",
"\n",
"Shed generator:\n",
"* **Vector** :: $\\text{n\\_gen}$\n",
"* **List** :: $[(\\text{gen\\_id}, \\text{status})]$\n",
"* **Dictionary** :: $\\text{gen\\_name}: \\text{status}$\n",
"\n",
"Where $\\text{status}$ is a boolean (True/False)."
"By default shedding is disabled in all environments, to provide the keyword argument allow_shedding when initializing the environment."
]
},
{
Expand All @@ -38,7 +26,7 @@
"from pathlib import Path\n",
"\n",
"data_path = Path.cwd() / \"grid2op\" / \"data\"\n",
"env = grid2op.make(data_path / \"rte_case5_example\", allow_shedding=True)\n",
"env = grid2op.make(data_path / \"rte_case5_example\", backend=LightSimBackend(), allow_shedding=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 Shedding: {env.allow_shedding}\")"
]
Expand All @@ -51,7 +39,9 @@
"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",
"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",
Expand All @@ -60,16 +50,6 @@
"plt.show()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"load_shed_mask = (init_obs + act).topo_vect[env.load_pos_topo_vect] == -1\n",
"gen_shed_mask = (init_obs + act).topo_vect[env.gen_pos_topo_vect] == -1"
]
},
{
"cell_type": "code",
"execution_count": null,
Expand Down
1 change: 1 addition & 0 deletions grid2op/Backend/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@ def set_shedding(self, allow_shedding:bool=False):
"""
Override if the Backend supports shedding.
"""

if allow_shedding:
raise BackendError("Backend does not support shedding")
else:
Expand Down
6 changes: 3 additions & 3 deletions grid2op/Space/GridObjects.py
Original file line number Diff line number Diff line change
Expand Up @@ -3930,6 +3930,9 @@ def _make_cls_dict(cls, res, as_list=True, copy_=True, _topo_vect_only=False):
else:
res["name_shunt"] = None
res["shunt_to_subid"] = None

# Shedding
save_to_dict(res, cls, "allow_shedding", bool, copy_)

if not _topo_vect_only:
# all the attributes bellow are not needed for the "first call"
Expand Down Expand Up @@ -4072,9 +4075,6 @@ def _make_cls_dict(cls, res, as_list=True, copy_=True, _topo_vect_only=False):
save_to_dict(
res, cls, "alertable_line_ids", (lambda li: [int(el) for el in li]) if as_list else None, copy_
)

# Shedding
save_to_dict(res, cls, "allow_shedding", str, copy_)

# avoid further computation and save it
if not as_list:
Expand Down
1 change: 1 addition & 0 deletions grid2op/tests/test_Observation.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,7 @@ def setUp(self):
"alertable_line_ids": [],
"assistant_warning_type": None,
"_PATH_GRID_CLASSES": None,
"allow_shedding": False,
}

self.json_ref = {
Expand Down

0 comments on commit 88f8ccf

Please sign in to comment.