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

Split NR and outer loops max iterations #730

Merged
merged 21 commits into from
Mar 20, 2023

Conversation

geofjamg
Copy link
Member

@geofjamg geofjamg commented Feb 12, 2023

Signed-off-by: Geoffroy Jamgotchian geoffroy.jamgotchian@gmail.com

Please check if the PR fulfills these requirements (please use '[x]' to check the checkboxes, or submit the PR and then click the checkboxes)

  • 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 ? If so, link to this issue using '#XXX' and skip the rest
No

What kind of change does this PR introduce? (Bug fix, feature, docs update, ...)
Feature

What is the current behavior? (You can also link to an open issue here)
We can only control the max number of cumulated NR iterations.

What is the new behavior (if this is a feature change)?
We can control the max number of iterations for each NR run and the max number of outer loop iterations. This will allow to better adapt the max number of outer loop iterations when more and more controls (outer loops) are added without changing the NR configuration.

Does this PR introduce a breaking change or deprecate an API? If yes, check the following:

  • The Breaking Change or Deprecated label has been added
  • The migration guide has been updated in the github wiki (What changes might users need to make in their application due to this PR?)

Other information:

(if any of the questions/checkboxes don't apply, please delete them entirely)

geofjamg and others added 6 commits February 12, 2023 20:38
Signed-off-by: Geoffroy Jamgotchian <geoffroy.jamgotchian@gmail.com>
Signed-off-by: Geoffroy Jamgotchian <geoffroy.jamgotchian@gmail.com>
Signed-off-by: Geoffroy Jamgotchian <geoffroy.jamgotchian@gmail.com>
Signed-off-by: Geoffroy Jamgotchian <geoffroy.jamgotchian@gmail.com>
Signed-off-by: Geoffroy Jamgotchian <geoffroy.jamgotchian@gmail.com>
@geofjamg geofjamg changed the title [WIP] Split NR and outer loops max iterations Split NR and outer loops max iterations Mar 6, 2023
@geofjamg geofjamg requested a review from annetill March 6, 2023 21:51
@geofjamg geofjamg changed the title Split NR and outer loops max iterations [WIP] Split NR and outer loops max iterations Mar 6, 2023
@@ -146,12 +158,9 @@ public AcLoadFlowResult run() {
outerLoop.cleanup(outerLoopContext);
}

int nrIterations = runningContext.lastNrResult.getIteration();
int outerLoopIterations = runningContext.outerLoopIterationByType.values().stream().mapToInt(MutableInt::getValue).sum() + 1;

AcLoadFlowResult result = new AcLoadFlowResult(context.getNetwork(),
Copy link
Member Author

Choose a reason for hiding this comment

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

To fix: add a status for max outer loop iterations reached.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

geofjamg added 2 commits March 7, 2023 13:22
Signed-off-by: Geoffroy Jamgotchian <geoffroy.jamgotchian@rte-france.com>
@geofjamg geofjamg changed the title [WIP] Split NR and outer loops max iterations Split NR and outer loops max iterations Mar 7, 2023
geofjamg and others added 5 commits March 7, 2023 14:01
Signed-off-by: Geoffroy Jamgotchian <geoffroy.jamgotchian@rte-france.com>
# Conflicts:
#	src/main/java/com/powsybl/openloadflow/OpenLoadFlowParameters.java
Signed-off-by: Geoffroy Jamgotchian <geoffroy.jamgotchian@gmail.com>
@@ -54,6 +54,10 @@ private static class RunningContext {
private NewtonRaphsonResult lastNrResult;

private final Map<String, MutableInt> outerLoopIterationByType = new HashMap<>();

private int cumulatedOuterLoopIterations = 0;
Copy link
Member

Choose a reason for hiding this comment

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

cumulated -> cumulative

Copy link
Member Author

Choose a reason for hiding this comment

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

after discussions -> total

private NewtonRaphsonStatus runIteration(StateVectorScaling svScaling) {
LOGGER.debug("Start iteration {}", iteration);
private NewtonRaphsonStatus runIteration(StateVectorScaling svScaling, MutableInt iterations) {
LOGGER.debug("Start iteration {}/{}", iterations, parameters.getMaxIterations());
Copy link
Member

Choose a reason for hiding this comment

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

This is weird: the max iterations is not always the total number of iterations.

Copy link
Member Author

Choose a reason for hiding this comment

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

Removed

@@ -13,23 +13,19 @@
*/
public class NewtonRaphsonParameters {

public static final int DEFAULT_MAX_ITERATION = 30;
public static final int DEFAULT_MAX_ITERATIONS = 15;
Copy link
Member

Choose a reason for hiding this comment

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

Why 15?

Copy link
Member Author

Choose a reason for hiding this comment

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

10 might be too low for very rare and difficult cases, 20 is probably too much so 15...

# Conflicts:
#	src/main/java/com/powsybl/openloadflow/OpenLoadFlowProvider.java
#	src/test/java/com/powsybl/openloadflow/OpenLoadFlowParametersTest.java
#	src/test/java/com/powsybl/openloadflow/OpenLoadFlowProviderTest.java
Signed-off-by: Geoffroy Jamgotchian <geoffroy.jamgotchian@rte-france.com>
Signed-off-by: Geoffroy Jamgotchian <geoffroy.jamgotchian@rte-france.com>
Signed-off-by: Geoffroy Jamgotchian <geoffroy.jamgotchian@rte-france.com>
@geofjamg geofjamg requested a review from annetill March 17, 2023 14:24
# Conflicts:
#	src/test/java/com/powsybl/openloadflow/OpenLoadFlowParametersTest.java
// continue with outer loops only if initial Newton-Raphson succeed
if (runningContext.lastNrResult.getStatus() == NewtonRaphsonStatus.CONVERGED) {

// re-run all outer loops until Newton-Raphson failed or no more Newton-Raphson iterations are needed
int oldIterationCount;
int oldCumulatedNrIterations;
Copy link
Member

Choose a reason for hiding this comment

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

You have kept here oldCumulatedNrIterations.

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed

Signed-off-by: Geoffroy Jamgotchian <geoffroy.jamgotchian@rte-france.com>
Signed-off-by: Geoffroy Jamgotchian <geoffroy.jamgotchian@rte-france.com>
Signed-off-by: Geoffroy Jamgotchian <geoffroy.jamgotchian@rte-france.com>
@sonarqubecloud
Copy link

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 1 Code Smell

95.3% 95.3% Coverage
0.0% 0.0% Duplication

}
}
throw new PowsyblException("No tap position found (should never happen)");
Copy link
Member

Choose a reason for hiding this comment

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

Do we need to log an error message or not? It is the issue I met last week but I am not sure to understand why we can have no tap position...

Copy link
Member

@annetill annetill left a comment

Choose a reason for hiding this comment

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

Maybe just a log but all is okay!

@annetill annetill merged commit 4ae2c3d into main Mar 20, 2023
@annetill annetill deleted the split_nr_outer_loop_max_iterations branch March 20, 2023 08:20
geofjamg added a commit that referenced this pull request Mar 20, 2023
Signed-off-by: Geoffroy Jamgotchian <geoffroy.jamgotchian@rte-france.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants