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

Features/inter temporal sensitivity #1235

Open
wants to merge 19 commits into
base: main
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@

package com.powsybl.openrao.raoapi;

import com.powsybl.openrao.commons.OpenRaoException;
import com.powsybl.openrao.commons.TemporalData;

import java.time.OffsetDateTime;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;

Expand All @@ -24,6 +26,7 @@ public class InterTemporalRaoInput {
public InterTemporalRaoInput(TemporalData<RaoInput> raoInputs, Set<OffsetDateTime> timestampsToRun) {
this.raoInputs = raoInputs;
this.timestampsToRun = timestampsToRun;
checkTimestampsToRun();
}

public InterTemporalRaoInput(TemporalData<RaoInput> raoInputs) {
Expand All @@ -38,4 +41,12 @@ public Set<OffsetDateTime> getTimestampsToRun() {
return timestampsToRun;
}

private void checkTimestampsToRun() {
List<OffsetDateTime> timestamps = raoInputs.getTimestamps();
timestampsToRun.forEach(timestamp -> {
if (!timestamps.contains(timestamp)) {
throw new OpenRaoException("Timestamp '" + timestamp + "' does not exist in the inputs.");
}
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,11 @@ private RaoParametersCommons() {
public static final String PTDF_BOUNDARIES = "ptdf-boundaries";
public static final String PTDF_SUM_LOWER_BOUND = "ptdf-sum-lower-bound";

// -- Inter Temporal parameters
public static final String INTER_TEMPORAL_PARAMETERS = "inter-temporal-parameters";
public static final String INTER_TEMPORAL_PARAMETERS_SECTION = "rao-inter-temporal-parameters";
public static final String SENSITIVITY_COMPUTATIONS_IN_PARALLEL = "sensitivity-computations-in-parallel";

public static PtdfApproximation stringToPtdfApproximation(String string) {
try {
return PtdfApproximation.valueOf(string);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/*
* 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 com.powsybl.openrao.raoapi.json.extensions;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.google.auto.service.AutoService;
import com.powsybl.openrao.commons.OpenRaoException;
import com.powsybl.openrao.raoapi.json.JsonRaoParameters;
import com.powsybl.openrao.raoapi.parameters.extensions.InterTemporalParametersExtension;

import java.io.IOException;

import static com.powsybl.openrao.raoapi.RaoParametersCommons.*;

/**
* @author Thomas Bouquet {@literal <thomas.bouquet at rte-france.com>}
* @author Roxane Chen {@literal <roxane.chen at rte-france.com>}
*/
@AutoService(JsonRaoParameters.ExtensionSerializer.class)
public class JsonInterTemporalParametersExtension implements JsonRaoParameters.ExtensionSerializer<InterTemporalParametersExtension> {

@Override
public void serialize(InterTemporalParametersExtension interTemporalParametersExtension, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException {
jsonGenerator.writeStartObject();
jsonGenerator.writeNumberField(SENSITIVITY_COMPUTATIONS_IN_PARALLEL, interTemporalParametersExtension.getSensitivityComputationsInParallel());
jsonGenerator.writeEndObject();
}

@Override
public InterTemporalParametersExtension deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException {
return deserializeAndUpdate(jsonParser, deserializationContext, new InterTemporalParametersExtension());
}

@Override
public InterTemporalParametersExtension deserializeAndUpdate(JsonParser jsonParser, DeserializationContext deserializationContext, InterTemporalParametersExtension parameters) throws IOException {
while (!jsonParser.nextToken().isStructEnd()) {
switch (jsonParser.getCurrentName()) {
case SENSITIVITY_COMPUTATIONS_IN_PARALLEL:
jsonParser.nextToken();
parameters.setSensitivityComputationsInParallel(jsonParser.getIntValue());
break;
default:
throw new OpenRaoException(String.format("Cannot deserialize inter temporal parameters: unexpected field in %s (%s)", INTER_TEMPORAL_PARAMETERS, jsonParser.getCurrentName()));
}
}
return parameters;
}

@Override
public String getExtensionName() {
return INTER_TEMPORAL_PARAMETERS;
}

@Override
public String getCategoryName() {
return "rao-parameters";
}

@Override
public Class<? super InterTemporalParametersExtension> getExtensionClass() {
return InterTemporalParametersExtension.class;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* 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 com.powsybl.openrao.raoapi.parameters.extensions;

import com.google.auto.service.AutoService;
import com.powsybl.commons.config.PlatformConfig;
import com.powsybl.openrao.raoapi.parameters.RaoParameters;

import java.util.Objects;

import static com.powsybl.openrao.raoapi.RaoParametersCommons.*;

/**
* @author Thomas Bouquet {@literal <thomas.bouquet at rte-france.com>}
* @author Roxane Chen {@literal <roxane.chen at rte-france.com>}
*/
@AutoService(RaoParameters.ConfigLoader.class)
public class InterTemporalParametersConfigLoader implements RaoParameters.ConfigLoader<InterTemporalParametersExtension> {

@Override
public InterTemporalParametersExtension load(PlatformConfig platformConfig) {
Objects.requireNonNull(platformConfig);
InterTemporalParametersExtension parameters = new InterTemporalParametersExtension();
platformConfig.getOptionalModuleConfig(INTER_TEMPORAL_PARAMETERS_SECTION)
.ifPresent(config -> parameters.setSensitivityComputationsInParallel(config.getIntProperty(SENSITIVITY_COMPUTATIONS_IN_PARALLEL, InterTemporalParametersExtension.DEFAULT_SENSITIVITY_COMPUTATIONS_IN_PARALLEL)));
return parameters;
}

@Override
public String getExtensionName() {
return INTER_TEMPORAL_PARAMETERS_SECTION;
}

@Override
public String getCategoryName() {
return "rao-parameters";
}

@Override
public Class<? super InterTemporalParametersExtension> getExtensionClass() {
return InterTemporalParametersExtension.class;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* 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 com.powsybl.openrao.raoapi.parameters.extensions;

import com.powsybl.commons.extensions.AbstractExtension;
import com.powsybl.openrao.raoapi.parameters.RaoParameters;

import static com.powsybl.openrao.raoapi.RaoParametersCommons.INTER_TEMPORAL_PARAMETERS;

/**
* Extension: parameters for inter-temporal RAO computations
*
* @author Thomas Bouquet {@literal <thomas.bouquet at rte-france.com>}
* @author Roxane Chen {@literal <roxane.chen at rte-france.com>}
*/
public class InterTemporalParametersExtension extends AbstractExtension<RaoParameters> {
static final int DEFAULT_SENSITIVITY_COMPUTATIONS_IN_PARALLEL = 1;
private int sensitivityComputationsInParallel = DEFAULT_SENSITIVITY_COMPUTATIONS_IN_PARALLEL;

@Override
public String getName() {
return INTER_TEMPORAL_PARAMETERS;
}

public int getSensitivityComputationsInParallel() {
return sensitivityComputationsInParallel;
}

public void setSensitivityComputationsInParallel(int sensitivityComputationsInParallel) {
this.sensitivityComputationsInParallel = sensitivityComputationsInParallel;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

package com.powsybl.openrao.raoapi;

import com.powsybl.openrao.commons.OpenRaoException;
import com.powsybl.openrao.commons.TemporalData;
import com.powsybl.openrao.commons.TemporalDataImpl;
import org.junit.jupiter.api.BeforeEach;
Expand All @@ -19,6 +20,7 @@
import java.util.Set;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;

/**
* @author Thomas Bouquet {@literal <thomas.bouquet at rte-france.com>}
Expand Down Expand Up @@ -55,4 +57,10 @@ void testInstantiateInterTemporalRaoInputAllTimestamps() {
assertEquals(temporalData, input.getRaoInputs());
assertEquals(Set.of(timestamp1, timestamp2, timestamp3), input.getTimestampsToRun());
}

@Test
void testInstantiateWithMissingTimestamps() {
OpenRaoException exception = assertThrows(OpenRaoException.class, () -> new InterTemporalRaoInput(temporalData, Set.of(OffsetDateTime.of(2024, 12, 11, 14, 29, 0, 0, ZoneOffset.UTC))));
assertEquals("Timestamp '2024-12-11T14:29Z' does not exist in the inputs.", exception.getMessage());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,7 @@
import com.powsybl.openrao.raoapi.parameters.RangeActionsOptimizationParameters;
import com.powsybl.openrao.raoapi.parameters.RaoParameters;
import com.powsybl.openrao.raoapi.parameters.SecondPreventiveRaoParameters;
import com.powsybl.openrao.raoapi.parameters.extensions.LoopFlowParametersExtension;
import com.powsybl.openrao.raoapi.parameters.extensions.MnecParametersExtension;
import com.powsybl.openrao.raoapi.parameters.extensions.PtdfApproximation;
import com.powsybl.openrao.raoapi.parameters.extensions.RelativeMarginsParametersExtension;
import com.powsybl.openrao.raoapi.parameters.extensions.*;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.DeserializationContext;
Expand Down Expand Up @@ -113,6 +110,9 @@ void roundTrip() throws IOException {
parameters.getExtension(RelativeMarginsParametersExtension.class).setPtdfBoundariesFromString(stringBoundaries);
parameters.getExtension(RelativeMarginsParametersExtension.class).setPtdfApproximation(PtdfApproximation.UPDATE_PTDF_WITH_TOPO);
parameters.getExtension(RelativeMarginsParametersExtension.class).setPtdfSumLowerBound(0.05);
// -- Inter-temporal parameters
parameters.addExtension(InterTemporalParametersExtension.class, new InterTemporalParametersExtension());
parameters.getExtension(InterTemporalParametersExtension.class).setSensitivityComputationsInParallel(4);

roundTripTest(parameters, JsonRaoParameters::write, JsonRaoParameters::read, "/RaoParametersSet_v2.json");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,16 @@ void checkRelativeMarginsConfig() {
assertEquals(expectedBoundaries, parameters.getPtdfBoundariesAsString());
}

@Test
void checkInterTemporalConfig() {
ModuleConfig interTemporalModuleConfig = Mockito.mock(ModuleConfig.class);
Mockito.when(interTemporalModuleConfig.getIntProperty(eq("sensitivity-computations-in-parallel"), anyInt())).thenReturn(4);
Mockito.when(mockedPlatformConfig.getOptionalModuleConfig("rao-inter-temporal-parameters")).thenReturn(Optional.of(interTemporalModuleConfig));
InterTemporalParametersConfigLoader configLoader = new InterTemporalParametersConfigLoader();
InterTemporalParametersExtension parameters = configLoader.load(mockedPlatformConfig);
assertEquals(4, parameters.getSensitivityComputationsInParallel());
}

@Test
void checkMultipleConfigs() {
MapModuleConfig objectiveFunctionModuleConfig = platformCfg.createModuleConfig("rao-objective-function");
Expand All @@ -229,6 +239,7 @@ void checkMultipleConfigs() {
assertTrue(Objects.isNull(parameters.getExtension(LoopFlowParametersExtension.class)));
assertTrue(Objects.isNull(parameters.getExtension(MnecParametersExtension.class)));
assertTrue(Objects.isNull(parameters.getExtension(RelativeMarginsParametersExtension.class)));
assertTrue(Objects.isNull(parameters.getExtension(InterTemporalParametersExtension.class)));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
package com.powsybl.openrao.raoapi.parameters;

import com.powsybl.openrao.raoapi.json.JsonRaoParameters;
import com.powsybl.openrao.raoapi.parameters.extensions.InterTemporalParametersExtension;
import com.powsybl.openrao.raoapi.parameters.extensions.LoopFlowParametersExtension;
import com.powsybl.openrao.raoapi.parameters.extensions.MnecParametersExtension;
import com.powsybl.openrao.raoapi.parameters.extensions.PtdfApproximation;
Expand Down Expand Up @@ -92,7 +93,7 @@ void testConfigWithExtensions() throws IOException {
assertEquals(2, loadFlowAndSensitivityParameters.getSensitivityFailureOvercost(), DOUBLE_TOLERANCE);

// EXTENSIONS
assertEquals(3, parameters.getExtensions().size());
assertEquals(4, parameters.getExtensions().size());

LoopFlowParametersExtension loopFlowParameters = parameters.getExtension(LoopFlowParametersExtension.class);
assertNotNull(loopFlowParameters);
Expand All @@ -116,6 +117,10 @@ void testConfigWithExtensions() throws IOException {
assertEquals(0.02, relativeMarginsParametersExtension.getPtdfSumLowerBound(), DOUBLE_TOLERANCE);
assertEquals(expectedBoundaries, relativeMarginsParametersExtension.getPtdfBoundariesAsString());

InterTemporalParametersExtension interTemporalParametersExtension = parameters.getExtension(InterTemporalParametersExtension.class);
assertNotNull(interTemporalParametersExtension);
assertEquals(4, interTemporalParametersExtension.getSensitivityComputationsInParallel());

// Compare to json
roundTripTest(parameters, JsonRaoParameters::write, JsonRaoParameters::read, "/RaoParameters_config_withExtensions.json");
}
Expand Down Expand Up @@ -187,6 +192,9 @@ void testConfigWithoutExtensions() throws IOException {
RelativeMarginsParametersExtension relativeMarginsParametersExtension = parameters.getExtension(RelativeMarginsParametersExtension.class);
assertNull(relativeMarginsParametersExtension);

InterTemporalParametersExtension interTemporalParametersExtension = parameters.getExtension(InterTemporalParametersExtension.class);
assertNull(interTemporalParametersExtension);

// Compare to json
roundTripTest(parameters, JsonRaoParameters::write, JsonRaoParameters::read, "/RaoParameters_config_withoutExtensions.json");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@
"ptdf-approximation" : "UPDATE_PTDF_WITH_TOPO",
"ptdf-sum-lower-bound" : 0.05
},
"inter-temporal-parameters" : {
"sensitivity-computations-in-parallel" : 4
},
"loop-flow-parameters" : {
"acceptable-increase" : 20.0,
"ptdf-approximation" : "UPDATE_PTDF_WITH_TOPO_AND_PST",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,9 @@
"ptdf-approximation" : "UPDATE_PTDF_WITH_TOPO_AND_PST",
"ptdf-sum-lower-bound" : 0.02
},
"inter-temporal-parameters" : {
"sensitivity-computations-in-parallel" : 4
},
"loop-flow-parameters" : {
"acceptable-increase" : 11.0,
"ptdf-approximation" : "UPDATE_PTDF_WITH_TOPO",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"version" : "2.4",
"objective-function" : {
"type" : "MAX_MIN_MARGIN_IN_MEGAWATT",
"preventive-stop-criterion" : "SECURE"
},
"range-actions-optimization" : {
"max-mip-iterations" : 5,
"pst-penalty-cost" : 0.01,
"pst-sensitivity-threshold" : 1.0E-6
},
"topological-actions-optimization" : {
"max-preventive-search-tree-depth" : 5,
"max-auto-search-tree-depth" : 2,
"max-curative-search-tree-depth" : 5,
"relative-minimum-impact-threshold" : 0.0,
"absolute-minimum-impact-threshold" : 0.0,
"skip-actions-far-from-most-limiting-element" : false,
"max-number-of-boundaries-for-skipping-actions" : 2
},
"not-optimized-cnecs" : {
"do-not-optimize-curative-cnecs-for-tsos-without-cras" : true
},
"multi-threading" : {
"preventive-leaves-in-parallel" : 8,
"auto-leaves-in-parallel" : 4,
"curative-leaves-in-parallel" : 3
},
"extensions" : {
"mnec-parameters" : {
"acceptable-margin-decrease" : 33.0,
"violation-cost" : 23.0,
"constraint-adjustment-coefficient" : 4.0
},
"inter-temporal-parameters" : {
"sensitivity-computations-in-parallel" : 4
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,7 @@ rao-mnec-parameters:
rao-relative-margins-parameters:
ptdf-boundaries: [ "{FR}-{BE}", "{FR}-{DE}" ]
ptdf-approximation: UPDATE_PTDF_WITH_TOPO_AND_PST
ptdf-sum-lower-bound: 0.02
ptdf-sum-lower-bound: 0.02

rao-inter-temporal-parameters:
sensitivity-computations-in-parallel: 4
Loading
Loading