Skip to content

Commit 46272b5

Browse files
committed
Merge remote-tracking branch 'origin/chore/refactor-loadflow-tests' into feat/setup-model-public
# Conflicts: # src/power_grid_model_ds/_core/load_flow.py
2 parents 933d78e + e541a52 commit 46272b5

File tree

6 files changed

+37
-59
lines changed

6 files changed

+37
-59
lines changed

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.3
1+
1.4

src/power_grid_model_ds/_core/load_flow.py

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
"""Power flow functions and classes"""
66

7+
import warnings
78
from typing import Dict, Optional
89

910
import numpy as np
@@ -50,18 +51,29 @@ def __init__(
5051
self.grid = grid or Grid.empty()
5152
self.system_frequency = system_frequency
5253

53-
self.input_data = input_data or {}
54+
self._input_data = input_data or {}
5455
self.output_data: dict[str, NDArray] = {}
5556
self.model: Optional[PowerGridModel] = None
5657

58+
@property
59+
def input_data(self) -> Dict[str, NDArray]:
60+
"""Get the input data for the PowerGridModel."""
61+
warnings.warn(
62+
"Input data has been made private and will be removed as public properety in a future version. "
63+
"Do not use it directly.",
64+
DeprecationWarning,
65+
stacklevel=2,
66+
)
67+
return self._input_data
68+
5769
def create_input_from_grid(self):
5870
"""
5971
Create input for the PowerGridModel
6072
"""
6173
for array_name in PGM_ARRAYS:
6274
pgm_array = self._create_power_grid_array(array_name=array_name)
63-
self.input_data[array_name] = pgm_array
64-
return self.input_data
75+
self._input_data[array_name] = pgm_array
76+
return self._input_data
6577

6678
def create_grid_from_input_data(self, check_ids: bool = True) -> Grid:
6779
"""
@@ -75,9 +87,9 @@ def create_grid_from_input_data(self, check_ids: bool = True) -> Grid:
7587
Returns a Grid object with the arrays filled with the PowerGridModel input.
7688
"""
7789
for pgm_name in PGM_ARRAYS:
78-
if pgm_name in self.input_data:
90+
if pgm_name in self._input_data:
7991
pgm_ds_array_class = getattr(self.grid, pgm_name).__class__
80-
pgm_ds_array = pgm_ds_array_class(self.input_data[pgm_name])
92+
pgm_ds_array = pgm_ds_array_class(self._input_data[pgm_name])
8193
self.grid.append(pgm_ds_array, check_max_id=False)
8294
if check_ids:
8395
self.grid.check_ids()
@@ -156,6 +168,6 @@ def _match_dtypes(first_dtype: np.dtype, second_dtype: np.dtype):
156168

157169
def setup_model(self):
158170
"""Setup the PowerGridModel with the input data."""
159-
self.input_data = self.input_data or self.create_input_from_grid()
160-
self.model = PowerGridModel(self.input_data, system_frequency=self.system_frequency)
171+
self._input_data = self._input_data or self.create_input_from_grid()
172+
self.model = PowerGridModel(self._input_data, system_frequency=self.system_frequency)
161173
return self.model

src/power_grid_model_ds/_core/model/graphs/container.py

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
"""Stores the GraphContainer class"""
66

77
import dataclasses
8-
import warnings
98
from dataclasses import dataclass
109
from typing import TYPE_CHECKING, Generator
1110

@@ -63,45 +62,18 @@ def add_node_array(self, node_array: NodeArray) -> None:
6362
graph = getattr(self, field.name)
6463
graph.add_node_array(node_array=node_array, raise_on_fail=False)
6564

66-
def add_node(self, node: NodeArray) -> None:
67-
"""Add a node to all graphs"""
68-
warnings.warn(
69-
"add_node is deprecated and will be removed in a future release, use add_node_array instead",
70-
category=DeprecationWarning,
71-
stacklevel=2,
72-
)
73-
self.add_node_array(node_array=node)
74-
7565
def add_branch_array(self, branch_array: BranchArray) -> None:
7666
"""Add a branch to all graphs"""
7767
for field in self.graph_attributes:
7868
graph = getattr(self, field.name)
7969
graph.add_branch_array(branch_array=branch_array)
8070

81-
def add_branch(self, branch: BranchArray) -> None:
82-
"""Add a branch to all graphs"""
83-
warnings.warn(
84-
"add_branch is deprecated and will be removed in a future release, use add_branch_array instead",
85-
category=DeprecationWarning,
86-
stacklevel=2,
87-
)
88-
self.add_branch_array(branch_array=branch)
89-
9071
def add_branch3_array(self, branch3_array: Branch3Array) -> None:
9172
"""Add a branch to all graphs"""
9273
for field in self.graph_attributes:
9374
graph = getattr(self, field.name)
9475
graph.add_branch3_array(branch3_array=branch3_array)
9576

96-
def add_branch3(self, branch: Branch3Array) -> None:
97-
"""Add a branch to all graphs"""
98-
warnings.warn(
99-
"add_branch3 is deprecated and will be removed in a future release, use add_branch3_array instead",
100-
category=DeprecationWarning,
101-
stacklevel=2,
102-
)
103-
self.add_branch3_array(branch3_array=branch)
104-
10577
def delete_node(self, node: NodeArray) -> None:
10678
"""Remove a node from all graphs"""
10779
for field in dataclasses.fields(self):

src/power_grid_model_ds/_core/model/graphs/models/base.py

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
#
33
# SPDX-License-Identifier: MPL-2.0
44

5-
import warnings
65
from abc import ABC, abstractmethod
76
from contextlib import contextmanager
87
from typing import TYPE_CHECKING, Generator
@@ -253,23 +252,17 @@ def get_all_paths(self, ext_start_node_id: int, ext_end_node_id: int) -> list[li
253252

254253
return [self._internals_to_externals(path) for path in internal_paths]
255254

256-
def get_components(self, substation_nodes: list[int] | None = None) -> list[list[int]]:
257-
"""Returns all separate components when the substation_nodes are removed of the graph as lists"""
258-
if substation_nodes:
259-
warnings.warn(
260-
message="""
261-
get_components: substation_nodes argument is deprecated and will be removed in a future release.
262-
The functionality is still available with the use of the `tmp_remove_nodes` context manager.
263-
264-
Example:
265-
>>> with graph.tmp_remove_nodes(substation_nodes):
266-
>>> components = graph.get_components()
267-
""",
268-
category=DeprecationWarning,
269-
stacklevel=2,
270-
)
271-
with self.tmp_remove_nodes(substation_nodes or []):
272-
internal_components = self._get_components()
255+
def get_components(self) -> list[list[int]]:
256+
"""Returns all separate components when the substation_nodes are removed of the graph as lists
257+
258+
If you want to get the components of the graph without certain nodes,
259+
use the `tmp_remove_nodes` context manager.
260+
261+
Example:
262+
>>> with graph.tmp_remove_nodes(substation_nodes):
263+
>>> components = graph.get_components()
264+
"""
265+
internal_components = self._get_components()
273266
return [self._internals_to_externals(component) for component in internal_components]
274267

275268
def get_connected(

tests/unit/model/graphs/test_container.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def graph_container_with_5_nodes():
3232
for node_id in range(1, 6):
3333
node = NodeArray.empty(1)
3434
node.id = node_id
35-
graph_container.add_node(node)
35+
graph_container.add_node_array(node)
3636
return graph_container
3737

3838

@@ -53,7 +53,7 @@ def three_winding_transformers():
5353
def test_add_branch3(
5454
graph_container_with_5_nodes: GraphContainer, three_winding_transformers: ThreeWindingTransformerArray
5555
):
56-
graph_container_with_5_nodes.add_branch3(three_winding_transformers)
56+
graph_container_with_5_nodes.add_branch3_array(three_winding_transformers)
5757
for from_node, to_node in [(1, 2), (1, 4), (1, 5), (4, 5)]:
5858
assert graph_container_with_5_nodes.active_graph.has_branch(from_node, to_node)
5959
assert graph_container_with_5_nodes.complete_graph.has_branch(from_node, to_node)
@@ -66,7 +66,7 @@ def test_add_branch3(
6666
def test_delete_branch3(
6767
graph_container_with_5_nodes: GraphContainer, three_winding_transformers: ThreeWindingTransformerArray
6868
):
69-
graph_container_with_5_nodes.add_branch3(three_winding_transformers)
69+
graph_container_with_5_nodes.add_branch3_array(three_winding_transformers)
7070
graph_container_with_5_nodes.delete_branch3(three_winding_transformers[0])
7171

7272
assert not graph_container_with_5_nodes.active_graph.has_branch(1, 2)

tests/unit/model/graphs/test_graph_model.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,13 +192,14 @@ def test_get_components(graph_with_2_routes: BaseGraphModel):
192192
assert set(components[2]) == {100}
193193

194194

195-
def test_get_components_with_substation_nodes(graph_with_2_routes):
195+
def test_get_components_with_tmp_removed_substation_nodes(graph_with_2_routes):
196196
graph = graph_with_2_routes
197197
graph.add_node(99)
198198
graph.add_branch(1, 99)
199199
substation_nodes = np.array([1])
200200

201-
components = graph.get_components(substation_nodes=substation_nodes)
201+
with graph.tmp_remove_nodes(substation_nodes):
202+
components = graph.get_components()
202203

203204
assert len(components) == 3
204205
assert set(components[0]) == {2, 3}

0 commit comments

Comments
 (0)