Skip to content

Commit

Permalink
Merge branch 'main' into add_dynawaltz_security_analysis
Browse files Browse the repository at this point in the history
Signed-off-by: Florian Dupuy <[email protected]>
  • Loading branch information
flo-dup committed Apr 29, 2024
2 parents bfd8115 + 23add3a commit 855b3d1
Show file tree
Hide file tree
Showing 109 changed files with 1,032 additions and 991 deletions.
2 changes: 1 addition & 1 deletion commons/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<parent>
<artifactId>powsybl-dynawo</artifactId>
<groupId>com.powsybl</groupId>
<version>2.4.0-SNAPSHOT</version>
<version>2.5.0-SNAPSHOT</version>
</parent>

<artifactId>powsybl-dynawo-commons</artifactId>
Expand Down
34 changes: 16 additions & 18 deletions commons/src/main/java/com/powsybl/dynawo/commons/CommonReports.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@
*/
package com.powsybl.dynawo.commons;

import com.powsybl.commons.reporter.Report;
import com.powsybl.commons.reporter.Reporter;
import com.powsybl.commons.reporter.TypedValue;
import com.powsybl.commons.report.ReportNode;
import com.powsybl.commons.report.TypedValue;
import com.powsybl.dynawo.commons.dynawologs.LogEntry;
import com.powsybl.dynawo.commons.timeline.TimelineEntry;

Expand All @@ -24,28 +23,27 @@ public final class CommonReports {
private CommonReports() {
}

public static Reporter createDynawoLogReporter(Reporter reporter) {
return reporter.createSubReporter("dynawoLog",
"Dynawo Log");
public static ReportNode createDynawoLogReportNode(ReportNode reportNode) {
return reportNode.newReportNode()
.withMessageTemplate("dynawoLog", "Dynawo Log")
.add();
}

public static void reportTimelineEvent(Reporter reporter, TimelineEntry timelineEntry) {
reporter.report(Report.builder()
.withKey("DynawoTimelineEvent")
.withDefaultMessage("[t=${time}] ${message} on equipment '${identifiableId}'")
public static void reportTimelineEntry(ReportNode reportNode, TimelineEntry timelineEntry) {
reportNode.newReportNode()
.withMessageTemplate("dynawoTimelineEntry", "[t=${time}] ${message} on equipment '${identifiableId}'")
.withTypedValue("time", timelineEntry.time(), TIME_MS)
.withTypedValue("identifiableId", timelineEntry.modelName(), ID)
.withValue("message", timelineEntry.message())
.withUntypedValue("message", timelineEntry.message())
.withSeverity(TypedValue.TRACE_SEVERITY)
.build());
.add();
}

public static void reportLogEvent(Reporter reporter, LogEntry logEntry) {
reporter.report(Report.builder()
.withKey("DynawoTimelineEvent")
.withDefaultMessage("${message}")
.withValue("message", logEntry.message())
public static void reportLogEntry(ReportNode reportNode, LogEntry logEntry) {
reportNode.newReportNode()
.withMessageTemplate("dynawoLogEntry", "${message}")
.withUntypedValue("message", logEntry.message())
.withSeverity(logEntry.severity())
.build());
.add();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/
package com.powsybl.dynawo.commons.dynawologs;

import com.powsybl.commons.reporter.TypedValue;
import com.powsybl.commons.report.TypedValue;

/**
* @author Laurent Issertial {@literal <laurent.issertial at rte-france.com>}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/
package com.powsybl.dynawo.commons.dynawologs;

import com.powsybl.commons.reporter.TypedValue;
import com.powsybl.commons.report.TypedValue;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down
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,7 +7,7 @@
*/
package com.powsybl.dynawo.commons.dynawologs;

import com.powsybl.commons.reporter.TypedValue;
import com.powsybl.commons.report.TypedValue;
import org.junit.jupiter.api.Test;

import java.net.URISyntaxException;
Expand Down
6 changes: 5 additions & 1 deletion distribution/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<parent>
<artifactId>powsybl-dynawo</artifactId>
<groupId>com.powsybl</groupId>
<version>2.4.0-SNAPSHOT</version>
<version>2.5.0-SNAPSHOT</version>
</parent>

<packaging>pom</packaging>
Expand All @@ -41,6 +41,10 @@
<groupId>${project.groupId}</groupId>
<artifactId>powsybl-dynawaltz-dsl</artifactId>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>powsybl-dynawo-dynamic-security-analysis</artifactId>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>powsybl-dynawo-integration-tests</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion dynaflow/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<parent>
<artifactId>powsybl-dynawo</artifactId>
<groupId>com.powsybl</groupId>
<version>2.4.0-SNAPSHOT</version>
<version>2.5.0-SNAPSHOT</version>
</parent>

<artifactId>powsybl-dynaflow</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/
package com.powsybl.dynaflow;

import com.powsybl.commons.reporter.Reporter;
import com.powsybl.commons.report.ReportNode;
import com.powsybl.contingency.Contingency;
import com.powsybl.dynaflow.xml.ConstraintsReader;
import com.powsybl.dynawo.commons.CommonReports;
Expand Down Expand Up @@ -67,10 +67,10 @@ private static PostContingencyResult getPostContingencyResult(Network network, L
}

// Report the timeline events from the timeline files written by dynawo
public static void reportContingenciesTimelines(List<Contingency> contingencies, Path timelineDir, Reporter reporter) {
public static void reportContingenciesTimelines(List<Contingency> contingencies, Path timelineDir, ReportNode reportNode) {
contingencies.forEach(c -> {
Reporter contingencyReporter = Reports.createContingenciesTimelineReporter(reporter, c.getId());
getTimeline(timelineDir, c).forEach(e -> CommonReports.reportTimelineEvent(contingencyReporter, e));
ReportNode contingencyReporter = Reports.createContingenciesTimelineReporter(reportNode, c.getId());
getTimeline(timelineDir, c).forEach(e -> CommonReports.reportTimelineEntry(contingencyReporter, e));
});
}

Expand Down
17 changes: 10 additions & 7 deletions dynaflow/src/main/java/com/powsybl/dynaflow/DynaFlowHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/
package com.powsybl.dynaflow;

import com.powsybl.commons.reporter.Reporter;
import com.powsybl.commons.report.ReportNode;
import com.powsybl.computation.AbstractExecutionHandler;
import com.powsybl.computation.Command;
import com.powsybl.computation.CommandExecution;
Expand All @@ -29,7 +29,10 @@
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import static com.powsybl.dynaflow.DynaFlowConstants.*;
import static com.powsybl.dynawo.commons.DynawoConstants.DYNAWO_TIMELINE_FOLDER;
Expand All @@ -45,16 +48,16 @@ public class DynaFlowHandler extends AbstractExecutionHandler<LoadFlowResult> {
private final DynaFlowParameters dynaFlowParameters;
private final LoadFlowParameters loadFlowParameters;
private final Command command;
private final Reporter reporter;
private final ReportNode reportNode;

public DynaFlowHandler(Network network, String workingStateId, DynaFlowParameters dynaFlowParameters, LoadFlowParameters loadFlowParameters, Command command, Reporter reporter) {
public DynaFlowHandler(Network network, String workingStateId, DynaFlowParameters dynaFlowParameters, LoadFlowParameters loadFlowParameters, Command command, ReportNode reportNode) {
this.network = network;
this.workingStateId = workingStateId;
this.dynaFlowParameters = dynaFlowParameters;
this.loadFlowParameters = loadFlowParameters;
this.command = command;
this.dynawoInput = this.dynaFlowParameters.isMergeLoads() ? LoadsMerger.mergeLoads(this.network) : this.network;
this.reporter = reporter;
this.reportNode = reportNode;
}

@Override
Expand Down Expand Up @@ -95,11 +98,11 @@ public LoadFlowResult after(Path workingDir, ExecutionReport report) {
}

private void reportTimeLine(Path workingDir) {
Reporter dfReporter = Reports.createDynaFlowReporter(reporter, network.getId());
ReportNode dfReporter = Reports.createDynaFlowReportNode(reportNode, network.getId());
Path timelineFile = workingDir.resolve(DYNAFLOW_OUTPUTS_FOLDER)
.resolve(DYNAWO_TIMELINE_FOLDER)
.resolve(DYNAFLOW_TIMELINE_FILE);
List<TimelineEntry> tl = new XmlTimeLineParser().parse(timelineFile);
tl.forEach(e -> CommonReports.reportTimelineEvent(dfReporter, e));
tl.forEach(e -> CommonReports.reportTimelineEntry(dfReporter, e));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import com.powsybl.commons.extensions.Extension;
import com.powsybl.commons.extensions.ExtensionJsonSerializer;
import com.powsybl.commons.parameters.Parameter;
import com.powsybl.commons.reporter.Reporter;
import com.powsybl.commons.report.ReportNode;
import com.powsybl.computation.*;
import com.powsybl.dynaflow.json.JsonDynaFlowParametersSerializer;
import com.powsybl.dynawo.commons.DynawoUtil;
Expand Down Expand Up @@ -94,7 +94,7 @@ public String getVersion() {

@Override
public CompletableFuture<LoadFlowResult> run(Network network, ComputationManager computationManager, String workingStateId,
LoadFlowParameters loadFlowParameters, Reporter reporter) {
LoadFlowParameters loadFlowParameters, ReportNode reportNode) {
Objects.requireNonNull(network);
Objects.requireNonNull(computationManager);
Objects.requireNonNull(workingStateId);
Expand All @@ -105,7 +105,7 @@ public CompletableFuture<LoadFlowResult> run(Network network, ComputationManager
ExecutionEnvironment execEnv = new ExecutionEnvironment(config.createEnv(), WORKING_DIR_PREFIX, config.isDebug());
Command versionCmd = getVersionCommand(config);
DynawoUtil.requireDynaMinVersion(execEnv, computationManager, versionCmd, DynaFlowConfig.DYNAFLOW_LAUNCHER_PROGRAM_NAME, true);
return computationManager.execute(execEnv, new DynaFlowHandler(network, workingStateId, dynaFlowParameters, loadFlowParameters, getCommand(config), reporter));
return computationManager.execute(execEnv, new DynaFlowHandler(network, workingStateId, dynaFlowParameters, loadFlowParameters, getCommand(config), reportNode));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.ObjectWriter;
import com.powsybl.commons.json.JsonUtil;
import com.powsybl.commons.reporter.Reporter;
import com.powsybl.commons.report.ReportNode;
import com.powsybl.computation.AbstractExecutionHandler;
import com.powsybl.computation.Command;
import com.powsybl.computation.CommandExecution;
Expand Down Expand Up @@ -54,20 +54,20 @@ public final class DynaFlowSecurityAnalysisHandler extends AbstractExecutionHand
private final List<Contingency> contingencies;
private final LimitViolationFilter violationFilter;
private final List<SecurityAnalysisInterceptor> interceptors;
private final Reporter reporter;
private final ReportNode reportNode;

public DynaFlowSecurityAnalysisHandler(Network network, String workingVariantId, Command command,
SecurityAnalysisParameters securityAnalysisParameters, List<Contingency> contingencies,
LimitViolationFilter violationFilter, List<SecurityAnalysisInterceptor> interceptors,
Reporter reporter) {
ReportNode reportNode) {
this.network = network;
this.workingVariantId = workingVariantId;
this.command = command;
this.securityAnalysisParameters = securityAnalysisParameters;
this.contingencies = contingencies;
this.violationFilter = violationFilter;
this.interceptors = interceptors;
this.reporter = reporter;
this.reportNode = reportNode;
}

@Override
Expand All @@ -84,7 +84,7 @@ public List<CommandExecution> before(Path workingDir) throws IOException {
public SecurityAnalysisReport after(Path workingDir, ExecutionReport report) throws IOException {
super.after(workingDir, report);
network.getVariantManager().setWorkingVariant(workingVariantId);
ContingencyResultsUtils.reportContingenciesTimelines(contingencies, workingDir.resolve(DYNAWO_TIMELINE_FOLDER), reporter);
ContingencyResultsUtils.reportContingenciesTimelines(contingencies, workingDir.resolve(DYNAWO_TIMELINE_FOLDER), reportNode);
return new SecurityAnalysisReport(
new SecurityAnalysisResult(
ContingencyResultsUtils.getPreContingencyResult(network, violationFilter),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,20 @@
package com.powsybl.dynaflow;

import com.google.auto.service.AutoService;
import com.powsybl.commons.reporter.Reporter;
import com.powsybl.computation.*;
import com.powsybl.action.Action;
import com.powsybl.commons.report.ReportNode;
import com.powsybl.computation.Command;
import com.powsybl.computation.ComputationManager;
import com.powsybl.computation.ExecutionEnvironment;
import com.powsybl.computation.SimpleCommandBuilder;
import com.powsybl.contingency.ContingenciesProvider;
import com.powsybl.contingency.Contingency;
import com.powsybl.dynawo.commons.DynawoUtil;
import com.powsybl.dynawo.commons.PowsyblDynawoVersion;
import com.powsybl.iidm.network.Network;
import com.powsybl.security.*;
import com.powsybl.security.action.Action;
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 org.slf4j.Logger;
Expand Down Expand Up @@ -62,7 +66,8 @@ public CompletableFuture<SecurityAnalysisReport> run(Network network,
List<OperatorStrategy> operatorStrategies,
List<Action> actions,
List<StateMonitor> monitors,
Reporter reporter) {
List<LimitReduction> limitReductions,
ReportNode reportNode) {
if (detector != null) {
LOG.error("LimitViolationDetector is not used in Dynaflow implementation.");
}
Expand All @@ -75,6 +80,9 @@ public CompletableFuture<SecurityAnalysisReport> run(Network network,
if (actions != null && !actions.isEmpty()) {
LOG.error("Actions are not implemented in Dynaflow");
}
if (limitReductions != null && !limitReductions.isEmpty()) {
LOG.error("Limit reductions are not implemented in Dynaflow");
}

Objects.requireNonNull(computationManager);
Objects.requireNonNull(network);
Expand All @@ -88,9 +96,10 @@ public CompletableFuture<SecurityAnalysisReport> run(Network network,
ExecutionEnvironment execEnv = new ExecutionEnvironment(config.createEnv(), WORKING_DIR_PREFIX, config.isDebug());
DynawoUtil.requireDynaMinVersion(execEnv, computationManager, getVersionCommand(config), DynaFlowConfig.DYNAFLOW_LAUNCHER_PROGRAM_NAME, true);
List<Contingency> contingencies = contingenciesProvider.getContingencies(network);
Reporter dfsaReporter = Reports.createDynaFlowSecurityAnalysisReporter(reporter, network.getId());
ReportNode dfsaReportNode = Reports.createDynaFlowSecurityAnalysisReportNode(reportNode, network.getId());

return computationManager.execute(execEnv, new DynaFlowSecurityAnalysisHandler(network, workingVariantId, getCommand(config), parameters, contingencies, filter, interceptors, dfsaReporter));
DynaFlowSecurityAnalysisHandler executionHandler = new DynaFlowSecurityAnalysisHandler(network, workingVariantId, getCommand(config), parameters, contingencies, filter, interceptors, dfsaReportNode);
return computationManager.execute(execEnv, executionHandler);
}

@Override
Expand Down
40 changes: 40 additions & 0 deletions dynaflow/src/main/java/com/powsybl/dynaflow/DynaflowReports.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/**
* Copyright (c) 2023, RTE (http://www.rte-france.com)
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
* SPDX-License-Identifier: MPL-2.0
*/
package com.powsybl.dynaflow;

import com.powsybl.commons.report.ReportNode;

/**
* @author Florian Dupuy {@literal <florian.dupuy at rte-france.com>}
*/
public final class DynaflowReports {

private DynaflowReports() {
}

public static ReportNode createDynaFlowReportNode(ReportNode reportNode, String networkId) {
return reportNode.newReportNode()
.withMessageTemplate("dynaflow", "Dynaflow loadflow on network '${networkId}'")
.withUntypedValue("networkId", networkId)
.add();
}

public static ReportNode createDynaFlowSecurityAnalysisReportNode(ReportNode reportNode, String networkId) {
return reportNode.newReportNode()
.withMessageTemplate("dynaflowSa", "Dynaflow security analysis on network '${networkId}'")
.withUntypedValue("networkId", networkId)
.add();
}

public static ReportNode createDynaFlowTimelineReportNode(ReportNode reportNode, String contingencyId) {
return reportNode.newReportNode()
.withMessageTemplate("dynaflowSaContingency", "Contingency '${contingencyId}'")
.withUntypedValue("contingencyId", contingencyId)
.add();
}
}
Loading

0 comments on commit 855b3d1

Please sign in to comment.