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

Improve equation system indexing performance #252

Merged
merged 12 commits into from
Jul 30, 2021
Merged

Conversation

geofjamg
Copy link
Member

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

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

What is the current behavior? (You can also link to an open issue here)

What is the new behavior (if this is a feature change)?

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)

Signed-off-by: Geoffroy Jamgotchian <geoffroy.jamgotchian@rte-france.com>
# Conflicts:
#	src/main/java/com/powsybl/openloadflow/equations/EquationSystem.java
# Conflicts:
#	src/main/java/com/powsybl/openloadflow/equations/EquationSystem.java
Signed-off-by: Geoffroy Jamgotchian <geoffroy.jamgotchian@rte-france.com>
@geofjamg geofjamg requested a review from flo-dup March 23, 2021 16:10
@sonarqubecloud
Copy link

Kudos, SonarCloud Quality Gate passed!

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

100.0% 100.0% Coverage
0.0% 0.0% Duplication

case EQUATION_DEACTIVATED:
invalidate();
if (!sortedEquationsToSolve.isEmpty()) { // not need to remove if not already indexed
Copy link
Contributor

Choose a reason for hiding this comment

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

You could add it to the equations to remove anyway and test instead only once before the remove loop if the equations map is empty.

@@ -118,7 +130,10 @@ public void onEquationTermChange(EquationTerm term, EquationTermEventType eventT
case EQUATION_TERM_ADDED:
case EQUATION_TERM_ACTIVATED:
case EQUATION_TERM_DEACTIVATED:
invalidate();
if (!sortedEquationsToSolve.isEmpty()) { // not need to remove if not already indexed
Copy link
Contributor

Choose a reason for hiding this comment

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

as above, you could add it to equationsToRemove anyway

if (equation.isActive() && EquationUpdateType.DEFAULT == equation.getUpdateType()) {
// do not use equations that would be updated only after NR
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe keep that comment? and/or anticipate this by not adding the equation to the list

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

Comment on lines 85 to 86
for (EquationTerm equationTerm : equation.getTerms()) {
if (equationTerm.isActive()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Just wondering if we shouldn't add a getActiveTerms() or getActiveTermsStream() as it's often what we're looking for.


private void update() {
if (reIndex()) {
int columnCount = 0;
Copy link
Contributor

Choose a reason for hiding this comment

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

Outside that PR, but just realized that we don't check here that the number of equations equals the number of variables. That could be done here instead of waiting until the matrix creation.

@@ -118,7 +130,10 @@ public void onEquationTermChange(EquationTerm term, EquationTermEventType eventT
case EQUATION_TERM_ADDED:
case EQUATION_TERM_ACTIVATED:
case EQUATION_TERM_DEACTIVATED:
Copy link
Contributor

Choose a reason for hiding this comment

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

couldn't you add a termsToRemove list and a termsToAdd list to avoid removing the whole equation and adding it again? well, maybe that's becoming too complex for the possible gain, it's sure easier like it is now - what do you think?

}
}
}
if (!atLeastOneTermIsValid) {
throw new IllegalStateException("Equation " + equation + " is active but all of its terms are inactive");
Copy link
Contributor

Choose a reason for hiding this comment

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

Oh I forgot about that, I didn't get why you removed that check, it could not happen anymore?

geofjamg added 2 commits June 28, 2021 09:17
Signed-off-by: Geoffroy Jamgotchian <geoffroy.jamgotchian@rte-france.com>
@sonarqubecloud
Copy link

Kudos, SonarCloud Quality Gate passed!

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

100.0% 100.0% Coverage
0.0% 0.0% Duplication

geofjamg added 3 commits July 30, 2021 14:38
# Conflicts:
#	src/main/java/com/powsybl/openloadflow/ac/equations/ClosedBranchSide1CurrentMagnitudeEquationTerm.java
#	src/main/java/com/powsybl/openloadflow/ac/equations/ClosedBranchSide2CurrentMagnitudeEquationTerm.java
#	src/main/java/com/powsybl/openloadflow/ac/equations/OpenBranchSide1CurrentMagnitudeEquationTerm.java
#	src/main/java/com/powsybl/openloadflow/ac/equations/OpenBranchSide2CurrentMagnitudeEquationTerm.java
#	src/test/java/com/powsybl/openloadflow/sa/OpenSecurityAnalysisTest.java
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

100.0% 100.0% Coverage
0.0% 0.0% Duplication

@geofjamg geofjamg merged commit 6ffbeed into master Jul 30, 2021
@geofjamg geofjamg deleted the eq_syst_optim_2 branch July 30, 2021 13:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants