Fix sensor output for disconnected measured components - #1540
Conversation
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>
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>
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>
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>
There was a problem hiding this comment.
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
energizedderivation 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.
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>
|
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 |
|
I see this PR got closed because underlying branch was deleted. That branch and PR is now merged. |
|
Nevermind, resolved! We will continue with review here. |
|
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>
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>
TonyXiang8787
left a comment
There was a problem hiding this comment.
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
left a comment
There was a problem hiding this comment.
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>
|
Thanks, Tony. I adapted the current-sensor output test state to the 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. |
Summary
energizedis 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 == 1and 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.power_grid_model_cbuild — passed, including productionmodel.cpptemplate instantiation and DLL linking.uv run --frozen ruff check .,uv run --frozen reuse lint, clang-format dry-run, andgit diff --check— passed.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