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

[GridDyna] Using gridsuite filter library for mapping #95

Merged
merged 30 commits into from
Jul 12, 2024
Merged
Show file tree
Hide file tree
Changes from 27 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
879fca6
Dynamic Simulation - Using gridsuite filter library for mapping
thangqp Apr 24, 2024
ebb1214
Accept mapping without filter
thangqp Apr 25, 2024
4a355cf
Update POM to add gridsuite-filter for compilation
thangqp Apr 26, 2024
3936315
do not need provide FilterLoader
thangqp May 6, 2024
7f26018
merge from main
thangqp May 6, 2024
5d24528
rename script DTO to parameter DTO
thangqp May 6, 2024
3fa01ce
Merge from main
thangqp May 21, 2024
9f71e3b
update mapping.json
thangqp May 21, 2024
772ead4
Adapt migration powsybl
thangqp Jun 4, 2024
b4a2e72
Adapt migration powsybl for PropertyType
thangqp Jun 5, 2024
21e0844
Adaptation to evolution in powsybl-dynawo on property type
thangqp Jun 5, 2024
0195116
Code clean
thangqp Jun 6, 2024
5256adc
Correct transforming ENUM TwoSides and trimming string
thangqp Jun 7, 2024
40ab90e
Using new event supplier instead of groovy event supplier
thangqp Jun 7, 2024
e4995e1
Delete unused code and test data
thangqp Jun 7, 2024
c5b4ef5
Add event FaultNode to test
thangqp Jun 7, 2024
c8b36af
Add update filters in batch to filter client service
thangqp Jun 11, 2024
c634e9c
Update pom to powsybl-dynawo 2.5.0-alpha-1
thangqp Jun 13, 2024
65a2b13
Remove snapshot filter in pom
thangqp Jun 13, 2024
c229cb1
Update to filter library 1.0.8
thangqp Jun 18, 2024
252474b
Merge from main
thangqp Jun 19, 2024
20f9f9e
Merge from main
thangqp Jun 26, 2024
3fff16f
Sonar
thangqp Jun 26, 2024
9c1f328
Correct following to Etienne comments
thangqp Jul 2, 2024
bde60a6
Sonar
thangqp Jul 2, 2024
00001c6
Sonar
thangqp Jul 2, 2024
56bf784
Correct as suggested by Mathieu
thangqp Jul 5, 2024
3f2f55b
Correct following to Mathieu comments
thangqp Jul 9, 2024
a49b389
Rectify namming for export parameters
thangqp Jul 10, 2024
c7caf7c
Merge from main
thangqp Jul 11, 2024
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
7 changes: 7 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -141,10 +141,17 @@
<dependency>
<groupId>com.powsybl</groupId>
<artifactId>powsybl-dynawaltz</artifactId>
<version>2.5.0-alpha-1</version>
</dependency>
<dependency>
<groupId>com.powsybl</groupId>
<artifactId>powsybl-dynawaltz-dsl</artifactId>
<version>2.5.0-alpha-1</version>
</dependency>
<dependency>
<groupId>org.gridsuite</groupId>
<artifactId>gridsuite-filter</artifactId>
<version>1.0.9</version>
</dependency>
<dependency>
<groupId>com.powsybl</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@
*/
package org.gridsuite.ds.server;

import lombok.Getter;

/**
* @author Abdelsalem Hedhili <abdelsalem.hedhili at rte-france.com>
*/
@Getter
public class DynamicSimulationException extends RuntimeException {

public enum Type {
Expand All @@ -17,7 +20,8 @@ public enum Type {
MAPPING_NOT_PROVIDED,
RESULT_UUID_NOT_FOUND,
DYNAMIC_MAPPING_NOT_FOUND,
CREATE_MAPPING_SCRIPT_ERROR,
GET_PARAMETER_ERROR,
GET_DYNAMIC_MAPPING_ERROR,
CREATE_TIME_SERIES_ERROR,
DELETE_TIME_SERIES_ERROR
}
Expand All @@ -28,8 +32,4 @@ public DynamicSimulationException(Type type, String message) {
super(message);
this.type = type;
}

public Type getType() {
return type;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ protected ResponseEntity<Object> handleDynamicSimulationException(DynamicSimulat
PROVIDER_NOT_FOUND
-> ResponseEntity.status(HttpStatus.NOT_FOUND).body(exception.getMessage());
case URI_SYNTAX,
CREATE_MAPPING_SCRIPT_ERROR,
GET_DYNAMIC_MAPPING_ERROR,
GET_PARAMETER_ERROR,
CREATE_TIME_SERIES_ERROR,
DELETE_TIME_SERIES_ERROR
-> ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(exception.getMessage());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/**
* Copyright (c) 2024, 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/.
*/
package org.gridsuite.ds.server.dto.dynamicmapping;

import io.swagger.v3.oas.annotations.media.Schema;
import org.gridsuite.ds.server.dto.dynamicmapping.automata.Automaton;

import java.util.List;

/**
* @author Thang PHAM <quyet-thang.pham at rte-france.com>
*/
@Schema(description = "Mapping")
public record InputMapping(
@Schema(description = "Name")
String name,
@Schema(description = "Mapping rules")
List<Rule> rules,
@Schema(description = "Mapping automata")
Mathieu-Deharbe marked this conversation as resolved.
Show resolved Hide resolved
List<Automaton> automata
Mathieu-Deharbe marked this conversation as resolved.
Show resolved Hide resolved
) {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/**
* Copyright (c) 2024, 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/.
*/
package org.gridsuite.ds.server.dto.dynamicmapping;

import io.swagger.v3.oas.annotations.media.Schema;

/**
* @author Thang PHAM <quyet-thang.pham at rte-france.com>
*/
@Schema(description = "Parameter sets in *.par format")
public record Parameter(
@Schema(description = "Name of the parent mapping")
String parentName,

@Schema(description = "Parameter file content in *.par format")
String parametersFile
) {

}
36 changes: 36 additions & 0 deletions src/main/java/org/gridsuite/ds/server/dto/dynamicmapping/Rule.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/**
* Copyright (c) 2024, 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/.
*/
package org.gridsuite.ds.server.dto.dynamicmapping;

import io.swagger.v3.oas.annotations.media.Schema;
import org.gridsuite.ds.server.utils.SetGroupType;
import org.gridsuite.filter.expertfilter.ExpertFilter;
import org.gridsuite.filter.utils.EquipmentType;

/**
* @author Thang PHAM <quyet-thang.pham at rte-france.com>
*/
@Schema(description = "Rule")
public record Rule(
@Schema(description = "Equipment type")
EquipmentType equipmentType,

@Schema(description = "Mapped Model Instance ID")
String mappedModel,

@Schema(description = "Mapped Parameter Set Group ID")
String setGroup,

@Schema(description = "Mapped Parameter Set Group Type")
SetGroupType groupType,

@Schema(description = "Filter")
ExpertFilter filter
) {

}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/**
* Copyright (c) 2024, 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/.
*/
package org.gridsuite.ds.server.dto.dynamicmapping.automata;

import io.swagger.v3.oas.annotations.media.Schema;

import java.util.List;

/**
* @author Thang PHAM <quyet-thang.pham at rte-france.com>
*/
public record Automaton(
@Schema(description = "Mapped Model Instance ID")
String model,
@Schema(description = "Mapped Parameters Set Group ID")
String setGroup,
@Schema(description = "Properties of automaton model")
List<BasicProperty> properties
) {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/**
* Copyright (c) 2024, 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/.
*/

package org.gridsuite.ds.server.dto.dynamicmapping.automata;

import io.swagger.v3.oas.annotations.media.Schema;
import org.gridsuite.ds.server.utils.PropertyType;

/**
* @author Thang PHAM <quyet-thang.pham at rte-france.com>
*/
Mathieu-Deharbe marked this conversation as resolved.
Show resolved Hide resolved
public record BasicProperty(
@Schema(description = "Property name")
String name,
@Schema(description = "Property value in string representation")
String value,
@Schema(description = "Property type")
PropertyType type
) {

}
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,25 @@
import com.powsybl.commons.PowsyblException;
import com.powsybl.computation.ComputationManager;
import com.powsybl.dynamicsimulation.*;
import com.powsybl.dynamicsimulation.groovy.*;
import com.powsybl.dynamicsimulation.groovy.CurveGroovyExtension;
import com.powsybl.dynamicsimulation.groovy.GroovyCurvesSupplier;
import com.powsybl.dynamicsimulation.groovy.GroovyExtension;
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.iidm.network.Network;
import com.powsybl.iidm.network.VariantManagerConstants;
import com.powsybl.network.store.client.NetworkStoreService;
import com.powsybl.timeseries.IrregularTimeSeriesIndex;
import com.powsybl.timeseries.TimeSeries;
import org.apache.commons.collections4.CollectionUtils;
import com.powsybl.ws.commons.computation.service.*;
import org.apache.commons.collections4.CollectionUtils;
import org.gridsuite.ds.server.dto.DynamicSimulationParametersInfos;
import org.gridsuite.ds.server.dto.DynamicSimulationStatus;
import org.gridsuite.ds.server.dto.dynamicmapping.Script;
import org.gridsuite.ds.server.dto.dynamicmapping.InputMapping;
import org.gridsuite.ds.server.dto.dynamicmapping.Parameter;
import org.gridsuite.ds.server.service.client.dynamicmapping.DynamicMappingClient;
import org.gridsuite.ds.server.service.contexts.DynamicSimulationResultContext;
import org.gridsuite.ds.server.service.contexts.DynamicSimulationRunContext;
Expand Down Expand Up @@ -127,21 +134,24 @@ public void preRun(DynamicSimulationRunContext runContext) {
super.preRun(runContext);
DynamicSimulationParametersInfos parametersInfos = runContext.getParameters();

// get script and parameters file from dynamic mapping server
Script scriptObj = dynamicMappingClient.createFromMapping(runContext.getMapping());
// get parameters file from dynamic mapping server
Parameter parameterObj = dynamicMappingClient.getParameters(runContext.getMapping());

// get all dynamic simulation parameters
String parametersFile = scriptObj.getParametersFile();
String parametersFile = parameterObj.parametersFile();
Mathieu-Deharbe marked this conversation as resolved.
Show resolved Hide resolved
DynamicSimulationParameters parameters = parametersService.getDynamicSimulationParameters(
parametersFile.getBytes(StandardCharsets.UTF_8), runContext.getProvider(), parametersInfos);

// get mapping then generate dynamic model configs
InputMapping inputMapping = dynamicMappingClient.getMapping(runContext.getMapping());
List<DynamicModelConfig> dynamicModel = parametersService.getDynamicModel(inputMapping, runContext.getNetwork());
List<EventModelConfig > eventModel = parametersService.getEventModel(parametersInfos.getEvents());

// set start and stop times
parameters.setStartTime(parametersInfos.getStartTime().intValue()); // TODO remove intValue() when correct startTime to double in powsybl
parameters.setStopTime(parametersInfos.getStopTime().intValue()); // TODO remove intValue() when correct stopTime to double in powsybl

// groovy scripts
String dynamicModel = scriptObj.getScript();
String eventModel = parametersService.getEventModel(parametersInfos.getEvents());
String curveModel = parametersService.getCurveModel(parametersInfos.getCurves());

// enrich runContext
Expand All @@ -154,15 +164,9 @@ public void preRun(DynamicSimulationRunContext runContext) {
@Override
public CompletableFuture<DynamicSimulationResult> getCompletableFuture(DynamicSimulationRunContext runContext, String provider, UUID resultUuid) {

List<DynamicModelGroovyExtension> dynamicModelExtensions = GroovyExtension.find(DynamicModelGroovyExtension.class, DynaWaltzProvider.NAME);
DynamicModelsSupplier dynamicModelsSupplier = new GroovyDynamicModelsSupplier(
new ByteArrayInputStream(runContext.getDynamicModelContent().getBytes()), dynamicModelExtensions
);
DynamicModelsSupplier dynamicModelsSupplier = new DynawoModelsSupplier(runContext.getDynamicModelContent());

List<EventModelGroovyExtension> eventModelExtensions = GroovyExtension.find(EventModelGroovyExtension.class, DynaWaltzProvider.NAME);
EventModelsSupplier eventModelsSupplier = new GroovyEventModelsSupplier(
new ByteArrayInputStream(runContext.getEventModelContent().getBytes()), eventModelExtensions
);
EventModelsSupplier eventModelsSupplier = new DynawoEventModelsSupplier(runContext.getEventModelContent());

List<CurveGroovyExtension> curveExtensions = GroovyExtension.find(CurveGroovyExtension.class, DynaWaltzProvider.NAME);
CurvesSupplier curvesSupplier = new GroovyCurvesSupplier(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* @author Thang PHAM <quyet-thang.pham at rte-france.com>
*/
public interface RestClient {
String DELIMITER = "/";
String URL_DELIMITER = "/";

RestTemplate getRestTemplate();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,19 @@
*/
package org.gridsuite.ds.server.service.client.dynamicmapping;

import org.gridsuite.ds.server.dto.dynamicmapping.Script;

import static org.gridsuite.ds.server.service.client.RestClient.DELIMITER;
import org.gridsuite.ds.server.dto.dynamicmapping.InputMapping;
import org.gridsuite.ds.server.dto.dynamicmapping.Parameter;

/**
* @author Thang PHAM <quyet-thang.pham at rte-france.com>
*/
public interface DynamicMappingClient {
String API_VERSION = "";
String DYNAMIC_MAPPING_SCRIPT_BASE_END_POINT = "scripts";
String DYNAMIC_MAPPING_SCRIPT_CREATE_END_POINT = DYNAMIC_MAPPING_SCRIPT_BASE_END_POINT + DELIMITER + "from";
String DYNAMIC_MAPPING_PARAMETER_BASE_ENDPOINT = "parameters";
String DYNAMIC_MAPPING_MAPPING_BASE_ENDPOINT = "mappings";
String DYNAMIC_MAPPING_PARAMETER_GET_ENDPOINT = DYNAMIC_MAPPING_PARAMETER_BASE_ENDPOINT;
Mathieu-Deharbe marked this conversation as resolved.
Show resolved Hide resolved

Parameter getParameters(String mappingName);

Script createFromMapping(String mappingName);
InputMapping getMapping(String mappingName);
}
Loading
Loading