Skip to content

Commit 8ff8761

Browse files
committed
Add tests for extended arrays. Changes based on review.
Signed-off-by: Marnix van Lieshout <[email protected]>
1 parent bf4b508 commit 8ff8761

File tree

4 files changed

+543
-97
lines changed

4 files changed

+543
-97
lines changed

docs/examples/pgm/basic_pgm_examples.ipynb

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,9 @@
159159
"cell_type": "markdown",
160160
"metadata": {},
161161
"source": [
162-
"## Create grid from input data example\n"
162+
"## Create grid from input data example\n",
163+
"\n",
164+
"To create a `Grid` object from `PGM` input data, the `create_grid_from_input_data()` method can be used."
163165
]
164166
},
165167
{
@@ -168,22 +170,11 @@
168170
"metadata": {},
169171
"outputs": [],
170172
"source": [
171-
"from power_grid_model_ds.arrays import SourceArray, SymLoadArray, TransformerArray\n",
172-
"\n",
173173
"input_data = core_interface.create_input_from_grid()\n",
174174
"\n",
175-
"array_mapping = {\n",
176-
" \"node\": NodeArray,\n",
177-
" \"line\": LineArray,\n",
178-
" \"sym_load\": SymLoadArray,\n",
179-
" \"source\": SourceArray,\n",
180-
" \"transformer\": TransformerArray,\n",
181-
"}\n",
182-
"\n",
183175
"core_interface = PowerGridModelInterface(input_data=input_data)\n",
184-
"output = core_interface.create_grid_from_input_data(\n",
185-
" array_mapping=array_mapping,\n",
186-
")\n",
176+
"output = core_interface.create_grid_from_input_data()\n",
177+
"\n",
187178
"print(input_data[\"node\"])\n",
188179
"print(output.node)"
189180
]

src/power_grid_model_ds/_core/load_flow.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,12 @@
44

55
"""Load flow functions and classes"""
66

7-
from typing import Dict, Optional, Type
7+
from typing import Dict, Optional
88

99
import numpy as np
1010
from numpy.typing import NDArray
1111
from power_grid_model import CalculationMethod, PowerGridModel, initialize_array
1212

13-
from power_grid_model_ds._core.model.arrays.base.array import FancyArray
1413
from power_grid_model_ds._core.model.grids.base import Grid
1514

1615
PGM_ARRAYS = [
@@ -66,19 +65,19 @@ def create_input_from_grid(self):
6665

6766
def create_grid_from_input_data(
6867
self,
69-
array_mapping: Dict[str, Type[FancyArray]],
7068
) -> Grid:
7169
"""
7270
Create Grid object from PowerGridModel input.
73-
Note that for some arrays, not all fields are available in the PowerGridModel input.
71+
Note that for some arrays, not all fields are available in the PowerGridModel input.
7472
In this case, the default values are used.
7573
7674
Returns a Grid object with the arrays filled with the PowerGridModel input.
7775
"""
78-
for pgm_name, pgm_ds_array_class in array_mapping.items():
76+
for pgm_name in PGM_ARRAYS:
7977
if pgm_name in self.input_data:
78+
pgm_ds_array_class = getattr(self.grid, pgm_name).__class__
8079
pgm_ds_array = pgm_ds_array_class(self.input_data[pgm_name])
81-
self.grid.append(pgm_ds_array)
80+
self.grid.append(pgm_ds_array, check_max_id=False)
8281
return self.grid
8382

8483
def calculate_power_flow(

0 commit comments

Comments
 (0)