|
60 | 60 | "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", |
61 | 61 | "\n", |
62 | 62 | "### 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" |
64 | 68 | ] |
65 | 69 | }, |
66 | 70 | { |
67 | 71 | "cell_type": "code", |
68 | 72 | "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", |
70 | 84 | "metadata": {}, |
71 | 85 | "outputs": [], |
72 | 86 | "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", |
76 | 87 | "# %load solutions/introduction_1_1_define_array_extensions" |
77 | 88 | ] |
78 | 89 | }, |
|
82 | 93 | "metadata": {}, |
83 | 94 | "source": [ |
84 | 95 | "### 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." |
86 | 103 | ] |
87 | 104 | }, |
88 | 105 | { |
89 | 106 | "cell_type": "code", |
90 | 107 | "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", |
92 | 119 | "metadata": {}, |
93 | 120 | "outputs": [], |
94 | 121 | "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", |
98 | 122 | "# %load solutions/introduction_1_2_define_my_grid" |
99 | 123 | ] |
100 | 124 | }, |
|
112 | 136 | "metadata": {}, |
113 | 137 | "source": [ |
114 | 138 | "### 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" |
116 | 144 | ] |
117 | 145 | }, |
118 | 146 | { |
|
122 | 150 | "metadata": {}, |
123 | 151 | "outputs": [], |
124 | 152 | "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": [ |
128 | 163 | "# %load solutions/introduction_1_3_grid_empty" |
129 | 164 | ] |
130 | 165 | }, |
|
133 | 168 | "id": "06983bc4", |
134 | 169 | "metadata": {}, |
135 | 170 | "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." |
137 | 176 | ] |
138 | 177 | }, |
139 | 178 | { |
|
143 | 182 | "metadata": {}, |
144 | 183 | "outputs": [], |
145 | 184 | "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": [ |
149 | 195 | "# %load solutions/introduction_1_3_grid_verification" |
150 | 196 | ] |
151 | 197 | }, |
|
177 | 223 | "### Step 1: Add a substation node\n", |
178 | 224 | "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", |
179 | 225 | "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" |
181 | 231 | ] |
182 | 232 | }, |
183 | 233 | { |
|
187 | 237 | "metadata": {}, |
188 | 238 | "outputs": [], |
189 | 239 | "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": [ |
193 | 250 | "# %load solutions/introduction_2_1_add_substation" |
194 | 251 | ] |
195 | 252 | }, |
|
218 | 275 | "metadata": {}, |
219 | 276 | "source": [ |
220 | 277 | "### 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. " |
222 | 281 | ] |
223 | 282 | }, |
224 | 283 | { |
|
228 | 287 | "metadata": {}, |
229 | 288 | "outputs": [], |
230 | 289 | "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": [ |
233 | 300 | "# %load solutions/introduction_2_2_add_node" |
234 | 301 | ] |
235 | 302 | }, |
|
250 | 317 | "metadata": {}, |
251 | 318 | "source": [ |
252 | 319 | "### 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" |
254 | 325 | ] |
255 | 326 | }, |
256 | 327 | { |
|
260 | 331 | "metadata": {}, |
261 | 332 | "outputs": [], |
262 | 333 | "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": [ |
266 | 344 | "# %load solutions/introduction_2_3_add_line" |
267 | 345 | ] |
268 | 346 | }, |
|
290 | 368 | "metadata": {}, |
291 | 369 | "source": [ |
292 | 370 | "### 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" |
294 | 376 | ] |
295 | 377 | }, |
296 | 378 | { |
|
300 | 382 | "metadata": {}, |
301 | 383 | "outputs": [], |
302 | 384 | "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": [ |
306 | 395 | "# %load solutions/introduction_2_4_add_load" |
307 | 396 | ] |
308 | 397 | }, |
|
330 | 419 | "metadata": {}, |
331 | 420 | "source": [ |
332 | 421 | "### 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" |
334 | 427 | ] |
335 | 428 | }, |
336 | 429 | { |
|
340 | 433 | "metadata": {}, |
341 | 434 | "outputs": [], |
342 | 435 | "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": [ |
346 | 446 | "# %load solutions/introduction_2_5_add_source" |
347 | 447 | ] |
348 | 448 | }, |
|
369 | 469 | "id": "e5e6eb1b", |
370 | 470 | "metadata": {}, |
371 | 471 | "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!" |
373 | 477 | ] |
374 | 478 | }, |
375 | 479 | { |
|
379 | 483 | "metadata": {}, |
380 | 484 | "outputs": [], |
381 | 485 | "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": [ |
385 | 496 | "# %load solutions/introduction_2_6_check_ids" |
386 | 497 | ] |
387 | 498 | }, |
|
429 | 540 | ], |
430 | 541 | "metadata": { |
431 | 542 | "kernelspec": { |
432 | | - "display_name": ".venv", |
| 543 | + "display_name": "Python 3 (ipykernel)", |
433 | 544 | "language": "python", |
434 | 545 | "name": "python3" |
435 | 546 | }, |
|
443 | 554 | "name": "python", |
444 | 555 | "nbconvert_exporter": "python", |
445 | 556 | "pygments_lexer": "ipython3", |
446 | | - "version": "3.12.6" |
| 557 | + "version": "3.13.2" |
447 | 558 | } |
448 | 559 | }, |
449 | 560 | "nbformat": 4, |
|
0 commit comments