Skip to content

[WIP] Cucumber steps for Marmot (POC) #1298

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

Open
wants to merge 3 commits into
base: idcc/ics_importer
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 @@ -51,7 +51,7 @@ FbConstraintCreationContext createCrac(FlowBasedConstraintDocument fbConstraintD
offsetDateTime = fbConstraintCracCreationParameters.getTimestamp();
}
FbConstraintCreationContext creationContext = new FbConstraintCreationContext(offsetDateTime, network.getNameOrId());
Crac crac = cracCreatorParameters.getCracFactory().create(fbConstraintDocument.getDocumentIdentification().getV());
Crac crac = cracCreatorParameters.getCracFactory().create(fbConstraintDocument.getDocumentIdentification().getV(), fbConstraintDocument.getDocumentIdentification().getV(), offsetDateTime);
addFbContraintInstants(crac);
RaUsageLimitsAdder.addRaUsageLimits(crac, cracCreatorParameters);

Expand Down
6 changes: 6 additions & 0 deletions tests/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,12 @@
</dependency>

<!-- Runtime dependencies -->
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.18.0</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>com.powsybl</groupId>
<artifactId>powsybl-cgmes-conversion</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@

public final class CommonTestData {

private static final String DEFAULT_CRAC_CREATION_PARAMETERS_PATH = "cracCreationParameters/common/CracCreationParameters_default.json";
static final String DEFAULT_CRAC_CREATION_PARAMETERS_PATH = "cracCreationParameters/common/CracCreationParameters_default.json";
private static final String DEFAULT_RAO_PARAMETERS_PATH = "configurations/common/RaoParameters_default.json";

private static String dataPrefix = "src/test/resources/files/";
Expand All @@ -56,13 +56,13 @@ public final class CommonTestData {
private static Boolean coreCcNetworkPreprocessing = false;
private static Network network;

private static String cracPath;
static String cracPath;
private static String cracCreationParametersPath;
private static CracCreationContext cracCreationContext;
private static Crac crac;

private static String raoParametersPath;
private static RaoParameters raoParameters;
static String raoParametersPath;
static RaoParameters raoParameters;

private static String loopflowGlskPath;
private static String monitoringGlskPath;
Expand Down Expand Up @@ -357,7 +357,7 @@ private static OffsetDateTime importTimestampFromCracCreationParameters(String c
}
}

private static void addTimestampToCracCreationParameters(String cracFormat, OffsetDateTime timestamp, CracCreationParameters cracCreationParameters) {
static void addTimestampToCracCreationParameters(String cracFormat, OffsetDateTime timestamp, CracCreationParameters cracCreationParameters) {

if (cracFormat.equals("CimCrac")) {
CimCracCreationParameters cimParams = new CimCracCreationParameters();
Expand All @@ -382,7 +382,7 @@ private static RaoParameters buildDefaultConfig() {
}
}

private static RaoParameters buildConfig(File configFile) {
static RaoParameters buildConfig(File configFile) {
RaoParameters config = buildDefaultConfig();
try (InputStream configStream = new FileInputStream(configFile)) {
JsonRaoParameters.update(config, configStream);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@

/*
* Copyright (c) 2025, 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.tests.steps;

import com.powsybl.iidm.network.Network;
import com.powsybl.openrao.commons.TemporalData;
import com.powsybl.openrao.commons.TemporalDataImpl;
import com.powsybl.openrao.data.crac.api.Crac;
import com.powsybl.openrao.data.crac.api.CracCreationContext;
import com.powsybl.openrao.data.crac.api.parameters.CracCreationParameters;
import com.powsybl.openrao.data.crac.api.parameters.JsonCracCreationParameters;
import com.powsybl.openrao.raoapi.IcsImporter;
import com.powsybl.openrao.raoapi.InterTemporalRao;
import com.powsybl.openrao.raoapi.InterTemporalRaoInput;
import com.powsybl.openrao.raoapi.RaoInput;
import com.powsybl.openrao.raoapi.parameters.extensions.OpenRaoSearchTreeParameters;
import com.powsybl.openrao.raoapi.parameters.extensions.SearchTreeRaoRangeActionsOptimizationParameters;
import io.cucumber.datatable.DataTable;
import io.cucumber.java.en.Given;
import io.cucumber.java.en.When;
import org.apache.commons.lang3.tuple.Pair;

import java.io.*;
import java.time.OffsetDateTime;
import java.util.*;

import static com.powsybl.openrao.tests.steps.CommonTestData.*;
import static com.powsybl.openrao.tests.utils.Helpers.*;
import static com.powsybl.openrao.tests.utils.Helpers.getFile;

public final class InterTemporalRaoSteps {
private static String networkFolderPath;
private static String icsStaticPath;
private static String icsSeriesPath;
private static InterTemporalRaoInput interTemporalRaoInput;

private InterTemporalRaoSteps() {
// should not be instantiated
}

@Given("network files are in folder {string}")
public static void networkFilesAreIn(String folderPath) {
setNetworkInputs(folderPath);
}

private static void setNetworkInputs(String folderPath) {
networkFolderPath = getResourcesPath().concat("cases/").concat(folderPath);
}

@Given("ics static file is {string}")
public static void icsStaticFileIs(String path) {
icsStaticPath = getResourcesPath().concat("ics/").concat(path);
}

@Given("ics series file is {string}")
public static void icsSeriesFileIs(String path) {
icsSeriesPath = getResourcesPath().concat("ics/").concat(path);
}

@Given("intertemporal rao inputs are:")
public static void intertemporalRaoInputsAre(DataTable arg1) throws IOException {
loadDataForInterTemporalRao(arg1);
}

public static void loadDataForInterTemporalRao(DataTable arg1) throws IOException {
CracCreationParameters cracCreationParameters;
try {
String ccpToImport = getResourcesPath().concat(DEFAULT_CRAC_CREATION_PARAMETERS_PATH);
InputStream cracCreationParametersInputStream = new BufferedInputStream(new FileInputStream(getFile(ccpToImport)));
cracCreationParameters = JsonCracCreationParameters.read(cracCreationParametersInputStream);
} catch (FileNotFoundException e) {
throw new RuntimeException(e);
}
File cracFile = getFile(CommonTestData.cracPath);

CommonTestData.raoParameters = buildConfig(getFile(CommonTestData.raoParametersPath));
raoParameters.getExtension(OpenRaoSearchTreeParameters.class).getRangeActionsOptimizationParameters().getLinearOptimizationSolver()
.setSolver(SearchTreeRaoRangeActionsOptimizationParameters.Solver.valueOf("XPRESS"));

TemporalData<RaoInput> raoInputs = new TemporalDataImpl<>();
List<Map<String, String>> inputs = arg1.asMaps(String.class, String.class);
for (Map<String, String> tsInput : inputs) {
OffsetDateTime offsetDateTime = getOffsetDateTimeFromBrusselsTimestamp(tsInput.get("Timestamp"));
addTimestampToCracCreationParameters("FlowBasedConstraintDocument", offsetDateTime, cracCreationParameters);
Network network = importNetwork(getFile(networkFolderPath.concat(tsInput.get("Network"))), false);
Pair<Crac, CracCreationContext> cracImportResult = importCrac(cracFile, network, cracCreationParameters);
RaoInput raoInput = RaoInput
.build(network, cracImportResult.getLeft())
.build();
raoInputs.add(offsetDateTime, raoInput);
}

interTemporalRaoInput = new InterTemporalRaoInput(raoInputs, new HashSet<>());
IcsImporter.populateInputWithICS(interTemporalRaoInput, new FileInputStream(getFile(icsStaticPath)), new FileInputStream(getFile(icsSeriesPath)));
}

@When("I launch marmot")
public static void iLaunchMarmot() {
InterTemporalRao.run(interTemporalRaoInput, CommonTestData.getRaoParameters());
}
}
Loading