Skip to content

Commit c2f9de6

Browse files
Fixed component graph validation to allow dangling components
Previously, a strict tree (connected acyclic undirected graph) structure was required, but now components can exist without being connected to anything. Signed-off-by: Elzbieta Kotulska <[email protected]>
1 parent b381834 commit c2f9de6

File tree

2 files changed

+9
-18
lines changed

2 files changed

+9
-18
lines changed

RELEASE_NOTES.md

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,10 @@
22

33
## Summary
44

5-
<!-- Here goes a general summary of what this release is about -->
6-
75
## Upgrading
86

9-
<!-- Here goes notes on how to upgrade from previous versions, including deprecations and what they should be replaced with -->
10-
117
## New Features
128

13-
<!-- Here goes the main new features and examples or instructions on how to use them -->
14-
159
## Bug Fixes
1610

17-
<!-- Here goes notable bug fixes that are worth a special mention or explanation -->
11+
* Fixed component graph validation to allow dangling components. Previously, a strict tree (connected acyclic undirected graph) structure was required, but now components can exist without being connected to anything.

src/frequenz/sdk/microgrid/component_graph.py

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -889,7 +889,7 @@ def _validate_graph(self) -> None:
889889
InvalidGraphError: If:
890890
- There are no components.
891891
- There are no connections.
892-
- The graph is not a tree.
892+
- The graph is not a tree (but tree with dangling components is allowed).
893893
- Any node lacks its associated component data.
894894
"""
895895
if self._graph.number_of_nodes() == 0:
@@ -899,7 +899,7 @@ def _validate_graph(self) -> None:
899899
raise InvalidGraphError("No connections in component graph!")
900900

901901
if not nx.is_directed_acyclic_graph(self._graph):
902-
raise InvalidGraphError("Component graph is not a tree!")
902+
raise InvalidGraphError("Component graph has a cycle!")
903903

904904
# This check doesn't seem to have much sense, it only search for nodes without
905905
# data associated with them. We leave it here for now, but we should consider
@@ -918,15 +918,12 @@ def _validate_graph(self) -> None:
918918
if sum(1 for _ in self.connections()) <= 0:
919919
raise InvalidGraphError("Graph must have a least one connection!")
920920

921-
# should be true as a consequence of the tree property:
922-
# there should be no unconnected components
923-
unconnected = filter(
924-
lambda c: self._graph.degree(c.component_id) == 0, self.components()
925-
)
926-
if sum(1 for _ in unconnected) != 0:
927-
raise InvalidGraphError(
928-
"Every component must have at least one connection!"
929-
)
921+
for component in self.components():
922+
if self._graph.degree(component.component_id) == 0:
923+
_logger.warning(
924+
"Component %s has no connections and will be ignored",
925+
component,
926+
)
930927

931928
def _validate_graph_root(self) -> None:
932929
"""Check that there is exactly one node without predecessors, of valid type.

0 commit comments

Comments
 (0)