Skip to content

Commit 5af57ab

Browse files
committed
Remove validation code for JUNCTIONs from the component graph
Signed-off-by: Sahas Subramanian <[email protected]>
1 parent 2161162 commit 5af57ab

File tree

2 files changed

+0
-76
lines changed

2 files changed

+0
-76
lines changed

src/frequenz/sdk/microgrid/_graph.py

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -502,7 +502,6 @@ def validate(self) -> None:
502502
self._validate_graph_root()
503503
self._validate_grid_endpoint()
504504
self._validate_intermediary_components()
505-
self._validate_junctions()
506505
self._validate_leaf_components()
507506

508507
def is_pv_inverter(self, component: Component) -> bool:
@@ -747,7 +746,6 @@ def _validate_graph_root(self) -> None:
747746
valid_root_types = {
748747
ComponentCategory.NONE,
749748
ComponentCategory.GRID,
750-
ComponentCategory.JUNCTION,
751749
}
752750

753751
valid_roots = list(
@@ -822,24 +820,6 @@ def _validate_intermediary_components(self) -> None:
822820
f"{missing_predecessors}"
823821
)
824822

825-
def _validate_junctions(self) -> None:
826-
"""Check that junctions are configured correctly in the graph.
827-
828-
Raises:
829-
InvalidGraphError: if any junction has no successors (it is allowed
830-
for a single junction to be the root of the component graph, in
831-
which case it will have no predecessors: this is taken care of
832-
by the `_validate_graph_root` check)
833-
"""
834-
junctions = self.components(component_category={ComponentCategory.JUNCTION})
835-
no_successors = list(
836-
filter(lambda c: self._graph.out_degree(c.component_id) == 0, junctions)
837-
)
838-
if len(no_successors) > 0:
839-
raise InvalidGraphError(
840-
f"Junctions missing graph successors: {no_successors}"
841-
)
842-
843823
def _validate_leaf_components(self) -> None:
844824
"""Check that leaf components (e.g. batteries) are configured correctly.
845825

tests/microgrid/test_graph.py

Lines changed: 0 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -804,21 +804,6 @@ def test_validate(self) -> None:
804804
):
805805
graph.validate()
806806

807-
# junctions are not set up correctly: a junction has no
808-
# successors in the graph
809-
graph._graph.clear()
810-
graph._graph.add_nodes_from(
811-
[
812-
(1, asdict(Component(1, ComponentCategory.GRID))),
813-
(2, asdict(Component(2, ComponentCategory.JUNCTION))),
814-
]
815-
)
816-
graph._graph.add_edges_from([(1, 2)])
817-
with pytest.raises(
818-
gr.InvalidGraphError, match="Junctions missing graph successors"
819-
):
820-
graph.validate()
821-
822807
# leaf components are not set up correctly: a battery has
823808
# a successor in the graph
824809
graph._graph.clear()
@@ -1129,47 +1114,6 @@ def test__validate_intermediary_components(self) -> None:
11291114
graph._graph.add_edges_from([(1, 2), (2, 3), (3, 4)])
11301115
graph._validate_intermediary_components()
11311116

1132-
def test__validate_junctions(self) -> None:
1133-
graph = gr._MicrogridComponentGraph()
1134-
assert set(graph.components()) == set()
1135-
assert list(graph.connections()) == []
1136-
1137-
# successors missing for at least one junction
1138-
graph._graph.clear()
1139-
graph._graph.add_nodes_from(
1140-
[(1, asdict(Component(1, ComponentCategory.JUNCTION)))]
1141-
)
1142-
with pytest.raises(
1143-
gr.InvalidGraphError, match="Junctions missing graph successors"
1144-
):
1145-
graph._validate_junctions()
1146-
1147-
graph._graph.clear()
1148-
graph._graph.add_nodes_from(
1149-
[
1150-
(1, asdict(Component(1, ComponentCategory.JUNCTION))),
1151-
(2, asdict(Component(2, ComponentCategory.JUNCTION))),
1152-
]
1153-
)
1154-
graph._graph.add_edges_from([(1, 2)])
1155-
with pytest.raises(
1156-
gr.InvalidGraphError, match="Junctions missing graph successors"
1157-
):
1158-
graph._validate_junctions()
1159-
1160-
# all junctions have at least one successor
1161-
graph._graph.clear()
1162-
graph._graph.add_nodes_from(
1163-
[
1164-
(1, asdict(Component(1, ComponentCategory.JUNCTION))),
1165-
(2, asdict(Component(2, ComponentCategory.JUNCTION))),
1166-
(3, asdict(Component(3, ComponentCategory.METER))),
1167-
]
1168-
)
1169-
1170-
graph._graph.add_edges_from([(1, 2), (2, 3)])
1171-
graph._validate_junctions()
1172-
11731117
def test__validate_leaf_components(self) -> None:
11741118
# to ensure clean testing of the individual method,
11751119
# we cheat by setting underlying graph data directly

0 commit comments

Comments
 (0)