Skip to content

Bump component-graph-rs version to 0.5#63

Merged
shsms merged 6 commits intofrequenz-floss:v0.x.xfrom
shsms:cg-0.5
May 6, 2026
Merged

Bump component-graph-rs version to 0.5#63
shsms merged 6 commits intofrequenz-floss:v0.x.xfrom
shsms:cg-0.5

Conversation

@shsms
Copy link
Copy Markdown
Collaborator

@shsms shsms commented May 5, 2026

Also revamp the config interface, to follow the rust interface.

shsms added 4 commits May 5, 2026 13:36
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>
@shsms shsms requested a review from a team as a code owner May 5, 2026 14:18
@shsms shsms requested review from Marenz and removed request for a team May 5, 2026 14:18
@github-actions github-actions Bot added part:tests Affects the unit, integration and performance (benchmarks) tests part:tooling Affects the development tooling (CI, deployment, dependency management, etc.) labels May 5, 2026
@github-actions github-actions Bot added the part:docs Affects the documentation label May 5, 2026
Copy link
Copy Markdown
Contributor

@llucax llucax left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_formulabattery_ac_coalesce_formula; pv_coalesce_formulapv_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.40.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.

Comment thread src/graph.rs
Comment thread tests/test_stub_drift.py
Comment thread RELEASE_NOTES.md Outdated
@shsms shsms mentioned this pull request May 6, 2026
shsms added 2 commits May 6, 2026 08:52
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>
@shsms shsms force-pushed the cg-0.5 branch 2 times, most recently from f2d815a to 5d7ab63 Compare May 6, 2026 09:56
@shsms shsms requested a review from llucax May 6, 2026 09:56
@shsms shsms added this pull request to the merge queue May 6, 2026
Merged via the queue into frequenz-floss:v0.x.x with commit 97a4bb2 May 6, 2026
8 checks passed
@shsms shsms deleted the cg-0.5 branch May 6, 2026 11:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

part:docs Affects the documentation part:tests Affects the unit, integration and performance (benchmarks) tests part:tooling Affects the development tooling (CI, deployment, dependency management, etc.)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants