-
Notifications
You must be signed in to change notification settings - Fork 43
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 proportional scalable infinite loop #3188
Conversation
Signed-off-by: Damien Jeandemange <damien.jeandemange@artelys.com>
…es (even after the fix) Signed-off-by: Philippe Edwards <philippe.edwards@rte-france.com>
Well spotted for the issue! |
Signed-off-by: Philippe Edwards <philippe.edwards@rte-france.com>
Signed-off-by: Damien Jeandemange <damien.jeandemange@artelys.com>
Signed-off-by: Damien Jeandemange <damien.jeandemange@artelys.com>
What should the behaviour be in the following case? (maybe too much of a marginal case for us to worry about) Initially load1 is at 0MW, load2 and load3 are at 100MW, and the coefficients on the different loads are ~100, 1e-5 and 1e-5. If we ask for a 100MW reduction, with the new code, we will scale by 2e-3MW at the first iteration and will exit the loop. |
Signed-off-by: Damien Jeandemange <damien.jeandemange@artelys.com>
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you very much for this pull request
indeed reverted the change causing this, was a bad idea, but maybe could be made different, e.g. if difference I am a bit worried of remaining very small values summed, summing many small floats can be surprising sometimes. You opinion @phiedw ? |
I think this fix seems to be a decent way to fix the issue. I can't think of any cases where the behaviour would not be the expected one. |
yes I am not sure as well refactoring would make things easier I was also wondering if to be on the safe side we should do as below, but cannot build a unit test for that. saving it here so it doesn't get lost: private double iterativeScale(Network n, double asked, ScalingParameters parameters) {
double done = 0;
boolean first = false;
while (Math.abs(asked - done) > EPSILON && notSaturated()) {
checkIterationPercentages();
double previousAskedMinusDone = asked - done;
done += scaleIteration(n, asked - done, parameters);
double newAskedMinusDone = asked - done;
if (Math.abs(previousAskedMinusDone - newAskedMinusDone) < EPSILON) {
if (!first) {
first = true;
} else {
LOGGER.warn("Proportional iterative scale did not distribute more than {} MW between 2 consecutive iterations, " +
"stopping iterative scale. asked={} MW, done={} MW", EPSILON, asked, done);
break;
}
} else {
first = false;
}
updateIterationPercentages();
}
return done;
} |
* Fix proportional scalable infinite loop Signed-off-by: Damien Jeandemange <damien.jeandemange@artelys.com> (cherry picked from commit 2b9eadc)
Please check if the PR fulfills these requirements
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?
Infinite loop in proportional scalable under the following condition:
In this case the iteration percentage of the scalable is never set to zero, there is remaining asked power, and the scaling is stuck in an infinite loop.
May sound like a marginal case, but was observed on real data. On large networks a given load may have a small percentage.
What is the new behavior (if this is a feature change)?
We set iteration percentage to zero when a scalable is saturated, in addition to the existing condition checking that not all asked power has been done.
Does this PR introduce a breaking change or deprecate an API?
Other information: