Skip to content

Add config load assets api#87

Merged
cwasicki merged 9 commits into
frequenz-floss:v0.x.xfrom
Mohammad-Tayyab-Frequenz:add-config-load-assets-api
Jun 15, 2026
Merged

Add config load assets api#87
cwasicki merged 9 commits into
frequenz-floss:v0.x.xfrom
Mohammad-Tayyab-Frequenz:add-config-load-assets-api

Conversation

@Mohammad-Tayyab-Frequenz

Copy link
Copy Markdown
Contributor

This PR improves how microgrid configuration data is loaded and managed (picked up functions from forecast repo). It adds support for fetching configuration-related information from Assets, including optional formula population from the component graph. It also introduces utilities to combine configuration sources more reliably through merge behavior.

@Mohammad-Tayyab-Frequenz Mohammad-Tayyab-Frequenz requested review from a team as code owners May 21, 2026 12:26
@Mohammad-Tayyab-Frequenz Mohammad-Tayyab-Frequenz requested review from Marenz and removed request for a team May 21, 2026 12:26
@github-actions github-actions Bot added the part:docs Affects the documentation label May 21, 2026

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR extends the microgrid configuration subsystem to support loading configuration-related data directly from the Assets API and introduces reusable merge utilities to combine configuration sources more predictably.

Changes:

  • Added MicrogridConfig.load_configs_from_assets_api(...) to fetch microgrid location metadata from Assets API and optionally populate formulas.
  • Added merge_microgrid_configs(...) and merge_config_maps(...) helpers for deep-merging configs while preventing None overrides.
  • Exported the new merge helpers in the public package API and updated release notes.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.

File Description
src/frequenz/gridpool/_microgrid_config.py Adds an Assets API config loader plus config-merge utilities.
src/frequenz/gridpool/__init__.py Exposes the new merge helpers as part of the public API.
RELEASE_NOTES.md Documents the new loader/merge helpers and includes an upgrade note that needs alignment with actual code changes.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +449 to +453
if populate_formulas:
await populate_missing_formulas(
microgrid_id=microgrid_id,
config=cfg,
assets_client=client,
Comment on lines +518 to +522
def merge_microgrid_configs(
base: MicrogridConfig,
override: MicrogridConfig,
) -> MicrogridConfig:
"""Merge two :class:`MicrogridConfig` objects.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Agree that tests would be good

Comment thread RELEASE_NOTES.md
Comment on lines +5 to 10
This release adds a new Assets API based configuration loader, introduces helpers to merge microgrid configs, and updates PV curtailability behavior to support unspecified values.

## Upgrading

* Change the `curtailable` flag default of the PV config to `None`.
* The `PVConfig.curtailable` field now defaults to `None` and its type changed from `bool` to `bool | None`.

Comment on lines +399 to +405
async def load_configs_from_assets_api(
assets_url: str,
assets_auth_key: str,
assets_sign_secret: str,
microgrid_ids: list[int],
populate_formulas: bool = True,
) -> dict[str, "MicrogridConfig"]:
Comment on lines +518 to +522
def merge_microgrid_configs(
base: MicrogridConfig,
override: MicrogridConfig,
) -> MicrogridConfig:
"""Merge two :class:`MicrogridConfig` objects.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Agree that tests would be good

Comment thread src/frequenz/gridpool/_microgrid_config.py
populate_formulas:
When ``True`` (default), formulas are derived from the component
graph and written into each config via
:func:`populate_missing_formulas`. Set to ``False`` to load

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

These keywords are not rendered as expected in our docs

Returns:
dict[str, MicrogridConfig]:
Mapping from microgrid ID (as string) to the populated
``MicrogridConfig`` instance.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

We use markdown so single ticks are sufficient.

Signed-off-by: Mohammad Tayyab <Mohammad.Tayyab@neustrom.de>
Signed-off-by: Mohammad Tayyab <Mohammad.Tayyab@neustrom.de>
@cwasicki cwasicki force-pushed the add-config-load-assets-api branch from b5a50d8 to d2306bd Compare June 12, 2026 13:34
cwasicki added 7 commits June 12, 2026 16:43
Replace `:func:`/`:class:` cross-reference roles and ``double-backtick``
literals with plain single-backtick Markdown, per the project docstring
style. Docs-only change, no behaviour change.

Signed-off-by: cwasicki <126617870+cwasicki@users.noreply.github.com>
Wrap each microgrid's fetch-and-populate in load_configs_from_assets_api
in a try/except: a microgrid that cannot be loaded is logged as a warning
and skipped, instead of aborting the whole batch.

Signed-off-by: cwasicki <126617870+cwasicki@users.noreply.github.com>
Cover merge_microgrid_configs and merge_config_maps.

Signed-off-by: cwasicki <126617870+cwasicki@users.noreply.github.com>
`generation` is not yet supported.

Signed-off-by: cwasicki <126617870+cwasicki@users.noreply.github.com>
Formulas for all these metrics are the same. The formula name should be
renamed to something more generic in the future.

Signed-off-by: cwasicki <126617870+cwasicki@users.noreply.github.com>
The assets-API loader calls populate_missing_formulas on a config with an
empty ctype map and no explicit component_types, so the previous default
(component types already present in the config) matched nothing and no
formulas were ever written. Default to every derivable component type and
create a ComponentTypeConfig for types not yet in the config.

Signed-off-by: cwasicki <126617870+cwasicki@users.noreply.github.com>
Component types absent from a microgrid yield an empty formula or a bare
zero constant; now that all types are derived by default, guard against
storing those no-op formulas.

Signed-off-by: cwasicki <126617870+cwasicki@users.noreply.github.com>
@github-actions github-actions Bot added the part:tests Affects the unit, integration and performance (benchmarks) tests label Jun 12, 2026
@cwasicki

Copy link
Copy Markdown
Collaborator

Rebased and addressed some of the comments (while Tayyab is on vacation).

@cyiallou Could you have a look at this please.

@cwasicki cwasicki requested a review from cyiallou June 12, 2026 14:45
@cwasicki cwasicki added this pull request to the merge queue Jun 15, 2026
@Mohammad-Tayyab-Frequenz

Copy link
Copy Markdown
Contributor Author

LGTM!

Merged via the queue into frequenz-floss:v0.x.x with commit 81068b2 Jun 15, 2026
8 checks passed
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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants