Skip to content

Commit

Permalink
Bump to 6.4.0-RC2 (#365)
Browse files Browse the repository at this point in the history
* Implements new SecurityAnalysisProvider (#348)
* Remove check on LimitViolationDetector
* Fix various breaking changes

Signed-off-by: lisrte <[email protected]>
  • Loading branch information
Lisrte authored Jun 26, 2024
1 parent ad0b1b5 commit bcce6b1
Show file tree
Hide file tree
Showing 27 changed files with 75 additions and 96 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import java.nio.file.Path;
import java.util.Objects;

import static com.powsybl.commons.test.ComparisonUtils.compareXml;
import static com.powsybl.commons.test.ComparisonUtils.assertXmlEquals;

/**
* @author Florian Dupuy {@literal <florian.dupuy at rte-france.com>}
Expand All @@ -26,11 +26,11 @@ abstract class AbstractDynawoCommonsTest extends AbstractSerDeTest {

protected void compare(String expectedIidmResource, Network actual) throws IOException {
InputStream expected = Objects.requireNonNull(getClass().getResourceAsStream(expectedIidmResource));
compareXml(expected, getInputStream(actual, tmpDir.resolve("actual.xiidm")));
assertXmlEquals(expected, getInputStream(actual, tmpDir.resolve("actual.xiidm")));
}

protected void compare(Network expected, Network actual) throws IOException {
compareXml(getInputStream(expected, tmpDir.resolve("expected.xiidm")),
assertXmlEquals(getInputStream(expected, tmpDir.resolve("expected.xiidm")),
getInputStream(actual, tmpDir.resolve("actual.xiidm")));
}

Expand Down
2 changes: 1 addition & 1 deletion commons/src/test/resources/mergedLoadsMultiBusesVl.xiidm
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<iidm:network xmlns:iidm="http://www.powsybl.org/schema/iidm/1_12" id="multiBusesVl" caseDate="2023-02-17T05:41:11.194+01:00" forecastDistance="0" sourceFormat="test" minimumValidationLevel="STEADY_STATE_HYPOTHESIS">
<iidm:network xmlns:iidm="http://www.powsybl.org/schema/iidm/1_13" id="multiBusesVl" caseDate="2023-02-17T05:41:11.194+01:00" forecastDistance="0" sourceFormat="test" minimumValidationLevel="STEADY_STATE_HYPOTHESIS">
<iidm:substation id="substation">
<iidm:voltageLevel id="vl1" nominalV="250.0" topologyKind="NODE_BREAKER">
<iidm:nodeBreakerTopology>
Expand Down
2 changes: 1 addition & 1 deletion commons/src/test/resources/mergedLoadsPnQn.xiidm
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<iidm:network xmlns:iidm="http://www.powsybl.org/schema/iidm/1_12" id="multiLoads" caseDate="2023-02-17T05:41:11.194+01:00" forecastDistance="0" sourceFormat="test" minimumValidationLevel="STEADY_STATE_HYPOTHESIS">
<iidm:network xmlns:iidm="http://www.powsybl.org/schema/iidm/1_13" id="multiLoads" caseDate="2023-02-17T05:41:11.194+01:00" forecastDistance="0" sourceFormat="test" minimumValidationLevel="STEADY_STATE_HYPOTHESIS">
<iidm:substation id="substation">
<iidm:voltageLevel id="vl1" nominalV="250.0" topologyKind="NODE_BREAKER">
<iidm:nodeBreakerTopology>
Expand Down
2 changes: 1 addition & 1 deletion commons/src/test/resources/mergedLoadsPnQp.xiidm
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<iidm:network xmlns:iidm="http://www.powsybl.org/schema/iidm/1_12" id="multiLoads" caseDate="2023-02-17T05:41:11.194+01:00" forecastDistance="0" sourceFormat="test" minimumValidationLevel="STEADY_STATE_HYPOTHESIS">
<iidm:network xmlns:iidm="http://www.powsybl.org/schema/iidm/1_13" id="multiLoads" caseDate="2023-02-17T05:41:11.194+01:00" forecastDistance="0" sourceFormat="test" minimumValidationLevel="STEADY_STATE_HYPOTHESIS">
<iidm:substation id="substation">
<iidm:voltageLevel id="vl1" nominalV="250.0" topologyKind="NODE_BREAKER">
<iidm:nodeBreakerTopology>
Expand Down
2 changes: 1 addition & 1 deletion commons/src/test/resources/mergedLoadsPpQn.xiidm
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<iidm:network xmlns:iidm="http://www.powsybl.org/schema/iidm/1_12" id="multiLoads" caseDate="2023-02-17T05:41:11.194+01:00" forecastDistance="0" sourceFormat="test" minimumValidationLevel="STEADY_STATE_HYPOTHESIS">
<iidm:network xmlns:iidm="http://www.powsybl.org/schema/iidm/1_13" id="multiLoads" caseDate="2023-02-17T05:41:11.194+01:00" forecastDistance="0" sourceFormat="test" minimumValidationLevel="STEADY_STATE_HYPOTHESIS">
<iidm:substation id="substation">
<iidm:voltageLevel id="vl1" nominalV="250.0" topologyKind="NODE_BREAKER">
<iidm:nodeBreakerTopology>
Expand Down
2 changes: 1 addition & 1 deletion commons/src/test/resources/mergedLoadsPpQp.xiidm
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<iidm:network xmlns:iidm="http://www.powsybl.org/schema/iidm/1_12" id="multiLoads" caseDate="2023-02-17T05:41:11.194+01:00" forecastDistance="0" sourceFormat="test" minimumValidationLevel="STEADY_STATE_HYPOTHESIS">
<iidm:network xmlns:iidm="http://www.powsybl.org/schema/iidm/1_13" id="multiLoads" caseDate="2023-02-17T05:41:11.194+01:00" forecastDistance="0" sourceFormat="test" minimumValidationLevel="STEADY_STATE_HYPOTHESIS">
<iidm:substation id="substation">
<iidm:voltageLevel id="vl1" nominalV="250.0" topologyKind="NODE_BREAKER">
<iidm:nodeBreakerTopology>
Expand Down
2 changes: 1 addition & 1 deletion commons/src/test/resources/mergedThreeLoadsGroups.xiidm
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<iidm:network xmlns:iidm="http://www.powsybl.org/schema/iidm/1_12" id="multiLoads" caseDate="2023-02-17T05:41:11.194+01:00" forecastDistance="0" sourceFormat="test" minimumValidationLevel="STEADY_STATE_HYPOTHESIS">
<iidm:network xmlns:iidm="http://www.powsybl.org/schema/iidm/1_13" id="multiLoads" caseDate="2023-02-17T05:41:11.194+01:00" forecastDistance="0" sourceFormat="test" minimumValidationLevel="STEADY_STATE_HYPOTHESIS">
<iidm:substation id="substation">
<iidm:voltageLevel id="vl1" nominalV="250.0" topologyKind="NODE_BREAKER">
<iidm:nodeBreakerTopology>
Expand Down
2 changes: 1 addition & 1 deletion commons/src/test/resources/nonMergeableLoads.xiidm
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<iidm:network xmlns:iidm="http://www.powsybl.org/schema/iidm/1_12" id="multiLoads" caseDate="2023-02-17T05:41:11.194+01:00" forecastDistance="0" sourceFormat="test" minimumValidationLevel="STEADY_STATE_HYPOTHESIS">
<iidm:network xmlns:iidm="http://www.powsybl.org/schema/iidm/1_13" id="multiLoads" caseDate="2023-02-17T05:41:11.194+01:00" forecastDistance="0" sourceFormat="test" minimumValidationLevel="STEADY_STATE_HYPOTHESIS">
<iidm:substation id="substation">
<iidm:voltageLevel id="vl1" nominalV="250.0" topologyKind="NODE_BREAKER">
<iidm:nodeBreakerTopology>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,21 @@
package com.powsybl.dynaflow;

import com.google.auto.service.AutoService;
import com.powsybl.action.Action;
import com.powsybl.commons.report.ReportNode;
import com.powsybl.computation.ComputationManager;
import com.powsybl.contingency.ContingenciesProvider;
import com.powsybl.dynawo.commons.PowsyblDynawoVersion;
import com.powsybl.iidm.network.Network;
import com.powsybl.security.*;
import com.powsybl.security.interceptors.SecurityAnalysisInterceptor;
import com.powsybl.security.limitreduction.LimitReduction;
import com.powsybl.security.monitor.StateMonitor;
import com.powsybl.security.strategy.OperatorStrategy;
import com.powsybl.security.SecurityAnalysisProvider;
import com.powsybl.security.SecurityAnalysisReport;
import com.powsybl.security.SecurityAnalysisRunParameters;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.List;
import java.util.Objects;
import java.util.concurrent.CompletableFuture;
import java.util.function.Supplier;

import static com.powsybl.dynaflow.DynaFlowConstants.*;
import static com.powsybl.dynaflow.DynaFlowConstants.DYNAFLOW_NAME;

/**
* @author Marcos de Miguel {@literal <demiguelm at aia.es>}
Expand All @@ -49,37 +44,25 @@ public DynaFlowSecurityAnalysisProvider(Supplier<DynaFlowConfig> configSupplier)
@Override
public CompletableFuture<SecurityAnalysisReport> run(Network network,
String workingVariantId,
LimitViolationDetector detector,
LimitViolationFilter filter,
ComputationManager computationManager,
SecurityAnalysisParameters parameters,
ContingenciesProvider contingenciesProvider,
List<SecurityAnalysisInterceptor> interceptors,
List<OperatorStrategy> operatorStrategies,
List<Action> actions,
List<StateMonitor> monitors,
List<LimitReduction> limitReductions,
ReportNode reportNode) {
if (detector != null) {
LOG.error("LimitViolationDetector is not used in Dynaflow implementation.");
}
if (monitors != null && !monitors.isEmpty()) {
SecurityAnalysisRunParameters runParameters) {
if (!runParameters.getMonitors().isEmpty()) {
LOG.error("Monitoring is not possible with Dynaflow implementation. There will not be supplementary information about monitored equipment.");
}
if (operatorStrategies != null && !operatorStrategies.isEmpty()) {
if (!runParameters.getOperatorStrategies().isEmpty()) {
LOG.error("Strategies are not implemented in Dynaflow");
}
if (actions != null && !actions.isEmpty()) {
if (!runParameters.getActions().isEmpty()) {
LOG.error("Actions are not implemented in Dynaflow");
}
if (limitReductions != null && !limitReductions.isEmpty()) {
if (!runParameters.getLimitReductions().isEmpty()) {
LOG.error("Limit reductions are not implemented in Dynaflow");
}
DynaFlowSecurityAnalysis securityAnalysis = new DynaFlowSecurityAnalysis(network, filter, computationManager, configSupplier);
interceptors.forEach(securityAnalysis::addInterceptor);
DynaFlowSecurityAnalysis securityAnalysis = new DynaFlowSecurityAnalysis(network, runParameters.getFilter(), runParameters.getComputationManager(), configSupplier);
runParameters.getInterceptors().forEach(securityAnalysis::addInterceptor);

ReportNode dfsaReportNode = DynaflowReports.createDynaFlowSecurityAnalysisReportNode(reportNode, network.getId());
return securityAnalysis.run(workingVariantId, parameters, contingenciesProvider, dfsaReportNode);
ReportNode dfsaReportNode = DynaflowReports.createDynaFlowSecurityAnalysisReportNode(runParameters.getReportNode(), network.getId());
return securityAnalysis.run(workingVariantId, runParameters.getSecurityAnalysisParameters(), contingenciesProvider, dfsaReportNode);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import java.util.List;
import java.util.Objects;

import static com.powsybl.commons.test.ComparisonUtils.compareTxt;
import static com.powsybl.commons.test.ComparisonUtils.assertTxtEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;

/**
Expand All @@ -40,6 +40,6 @@ void test() throws IOException {
ObjectMapper mapper = JsonUtil.createObjectMapper().registerModule(new SecurityAnalysisJsonModule());
mapper.writerWithDefaultPrettyPrinter().writeValue(stringWriter, violations);

compareTxt(Objects.requireNonNull(getClass().getResourceAsStream("/limitViolations.json")), stringWriter.toString());
assertTxtEquals(Objects.requireNonNull(getClass().getResourceAsStream("/limitViolations.json")), stringWriter.toString());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import java.nio.file.Path;
import java.util.*;

import static com.powsybl.commons.test.ComparisonUtils.compareTxt;
import static com.powsybl.commons.test.ComparisonUtils.assertTxtEquals;
import static com.powsybl.dynaflow.DynaFlowProvider.MODULE_SPECIFIC_PARAMETERS;
import static org.junit.jupiter.api.Assertions.*;

Expand Down Expand Up @@ -205,7 +205,7 @@ void defaultParametersSerialization() throws IOException {

try (InputStream actual = Files.newInputStream(parameterFile);
InputStream expected = getClass().getResourceAsStream("/params_default.json")) {
compareTxt(expected, actual);
assertTxtEquals(expected, actual);
}
}

Expand Down Expand Up @@ -239,7 +239,7 @@ void parametersSerialization() throws IOException {

try (InputStream actual = Files.newInputStream(parameterFile);
InputStream expected = getClass().getResourceAsStream("/params.json")) {
compareTxt(expected, actual);
assertTxtEquals(expected, actual);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
import java.util.Objects;
import java.util.concurrent.ForkJoinPool;

import static com.powsybl.commons.test.ComparisonUtils.compareXml;
import static com.powsybl.commons.test.ComparisonUtils.assertXmlEquals;
import static com.powsybl.dynaflow.DynaFlowConstants.*;
import static com.powsybl.loadflow.LoadFlowResult.Status.FAILED;
import static com.powsybl.loadflow.LoadFlowResult.Status.FULLY_CONVERGED;
Expand Down Expand Up @@ -222,7 +222,7 @@ private void compare(Network expected, Network actual) throws IOException {
NetworkSerDe.write(expected, pexpected);
actual.setCaseDate(expected.getCaseDate());
NetworkSerDe.write(actual, pactual);
compareXml(Files.newInputStream(pexpected), Files.newInputStream(pactual));
assertXmlEquals(Files.newInputStream(pexpected), Files.newInputStream(pactual));
}

private static Network createTestNetwork() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,14 @@

import com.powsybl.commons.PowsyblException;
import com.powsybl.commons.test.AbstractSerDeTest;
import com.powsybl.computation.ComputationManager;
import com.powsybl.computation.local.LocalCommandExecutor;
import com.powsybl.computation.local.LocalComputationConfig;
import com.powsybl.computation.local.LocalComputationManager;
import com.powsybl.contingency.ContingenciesProvider;
import com.powsybl.contingency.Contingency;
import com.powsybl.iidm.network.*;
import com.powsybl.iidm.network.test.EurostagTutorialExample1Factory;
import com.powsybl.loadflow.LoadFlowResult;
import com.powsybl.security.SecurityAnalysis;
import com.powsybl.security.SecurityAnalysisParameters;
import com.powsybl.security.SecurityAnalysisReport;
import com.powsybl.security.SecurityAnalysisResult;
import com.powsybl.security.*;
import com.powsybl.security.json.SecurityAnalysisResultSerializer;
import org.junit.jupiter.api.Test;

Expand All @@ -36,8 +31,8 @@
import java.util.Objects;
import java.util.concurrent.ForkJoinPool;

import static com.powsybl.commons.test.ComparisonUtils.compareTxt;
import static com.powsybl.commons.test.ComparisonUtils.compareXml;
import static com.powsybl.commons.test.ComparisonUtils.assertTxtEquals;
import static com.powsybl.commons.test.ComparisonUtils.assertXmlEquals;
import static com.powsybl.dynaflow.DynaFlowConstants.DYNAFLOW_NAME;
import static com.powsybl.dynaflow.DynaFlowConstants.IIDM_FILENAME;
import static org.junit.jupiter.api.Assertions.assertEquals;
Expand Down Expand Up @@ -86,11 +81,11 @@ public int execute(String program, List<String> args, Path outFile, Path errFile

private void validateInputs(Path workingDir) throws IOException {
if (inputFile != null) {
compareXml(getClass().getResourceAsStream(inputFile), Files.newInputStream(workingDir.resolve(IIDM_FILENAME)));
assertXmlEquals(getClass().getResourceAsStream(inputFile), Files.newInputStream(workingDir.resolve(IIDM_FILENAME)));
}
if (contingencyFile != null) {
InputStream contingencyIs = Objects.requireNonNull(getClass().getResourceAsStream(contingencyFile));
compareTxt(contingencyIs, Files.newInputStream(workingDir.resolve("contingencies.json")));
assertTxtEquals(contingencyIs, Files.newInputStream(workingDir.resolve("contingencies.json")));
}
}

Expand Down Expand Up @@ -120,25 +115,25 @@ void test() throws IOException {
LocalCommandExecutor commandExecutor = new LocalCommandExecutorMock("/dynawo_version.out",
"/SecurityAnalysis/input.xiidm", "/SecurityAnalysis/contingencies.json",
contingencyIds, List.of("/SecurityAnalysis/constraints1.xml", "/SecurityAnalysis/constraints2.xml"));
ComputationManager computationManager = new LocalComputationManager(new LocalComputationConfig(fileSystem.getPath("/working-dir"), 1), commandExecutor, ForkJoinPool.commonPool());

SecurityAnalysisReport report = SecurityAnalysis.run(network, n -> contingencies, SecurityAnalysisParameters.load(), computationManager);
SecurityAnalysisRunParameters runParameters = new SecurityAnalysisRunParameters()
.setComputationManager(new LocalComputationManager(new LocalComputationConfig(fileSystem.getPath("/working-dir"), 1), commandExecutor, ForkJoinPool.commonPool()));
SecurityAnalysisReport report = SecurityAnalysis.run(network, contingencies, runParameters);
SecurityAnalysisResult result = report.getResult();
assertEquals(LoadFlowResult.ComponentResult.Status.CONVERGED, result.getPreContingencyResult().getStatus());

StringWriter writer = new StringWriter();
SecurityAnalysisResultSerializer.write(result, writer);
compareTxt(Objects.requireNonNull(getClass().getResourceAsStream("/SecurityAnalysis/result.json")), writer.toString());
assertTxtEquals(Objects.requireNonNull(getClass().getResourceAsStream("/SecurityAnalysis/result.json")), writer.toString());
}

@Test
void testCallingBadVersionDynawo() throws IOException {
Network network = Network.create("test", "test");
ContingenciesProvider contingenciesProvider = n -> List.of();
LocalCommandExecutor commandExecutor = new LocalCommandExecutorMock("/dynawo_bad_version.out", null);
ComputationManager computationManager = new LocalComputationManager(new LocalComputationConfig(fileSystem.getPath("/working-dir"), 1), commandExecutor, ForkJoinPool.commonPool());
SecurityAnalysisParameters sap = SecurityAnalysisParameters.load();
assertThrows(PowsyblException.class, () -> SecurityAnalysis.run(network, contingenciesProvider, sap, computationManager));
SecurityAnalysisRunParameters runParameters = new SecurityAnalysisRunParameters()
.setComputationManager(new LocalComputationManager(new LocalComputationConfig(fileSystem.getPath("/working-dir"), 1), commandExecutor, ForkJoinPool.commonPool()));
List<Contingency> contingencies = List.of();
assertThrows(PowsyblException.class, () -> SecurityAnalysis.run(network, contingencies, runParameters));
}

private static Network buildNetwork() {
Expand Down
2 changes: 1 addition & 1 deletion dynaflow/src/test/resources/output.xiidm
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<iidm:network xmlns:iidm="http://www.powsybl.org/schema/iidm/1_12" id="test" caseDate="2023-02-17T04:49:40.620+01:00" forecastDistance="0" sourceFormat="test" minimumValidationLevel="STEADY_STATE_HYPOTHESIS">
<iidm:network xmlns:iidm="http://www.powsybl.org/schema/iidm/1_13" id="test" caseDate="2023-02-17T04:49:40.620+01:00" forecastDistance="0" sourceFormat="test" minimumValidationLevel="STEADY_STATE_HYPOTHESIS">
<iidm:substation id="substation">
<iidm:voltageLevel id="vl1" nominalV="400.0" topologyKind="NODE_BREAKER">
<iidm:nodeBreakerTopology>
Expand Down
2 changes: 1 addition & 1 deletion dynaflow/src/test/resources/outputMergedLoads.xiidm
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<iidm:network xmlns:iidm="http://www.powsybl.org/schema/iidm/1_12" id="test" caseDate="2023-02-17T04:57:37.251+01:00" forecastDistance="0" sourceFormat="test" minimumValidationLevel="STEADY_STATE_HYPOTHESIS">
<iidm:network xmlns:iidm="http://www.powsybl.org/schema/iidm/1_13" id="test" caseDate="2023-02-17T04:57:37.251+01:00" forecastDistance="0" sourceFormat="test" minimumValidationLevel="STEADY_STATE_HYPOTHESIS">
<iidm:substation id="substation">
<iidm:voltageLevel id="vl1" nominalV="400.0" topologyKind="NODE_BREAKER">
<iidm:nodeBreakerTopology>
Expand Down
Loading

0 comments on commit bcce6b1

Please sign in to comment.