Skip to content

Commit f7d7d18

Browse files
committed
merge main
Signed-off-by: Thijs Baaijen <[email protected]>
2 parents c93cd2f + d61f85d commit f7d7d18

File tree

3 files changed

+53
-12
lines changed

3 files changed

+53
-12
lines changed

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

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
import dataclasses
88
from dataclasses import dataclass
9-
from pathlib import PosixPath
109
from typing import Generator
1110

1211
import numpy as np
@@ -119,15 +118,6 @@ def make_inactive(self, branch: BranchArray) -> None:
119118
graph.delete_branch(from_ext_node_id=from_node, to_ext_node_id=to_node)
120119
setattr(self, field.name, graph)
121120

122-
def cache(self, cache_dir: PosixPath, compress: bool) -> PosixPath:
123-
"""Cache the container into a folder with .pkl and graph files"""
124-
cache_dir.mkdir(parents=True, exist_ok=True)
125-
126-
for field in self.graph_attributes:
127-
graph = getattr(self, field.name)
128-
graph.cache(cache_dir=cache_dir, graph_name=field.name, compress=compress)
129-
return cache_dir
130-
131121
@classmethod
132122
def from_arrays(cls, arrays: MinimalGridArrays) -> "GraphContainer":
133123
"""Build from arrays"""

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,9 +176,9 @@ def delete_branch_array(self, branch_array: BranchArray, raise_on_fail: bool = T
176176
if self._branch_is_relevant(branch):
177177
self.delete_branch(branch.from_node.item(), branch.to_node.item(), raise_on_fail=raise_on_fail)
178178

179-
def delete_branch3_array(self, branch_array: Branch3Array, raise_on_fail: bool = True) -> None:
179+
def delete_branch3_array(self, branch3_array: Branch3Array, raise_on_fail: bool = True) -> None:
180180
"""Delete all branch3s in the branch3 array from the graph."""
181-
for branch3 in branch_array:
181+
for branch3 in branch3_array:
182182
branches = _get_branch3_branches(branch3)
183183
self.delete_branch_array(branches, raise_on_fail=raise_on_fail)
184184

tests/unit/model/graphs/test_container.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,57 @@ def test_from_arrays(basic_grid):
2626
assert set(basic_grid.node.id) == set(graphs.complete_graph.external_ids)
2727

2828

29+
@pytest.fixture
30+
def graph_container_with_5_nodes():
31+
graph_container = GraphContainer.empty()
32+
for node_id in range(1, 6):
33+
node = NodeArray.empty(1)
34+
node.id = node_id
35+
graph_container.add_node(node)
36+
return graph_container
37+
38+
39+
@pytest.fixture
40+
def three_winding_transformers():
41+
three_winding_transformers = ThreeWindingTransformerArray.empty(2)
42+
three_winding_transformers.id = [301, 302]
43+
three_winding_transformers.node_1 = [1, 1]
44+
three_winding_transformers.node_2 = [2, 4]
45+
three_winding_transformers.node_3 = [3, 5]
46+
three_winding_transformers.status_1 = [1, 1]
47+
three_winding_transformers.status_2 = [1, 1]
48+
three_winding_transformers.status_3 = [0, 1]
49+
50+
return three_winding_transformers
51+
52+
53+
def test_add_branch3(graph_container_with_5_nodes, three_winding_transformers):
54+
graph_container_with_5_nodes.add_branch3(three_winding_transformers)
55+
for from_node, to_node in [(1, 2), (1, 4), (1, 5), (4, 5)]:
56+
assert graph_container_with_5_nodes.active_graph.has_branch(from_node, to_node)
57+
assert graph_container_with_5_nodes.complete_graph.has_branch(from_node, to_node)
58+
59+
for from_node, to_node in [(1, 3), (2, 3)]:
60+
assert not graph_container_with_5_nodes.active_graph.has_branch(from_node, to_node)
61+
assert graph_container_with_5_nodes.complete_graph.has_branch(from_node, to_node)
62+
63+
64+
def test_delete_branch3(graph_container_with_5_nodes, three_winding_transformers):
65+
graph_container_with_5_nodes.add_branch3(three_winding_transformers)
66+
graph_container_with_5_nodes.delete_branch3(three_winding_transformers[0])
67+
68+
assert not graph_container_with_5_nodes.active_graph.has_branch(1, 2)
69+
assert not graph_container_with_5_nodes.complete_graph.has_branch(1, 2)
70+
for from_node, to_node in [(1, 4), (1, 5), (4, 5)]:
71+
assert graph_container_with_5_nodes.active_graph.has_branch(from_node, to_node)
72+
assert graph_container_with_5_nodes.complete_graph.has_branch(from_node, to_node)
73+
graph_container_with_5_nodes.delete_branch3(three_winding_transformers[1])
74+
75+
for from_node, to_node in [(1, 2), (1, 4), (1, 5), (4, 5)]:
76+
assert not graph_container_with_5_nodes.active_graph.has_branch(from_node, to_node)
77+
assert not graph_container_with_5_nodes.complete_graph.has_branch(from_node, to_node)
78+
79+
2980
def test_from_arrays_active_three_winding(basic_grid):
3081
nodes = NodeArray.zeros(3)
3182
nodes.id = [1000, 1001, 1002]

0 commit comments

Comments
 (0)