Bump component-graph-rs version to 0.5#63
Merged
shsms merged 6 commits intofrequenz-floss:v0.x.xfrom May 6, 2026
Merged
Conversation
Upstream `frequenz-microgrid-component-graph` 0.5 replaces the six
per-category `prefer_X_in_Y_formula` config fields with a global
`prefer_meters_in_component_formulas` plus a `FormulaOverrides`
sub-config, and its `ComponentGraphConfig` fields are now `pub(crate)`
so construction goes through the cg builder instead of struct literals.
Mirrors that on the Python side:
* `ComponentGraphConfig.__init__` swaps the six per-category booleans
for `prefer_meters_in_component_formulas: bool = True` and
`formula_overrides: FormulaOverrides | None = None`.
* Adds a new `FormulaOverrides` pyclass exposing the six per-formula
`prefer_meters_in_<device>_formula: bool | None` overrides, and
re-exports it from the top-level package.
* Both Rust `#[pyo3(signature = ...)]` blocks keep `*,` so all params
stay keyword-only -- the actual forward-compat contract. Adds the
same `*,` to the `ComponentGraphConfig.__init__` stub, where it had
been silently missing.
* The Rust binding constructor now drives the cg builder internally
rather than constructing the (newly crate-private) struct directly.
Signed-off-by: Sahas Subramanian <sahas.subramanian@proton.me>
`__init__.pyi` declared `battery_coalesce_formula` and `pv_coalesce_formula`, but the Rust `#[pymethods]` block exposes `battery_ac_coalesce_formula` and `pv_ac_coalesce_formula` (matching the upstream cg crate). Calling the stubbed names raises `AttributeError` at runtime; calling the real names is rejected by `mypy` against this stub. Renames the stubs to match the actual bindings. Signed-off-by: Sahas Subramanian <sahas.subramanian@proton.me>
The stub file is hand-written, so a Rust `#[pymethod]` rename or a new
`#[pyo3(signature = ...)]` parameter must be mirrored manually. The
previous coalesce-method-name drift and the missing kw-only `*,` on
`ComponentGraphConfig.__init__` both went unnoticed for a release
because nothing was checking.
Adds two tests under `tests/test_stub_drift.py`:
* `test_stub_and_runtime_methods_agree` -- the set of public methods
declared on each class in the `.pyi` must equal the set actually
present at runtime. Catches renames, removals, and additions on
either side.
* `test_stub_and_runtime_init_params_agree` -- the `__init__`
parameter names in the stub must equal the runtime
`inspect.signature` parameter list, in order. Catches reordered
or renamed kwargs (which would silently break callers who pass
them positionally if `*,` is ever dropped).
Signed-off-by: Sahas Subramanian <sahas.subramanian@proton.me>
The upstream cg crate gained `ComponentGraph::steam_boiler_formula` in 0.5 (alongside the new `SteamBoiler` component category), but the Python bindings never wired it up. Adds the binding and the matching stub. Signed-off-by: Sahas Subramanian <sahas.subramanian@proton.me>
llucax
reviewed
May 6, 2026
Contributor
llucax
left a comment
There was a problem hiding this comment.
I'm being mostly a AI proxy here. It all sounds relatively minor to me, so posting mostly in case there is anything here you want to address.
LGTM in general, so I'm approving anyway in case you want to merge as-is.
Breaking changes detected
| Area | Change | Notes |
|---|---|---|
| Python API signature | ComponentGraphConfig.__init__ becomes keyword-only |
Existing positional calls break. |
| Python API signature | Removed old flags: 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 |
Replaced by global prefer_meters_in_component_formulas plus FormulaOverrides. |
| Python API addition | New FormulaOverrides class |
Exported in __init__.py and __all__. |
| Python API addition | New steam_boiler_formula() method |
Stub and Rust binding added. |
| Stub API rename | battery_coalesce_formula → battery_ac_coalesce_formula; pv_coalesce_formula → pv_ac_coalesce_formula |
Release notes state runtime already used the new names, so this is mostly a stub correction. |
| Dependency | Rust crate frequenz-microgrid-component-graph 0.4 → 0.5 |
Lockfile checksum updated. |
Testing assessment
The new drift test is useful and directly addresses the stale-stub problem that the PR also fixes. However, current coverage is mostly structural:
| Covered | Missing |
|---|---|
| Runtime public method names vs stub method names | Actual formula generation behavior |
Runtime/stub __init__ parameter names |
Parameter kind/default/required drift |
Export presence for FormulaOverrides indirectly |
FormulaOverrides semantic behavior |
steam_boiler_formula name present |
steam_boiler_formula() valid/error behavior |
I would not block solely on the drift-test limitation, but I would strongly prefer at least one behavioral test for FormulaOverrides, because the new config path is the most user-visible risk in this PR.
Closed
The drift test in `test_stub_drift.py` only catches signature changes; nothing checks that the new `prefer_meters_in_component_formulas` and `FormulaOverrides` actually map through the binding to the expected formula output. An inverted boolean, a swapped override, or a missing builder call would compile, satisfy the stubs, and silently change live formula output. Adds `tests/test_formula_preferences.py`, a parametrised pytest suite that builds a small `Grid -> Meter -> Device` graph for each per-category formula method (PV / wind turbine / battery / CHP / EV charger) and asserts the actual formula string for the four meter/device-preference combinations: * default config -> meter primary * `prefer_meters_in_component_formulas=False` -> device primary * per-formula override = True over global False -> meter primary * per-formula override = False over global True -> device primary Plus four edge-case tests for `steam_boiler_formula`: `None`, empty set, unknown ID, wrong-category ID. The "valid IDs" case is not reachable today because the upstream `frequenz.client.microgrid` package has no `SteamBoiler` component class -- noted in a comment. 24 new test cases; everything in the existing suite still passes. Signed-off-by: Sahas Subramanian <sahas.subramanian@proton.me>
Signed-off-by: Sahas Subramanian <sahas.subramanian@proton.me>
f2d815a to
5d7ab63
Compare
llucax
approved these changes
May 6, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Also revamp the config interface, to follow the rust interface.