Skip to content

Commit b34b1d3

Browse files
feat: prepare advanced excercises
1 parent 6676c89 commit b34b1d3

File tree

2 files changed

+78
-6
lines changed

2 files changed

+78
-6
lines changed

power-grid-model-ds/advanced.ipynb

Lines changed: 65 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,20 @@
22
"cells": [
33
{
44
"cell_type": "code",
5-
"execution_count": null,
5+
"execution_count": 2,
66
"id": "59d49e29",
77
"metadata": {},
8-
"outputs": [],
8+
"outputs": [
9+
{
10+
"name": "stdout",
11+
"output_type": "stream",
12+
"text": [
13+
"\n",
14+
"\u001b[1m[\u001b[0m\u001b[34;49mnotice\u001b[0m\u001b[1;39;49m]\u001b[0m\u001b[39;49m A new release of pip is available: \u001b[0m\u001b[31;49m24.2\u001b[0m\u001b[39;49m -> \u001b[0m\u001b[32;49m25.1.1\u001b[0m\n",
15+
"\u001b[1m[\u001b[0m\u001b[34;49mnotice\u001b[0m\u001b[1;39;49m]\u001b[0m\u001b[39;49m To update, run: \u001b[0m\u001b[32;49mpip install --upgrade pip\u001b[0m\n"
16+
]
17+
}
18+
],
919
"source": [
1020
"!pip install pandas power-grid-model-ds[visualizer] --quiet"
1121
]
@@ -33,7 +43,7 @@
3343
},
3444
{
3545
"cell_type": "code",
36-
"execution_count": null,
46+
"execution_count": 3,
3747
"id": "cf475775",
3848
"metadata": {},
3949
"outputs": [],
@@ -65,7 +75,7 @@
6575
},
6676
{
6777
"cell_type": "code",
68-
"execution_count": null,
78+
"execution_count": 4,
6979
"id": "37f4bd29",
7080
"metadata": {},
7181
"outputs": [],
@@ -118,7 +128,7 @@
118128
},
119129
{
120130
"cell_type": "code",
121-
"execution_count": null,
131+
"execution_count": 5,
122132
"id": "78d0639e",
123133
"metadata": {},
124134
"outputs": [],
@@ -157,7 +167,15 @@
157167
"execution_count": null,
158168
"id": "206be67b",
159169
"metadata": {},
160-
"outputs": [],
170+
"outputs": [
171+
{
172+
"name": "stdout",
173+
"output_type": "stream",
174+
"text": [
175+
"None\n"
176+
]
177+
}
178+
],
161179
"source": [
162180
"# Check the grid for capacity issues\n",
163181
"# 1. Use the PowerGridModelInterface to calculate power flow\n",
@@ -212,6 +230,8 @@
212230
"metadata": {},
213231
"outputs": [],
214232
"source": [
233+
"# Check the introduction workshop on adding a substation\n",
234+
"\n",
215235
"def build_new_substation(grid: Grid, location: tuple[float, float]) -> NodeArray:\n",
216236
" \"\"\"Build a new substation at the given location.\n",
217237
" Return the new substation.\n",
@@ -243,12 +263,23 @@
243263
"metadata": {},
244264
"outputs": [],
245265
"source": [
266+
"# Hint: The lines have been extended with extra properties in Step 1\n",
267+
"# Hint: The arrays in the grid have a filter option, https://power-grid-model-ds.readthedocs.io/en/stable/examples/model/array_examples.html#using-filters\n",
268+
"\n",
246269
"def get_all_congested_routes(grid: Grid) -> list[NodeArray]:\n",
247270
" \"\"\"Get all routes that originate from a given substation node.\"\"\"\n",
248271
"\n",
249272
"# %load solutions/advanced_5_1_get_all_congested_routes.py"
250273
]
251274
},
275+
{
276+
"cell_type": "markdown",
277+
"id": "ee84e60c",
278+
"metadata": {},
279+
"source": [
280+
"Next we will use the nodes x and y coordinates to find a suitable node to connect to the new substation. You will create a find_connection_point function that return the Node in a route which is closest to the new_substation."
281+
]
282+
},
252283
{
253284
"cell_type": "code",
254285
"execution_count": null,
@@ -260,17 +291,29 @@
260291
" \"\"\"Calculate the connection point for the new route.\n",
261292
" This should be the geographically closest node to the new substation.\n",
262293
" \"\"\"\n",
294+
" # Calculate the distance of each node in the route to the new_substation\n",
295+
" # Return the closest one\n",
263296
"\n",
264297
"# %load solutions/advanced_5_2_find_connection_point.py"
265298
]
266299
},
300+
{
301+
"cell_type": "markdown",
302+
"id": "a75e9b73",
303+
"metadata": {},
304+
"source": [
305+
"Finally we build a function that creates a new line between the connection point and the new substation. We will first create it with an open connection and optimize the opening in the next step."
306+
]
307+
},
267308
{
268309
"cell_type": "code",
269310
"execution_count": null,
270311
"id": "263818f6",
271312
"metadata": {},
272313
"outputs": [],
273314
"source": [
315+
"# Hint: in the introduction you learned how to add a LineArray to the grid\n",
316+
"\n",
274317
"def connect_to_route(grid: Grid, connection_point: NodeArray, new_substation: NodeArray) -> None:\n",
275318
" \"\"\"Connect the new substation node to the connection point.\n",
276319
" \"\"\"\n",
@@ -325,6 +368,14 @@
325368
"# %load solutions/advanced_6_optimize_route_transfer.py"
326369
]
327370
},
371+
{
372+
"cell_type": "markdown",
373+
"id": "dbf3243e",
374+
"metadata": {},
375+
"source": [
376+
"Now we combine the functions you created to solve the issues in the network"
377+
]
378+
},
328379
{
329380
"cell_type": "code",
330381
"execution_count": null,
@@ -361,6 +412,14 @@
361412
"transfer_routes(grid=grid, new_substation=new_substation)"
362413
]
363414
},
415+
{
416+
"cell_type": "markdown",
417+
"id": "82546c38",
418+
"metadata": {},
419+
"source": [
420+
"Check we resolved all contingencies"
421+
]
422+
},
364423
{
365424
"cell_type": "code",
366425
"execution_count": null,
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
def connect_to_route(grid: Grid, connection_point: NodeArray, new_substation: NodeArray) -> None:
2+
"""Connect the new substation node to the connection point.
3+
"""
4+
# Create a new line that connects the two nodes
5+
new_line = MyLineArray(
6+
from_node=[new_substation.id],
7+
to_node=[connection_point.id],
8+
from_status=[0], # status is 0 to make sure the line is not active
9+
to_status=[1],
10+
i_n=[360.0],
11+
r1=[0.05], x1=[0.01], c1=[0.0], tan1=[0.0]
12+
)
13+
grid.append(new_line)

0 commit comments

Comments
 (0)