From 5ca2199d07fdf385d95297ce00ed69e56e5e32a6 Mon Sep 17 00:00:00 2001 From: Sahas Subramanian Date: Sun, 21 Dec 2025 11:25:08 +0100 Subject: [PATCH 1/2] Bump `frequenz-microgrid-component-graph` version to 0.4 Signed-off-by: Sahas Subramanian --- Cargo.lock | 4 +-- Cargo.toml | 2 +- .../microgrid_component_graph/__init__.pyi | 33 +++++++++++++++++++ src/graph.rs | 20 ++++++++++- tests/test_microgrid_component_graph.py | 2 +- 5 files changed, 56 insertions(+), 5 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 58958f8..1222991 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -22,9 +22,9 @@ checksum = "0ce7134b9999ecaf8bcd65542e436736ef32ddca1b3e06094cb6ec5755203b80" [[package]] name = "frequenz-microgrid-component-graph" -version = "0.3.0" +version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "96b3e6a856da39ea69dcfa516398e87c1e1b655f33df0530fefd35dcb7ab724f" +checksum = "eb3e7cc6d7f8b142a41cd40ada08e2c94334a64adcfa9a6162dd964a590d7305" dependencies = [ "petgraph", "tracing", diff --git a/Cargo.toml b/Cargo.toml index c21a50c..0d1b161 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,4 +10,4 @@ crate-type = ["cdylib"] [dependencies] pyo3 = "0.27.1" -frequenz-microgrid-component-graph = "0.3.0" +frequenz-microgrid-component-graph = "0.4" diff --git a/python/frequenz/microgrid_component_graph/__init__.pyi b/python/frequenz/microgrid_component_graph/__init__.pyi index 6d77221..1e2a668 100644 --- a/python/frequenz/microgrid_component_graph/__init__.pyi +++ b/python/frequenz/microgrid_component_graph/__init__.pyi @@ -23,6 +23,12 @@ class ComponentGraphConfig: allow_unconnected_components: bool = False, allow_unspecified_inverters: bool = False, disable_fallback_components: bool = False, + include_phantom_loads_in_consumer_formula: bool = False, + prefer_inverters_in_battery_formula: bool = False, + prefer_inverters_in_pv_formula: bool = False, + prefer_chp_in_chp_formula: bool = False, + prefer_ev_chargers_in_ev_formula: bool = False, + prefer_wind_turbines_in_wind_formula: bool = False, ) -> None: """Initialize this instance. @@ -38,6 +44,33 @@ class ComponentGraphConfig: disable_fallback_components: Whether to disable fallback components in generated formulas. When this is `True`, the formulas will not include fallback components. + include_phantom_loads_in_consumer_formula: Whether to consider phantom loads + in the consumer formula. Meters with successors can still have loads + not represented in the component graph. These are called phantom loads. + When this is `true`, phantom loads are included in formulas by excluding + the measurements of successor meters from the measurements of their + predecessor meters. When `false`, consumer formula is generated by + excluding production and battery components from the grid measurements. + prefer_inverters_in_battery_formula: Whether to prefer battery inverters + when generating Battery formulas. When this is `true`, battery inverters + will be the primary source and battery meters will be secondary. When + `false`, battery meters will be the primary source. + prefer_inverters_in_pv_formula: Whether to prefer PV inverters when + generating PV formulas. When this is `true`, PV inverters will be the + primary source and PV meters will be secondary. When `false`, PV meters + will be the primary source. + prefer_chp_in_chp_formula: Whether to prefer CHP when generating CHP + formulas. When this is `true`, CHPs will be the primary source and CHP + meters will be secondary. When `false`, CHP meters will be the primary + source. + prefer_ev_chargers_in_ev_formula: Whether to prefer EV chargers when + generating EV charger formulas. When this is `true`, EV chargers will be + the primary source and EV meters will be secondary. When `false`, EV + meters will be the primary source. + prefer_wind_turbines_in_wind_formula: Whether to prefer wind turbines when + generating wind turbine formulas. When this is `true`, wind turbines + will be the primary source and wind meters will be secondary. When + `false`, wind meters will be the primary source. """ class ComponentIdProtocol(Protocol): diff --git a/src/graph.rs b/src/graph.rs index f0811c5..c75f2ba 100644 --- a/src/graph.rs +++ b/src/graph.rs @@ -30,13 +30,25 @@ impl ComponentGraphConfig { allow_component_validation_failures = false, allow_unconnected_components = false, allow_unspecified_inverters = false, - disable_fallback_components = false + disable_fallback_components = false, + include_phantom_loads_in_consumer_formula = false, + prefer_inverters_in_battery_formula = false, + prefer_inverters_in_pv_formula = false, + prefer_chp_in_chp_formula = false, + prefer_ev_chargers_in_ev_formula = false, + prefer_wind_turbines_in_wind_formula = false, ))] fn new( allow_component_validation_failures: bool, allow_unconnected_components: bool, allow_unspecified_inverters: bool, disable_fallback_components: bool, + include_phantom_loads_in_consumer_formula: bool, + prefer_inverters_in_battery_formula: bool, + prefer_inverters_in_pv_formula: bool, + prefer_chp_in_chp_formula: bool, + prefer_ev_chargers_in_ev_formula: bool, + prefer_wind_turbines_in_wind_formula: bool, ) -> Self { ComponentGraphConfig { config: cg::ComponentGraphConfig { @@ -44,6 +56,12 @@ impl ComponentGraphConfig { allow_unconnected_components, allow_unspecified_inverters, disable_fallback_components, + include_phantom_loads_in_consumer_formula, + prefer_inverters_in_battery_formula, + prefer_inverters_in_pv_formula, + prefer_chp_in_chp_formula, + prefer_ev_chargers_in_ev_formula, + prefer_wind_turbines_in_wind_formula, }, } } diff --git a/tests/test_microgrid_component_graph.py b/tests/test_microgrid_component_graph.py index 86f8c92..6cf4edb 100644 --- a/tests/test_microgrid_component_graph.py +++ b/tests/test_microgrid_component_graph.py @@ -116,7 +116,7 @@ def test_wind_turbine_graph() -> None: # References the Meter (ID 2) measuring the Turbine (ID 3). assert ( graph.wind_turbine_formula(wind_turbine_ids={ComponentId(3)}) - == "COALESCE(#3, #2, 0.0)" + == "COALESCE(#2, #3, 0.0)" ) # 4. Test Topology (Successors/Predecessors) From c0f9fec26cd8e9e5caa8f648bf287cc1e37f1d93 Mon Sep 17 00:00:00 2001 From: Sahas Subramanian Date: Sun, 21 Dec 2025 11:26:44 +0100 Subject: [PATCH 2/2] Update release notes Signed-off-by: Sahas Subramanian --- RELEASE_NOTES.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md index e879121..40dd2cc 100644 --- a/RELEASE_NOTES.md +++ b/RELEASE_NOTES.md @@ -1,5 +1,5 @@ # Frequenz Microgrid Component Graph Library Release Notes -## New Features +## Upgrading -- It is now possible to create subclasses of the `ComponentGraph` and `ComponentGraphConfig` classes from python. +- This release updates the `frequenz-microgrid-component-graph` rust crate version to 0.4.