Skip to content

Fix sensor output for disconnected measured components - #1540

Merged
TonyXiang8787 merged 12 commits into
PowerGridModel:mainfrom
appleweiping:fix/1464
Aug 25, 2026
Merged

Fix sensor output for disconnected measured components#1540
TonyXiang8787 merged 12 commits into
PowerGridModel:mainfrom
appleweiping:fix/1464

Conversation

@appleweiping

@appleweiping appleweiping commented Aug 18, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Return null sensor output when a measured source, shunt, load, or generator is disabled, or when the measured terminal of a branch or branch3 is disconnected.
  • Preserve the topology-group check for grids that are not connected to a source, and apply the same terminal-status semantics to power and current sensors.
  • Preserve reduced main-core component-container compatibility with compile-time guards for component types that a container omits.
  • Re-enable the existing symmetric/asymmetric batch regression cases, add focused C++ coverage, and document how sensor-output energized is derived at the measured terminal.

Root cause

Sensor output only checked whether the measured object had a connected mathematical topology group. Status-only updates for shunts, loads, and generators do not rebuild that topology, so a disabled appliance could still produce energized == 1 and non-zero residuals. A partially disconnected branch or branch3 also retains a mathematical group through its connected terminals, so the group alone does not describe whether the terminal measured by a sensor is connected.

The output path now keeps the topology check and additionally reads the actual status of the measured appliance or measured branch terminal. Power and current sensors share the same terminal-status mapping.

Because the measured terminal is selected at runtime, all lookup branches are instantiated at compile time. Compile-time type guards preserve support for reduced component containers that omit unused measured-object types.

Validation

  • uv run --frozen pytest — 1778 passed, 4 skipped, 13 xfailed; 97.13% coverage, using the newly built C++ core.
  • Release power_grid_model_c build — passed, including production model.cpp template instantiation and DLL linking.
  • Focused C++ main-core build and CTest selection — 9/9 passed, including symmetric/asymmetric power and current sensor cases.
  • The two affected dataset fixture families — 9/9 passed.
  • uv run --frozen ruff check ., uv run --frozen reuse lint, clang-format dry-run, and git diff --check — passed.
  • The old behavior returns energized output for a sensor on a disconnected terminal of a partially connected branch/branch3; the new regression cases require null output with zero residuals.

The temporary Python migration reference was removed after the maintainer resolved the C++ test-migration thread.

No public API, schema, or generated file is changed.

Closes #1464

Assisted-by: OpenAI Codex

Return null output for power sensors whose measured appliance is disabled, while preserving topology-based branch behavior.

Signed-off-by: Weiping Yan <152196713+appleweiping@users.noreply.github.com>
@appleweiping
appleweiping marked this pull request as ready for review August 18, 2026 08:53
Comment thread docs/user_manual/components.md Outdated
Comment thread tests/data/state_estimation/dummy-test-line-into-itself/params.json
Comment thread tests/unit/test_sensor_output_energized.py Outdated
Document how sensor output derives energized from the measured object and add symmetric/asymmetric C++ coverage for appliance status and branch topology semantics.

Signed-off-by: Weiping Yan <152196713+appleweiping@users.noreply.github.com>
Comment thread docs/user_manual/components.md Outdated
@mgovers mgovers added the bug Something isn't working label Aug 18, 2026
Keep the sensor section focused on how its output reflects the measured object's energized state and residual behavior.

Signed-off-by: Weiping Yan <152196713+appleweiping@users.noreply.github.com>
Comment thread docs/user_manual/components.md Outdated
Adopt the maintainer's concise sensor-output wording and remove the temporary Python test now that the C++ migration thread is resolved.

Signed-off-by: Weiping Yan <152196713+appleweiping@users.noreply.github.com>
@mgovers
mgovers changed the base branch from main to pin-earlier-pgm-build-dep August 18, 2026 11:56

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 fixes state-estimation power-sensor outputs so that sensors measuring disabled appliances (source, shunt, load, generator) return a null output (energized = 0 and zero residuals), while preserving topology-governed energized semantics for branch/branch3 power sensors and leaving current-sensor behavior unchanged.

Changes:

  • Update main-core power-sensor output logic to additionally gate energized output on the measured appliance’s status() (for appliance terminal types).
  • Re-enable previously xfailed regression datasets by updating expected outputs to reflect null residuals when measured appliances are disabled.
  • Add C++ unit tests for energized/null-output behavior across appliance-vs-branch topology semantics and document the energized derivation in the user manual.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
tests/data/state_estimation/dummy-test-line-into-itself/params.json Removes xfail now that appliance-disabled behavior is fixed.
tests/data/state_estimation/dummy-test-line-into-itself/asym_output_batch.json Updates expected residuals to zeros for null (energized=0) outputs.
tests/data/state_estimation/dummy-test-line-into-itself-minimal/sym_output_batch.json Updates expected null-output residuals to zero for disabled measured appliance.
tests/data/state_estimation/dummy-test-line-into-itself-minimal/params.json Removes xfail now that appliance-disabled behavior is fixed.
tests/cpp_unit_tests/main_core/test_main_core_output.cpp Adds focused unit tests for power/current sensor energized semantics.
power_grid_model_c/power_grid_model/include/power_grid_model/main_core/output.hpp Implements measured-object status gating for appliance-measured power sensors.
docs/user_manual/components.md Documents how energized is derived and that null outputs have zero residuals.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread power_grid_model_c/power_grid_model/include/power_grid_model/main_core/output.hpp Outdated
Guard appliance lookups for reduced component containers and add a compile regression test.

Signed-off-by: Weiping Yan <vipinapple986@gmail.com>
…noreply.github.com>

I, Weiping Yan <152196713+appleweiping@users.noreply.github.com>, hereby add my Signed-off-by to this commit: 7999511

Signed-off-by: Weiping Yan <152196713+appleweiping@users.noreply.github.com>
@mgovers
mgovers deleted the branch PowerGridModel:main August 18, 2026 13:07
@mgovers mgovers closed this Aug 18, 2026
@mgovers

mgovers commented Aug 18, 2026

Copy link
Copy Markdown
Member

Hi @appleweiping, Something seems to have gone wrong with the base branch. I had to change the base branch due to some blocking things in the root, but the base branch was not automatically updated. Can you please re-open the PR and point the base branch to PowerGridModel:main?

@nitbharambe

Copy link
Copy Markdown
Member

I see this PR got closed because underlying branch was deleted. That branch and PR is now merged.
@appleweiping would you please create a new PR where we can continue with the contribution?

@nitbharambe nitbharambe reopened this Aug 18, 2026
@nitbharambe
nitbharambe changed the base branch from pin-earlier-pgm-build-dep to main August 18, 2026 14:19
@nitbharambe

Copy link
Copy Markdown
Member

Nevermind, resolved! We will continue with review here.

@mgovers

mgovers commented Aug 20, 2026

Copy link
Copy Markdown
Member

Hi @appleweiping,

It looks like compilation is failing for MSVC and clang-tidy for unreachable code and misc-include-cleaner reasons, respectively. If you need any help, please let us know and we'll have a look.

Use an explicit constexpr else branch to avoid MSVC's unreachable-code warning and directly include headers required by include-cleaner.

Signed-off-by: Weiping Yan <152196713+appleweiping@users.noreply.github.com>
Comment thread power_grid_model_c/power_grid_model/include/power_grid_model/main_core/output.hpp Outdated
Comment thread tests/cpp_unit_tests/main_core/test_main_core_output.cpp
Apply per-terminal status gating to branch and branch3 power and current sensor outputs while preserving topology checks.

Add symmetric and asymmetric regression coverage for partially disconnected branches, branch3 components, and reduced component containers.

Signed-off-by: Weiping Yan <152196713+appleweiping@users.noreply.github.com>
@appleweiping appleweiping changed the title Fix power sensor output for disabled appliances Fix sensor output for disconnected measured components Aug 24, 2026

@TonyXiang8787 TonyXiang8787 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Hi @appleweiping,

Thank you again for your contribution. The PR is in good shape and will be added to the merge queue if CI succeeds.

@TonyXiang8787
TonyXiang8787 added this pull request to the merge queue Aug 25, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Aug 25, 2026

@TonyXiang8787 TonyXiang8787 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Hi @appleweiping,

The code is now breaking due to another change in #1546 causing the code not compatible anymore. Please have a look and adjust accordingly.

Register Edge as retrievable in the current sensor output test state after the topology base migration in PowerGridModel#1546.

Signed-off-by: Weiping Yan <152196713+appleweiping@users.noreply.github.com>
@appleweiping

Copy link
Copy Markdown
Contributor Author

Thanks, Tony. I adapted the current-sensor output test state to the Edge topology base introduced by #1546 in commit 91cc2ff, while retaining Branch because the sensor object sequence is still branch-relative.

I verified the change against a fresh snapshot of the merged head with GCC 14 / C++23: the main-core target builds and all 9 test cases (266 assertions) pass. clang-format --dry-run --Werror also passes. The full CI has been triggered again.

@TonyXiang8787
TonyXiang8787 added this pull request to the merge queue Aug 25, 2026
Merged via the queue into PowerGridModel:main with commit ef509da Aug 25, 2026
32 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] inconsistent sensor output behavior on disconnected branches vs appliances

5 participants