component_graph
frequenz.sdk.microgrid.component_graph ¤
Defines a graph representation of how microgrid components are connected.
The component graph is an approximate representation of the microgrid circuit, abstracted to a level appropriate for higher-level monitoring and control. Examples of use-cases would be:
-
using the graph structure to infer which component measurements need to be combined to obtain grid power or onsite load
-
identifying which inverter(s) need to be engaged to (dis)charge a particular battery
-
understanding which power flows in the microgrid are derived from green and grey sources
It deliberately does not include all pieces of hardware placed in the microgrid, instead limiting itself to just those that are needed to monitor and control the flow of power.
Classes¤
frequenz.sdk.microgrid.component_graph.ComponentGraph ¤
Bases: ABC
Interface for component graph implementations.
Source code in frequenz/sdk/microgrid/component_graph.py
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 |
|
Functions¤
components
abstractmethod
¤
components(
component_ids: set[int] | None = None,
component_categories: (
set[ComponentCategory] | None
) = None,
) -> set[Component]
Fetch the components of the microgrid.
PARAMETER | DESCRIPTION |
---|---|
component_ids
|
filter out any components not matching one of the provided IDs |
component_categories
|
filter out any components not matching one of the provided types
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
set[Component]
|
Set of the components currently connected to the microgrid, filtered by
the provided |
Source code in frequenz/sdk/microgrid/component_graph.py
connections
abstractmethod
¤
Fetch the connections between microgrid components.
PARAMETER | DESCRIPTION |
---|---|
start
|
filter out any connections whose |
end
|
filter out any connections whose |
RETURNS | DESCRIPTION |
---|---|
set[Connection]
|
Set of the connections between components in the microgrid, filtered by
the provided |
Source code in frequenz/sdk/microgrid/component_graph.py
dfs
abstractmethod
¤
dfs(
current_node: Component,
visited: set[Component],
condition: Callable[[Component], bool],
) -> set[Component]
Search for components that fulfill the condition in the Graph.
DFS is used for searching the graph. The graph traversal is stopped once a component fulfills the condition.
PARAMETER | DESCRIPTION |
---|---|
current_node
|
The current node to search from.
TYPE:
|
visited
|
The set of visited nodes. |
condition
|
The condition function to check for. |
RETURNS | DESCRIPTION |
---|---|
set[Component]
|
A set of component ids where the corresponding components fulfill |
set[Component]
|
the condition function. |
Source code in frequenz/sdk/microgrid/component_graph.py
find_first_descendant_component
abstractmethod
¤
find_first_descendant_component(
*,
root_category: ComponentCategory,
descendant_categories: Iterable[ComponentCategory]
) -> Component
Find the first descendant component given root and descendant categories.
This method searches for the root component within the provided root category. If multiple components share the same root category, the first found one is considered as the root component.
Subsequently, it looks for the first descendant component from the root component, considering only the immediate descendants.
The priority of the component to search for is determined by the order of the descendant categories, with the first category having the highest priority.
PARAMETER | DESCRIPTION |
---|---|
root_category
|
The category of the root component to search for.
TYPE:
|
descendant_categories
|
The descendant categories to search for the first descendant component in.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Component
|
The first descendant component found in the component graph, |
Component
|
considering the specified root and descendant categories. |
Source code in frequenz/sdk/microgrid/component_graph.py
is_battery_chain
abstractmethod
¤
Check if the specified component is part of a battery chain.
A component is part of a battery chain if it is a battery meter or a battery inverter.
PARAMETER | DESCRIPTION |
---|---|
component
|
component to check.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
bool
|
Whether the specified component is part of a battery chain. |
Source code in frequenz/sdk/microgrid/component_graph.py
is_battery_inverter
abstractmethod
¤
is_battery_meter
abstractmethod
¤
Check if the specified component is a battery meter.
This is done by checking if the component has only battery inverters as its predecessors.
PARAMETER | DESCRIPTION |
---|---|
component
|
component to check.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
bool
|
Whether the specified component is a battery meter. |
Source code in frequenz/sdk/microgrid/component_graph.py
is_chp
abstractmethod
¤
is_chp_chain
abstractmethod
¤
Check if the specified component is part of a CHP chain.
A component is part of a CHP chain if it is a CHP meter or a CHP.
PARAMETER | DESCRIPTION |
---|---|
component
|
component to check.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
bool
|
Whether the specified component is part of a CHP chain. |
Source code in frequenz/sdk/microgrid/component_graph.py
is_chp_meter
abstractmethod
¤
Check if the specified component is a CHP meter.
This is done by checking if the component has only CHPs as its successors.
PARAMETER | DESCRIPTION |
---|---|
component
|
component to check.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
bool
|
Whether the specified component is a CHP meter. |
Source code in frequenz/sdk/microgrid/component_graph.py
is_ev_charger
abstractmethod
¤
is_ev_charger_chain
abstractmethod
¤
Check if the specified component is part of an EV charger chain.
A component is part of an EV charger chain if it is an EV charger meter or an EV charger.
PARAMETER | DESCRIPTION |
---|---|
component
|
component to check.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
bool
|
Whether the specified component is part of an EV charger chain. |
Source code in frequenz/sdk/microgrid/component_graph.py
is_ev_charger_meter
abstractmethod
¤
Check if the specified component is an EV charger meter.
This is done by checking if the component has only EV chargers as its successors.
PARAMETER | DESCRIPTION |
---|---|
component
|
component to check.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
bool
|
Whether the specified component is an EV charger meter. |
Source code in frequenz/sdk/microgrid/component_graph.py
is_grid_meter
abstractmethod
¤
Check if the specified component is a grid meter.
This is done by checking if the component is the only successor to the Grid
component.
PARAMETER | DESCRIPTION |
---|---|
component
|
component to check.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
bool
|
Whether the specified component is a grid meter. |
Source code in frequenz/sdk/microgrid/component_graph.py
is_pv_chain
abstractmethod
¤
Check if the specified component is part of a PV chain.
A component is part of a PV chain if it is a PV meter or a PV inverter.
PARAMETER | DESCRIPTION |
---|---|
component
|
component to check.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
bool
|
Whether the specified component is part of a PV chain. |
Source code in frequenz/sdk/microgrid/component_graph.py
is_pv_inverter
abstractmethod
¤
is_pv_meter
abstractmethod
¤
Check if the specified component is a PV meter.
This is done by checking if the component has only PV inverters as its successors.
PARAMETER | DESCRIPTION |
---|---|
component
|
component to check.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
bool
|
Whether the specified component is a PV meter. |
Source code in frequenz/sdk/microgrid/component_graph.py
predecessors
abstractmethod
¤
Fetch the graph predecessors of the specified component.
PARAMETER | DESCRIPTION |
---|---|
component_id
|
numerical ID of the component whose predecessors should be fetched
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
set[Component]
|
Set of IDs of the components that are predecessors of |
RAISES | DESCRIPTION |
---|---|
KeyError
|
if the specified |
Source code in frequenz/sdk/microgrid/component_graph.py
successors
abstractmethod
¤
Fetch the graph successors of the specified component.
PARAMETER | DESCRIPTION |
---|---|
component_id
|
numerical ID of the component whose successors should be fetched
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
set[Component]
|
Set of IDs of the components that are successors of |
RAISES | DESCRIPTION |
---|---|
KeyError
|
if the specified |