Skip to content

Pass-through component support in the Python bindings#49

Draft
shsms wants to merge 5 commits intofrequenz-floss:v0.x.xfrom
shsms:passthrough-categories
Draft

Pass-through component support in the Python bindings#49
shsms wants to merge 5 commits intofrequenz-floss:v0.x.xfrom
shsms:passthrough-categories

Conversation

@shsms
Copy link
Copy Markdown
Collaborator

@shsms shsms commented Apr 30, 2026

Updates the bindings to support the feature to treat unknown categories as pass-through in the rust implementation: frequenz-floss/frequenz-microgrid-component-graph-rs#35

shsms added 5 commits April 30, 2026 09:38
`category_from_python_component` now recognises six additional
classes from `frequenz-client-microgrid` that correspond to the Rust
crate's pass-through categories:

  Converter, Precharger, Electrolyzer, Hvac, CryptoMiner    (1:1 names)
  VoltageTransformer  →  cg::ComponentCategory::PowerTransformer

The last one is a name mismatch the upstream client and the Rust enum
carry from before this work — there's no `PowerTransformer` class on
the Python side and no `VoltageTransformer` variant on the Rust side,
so the mapping crosses the gap.

Adds a `test_passthrough_voltage_transformer` end-to-end test:
builds `Grid → VoltageTransformer → Meter → SolarInverter`, verifies
the graph constructs (the validator walks past the transformer when
checking the meter's predecessor), and asserts that
`predecessors` / `successors` skip it. The next commit extends the
test to also cover `raw_predecessors` / `raw_successors` once those
are exposed.

Signed-off-by: Sahas Subramanian <sahas.subramanian@proton.me>
Wraps the Rust crate's `raw_predecessors` and `raw_successors`
methods on the pyclass so Python callers can ask for the unfiltered,
graph-direct view of a node's neighbors (the one that includes
pass-through nodes), as a counterpart to the now-pass-through-aware
`predecessors` and `successors`.

Updates the type stubs to declare both pairs of methods and document
which is which. Extends the `test_passthrough_voltage_transformer`
test from the previous commits with assertions on the new `raw_*`
methods, exposing the pass-through that the effective view skips.

Signed-off-by: Sahas Subramanian <sahas.subramanian@proton.me>
The four pyclass methods that wrap the Rust crate's
`predecessors` / `successors` / `raw_predecessors` /
`raw_successors` had near-identical bodies: extract the component
id, dispatch to the rust method, map the error onto `ValueError`,
and build a `PySet` from the yielded `&Component`s. Pull that
boilerplate into a private `neighbors_set` free function so each
method shrinks to a single delegating call. Pure refactor; no
behavior or API change.

Signed-off-by: Sahas Subramanian <sahas.subramanian@proton.me>
The upstream `frequenz-client-microgrid` client publishes a `Relay`
class, but internally it carries the protobuf
`ELECTRICAL_COMPONENT_CATEGORY_BREAKER` value (see `_category.py`'s
`RELAY = ELECTRICAL_COMPONENT_CATEGORY_BREAKER`). The Rust crate
doesn't have a separate `Relay` variant either — `Breaker` covers
both, so the mapping lands there to match the upstream protobuf
source of truth.

Like the other pass-through mappings added two commits ago, `Relay`
becomes transparent to validators and formula generators. Extends
the `test_passthrough_category_recognized` parametrize list with
`Relay` so the new arm is exercised.

The Python-side cleanup to expose `Breaker` directly instead of
carrying the `Relay` alias is left for a follow-up.

Signed-off-by: Sahas Subramanian <sahas.subramanian@proton.me>
Local Cargo overrides (e.g. `[paths]` in `.cargo/config.toml`)
shouldn't be checked in — they're per-developer, used to point this
crate at sibling local repos during cross-repo development. Adds the
directory to .gitignore so the clutter stays out of `git status`.

Signed-off-by: Sahas Subramanian <sahas.subramanian@proton.me>
@shsms shsms requested a review from a team as a code owner April 30, 2026 13:07
@shsms shsms requested review from florian-wagner-frequenz and removed request for a team April 30, 2026 13:07
@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 Apr 30, 2026
@shsms shsms marked this pull request as draft April 30, 2026 13:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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.

1 participant