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

Inter temporal extension of parameters for sensitivity computation #1254

Open
wants to merge 28 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
c784265
create class InterTemporalRaoInput
Dec 10, 2024
4a3ee38
removed parameters from input class
Dec 11, 2024
218582b
Merge branch 'main' into features/InterTemporalSensitivity
Dec 11, 2024
cb1b85d
WIP Beginning of InterTemporal Sensitivity Analysis
Dec 11, 2024
d14c18a
add LF and sensi values in test
bqth29 Dec 12, 2024
1a0e329
Fixed sensi computation in parallel
Dec 12, 2024
ff7c80a
add InterTemporalParameters
Dec 12, 2024
f590971
Merge branch 'main' into features/InterTemporalSensitivity
bqth29 Dec 12, 2024
18eda9c
more relevant tests
bqth29 Dec 12, 2024
9118bf0
merge head
Dec 12, 2024
5db3cbe
add json for inter temporal parameter
Dec 12, 2024
2d0d2a0
fix conflict
Dec 12, 2024
751ec91
fix style
Dec 13, 2024
5f81d1f
fix tests
bqth29 Dec 13, 2024
73ad3a8
parallel RAOs
bqth29 Dec 13, 2024
4c9b880
use right Pait class
bqth29 Dec 13, 2024
44e255f
intertemporal pool
bqth29 Dec 13, 2024
481fe3e
Merge branch 'feature/multi-ts-topological-optimization' into feature…
bqth29 Dec 13, 2024
ee64c9c
use of inter-temporal pool for parallel computation
bqth29 Dec 13, 2024
e2e0dd4
Merge branch 'main' into features/InterTemporalSensitivity
bqth29 Jan 2, 2025
49129bd
some fixes
bqth29 Jan 2, 2025
c9f5777
refactored inputs
bqth29 Jan 2, 2025
ae8b9ff
changes after comments
bqth29 Jan 3, 2025
c9a1419
Merge branch 'main' into features/InterTemporalSensitivity
bqth29 Jan 6, 2025
0819feb
use ThreadPoolExecutor for more relevant nested inter temporal pools
bqth29 Jan 6, 2025
ec84aac
Merge branch 'features/InterTemporalSensitivity' of https://github.co…
bqth29 Jan 6, 2025
926c9ef
Merge branch 'main' into feature/inter-temporal-parameters-for-sensit…
bqth29 Jan 6, 2025
f273b1b
Merge branch 'main' into feature/inter-temporal-parameters-for-sensit…
bqth29 Jan 17, 2025
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,12 +7,14 @@

package com.powsybl.openrao.raoapi;

import com.powsybl.openrao.commons.OpenRaoException;
import com.powsybl.openrao.commons.TemporalData;
import com.powsybl.openrao.data.intertemporalconstraint.PowerGradientConstraint;

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

/**
* @author Thomas Bouquet {@literal <thomas.bouquet at rte-france.com>}
Expand All @@ -27,6 +29,7 @@ public InterTemporalRaoInput(TemporalData<RaoInput> raoInputs, Set<OffsetDateTim
this.raoInputs = raoInputs;
this.timestampsToRun = timestampsToRun;
this.powerGradientConstraints = powerGradientConstraints;
checkTimestampsToRun();
}

public InterTemporalRaoInput(TemporalData<RaoInput> raoInputs, Set<PowerGradientConstraint> powerGradientConstraints) {
Expand All @@ -44,4 +47,11 @@ public Set<OffsetDateTime> getTimestampsToRun() {
public Set<PowerGradientConstraint> getPowerGradientConstraints() {
return powerGradientConstraints;
}

private void checkTimestampsToRun() {
Set<String> invalidTimestampsToRun = timestampsToRun.stream().filter(timestamp -> !raoInputs.getTimestamps().contains(timestamp)).map(OffsetDateTime::toString).collect(Collectors.toSet());
if (!invalidTimestampsToRun.isEmpty()) {
throw new OpenRaoException("Timestamp(s) '" + String.join("', '", invalidTimestampsToRun) + "' are not defined 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 com.powsybl.openrao.data.crac.api.rangeaction.VariationDirection;
Expand All @@ -21,6 +22,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 @@ -60,4 +62,16 @@ void testInstantiateInterTemporalRaoInputAllTimestamps() {
assertEquals(Set.of(timestamp1, timestamp2, timestamp3), input.getTimestampsToRun());
assertEquals(powerGradientConstraints, input.getPowerGradientConstraints());
}

@Test
void testInstantiateWithMissingTimestamp() {
OpenRaoException exception = assertThrows(OpenRaoException.class, () -> new InterTemporalRaoInput(temporalData, Set.of(OffsetDateTime.of(2024, 12, 11, 14, 29, 0, 0, ZoneOffset.UTC)), Set.of()));
assertEquals("Timestamp(s) '2024-12-11T14:29Z' are not defined in the inputs.", exception.getMessage());
}

@Test
void testInstantiateWithMissingTimestamps() {
OpenRaoException exception = assertThrows(OpenRaoException.class, () -> new InterTemporalRaoInput(temporalData, Set.of(OffsetDateTime.of(2024, 12, 11, 14, 29, 0, 0, ZoneOffset.UTC), OffsetDateTime.of(2024, 11, 11, 14, 29, 0, 0, ZoneOffset.UTC)), Set.of()));
assertEquals("Timestamp(s) '2024-11-11T14:29Z', '2024-12-11T14:29Z' are not defined 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
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