Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix slack distribution outerloop incorrect stable status #1157

Merged
merged 4 commits into from
Dec 18, 2024

Conversation

jeandemanged
Copy link
Member

@jeandemanged jeandemanged commented Dec 17, 2024

Please check if the PR fulfills these requirements

  • The commit message follows our guidelines
  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been added / updated (for bug fixes / features)

Does this PR already have an issue describing the problem?

No

What kind of change does this PR introduce?

Bug fix

What is the current behavior?

Regression introduced in the #1148 refactoring.
The root problem is not really the refactoring, actually the code before the refactor was hiding a bug. The real problem is the computation of the movedBuses indicator in ActivePowerDistribution.
In the following situation:

  • the slack power to be distributed is small but above threshold, e.g. 0.15 MW vs. 0.10 MW threshold,
  • and there are many elements over which we distribute the mismatch (e.g. 1000 elements)
    then each element moves by only 0.000015 MW, below epsilon threshold. Consequently ActivePowerDistribution reports that no bus has moved.

Next Consequences:

  • DistributedSlackOuterloop returns a stable status,
  • no new NR is launched,
  • result is not balanced at slack bus

What is the new behavior (if this is a feature change)?
movedBuses indicator in ActivePowerDistribution correctly accounts for many many small changes, by summing them instead of checking individual values.

Does this PR introduce a breaking change or deprecate an API?

  • No

Signed-off-by: Damien Jeandemange <damien.jeandemange@artelys.com>
Signed-off-by: Damien Jeandemange <damien.jeandemange@artelys.com>
Signed-off-by: Damien Jeandemange <damien.jeandemange@artelys.com>
@jeandemanged jeandemanged changed the title [WIP] Fix slack distribution regression Fix slack distribution regression Dec 17, 2024
@jeandemanged jeandemanged changed the title Fix slack distribution regression Fix slack distribution outerloop incorrect stable status Dec 17, 2024
final boolean movedBuses = initialP.entrySet().stream()
.anyMatch(e -> Math.abs(e.getKey().getTargetP() - e.getValue()) > P_RESIDUE_EPS);
final boolean movedBuses = Math.abs(initialP.entrySet().stream()
.mapToDouble(e -> e.getKey().getTargetP() - e.getValue()).sum()) > P_RESIDUE_EPS;

Copy link
Collaborator

Choose a reason for hiding this comment

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

If unlucky (mismatch very close to P_RESIDUE_EPS, and roundings you could be below the criteria)
Maybe > P_RESIDUE_EPS*0.9 to avoid rounding effects ?

Copy link
Member Author

Choose a reason for hiding this comment

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

indeed, thanks

final boolean movedBuses = initialP.entrySet().stream()
.anyMatch(e -> Math.abs(e.getKey().getTargetP() - e.getValue()) > P_RESIDUE_EPS);
final boolean movedBuses = Math.abs(initialP.entrySet().stream()
.mapToDouble(e -> e.getKey().getTargetP() - e.getValue()).sum()) > P_RESIDUE_EPS;
Copy link
Contributor

@SylvestreSakti SylvestreSakti Dec 17, 2024

Choose a reason for hiding this comment

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

Isn't it better to sum the abs values instead of doing the abs value of the sum ?

Copy link
Member Author

@jeandemanged jeandemanged Dec 17, 2024

Choose a reason for hiding this comment

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

in today's distribution all elements go always in the same direction, therefore we can spare a few cpu cycles with a single Math.abs
But maybe we should indeed put abs on each element to avoid surprises in the future in case we add more fancy distributions, no strong opinion here ...

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh yes that's true. No strong opinion neither, these cpu cycles may not be perceptible, but it can stay as it is.

Copy link
Member Author

Choose a reason for hiding this comment

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

in the end I change to what you suggested, imagine in the future we do fancy distribution on both loads and generators...

Signed-off-by: Damien Jeandemange <damien.jeandemange@artelys.com>
@jeandemanged jeandemanged added the bug Something isn't working label Dec 18, 2024
@jeandemanged jeandemanged merged commit c7f69ad into main Dec 18, 2024
8 checks passed
@jeandemanged jeandemanged deleted the fix-slack-distrib-regression branch December 18, 2024 08:57
jeandemanged added a commit that referenced this pull request Dec 18, 2024
Signed-off-by: Damien Jeandemange <damien.jeandemange@artelys.com>
(cherry picked from commit c7f69ad)
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.

3 participants