Skip to content

Commit 8c4a8a4

Browse files
authored
refactor: make PowerGridModelInterface._setup_model a public method (#59)
* Make PowerGridModelInterface._setup_model a public method Signed-off-by: Thijs Baaijen <[email protected]> * Refactor some tests Signed-off-by: Thijs Baaijen <[email protected]> * Refactor loadflow tests Signed-off-by: Thijs Baaijen <[email protected]> * Fix tests Signed-off-by: Thijs Baaijen <[email protected]> * Move tests into class Signed-off-by: Thijs Baaijen <[email protected]> * Add test_setup_model Signed-off-by: Thijs Baaijen <[email protected]> * Update test Signed-off-by: Thijs Baaijen <[email protected]> --------- Signed-off-by: Thijs Baaijen <[email protected]>
1 parent 0cd8cb3 commit 8c4a8a4

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

src/power_grid_model_ds/_core/load_flow.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ def calculate_power_flow(
107107
108108
Returns output of the power flow calculation (also stored in self.output_data)
109109
"""
110-
self.model = self.model or self._setup_model()
110+
self.model = self.model or self.setup_model()
111111

112112
self.output_data = self.model.calculate_power_flow(
113113
calculation_method=calculation_method, update_data=update_data, **kwargs
@@ -146,7 +146,7 @@ def update_model(self, update_data: Dict):
146146
147147
148148
"""
149-
self.model = self.model or self._setup_model()
149+
self.model = self.model or self.setup_model()
150150
self.model.update(update_data=update_data)
151151

152152
def update_grid(self) -> None:
@@ -166,7 +166,8 @@ def update_grid(self) -> None:
166166
def _match_dtypes(first_dtype: np.dtype, second_dtype: np.dtype):
167167
return list(set(first_dtype.names).intersection(set(second_dtype.names))) # type: ignore[arg-type]
168168

169-
def _setup_model(self):
169+
def setup_model(self):
170+
"""Setup the PowerGridModel with the input data."""
170171
self._input_data = self._input_data or self.create_input_from_grid()
171172
self.model = PowerGridModel(self._input_data, system_frequency=self.system_frequency)
172173
return self.model

tests/integration/loadflow/test_power_grid_model.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,18 @@ def test_batch_run(self):
176176
# Results have been calculated for all 10 scenarios
177177
assert 10 == len(output["line"])
178178

179+
def test_setup_model(self):
180+
"""Test whether a pgm model can be setup with a custom grid"""
181+
grid_generator = RadialGridGenerator(grid_class=CustomGrid, nr_nodes=5, nr_sources=1, nr_nops=0)
182+
grid = grid_generator.run(seed=0)
183+
184+
core_interface = PowerGridModelInterface(grid=grid)
185+
assert core_interface.model is None
186+
assert core_interface._input_data is None
187+
core_interface.setup_model()
188+
assert core_interface.model
189+
assert core_interface._input_data
190+
179191

180192
class TestCreateGridFromInputData:
181193
def test_create_grid_from_input_data(self, input_data_pgm):

0 commit comments

Comments
 (0)