Skip to content

Commit 76babd9

Browse files
committed
Split solution cells
Signed-off-by: Thijs Baaijen <[email protected]>
1 parent e2ea1b7 commit 76babd9

File tree

1 file changed

+154
-43
lines changed

1 file changed

+154
-43
lines changed

power-grid-model-ds/introduction.ipynb

Lines changed: 154 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -60,19 +60,30 @@
6060
"In this exercise, we will extend the grid to include an output voltage u for nodes and an output current i_from for lines, which are not present in the basic grid.\n",
6161
"\n",
6262
"### Step 1: Define Extended Node and Line arrays\n",
63-
"We create subclasses of NodeArray and LineArray that include the new properties. We'll call them MyNodeArray and MyLineArray. Each subclass defines a class attribute for the new column and (optionally) a default value for that column via a _defaults dictionary."
63+
"We create subclasses of NodeArray and LineArray that include the new properties. We'll call them MyNodeArray and MyLineArray. Each subclass defines a class attribute for the new column and (optionally) a default value for that column via a _defaults dictionary.\n",
64+
"\n",
65+
"**⚙️ Assignment**: Create two Array extensions to hold the x, y, u (extending NodeArray) and i_from (extending LineArray) attributes\n",
66+
"\n",
67+
"**💡 Hint**: https://power-grid-model-ds.readthedocs.io/en/stable/examples/model/grid_extensions_examples.html"
6468
]
6569
},
6670
{
6771
"cell_type": "code",
6872
"execution_count": null,
69-
"id": "fcb5c7f4",
73+
"id": "7cfe11a7-80ed-4fe9-8c7f-0daf0ec1c27a",
74+
"metadata": {},
75+
"outputs": [],
76+
"source": [
77+
"# Build your solution here..."
78+
]
79+
},
80+
{
81+
"cell_type": "code",
82+
"execution_count": null,
83+
"id": "6ada3e60-8bd7-4687-9f29-3ae5ff029228",
7084
"metadata": {},
7185
"outputs": [],
7286
"source": [
73-
"# ⚙️ Create two Array extensions to hold the x, y, u (extending NodeArray) and i_from (extending LineArray) attributes\n",
74-
"# Hint: https://power-grid-model-ds.readthedocs.io/en/stable/examples/model/grid_extensions_examples.html\n",
75-
"\n",
7687
"# %load solutions/introduction_1_1_define_array_extensions"
7788
]
7889
},
@@ -82,19 +93,32 @@
8293
"metadata": {},
8394
"source": [
8495
"### Step 2: Create an Extended Grid class\n",
85-
"Now we'll integrate these new arrays into a custom Grid class. We do this by subclassing the PGM-DS Grid and specifying that our grid should use MyNodeArray and MyLineArray instead of the default NodeArray and LineArray. We'll use Python's dataclass to define the new Grid schema:"
96+
"Now we'll integrate these new arrays into a custom Grid class. We do this by subclassing the PGM-DS Grid and specifying that our grid should use MyNodeArray and MyLineArray instead of the default NodeArray and LineArray. We'll use Python's dataclass to define the new Grid schema:\n",
97+
"\n",
98+
"**⚙️ Assignment**: Create a new grid class that uses the extended arrays.\n",
99+
"\n",
100+
"**💡 Hint 1**: https://power-grid-model-ds.readthedocs.io/en/stable/examples/model/grid_extensions_examples.html#adding-the-new-arrays-to-the-grid\n",
101+
"\n",
102+
"**💡 Hint 2**: Make sure to add the `@dataclass` decorator to your grid."
86103
]
87104
},
88105
{
89106
"cell_type": "code",
90107
"execution_count": null,
91-
"id": "2da55398",
108+
"id": "de236a67-1632-4f81-9145-7a904c63746b",
109+
"metadata": {},
110+
"outputs": [],
111+
"source": [
112+
"# Build your solution here..."
113+
]
114+
},
115+
{
116+
"cell_type": "code",
117+
"execution_count": null,
118+
"id": "a7512d0d-5d85-44b6-b42e-11be0fa6802a",
92119
"metadata": {},
93120
"outputs": [],
94121
"source": [
95-
"# ⚙️ Create a new grid class that uses the extended arrays\n",
96-
"# Hint: https://power-grid-model-ds.readthedocs.io/en/stable/examples/model/grid_extensions_examples.html\n",
97-
"\n",
98122
"# %load solutions/introduction_1_2_define_my_grid"
99123
]
100124
},
@@ -112,7 +136,11 @@
112136
"metadata": {},
113137
"source": [
114138
"### Step 3: Initialize an Extended Grid\n",
115-
"With the classes defined, let's create an instance of our extended grid. PGM-DS provides a convenient class method Grid.empty() to initialize an empty grid. We'll call this on our ExtendedGrid:"
139+
"With the classes defined, let's create an instance of our extended grid. PGM-DS provides a convenient class method Grid.empty() to initialize an empty grid. We'll call this on our ExtendedGrid:\n",
140+
"\n",
141+
"**⚙️ Assignment**: Instantiate an empty extended grid\n",
142+
"\n",
143+
"**💡 Hint**: https://power-grid-model-ds.readthedocs.io/en/stable/examples/model/grid_examples.html#creating-an-empty-grid"
116144
]
117145
},
118146
{
@@ -122,9 +150,16 @@
122150
"metadata": {},
123151
"outputs": [],
124152
"source": [
125-
"# ⚙️ Instantiate an empty extended grid\n",
126-
"# Hint: https://power-grid-model-ds.readthedocs.io/en/stable/examples/model/grid_examples.html#creating-an-empty-grid\n",
127-
"\n",
153+
"# Build your solution here..."
154+
]
155+
},
156+
{
157+
"cell_type": "code",
158+
"execution_count": null,
159+
"id": "8d5464bf-5689-4919-a85b-b6548b475537",
160+
"metadata": {},
161+
"outputs": [],
162+
"source": [
128163
"# %load solutions/introduction_1_3_grid_empty"
129164
]
130165
},
@@ -133,7 +168,11 @@
133168
"id": "06983bc4",
134169
"metadata": {},
135170
"source": [
136-
"Verification: To ensure our extended properties exist, you can access the new attributes:"
171+
"Verification: To ensure our extended properties exist, you can access the new attributes:\n",
172+
"\n",
173+
"**⚙️ Assignment**: Print some information about the grid.\n",
174+
"\n",
175+
"**💡 Hint**: Be creative! You can use the grid's attributes and methods to get information about the grid. Using `print()` on an array will format it for better readability."
137176
]
138177
},
139178
{
@@ -143,9 +182,16 @@
143182
"metadata": {},
144183
"outputs": [],
145184
"source": [
146-
"# ⚙️ Print some information about the grid\n",
147-
"# Hint: be creative! You can use the grid's attributes and methods to get information about the grid.\n",
148-
"\n",
185+
"# Build your solution here..."
186+
]
187+
},
188+
{
189+
"cell_type": "code",
190+
"execution_count": null,
191+
"id": "b4d131c6-094a-49a2-a283-5bdbd05e961d",
192+
"metadata": {},
193+
"outputs": [],
194+
"source": [
149195
"# %load solutions/introduction_1_3_grid_verification"
150196
]
151197
},
@@ -177,7 +223,11 @@
177223
"### Step 1: Add a substation node\n",
178224
"First, let's add a substation node to the grid. We create an MyNodeArray with one entry representing the substation. We need to provide at least an id, a rated voltage (u_rated), and a node type.\n",
179225
"We will use the enum NodeType.SUBSTATION_NODE for the type.\n",
180-
"In this example, we will assign the substation an ID of 101 and a rated voltage of 10500.0 (which could represent 10.5 kV):"
226+
"In this example, we will assign the substation an ID of 101 and a rated voltage of 10500.0 (which could represent 10.5 kV):\n",
227+
"\n",
228+
"**⚙️ Assignment**: Add a substation to the grid.\n",
229+
"\n",
230+
"**💡 Hint**: https://power-grid-model-ds.readthedocs.io/en/stable/examples/model/grid_examples.html#adding-substations"
181231
]
182232
},
183233
{
@@ -187,9 +237,16 @@
187237
"metadata": {},
188238
"outputs": [],
189239
"source": [
190-
"# ⚙️ Add a substation to the grid\n",
191-
"# Hint: https://power-grid-model-ds.readthedocs.io/en/stable/examples/model/grid_examples.html#adding-substations\n",
192-
"\n",
240+
"# Build your solution here..."
241+
]
242+
},
243+
{
244+
"cell_type": "code",
245+
"execution_count": null,
246+
"id": "5c641c07-1cc7-44bc-87ff-49bed38e7d5c",
247+
"metadata": {},
248+
"outputs": [],
249+
"source": [
193250
"# %load solutions/introduction_2_1_add_substation"
194251
]
195252
},
@@ -218,7 +275,9 @@
218275
"metadata": {},
219276
"source": [
220277
"### Step 2: Add a second node\n",
221-
"Next, we'll add another node to represent a load or another bus in the grid. This node will be of a generic type (we'll use NodeType.UNSPECIFIED, which equals 0 in the enum). We'll give it an ID of 102 and the same base voltage (10.5 kV):"
278+
"Next, we'll add another node to represent a load or another bus in the grid. This node will be of a generic type (we'll use NodeType.UNSPECIFIED, which equals 0 in the enum). We'll give it an ID of 102 and the same base voltage (10.5 kV).\n",
279+
"\n",
280+
"**⚙️ Assignment**: Add a node to the grid. "
222281
]
223282
},
224283
{
@@ -228,8 +287,16 @@
228287
"metadata": {},
229288
"outputs": [],
230289
"source": [
231-
"# ⚙️ Add a node to the grid\n",
232-
"\n",
290+
"# Build your solution here..."
291+
]
292+
},
293+
{
294+
"cell_type": "code",
295+
"execution_count": null,
296+
"id": "3f987c7c-ea3b-472c-b9f9-f379a478bc4e",
297+
"metadata": {},
298+
"outputs": [],
299+
"source": [
233300
"# %load solutions/introduction_2_2_add_node"
234301
]
235302
},
@@ -250,7 +317,11 @@
250317
"metadata": {},
251318
"source": [
252319
"### Step 3: Add a line connecting the two nodes\n",
253-
"Now that we have two nodes, we will connect them with a line. We'll use our MyLineArray to create a single line record. We need to specify an ID for the line (let's use 201), the from_node and to_node it connects (101 to 102), and statuses to indicate the line is active. We should also provide line electrical parameters (resistance, reactance, etc.) – we'll use some placeholder values here for demonstration:"
320+
"Now that we have two nodes, we will connect them with a line. We'll use our MyLineArray to create a single line record. We need to specify an ID for the line (let's use 201), the from_node and to_node it connects (101 to 102), and statuses to indicate the line is active. We should also provide line electrical parameters (resistance, reactance, etc.) – we'll use some placeholder values here for demonstration:\n",
321+
"\n",
322+
"**⚙️ Assignment**: Add a line to the grid.\n",
323+
"\n",
324+
"**💡 Hint**: https://power-grid-model-ds.readthedocs.io/en/stable/examples/model/grid_examples.html#adding-lines"
254325
]
255326
},
256327
{
@@ -260,9 +331,16 @@
260331
"metadata": {},
261332
"outputs": [],
262333
"source": [
263-
"# ⚙️ Add a line to the grid\n",
264-
"# Hint: https://power-grid-model-ds.readthedocs.io/en/stable/examples/model/grid_examples.html#adding-lines\n",
265-
"\n",
334+
"# Build your solution here..."
335+
]
336+
},
337+
{
338+
"cell_type": "code",
339+
"execution_count": null,
340+
"id": "0211f7ec-0890-4880-b78a-65610e1eaf10",
341+
"metadata": {},
342+
"outputs": [],
343+
"source": [
266344
"# %load solutions/introduction_2_3_add_line"
267345
]
268346
},
@@ -290,7 +368,11 @@
290368
"metadata": {},
291369
"source": [
292370
"### Step 4: Add a load to the second node\n",
293-
"We'll now add a load connected to node 102. PGM-DS uses a SymLoadArray for symmetrical loads. We will create a single load with an ID of 401 at node 102. We need to specify the node it is attached to, a load type code (we'll use 1 for a basic load type), the specified active (p_specified) and reactive (q_specified) power (let's say 1e6 each, representing 1 MW and 1 Mvar for example), and set its status to active (1):"
371+
"We'll now add a load connected to node 102. PGM-DS uses a SymLoadArray for symmetrical loads. We will create a single load with an ID of 401 at node 102. We need to specify the node it is attached to, a load type code (we'll use 1 for a basic load type), the specified active (p_specified) and reactive (q_specified) power (let's say 1e6 each, representing 1 MW and 1 Mvar for example), and set its status to active (1):\n",
372+
"\n",
373+
"**⚙️ Assignment**: Add a load to the grid.\n",
374+
"\n",
375+
"**💡 Hint**: https://power-grid-model-ds.readthedocs.io/en/stable/examples/model/grid_examples.html#adding-loads"
294376
]
295377
},
296378
{
@@ -300,9 +382,16 @@
300382
"metadata": {},
301383
"outputs": [],
302384
"source": [
303-
"# ⚙️ Add a load to the grid\n",
304-
"# Hint: https://power-grid-model-ds.readthedocs.io/en/stable/examples/model/grid_examples.html#adding-loads\n",
305-
"\n",
385+
"# Build your solution here..."
386+
]
387+
},
388+
{
389+
"cell_type": "code",
390+
"execution_count": null,
391+
"id": "5499a30c-8820-4066-a322-ee03d5cfb8cf",
392+
"metadata": {},
393+
"outputs": [],
394+
"source": [
306395
"# %load solutions/introduction_2_4_add_load"
307396
]
308397
},
@@ -330,7 +419,11 @@
330419
"metadata": {},
331420
"source": [
332421
"### Step 5: Add a source to the substation node\n",
333-
"Finally, we'll add a power source to supply the grid at the substation (node 101). We'll use SourceArray for this. We'll create a source with ID 501 at node 101, status active (1), and set a reference voltage u_ref. Typically, u_ref might be the slack/reference voltage magnitude or angle; we'll use 0.0 as a reference angle (assuming the default usage):"
422+
"Finally, we'll add a power source to supply the grid at the substation (node 101). We'll use SourceArray for this. We'll create a source with ID 501 at node 101, status active (1), and set a reference voltage u_ref. Typically, u_ref might be the slack/reference voltage magnitude or angle; we'll use 0.0 as a reference angle (assuming the default usage):\n",
423+
"\n",
424+
"**⚙️ Assignment**: Add a source to the grid.\n",
425+
"\n",
426+
"**💡 Hint**: https://power-grid-model-ds.readthedocs.io/en/stable/examples/model/grid_examples.html#adding-a-source"
334427
]
335428
},
336429
{
@@ -340,9 +433,16 @@
340433
"metadata": {},
341434
"outputs": [],
342435
"source": [
343-
"# ⚙️ Add a source to the grid\n",
344-
"# Hint: https://power-grid-model-ds.readthedocs.io/en/stable/examples/model/grid_examples.html#adding-a-source\n",
345-
"\n",
436+
"# Build your solution here..."
437+
]
438+
},
439+
{
440+
"cell_type": "code",
441+
"execution_count": null,
442+
"id": "1ab72aec-acc5-42ac-b429-18f608d6bd38",
443+
"metadata": {},
444+
"outputs": [],
445+
"source": [
346446
"# %load solutions/introduction_2_5_add_source"
347447
]
348448
},
@@ -369,7 +469,11 @@
369469
"id": "e5e6eb1b",
370470
"metadata": {},
371471
"source": [
372-
"You should see [501] as the source ID and [101] as the node, indicating the source is at node 101. The count of sources should be 1. Now we have built a simple grid with 2 nodes (101 and 102), 1 line connecting them, 1 load at node 102, and 1 source at node 101. It's good practice to ensure all IDs are unique and there are no inconsistencies. PGM-DS provides a method grid.check_ids() to validate this​"
472+
"You should see [501] as the source ID and [101] as the node, indicating the source is at node 101. The count of sources should be 1. Now we have built a simple grid with 2 nodes (101 and 102), 1 line connecting them, 1 load at node 102, and 1 source at node 101. It's good practice to ensure all IDs are unique and there are no inconsistencies. PGM-DS provides a method grid.check_ids() to validate this.\n",
473+
"\n",
474+
"**⚙️ Assignment**: Check whether all IDs are correct.\n",
475+
"\n",
476+
"**💡 Hint**: The grid has a method for that!"
373477
]
374478
},
375479
{
@@ -379,9 +483,16 @@
379483
"metadata": {},
380484
"outputs": [],
381485
"source": [
382-
"# ⚙️ Check whether all IDs are correct\n",
383-
"# Hint: The grid has a method for that!\n",
384-
"\n",
486+
"# Build your solution here..."
487+
]
488+
},
489+
{
490+
"cell_type": "code",
491+
"execution_count": null,
492+
"id": "403f00f3-d0bd-497a-8b93-8eaba629d68b",
493+
"metadata": {},
494+
"outputs": [],
495+
"source": [
385496
"# %load solutions/introduction_2_6_check_ids"
386497
]
387498
},
@@ -429,7 +540,7 @@
429540
],
430541
"metadata": {
431542
"kernelspec": {
432-
"display_name": ".venv",
543+
"display_name": "Python 3 (ipykernel)",
433544
"language": "python",
434545
"name": "python3"
435546
},
@@ -443,7 +554,7 @@
443554
"name": "python",
444555
"nbconvert_exporter": "python",
445556
"pygments_lexer": "ipython3",
446-
"version": "3.12.6"
557+
"version": "3.13.2"
447558
}
448559
},
449560
"nbformat": 4,

0 commit comments

Comments
 (0)