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

Clean predefined results #618

Merged
merged 13 commits into from
Nov 14, 2022
Merged

Clean predefined results #618

merged 13 commits into from
Nov 14, 2022

Conversation

annetill
Copy link
Member

@annetill annetill commented Oct 5, 2022

Signed-off-by: Anne Tilloy anne.tilloy@rte-france.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

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: Anne Tilloy <anne.tilloy@rte-france.com>
Signed-off-by: Anne Tilloy <anne.tilloy@rte-france.com>
Signed-off-by: Anne Tilloy <anne.tilloy@rte-france.com>
Signed-off-by: Anne Tilloy <anne.tilloy@rte-france.com>
Signed-off-by: Anne Tilloy <anne.tilloy@rte-france.com>
Signed-off-by: Anne Tilloy <anne.tilloy@rte-france.com>
Signed-off-by: Anne Tilloy <anne.tilloy@rte-france.com>
@annetill annetill requested a review from geofjamg October 7, 2022 07:46
Signed-off-by: Anne Tilloy <anne.tilloy@rte-france.com>
@annetill annetill requested a review from flo-dup October 14, 2022 07:12
@annetill annetill changed the title [WIP] Clean predefined results Clean predefined results Oct 17, 2022
Copy link
Contributor

@flo-dup flo-dup left a comment

Choose a reason for hiding this comment

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

Great cleaning!

annetill and others added 3 commits October 20, 2022 09:08
Signed-off-by: Anne Tilloy <anne.tilloy@rte-france.com>
Signed-off-by: Anne Tilloy <anne.tilloy@rte-france.com>
Signed-off-by: Anne Tilloy <anne.tilloy@rte-france.com>
@geofjamg
Copy link
Member

geofjamg commented Nov 9, 2022

@annetill @flo-dup
I tried performance comparison with main branch with such a code:

        Network network = Network.read("<path>");

        List<Contingency> contingencies = network.getLineStream()
                .filter(line -> line.getTerminal1().getVoltageLevel().getSubstation().map(Substation::getNullableCountry).orElse(null) == Country.FR
                        && line.getTerminal2().getVoltageLevel().getSubstation().map(Substation::getNullableCountry).orElse(null) == Country.FR)
                .limit(500)
                .map(line -> Contingency.line(line.getId()))
                .collect(Collectors.toList());

        List<Generator> generators = network.getGeneratorStream()
                .filter(g -> g.getTerminal().getVoltageLevel().getSubstation().map(Substation::getNullableCountry).orElse(null) == Country.FR)
                .limit(1000)
                .collect(Collectors.toList());

        List<Line> lines = network.getLineStream()
                .filter(line -> line.getTerminal1().getVoltageLevel().getSubstation().map(Substation::getNullableCountry).orElse(null) == Country.FR
                        && line.getTerminal2().getVoltageLevel().getSubstation().map(Substation::getNullableCountry).orElse(null) == Country.FR)
                .limit(1000)
                .collect(Collectors.toList());

        SensitivityFactorReader reader = new SensitivityFactorReader() {
            @Override
            public void read(Handler handler) {
                for (Line l : lines) {
                    for (Generator g : generators) {
                        handler.onFactor(SensitivityFunctionType.BRANCH_ACTIVE_POWER, l.getId(),
                                SensitivityVariableType.INJECTION_ACTIVE_POWER, g.getId(), false,
                                ContingencyContext.all());
                    }
                }
            }
        };

        SensitivityResultWriter writer = new SensitivityResultWriter() {
            @Override
            public void writeSensitivityValue(int i, int i1, double v, double v1) {

            }

            @Override
            public void writeContingencyStatus(int i, SensitivityAnalysisResult.Status status) {

            }
        };

        var parameters = new SensitivityAnalysisParameters();
        parameters.getLoadFlowParameters().setDc(true);

        Stopwatch stopwatch = Stopwatch.createStarted();

        SensitivityAnalysis.find("OpenLoadFlow")
                .run(network, VariantManagerConstants.INITIAL_VARIANT_ID, reader, writer, contingencies, List.of(),
                        parameters, LocalComputationManager.getDefault(), Reporter.NO_OP);

        System.out.println("Done in " + stopwatch.elapsed(TimeUnit.MILLISECONDS));

And surprisingly, this branch is much faster: 133 s vs 198 for main branch.

@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 3 Code Smells

95.0% 95.0% Coverage
0.0% 0.0% Duplication

@annetill annetill merged commit ac9b798 into main Nov 14, 2022
@annetill annetill deleted the clean-predefined-results branch November 14, 2022 10:39
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.

4 participants