Skip to content

Commit

Permalink
Merge from main
Browse files Browse the repository at this point in the history
Signed-off-by: Thang PHAM <[email protected]>
  • Loading branch information
thangqp committed Nov 13, 2024
2 parents 965a38e + 16038c2 commit a424c8c
Show file tree
Hide file tree
Showing 12 changed files with 66 additions and 63 deletions.
7 changes: 4 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
</developers>

<properties>
<gridsuite-dependencies.version>35-SNAPSHOT</gridsuite-dependencies.version>
<gridsuite-dependencies.version>35</gridsuite-dependencies.version>
<jib.from.image>powsybl/java-dynawo:2.2.0</jib.from.image>

<h2database.version>1.4.200</h2database.version>
Expand Down Expand Up @@ -87,6 +87,7 @@
<dependencyManagement>
<dependencies>
<!-- overrides of imports -->

<!-- imports -->
<dependency>
<groupId>org.gridsuite</groupId>
Expand Down Expand Up @@ -138,11 +139,11 @@
</dependency>
<dependency>
<groupId>com.powsybl</groupId>
<artifactId>powsybl-dynawaltz</artifactId>
<artifactId>powsybl-dynawo-simulation</artifactId>
</dependency>
<dependency>
<groupId>com.powsybl</groupId>
<artifactId>powsybl-dynawaltz-dsl</artifactId>
<artifactId>powsybl-dynawo-dsl</artifactId>
</dependency>
<dependency>
<groupId>org.gridsuite</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/

package com.powsybl.dynawaltz.xml;
package com.powsybl.dynawo.xml;

import javanet.staxutils.IndentingXMLStreamWriter;

Expand All @@ -16,7 +16,7 @@
import java.io.Writer;

/**
* TODO update next version powsybl dynawo 1.15.0
* TODO update next version powsybl-dynawo 2.7.0
* @author Mathieu Bague <[email protected]>
*/
public final class XmlStreamWriterFactory {
Expand Down Expand Up @@ -47,7 +47,7 @@ public static XMLStreamWriter newInstance(OutputStream os, boolean indent) throw
private static XMLStreamWriter withIndent(XMLStreamWriter xmlStreamWriter, boolean indent) {
if (indent) {
IndentingXMLStreamWriter indentingWriter = new IndentingXMLStreamWriter(xmlStreamWriter);
indentingWriter.setIndent(DynaWaltzXmlConstants.INDENT);
indentingWriter.setIndent(DynawoSimulationXmlConstants.INDENT);
return indentingWriter;
}
return xmlStreamWriter;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

package org.gridsuite.ds.server.dto;

import com.powsybl.dynawaltz.xml.XmlStreamWriterFactory;
import com.powsybl.dynawo.xml.XmlStreamWriterFactory;

import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamWriter;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

package org.gridsuite.ds.server.dto.solver;

import com.powsybl.dynawaltz.DynaWaltzParameters;
import com.powsybl.dynawo.DynawoSimulationParameters;

/**
* @author Thang PHAM <quyet-thang.pham at rte-france.com>
Expand All @@ -16,10 +16,10 @@ public enum SolverTypeInfos {
SIM,
IDA;

public DynaWaltzParameters.SolverType toSolverType() {
public DynawoSimulationParameters.SolverType toSolverType() {
switch (this) {
case SIM : return DynaWaltzParameters.SolverType.SIM;
case IDA : return DynaWaltzParameters.SolverType.IDA;
case SIM : return DynawoSimulationParameters.SolverType.SIM;
case IDA : return DynawoSimulationParameters.SolverType.IDA;
default : return null;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@
import com.powsybl.commons.io.FileUtil;
import com.powsybl.computation.ComputationManager;
import com.powsybl.dynamicsimulation.*;
import com.powsybl.dynamicsimulation.groovy.CurveGroovyExtension;
import com.powsybl.dynamicsimulation.groovy.GroovyCurvesSupplier;
import com.powsybl.dynamicsimulation.groovy.GroovyExtension;
import com.powsybl.dynawaltz.DumpFileParameters;
import com.powsybl.dynawaltz.DynaWaltzParameters;
import com.powsybl.dynawaltz.DynaWaltzProvider;
import com.powsybl.dynawaltz.suppliers.dynamicmodels.DynamicModelConfig;
import com.powsybl.dynawaltz.suppliers.dynamicmodels.DynawoModelsSupplier;
import com.powsybl.dynawaltz.suppliers.events.DynawoEventModelsSupplier;
import com.powsybl.dynawaltz.suppliers.events.EventModelConfig;
import com.powsybl.dynamicsimulation.groovy.GroovyOutputVariablesSupplier;
import com.powsybl.dynamicsimulation.groovy.OutputVariableGroovyExtension;
import com.powsybl.dynawo.DumpFileParameters;
import com.powsybl.dynawo.DynawoSimulationParameters;
import com.powsybl.dynawo.DynawoSimulationProvider;
import com.powsybl.dynawo.suppliers.dynamicmodels.DynamicModelConfig;
import com.powsybl.dynawo.suppliers.dynamicmodels.DynawoModelsSupplier;
import com.powsybl.dynawo.suppliers.events.DynawoEventModelsSupplier;
import com.powsybl.dynawo.suppliers.events.EventModelConfig;
import com.powsybl.iidm.network.Network;
import com.powsybl.iidm.network.VariantManagerConstants;
import com.powsybl.network.store.client.NetworkStoreService;
Expand Down Expand Up @@ -131,8 +131,8 @@ protected void saveResult(Network network, AbstractResultContext<DynamicSimulati
// read dump file
byte[] outputState = null;
Path dumpDir = Optional.ofNullable(resultContext.getRunContext().getDynamicSimulationParameters())
.map(parameters -> parameters.getExtension(DynaWaltzParameters.class))
.map(dynaWaltzParameters -> ((DynaWaltzParameters) dynaWaltzParameters).getDumpFileParameters().dumpFileFolder())
.map(parameters -> parameters.getExtension(DynawoSimulationParameters.class))
.map(dynawoSimulationParameters -> ((DynawoSimulationParameters) dynawoSimulationParameters).getDumpFileParameters().dumpFileFolder())
.orElse(null);
if (dumpDir != null) {
try (Stream<Path> files = Files.list(dumpDir)) {
Expand Down Expand Up @@ -201,8 +201,8 @@ public void preRun(DynamicSimulationRunContext runContext) {
// enrich dump parameters
Path dumpDir = workDir.resolve("dump");
FileUtil.createDirectory(dumpDir);
DynaWaltzParameters dynaWaltzParameters = parameters.getExtension(DynaWaltzParameters.class);
dynaWaltzParameters.setDumpFileParameters(DumpFileParameters.createExportDumpFileParameters(dumpDir));
DynawoSimulationParameters dynawoSimulationParameters = parameters.getExtension(DynawoSimulationParameters.class);
dynawoSimulationParameters.setDumpFileParameters(DumpFileParameters.createExportDumpFileParameters(dumpDir));
}

@Override
Expand All @@ -212,10 +212,9 @@ public CompletableFuture<DynamicSimulationResult> getCompletableFuture(DynamicSi

EventModelsSupplier eventModelsSupplier = new DynawoEventModelsSupplier(runContext.getEventModelContent());

List<CurveGroovyExtension> curveExtensions = GroovyExtension.find(CurveGroovyExtension.class, DynaWaltzProvider.NAME);
CurvesSupplier curvesSupplier = new GroovyCurvesSupplier(
new ByteArrayInputStream(runContext.getCurveContent().getBytes()), curveExtensions
);
GroovyOutputVariablesSupplier outputVariablesSupplier = new GroovyOutputVariablesSupplier(
new ByteArrayInputStream(runContext.getCurveContent().getBytes()),
GroovyExtension.find(OutputVariableGroovyExtension.class, DynawoSimulationProvider.NAME));

DynamicSimulationParameters parameters = runContext.getDynamicSimulationParameters();
LOGGER.info("Run dynamic simulation on network {}, startTime {}, stopTime {},",
Expand All @@ -225,7 +224,7 @@ public CompletableFuture<DynamicSimulationResult> getCompletableFuture(DynamicSi
return runner.runAsync(runContext.getNetwork(),
dynamicModelsSupplier,
eventModelsSupplier,
curvesSupplier,
outputVariablesSupplier,
runContext.getVariantId() != null ? runContext.getVariantId() : VariantManagerConstants.INITIAL_VARIANT_ID,
getComputationManager(),
parameters,
Expand Down Expand Up @@ -253,7 +252,7 @@ protected void clean(AbstractResultContext<DynamicSimulationRunContext> resultCo
try {
FileUtil.removeDir(workDir);
} catch (IOException e) {
LOGGER.error("{}: error while cleaning working directory", getComputationType(), e);
LOGGER.error("{}: Error occurs while cleaning working directory", getComputationType(), e);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
package org.gridsuite.ds.server.service.contexts;

import com.powsybl.dynamicsimulation.DynamicSimulationParameters;
import com.powsybl.dynawaltz.suppliers.dynamicmodels.DynamicModelConfig;
import com.powsybl.dynawaltz.suppliers.events.EventModelConfig;
import com.powsybl.dynawo.suppliers.dynamicmodels.DynamicModelConfig;
import com.powsybl.dynawo.suppliers.events.EventModelConfig;
import com.powsybl.ws.commons.computation.dto.ReportInfos;
import com.powsybl.ws.commons.computation.service.AbstractComputationRunContext;
import lombok.Builder;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
package org.gridsuite.ds.server.service.parameters;

import com.powsybl.dynamicsimulation.DynamicSimulationParameters;
import com.powsybl.dynawaltz.suppliers.dynamicmodels.DynamicModelConfig;
import com.powsybl.dynawaltz.suppliers.events.EventModelConfig;
import com.powsybl.dynawo.suppliers.dynamicmodels.DynamicModelConfig;
import com.powsybl.dynawo.suppliers.events.EventModelConfig;
import com.powsybl.iidm.network.Network;
import com.powsybl.ws.commons.computation.dto.ReportInfos;
import org.gridsuite.ds.server.dto.DynamicSimulationParametersInfos;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@
import com.powsybl.commons.exceptions.UncheckedXmlStreamException;
import com.powsybl.dynamicsimulation.DynamicSimulationParameters;
import com.powsybl.dynamicsimulation.DynamicSimulationProvider;
import com.powsybl.dynawaltz.DynaWaltzParameters;
import com.powsybl.dynawaltz.DynaWaltzProvider;
import com.powsybl.dynawaltz.parameters.ParametersSet;
import com.powsybl.dynawaltz.suppliers.PropertyBuilder;
import com.powsybl.dynawaltz.suppliers.PropertyType;
import com.powsybl.dynawaltz.suppliers.SetGroupType;
import com.powsybl.dynawaltz.suppliers.dynamicmodels.DynamicModelConfig;
import com.powsybl.dynawaltz.suppliers.events.EventModelConfig;
import com.powsybl.dynawaltz.xml.ParametersXml;
import com.powsybl.dynawo.DynawoSimulationParameters;
import com.powsybl.dynawo.DynawoSimulationProvider;
import com.powsybl.dynawo.parameters.ParametersSet;
import com.powsybl.dynawo.suppliers.PropertyBuilder;
import com.powsybl.dynawo.suppliers.PropertyType;
import com.powsybl.dynawo.suppliers.SetGroupType;
import com.powsybl.dynawo.suppliers.dynamicmodels.DynamicModelConfig;
import com.powsybl.dynawo.suppliers.events.EventModelConfig;
import com.powsybl.dynawo.xml.ParametersXml;
import com.powsybl.iidm.network.Identifiable;
import com.powsybl.iidm.network.Network;
import com.powsybl.ws.commons.computation.dto.ReportInfos;
Expand Down Expand Up @@ -101,14 +101,14 @@ public DynamicSimulationParameters getDynamicSimulationParameters(byte[] dynamic
try {
DynamicSimulationParameters parameters = new DynamicSimulationParameters();

// TODO: Powsybl side - create an explicit dependency to DynaWaltz class and keep dynamic simulation abstraction all over this micro service
if (DynaWaltzProvider.NAME.equals(provider)) {
// TODO: Powsybl side - create an explicit dependency to Dynawo class and keep dynamic simulation abstraction all over this micro service
if (DynawoSimulationProvider.NAME.equals(provider)) {
// --- MODEL PAR --- //
List<ParametersSet> modelsParameters = !ArrayUtils.isEmpty(dynamicParams) ? ParametersXml.load(new ByteArrayInputStream(dynamicParams)) : List.of();

DynaWaltzParameters dynaWaltzParameters = new DynaWaltzParameters();
dynaWaltzParameters.setModelsParameters(modelsParameters);
parameters.addExtension(DynaWaltzParameters.class, dynaWaltzParameters);
DynawoSimulationParameters dynawoSimulationParameters = new DynawoSimulationParameters();
dynawoSimulationParameters.setModelsParameters(modelsParameters);
parameters.addExtension(DynawoSimulationParameters.class, dynawoSimulationParameters);

// --- SOLVER PAR --- //
// solver from input parameter
Expand All @@ -117,8 +117,8 @@ public DynamicSimulationParameters getDynamicSimulationParameters(byte[] dynamic
ByteArrayOutputStream os = new ByteArrayOutputStream();
XmlSerializableParameter.writeParameter(os, XmlSerializableParameter.PARAMETER_SET, inputSolver);
ParametersSet solverParameters = ParametersXml.load(new ByteArrayInputStream(os.toByteArray()), inputSolver.getId());
dynaWaltzParameters.setSolverType(inputSolver.getType().toSolverType());
dynaWaltzParameters.setSolverParameters(solverParameters);
dynawoSimulationParameters.setSolverType(inputSolver.getType().toSolverType());
dynawoSimulationParameters.setSolverParameters(solverParameters);
}

// --- NETWORK PAR --- //
Expand All @@ -128,7 +128,7 @@ public DynamicSimulationParameters getDynamicSimulationParameters(byte[] dynamic
ByteArrayOutputStream os = new ByteArrayOutputStream();
XmlSerializableParameter.writeParameter(os, XmlSerializableParameter.PARAMETER_SET, network);
ParametersSet networkParameters = ParametersXml.load(new ByteArrayInputStream(os.toByteArray()), network.getId());
dynaWaltzParameters.setNetworkParameters(networkParameters);
dynawoSimulationParameters.setNetworkParameters(networkParameters);
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/main/java/org/gridsuite/ds/server/utils/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@

package org.gridsuite.ds.server.utils;

import com.powsybl.dynawaltz.suppliers.Property;
import com.powsybl.dynawaltz.suppliers.PropertyBuilder;
import com.powsybl.dynawaltz.suppliers.PropertyType;
import com.powsybl.dynawo.suppliers.Property;
import com.powsybl.dynawo.suppliers.PropertyBuilder;
import com.powsybl.dynawo.suppliers.PropertyType;
import com.powsybl.iidm.network.TwoSides;
import org.apache.commons.lang3.StringUtils;
import org.gridsuite.ds.server.dto.dynamicmapping.automata.BasicProperty;
Expand Down
4 changes: 2 additions & 2 deletions src/main/resources/config/application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,6 @@ powsybl-ws:
database:
name: ds

# default values for dynamic simulation providers is "DynaWaltz"
# default values for dynamic simulation providers is "Dynawo"
dynamic-simulation:
default-provider: DynaWaltz
default-provider: Dynawo
Original file line number Diff line number Diff line change
Expand Up @@ -194,9 +194,11 @@ public void testGivenTimeSeriesAndTimeLine() throws Exception {
new TimelineEvent(104396, "CLA_2_4 - CLA", "arming by over-current constraint")
);

doReturn(CompletableFuture.completedFuture(new DynamicSimulationResultImpl(DynamicSimulationResult.Status.SUCCESS, "", curves, timeLine)))
Map<String, Double> finalStateValues = new HashMap<>();

doReturn(CompletableFuture.completedFuture(new DynamicSimulationResultImpl(DynamicSimulationResult.Status.SUCCESS, "", curves, finalStateValues, timeLine)))
.when(dynamicSimulationWorkerService).getCompletableFuture(any(), any(), any());
doReturn(CompletableFuture.completedFuture(new DynamicSimulationResultImpl(DynamicSimulationResult.Status.SUCCESS, "", curves, timeLine)))
doReturn(CompletableFuture.completedFuture(new DynamicSimulationResultImpl(DynamicSimulationResult.Status.SUCCESS, "", curves, finalStateValues, timeLine)))
.when(dynamicSimulationWorkerService).getCompletableFuture(any(), any(), isNull());

// prepare parameters
Expand Down Expand Up @@ -330,8 +332,9 @@ public void testGivenEmptyTimeSeriesAndTimeLine() throws Exception {
// mock DynamicSimulationWorkerService without time-series and timeline
Map<String, DoubleTimeSeries> curves = new HashMap<>();
List<TimelineEvent> timeLine = List.of();
Map<String, Double> finalStateValues = new HashMap<>();

doReturn(CompletableFuture.completedFuture(new DynamicSimulationResultImpl(DynamicSimulationResult.Status.SUCCESS, "", curves, timeLine)))
doReturn(CompletableFuture.completedFuture(new DynamicSimulationResultImpl(DynamicSimulationResult.Status.SUCCESS, "", curves, finalStateValues, timeLine)))
.when(dynamicSimulationWorkerService).getCompletableFuture(any(), any(), any());

// prepare parameters
Expand Down Expand Up @@ -491,7 +494,7 @@ public void testStopOnTime() throws Exception {

// fake a long computation 1s
return CompletableFuture.supplyAsync(() ->
new DynamicSimulationResultImpl(DynamicSimulationResult.Status.SUCCESS, "", Map.of(), List.of()),
new DynamicSimulationResultImpl(DynamicSimulationResult.Status.SUCCESS, "", Map.of(), Map.of(), List.of()),
CompletableFuture.delayedExecutor(1000, TimeUnit.MILLISECONDS)
);
});
Expand All @@ -515,7 +518,7 @@ public void testStopEarly() throws Exception {
CountDownLatch cancelLatch = new CountDownLatch(1);
// Emit messages in separate threads, like in production.
mockSendRunMessage(() -> CompletableFuture.supplyAsync(() ->
new DynamicSimulationResultImpl(DynamicSimulationResult.Status.SUCCESS, "", Map.of(), List.of())
new DynamicSimulationResultImpl(DynamicSimulationResult.Status.SUCCESS, "", Map.of(), Map.of(), List.of())
)
);

Expand Down Expand Up @@ -555,7 +558,7 @@ public void testStopLately() throws Exception {

// fake a short computation
return CompletableFuture.supplyAsync(() ->
new DynamicSimulationResultImpl(DynamicSimulationResult.Status.SUCCESS, "", Map.of(), List.of())
new DynamicSimulationResultImpl(DynamicSimulationResult.Status.SUCCESS, "", Map.of(), Map.of(), List.of())
);
});

Expand Down
2 changes: 1 addition & 1 deletion src/test/resources/com/powsybl/config/test/config.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
dynawaltz:
dynawo:
# home dir references to directory inside the container java-dynawo
homeDir: /dynaflow-launcher
debug: true
Expand Down

0 comments on commit a424c8c

Please sign in to comment.