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

Migrate to core 6.4.0 #1034

Merged
merged 9 commits into from
Jun 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<parent>
<groupId>com.powsybl</groupId>
<artifactId>powsybl-parent</artifactId>
<version>16</version>
<version>18</version>
<relativePath/>
</parent>

Expand Down Expand Up @@ -54,7 +54,7 @@
<slf4jtoys.version>1.6.3</slf4jtoys.version>
<asciitable.version>0.3.2</asciitable.version>

<powsybl-core.version>6.3.0</powsybl-core.version>
<powsybl-core.version>6.4.0-RC2</powsybl-core.version>
</properties>

<build>
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/powsybl/openloadflow/network/LfNetwork.java
Original file line number Diff line number Diff line change
Expand Up @@ -698,12 +698,12 @@ public static <T> List<LfNetwork> load(T network, LfNetworkLoader<T> networkLoad
lfNetwork.reportSize(networkReport);
lfNetwork.reportBalance(networkReport);
Reports.reportAngleReferenceBusAndSlackBuses(networkReport, lfNetwork.getReferenceBus().getId(), lfNetwork.getSlackBuses().stream().map(LfBus::getId).toList());
lfNetwork.setReportNode(Reports.createLfNetworkReportNode(reportNode, lfNetwork.getReportNode(), lfNetwork.getNumCC(), lfNetwork.getNumCC()));
lfNetwork.setReportNode(Reports.includeLfNetworkReportNode(reportNode, lfNetwork.getReportNode()));
}
case INVALID_NO_GENERATOR_VOLTAGE_CONTROL -> {
LOGGER.info("Network {} is invalid, no calculation will be done", lfNetwork);
// we want to report this
lfNetwork.setReportNode(Reports.createLfNetworkReportNode(reportNode, lfNetwork.getReportNode(), lfNetwork.getNumCC(), lfNetwork.getNumCC()));
lfNetwork.setReportNode(Reports.includeLfNetworkReportNode(reportNode, lfNetwork.getReportNode()));
}
case INVALID_NO_GENERATOR -> deadComponentsCount++; // will be reported later on altogether
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,9 @@
package com.powsybl.openloadflow.sa;

import com.google.auto.service.AutoService;
import com.powsybl.action.Action;
import com.powsybl.commons.config.PlatformConfig;
import com.powsybl.commons.extensions.Extension;
import com.powsybl.commons.extensions.ExtensionJsonSerializer;
import com.powsybl.commons.report.ReportNode;
import com.powsybl.computation.ComputationManager;
import com.powsybl.contingency.ContingenciesProvider;
import com.powsybl.iidm.network.Network;
import com.powsybl.loadflow.LoadFlowParameters;
Expand All @@ -27,11 +24,10 @@
import com.powsybl.openloadflow.network.LfBus;
import com.powsybl.openloadflow.util.PowsyblOpenLoadFlowVersion;
import com.powsybl.openloadflow.util.ProviderConstants;
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.SecurityAnalysisParameters;
import com.powsybl.security.SecurityAnalysisProvider;
import com.powsybl.security.SecurityAnalysisReport;
import com.powsybl.security.SecurityAnalysisRunParameters;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -63,28 +59,21 @@ public OpenSecurityAnalysisProvider() {
}

@Override
public CompletableFuture<SecurityAnalysisReport> run(Network network, String workingVariantId, LimitViolationDetector limitViolationDetector,
LimitViolationFilter limitViolationFilter, ComputationManager computationManager,
SecurityAnalysisParameters securityAnalysisParameters, ContingenciesProvider contingenciesProvider,
List<SecurityAnalysisInterceptor> interceptors, List<OperatorStrategy> operatorStrategies, List<Action> actions,
List<StateMonitor> stateMonitors, List<LimitReduction> limitReductions, ReportNode reportNode) {
public CompletableFuture<SecurityAnalysisReport> run(Network network,
String workingVariantId,
ContingenciesProvider contingenciesProvider,
SecurityAnalysisRunParameters runParameters) {
Objects.requireNonNull(network);
Objects.requireNonNull(workingVariantId);
Objects.requireNonNull(computationManager);
Objects.requireNonNull(securityAnalysisParameters);
Objects.requireNonNull(contingenciesProvider);
Objects.requireNonNull(interceptors);
Objects.requireNonNull(operatorStrategies);
Objects.requireNonNull(actions);
Objects.requireNonNull(stateMonitors);
Objects.requireNonNull(reportNode);
Objects.requireNonNull(runParameters);

LoadFlowParameters loadFlowParameters = securityAnalysisParameters.getLoadFlowParameters();
LoadFlowParameters loadFlowParameters = runParameters.getSecurityAnalysisParameters().getLoadFlowParameters();
OpenLoadFlowParameters loadFlowParametersExt = OpenLoadFlowParameters.get(loadFlowParameters);

// FIXME implement a fast incremental connectivity algorithm
GraphConnectivityFactory<LfBus, LfBranch> selectedConnectivityFactory;
if (operatorStrategies.isEmpty() && !loadFlowParametersExt.isSimulateAutomationSystems()) {
if (runParameters.getOperatorStrategies().isEmpty() && !loadFlowParametersExt.isSimulateAutomationSystems()) {
selectedConnectivityFactory = connectivityFactory;
} else {
LOGGER.warn("Naive (and slow!!!) connectivity algorithm has been selected because at least one operator strategy is configured");
Expand All @@ -93,12 +82,13 @@ public CompletableFuture<SecurityAnalysisReport> run(Network network, String wor

AbstractSecurityAnalysis<?, ?, ?, ?, ?> securityAnalysis;
if (loadFlowParameters.isDc()) {
securityAnalysis = new DcSecurityAnalysis(network, matrixFactory, selectedConnectivityFactory, stateMonitors, reportNode);
securityAnalysis = new DcSecurityAnalysis(network, matrixFactory, selectedConnectivityFactory, runParameters.getMonitors(), runParameters.getReportNode());
} else {
securityAnalysis = new AcSecurityAnalysis(network, matrixFactory, selectedConnectivityFactory, stateMonitors, reportNode);
securityAnalysis = new AcSecurityAnalysis(network, matrixFactory, selectedConnectivityFactory, runParameters.getMonitors(), runParameters.getReportNode());
}

return securityAnalysis.run(workingVariantId, securityAnalysisParameters, contingenciesProvider, computationManager, operatorStrategies, actions, limitReductions);
return securityAnalysis.run(workingVariantId, runParameters.getSecurityAnalysisParameters(), contingenciesProvider,
runParameters.getComputationManager(), runParameters.getOperatorStrategies(), runParameters.getActions(), runParameters.getLimitReductions());
}

@Override
Expand Down
11 changes: 3 additions & 8 deletions src/main/java/com/powsybl/openloadflow/util/Reports.java
Original file line number Diff line number Diff line change
Expand Up @@ -348,14 +348,9 @@ public static ReportNode createRootLfNetworkReportNode(int networkNumCc, int net
.build();
}

public static ReportNode createLfNetworkReportNode(ReportNode reportNode, ReportNode lfNetworkReportNode, int networkNumCc, int networkNumSc) {
ReportNode newReportNode = reportNode.newReportNode()
.withMessageTemplate("lfNetwork", "Network CC${networkNumCc} SC${networkNumSc}")
.withUntypedValue(NETWORK_NUM_CC, networkNumCc)
.withUntypedValue(NETWORK_NUM_SC, networkNumSc)
.add();
newReportNode.include(lfNetworkReportNode);
return newReportNode;
public static ReportNode includeLfNetworkReportNode(ReportNode reportNode, ReportNode lfNetworkReportNode) {
reportNode.include(lfNetworkReportNode);
return lfNetworkReportNode;
}
olperr1 marked this conversation as resolved.
Show resolved Hide resolved

public static ReportNode createNetworkInfoReporter(ReportNode reportNode) {
Expand Down
28 changes: 11 additions & 17 deletions src/test/java/com/powsybl/openloadflow/NonImpedantBranchTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
*/
package com.powsybl.openloadflow;

import com.powsybl.commons.report.ReportNode;
import com.powsybl.computation.local.LocalComputationManager;
import com.powsybl.contingency.BranchContingency;
import com.powsybl.contingency.ContingenciesProvider;
Expand All @@ -29,7 +28,6 @@
import com.powsybl.openloadflow.sa.OpenSecurityAnalysisParameters;
import com.powsybl.openloadflow.sa.OpenSecurityAnalysisProvider;
import com.powsybl.security.*;
import com.powsybl.security.detectors.DefaultLimitViolationDetector;
import com.powsybl.security.monitor.StateMonitor;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -365,11 +363,11 @@ void securityAnalysisTest() {

ContingenciesProvider provider = n -> contingencies;
SecurityAnalysisProvider securityAnalysisProvider = new OpenSecurityAnalysisProvider(new DenseMatrixFactory(), new EvenShiloachGraphDecrementalConnectivityFactory<>());
SecurityAnalysisReport report = securityAnalysisProvider.run(network, network.getVariantManager().getWorkingVariantId(), new DefaultLimitViolationDetector(),
new LimitViolationFilter(), LocalComputationManager.getDefault(), new SecurityAnalysisParameters(), provider, Collections.emptyList(),
Collections.emptyList(), Collections.emptyList(),
Collections.emptyList(), Collections.emptyList(),
ReportNode.NO_OP).join();
SecurityAnalysisRunParameters runParameters = new SecurityAnalysisRunParameters()
.setFilter(new LimitViolationFilter())
.setComputationManager(LocalComputationManager.getDefault())
.setSecurityAnalysisParameters(new SecurityAnalysisParameters());
SecurityAnalysisReport report = securityAnalysisProvider.run(network, network.getVariantManager().getWorkingVariantId(), provider, runParameters).join();
assertEquals(PostContingencyComputationStatus.CONVERGED, report.getResult().getPostContingencyResults().get(0).getStatus());
assertEquals(PostContingencyComputationStatus.CONVERGED, report.getResult().getPostContingencyResults().get(1).getStatus());
}
Expand Down Expand Up @@ -402,19 +400,15 @@ void securityAnalysisNotSameNumberOfVariablesAndEquationsIssueTest() {
Set.of("tr34"),
Set.of("b0_vl", "b1_vl", "b2_vl", "b3_vl", "b4_vl", "b5_vl"),
Collections.emptySet()));
SecurityAnalysisRunParameters runParameters = new SecurityAnalysisRunParameters()
.setFilter(new LimitViolationFilter())
.setComputationManager(LocalComputationManager.getDefault())
.setSecurityAnalysisParameters(securityAnalysisParameters)
.setMonitors(monitors);
SecurityAnalysisResult result = provider.run(network,
network.getVariantManager().getWorkingVariantId(),
new DefaultLimitViolationDetector(),
new LimitViolationFilter(),
LocalComputationManager.getDefault(),
securityAnalysisParameters,
n -> contingencies,
Collections.emptyList(),
Collections.emptyList(),
Collections.emptyList(),
monitors,
Collections.emptyList(),
ReportNode.NO_OP)
runParameters)
.join()
.getResult();
assertEquals(LoadFlowResult.ComponentResult.Status.CONVERGED, result.getPreContingencyResult().getStatus());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ void test() throws IOException {
Path file = fileSystem.getPath("/work/n.json");
mainNetwork.writeJson(file);
try (InputStream is = Files.newInputStream(file)) {
ComparisonUtils.compareTxt(getClass().getResourceAsStream("/n.json"), is);
ComparisonUtils.assertTxtEquals(getClass().getResourceAsStream("/n.json"), is);
}
}

Expand All @@ -103,7 +103,7 @@ void testPhaseShifter() throws IOException {
Path file = fileSystem.getPath("/work/n2.json");
mainNetwork.writeJson(file);
try (InputStream is = Files.newInputStream(file)) {
ComparisonUtils.compareTxt(getClass().getResourceAsStream("/n2.json"), is);
ComparisonUtils.assertTxtEquals(getClass().getResourceAsStream("/n2.json"), is);
}
}

Expand Down Expand Up @@ -197,7 +197,7 @@ private static void testGraphViz(Network network, boolean breakers, String ref)
try (StringWriter writer = new StringWriter()) {
lfNetwork.writeGraphViz(writer, LoadFlowModel.AC);
writer.flush();
ComparisonUtils.compareTxt(Objects.requireNonNull(LfNetworkTest.class.getResourceAsStream("/" + ref)), writer.toString());
ComparisonUtils.assertTxtEquals(Objects.requireNonNull(LfNetworkTest.class.getResourceAsStream("/" + ref)), writer.toString());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
import com.powsybl.security.SecurityAnalysisParameters;
import com.powsybl.security.SecurityAnalysisReport;
import com.powsybl.security.SecurityAnalysisResult;
import com.powsybl.security.detectors.DefaultLimitViolationDetector;
import com.powsybl.security.SecurityAnalysisRunParameters;
import com.powsybl.security.limitreduction.LimitReduction;
olperr1 marked this conversation as resolved.
Show resolved Hide resolved
import com.powsybl.security.monitor.StateMonitor;
import com.powsybl.security.results.*;
Expand Down Expand Up @@ -138,39 +138,33 @@ protected SecurityAnalysisResult runSecurityAnalysis(Network network, List<Conti
protected SecurityAnalysisResult runSecurityAnalysis(Network network, List<Contingency> contingencies, List<StateMonitor> monitors,
SecurityAnalysisParameters saParameters, ReportNode reportNode) {
ContingenciesProvider provider = n -> contingencies;
SecurityAnalysisRunParameters runParameters = new SecurityAnalysisRunParameters()
.setFilter(new LimitViolationFilter())
.setComputationManager(computationManager)
.setSecurityAnalysisParameters(saParameters)
.setMonitors(monitors)
.setReportNode(reportNode);
SecurityAnalysisReport report = securityAnalysisProvider.run(network,
network.getVariantManager().getWorkingVariantId(),
new DefaultLimitViolationDetector(),
new LimitViolationFilter(),
computationManager,
saParameters,
provider,
Collections.emptyList(),
Collections.emptyList(),
Collections.emptyList(),
monitors,
Collections.emptyList(),
reportNode)
runParameters)
.join();
return report.getResult();
}

protected SecurityAnalysisResult runSecurityAnalysis(Network network, List<Contingency> contingencies, List<StateMonitor> monitors,
List<LimitReduction> limitReductions, SecurityAnalysisParameters saParameters) {
ContingenciesProvider provider = n -> contingencies;
SecurityAnalysisRunParameters runParameters = new SecurityAnalysisRunParameters()
.setFilter(new LimitViolationFilter())
.setComputationManager(computationManager)
.setSecurityAnalysisParameters(saParameters)
.setMonitors(monitors)
.setLimitReductions(limitReductions);
SecurityAnalysisReport report = securityAnalysisProvider.run(network,
network.getVariantManager().getWorkingVariantId(),
new DefaultLimitViolationDetector(),
new LimitViolationFilter(),
computationManager,
saParameters,
provider,
Collections.emptyList(),
Collections.emptyList(),
Collections.emptyList(),
monitors,
limitReductions,
ReportNode.NO_OP)
runParameters)
.join();
return report.getResult();
}
Expand All @@ -179,19 +173,18 @@ protected SecurityAnalysisResult runSecurityAnalysis(Network network, List<Conti
SecurityAnalysisParameters saParameters, List<OperatorStrategy> operatorStrategies,
List<Action> actions, ReportNode reportNode) {
ContingenciesProvider provider = n -> contingencies;
SecurityAnalysisRunParameters runParameters = new SecurityAnalysisRunParameters()
.setFilter(new LimitViolationFilter())
.setComputationManager(computationManager)
.setSecurityAnalysisParameters(saParameters)
.setOperatorStrategies(operatorStrategies)
.setActions(actions)
.setMonitors(monitors)
.setReportNode(reportNode);
SecurityAnalysisReport report = securityAnalysisProvider.run(network,
network.getVariantManager().getWorkingVariantId(),
new DefaultLimitViolationDetector(),
new LimitViolationFilter(),
computationManager,
saParameters,
provider,
Collections.emptyList(),
operatorStrategies,
actions,
monitors,
Collections.emptyList(),
reportNode)
runParameters)
.join();
return report.getResult();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ void test() throws IOException {
}

try (InputStream is = Files.newInputStream(file)) {
ComparisonUtils.compareTxt(Objects.requireNonNull(getClass().getResourceAsStream("/lfc.json")), is);
ComparisonUtils.assertTxtEquals(Objects.requireNonNull(getClass().getResourceAsStream("/lfc.json")), is);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1671,19 +1671,19 @@ void testDebug() throws IOException {
assertNotNull(parametersFile);
assertNotNull(variableSetsFile);
try (InputStream is = Files.newInputStream(contingenciesFile)) {
ComparisonUtils.compareTxt(Objects.requireNonNull(getClass().getResourceAsStream("/debug-contingencies.json")), is);
ComparisonUtils.assertTxtEquals(Objects.requireNonNull(getClass().getResourceAsStream("/debug-contingencies.json")), is);
}
try (InputStream is = Files.newInputStream(factorsFile)) {
ComparisonUtils.compareTxt(Objects.requireNonNull(getClass().getResourceAsStream("/debug-factors.json")), is);
ComparisonUtils.assertTxtEquals(Objects.requireNonNull(getClass().getResourceAsStream("/debug-factors.json")), is);
}
try (InputStream is = Files.newInputStream(networkFile)) {
ComparisonUtils.compareXml(Objects.requireNonNull(getClass().getResourceAsStream("/debug-network.xiidm")), is);
ComparisonUtils.assertXmlEquals(Objects.requireNonNull(getClass().getResourceAsStream("/debug-network.xiidm")), is);
}
try (InputStream is = Files.newInputStream(parametersFile)) {
ComparisonUtils.compareTxt(Objects.requireNonNull(getClass().getResourceAsStream("/debug-parameters.json")), is);
ComparisonUtils.assertTxtEquals(Objects.requireNonNull(getClass().getResourceAsStream("/debug-parameters.json")), is);
}
try (InputStream is = Files.newInputStream(variableSetsFile)) {
ComparisonUtils.compareTxt(Objects.requireNonNull(getClass().getResourceAsStream("/debug-variable-sets.json")), is);
ComparisonUtils.assertTxtEquals(Objects.requireNonNull(getClass().getResourceAsStream("/debug-variable-sets.json")), is);
}

String fileName = contingenciesFile.getFileName().toString();
Expand Down
Loading