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

Bump to powsybl-core 6.4.0-SNAPSHOT #347

Closed
wants to merge 11 commits into from
22 changes: 17 additions & 5 deletions .github/workflows/maven.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,28 +18,40 @@ jobs:

steps:
- name: Checkout sources
uses: actions/checkout@v1
uses: actions/checkout@v4
with:
path: main

- name: Checkout powsybl-core branch
uses: actions/checkout@v4
with:
repository: powsybl/powsybl-core
ref: refs/heads/main
path: powsybl-core

- name: Set up JDK 17
uses: actions/setup-java@v1
with:
java-version: 17

- name: Build and install powsybl-core with Maven
run: mvn --batch-mode -DskipTests=true --file ./powsybl-core/pom.xml install

- name: Build with Maven
if: matrix.os == 'ubuntu-latest'
run: mvn --batch-mode -Pintegration-tests,jacoco install
run: mvn --batch-mode -Pintegration-tests,jacoco --file ./main/pom.xml install

- name: Build with Maven
if: matrix.os != 'ubuntu-latest'
run: mvn --batch-mode install
run: mvn --batch-mode --file ./main/pom.xml install

- name: Run SonarCloud analysis
if: matrix.os == 'ubuntu-latest'
run: >
mvn --batch-mode -DskipTests sonar:sonar
mvn --batch-mode -DskipTests --file ./main/pom.xml sonar:sonar
-Dsonar.host.url=https://sonarcloud.io
-Dsonar.organization=powsybl-ci-github
-Dsonar.projectKey=com.powsybl:powsybl-dynawo
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
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
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,24 @@ 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()));
assertThrows(PowsyblException.class, () -> SecurityAnalysis.run(network, List.of(), runParameters));
}

private static Network buildNetwork() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,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 Down Expand Up @@ -73,7 +73,7 @@ public void validate(String schemaDefinition, String expectedResourceName, Path
Schema schema = factory.newSchema(xsd);
Validator validator = schema.newValidator();
validator.validate(xml);
compareTxt(expected, actual);
assertTxtEquals(expected, actual);
}

void setupDynawaltzContext() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,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;

/**
* @author Laurent Issertial {@literal <laurent.issertial at rte-france.com>}
Expand All @@ -52,7 +52,7 @@ public void validate(String schemaDefinition, String expectedResourceName, Path
Schema schema = factory.newSchema(xsd);
Validator validator = schema.newValidator();
validator.validate(xml);
compareTxt(expected, actual);
assertTxtEquals(expected, actual);
}

void setupDynawaltzContext() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,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;

/**
* @author Marcos de Miguel {@literal <demiguelm at aia.es>}
Expand Down Expand Up @@ -161,7 +161,7 @@ public void validate(String schemaDefinition, String expectedResourceName, Path
Schema schema = factory.newSchema(xsd);
Validator validator = schema.newValidator();
validator.validate(xml);
compareTxt(Objects.requireNonNull(getClass().getResourceAsStream("/" + expectedResourceName)), Files.newInputStream(xmlFile));
assertTxtEquals(Objects.requireNonNull(getClass().getResourceAsStream("/" + expectedResourceName)), Files.newInputStream(xmlFile));
}

private static Network createEurostagTutorialExample1WithMoreLoads() {
Expand Down
Loading
Loading