Skip to content

Commit

Permalink
Fix useModelOptimizers parameter
Browse files Browse the repository at this point in the history
Add getParameter to ParametersSet

Signed-off-by: lisrte <laurent.issertial@rte-france.com>
  • Loading branch information
Lisrte committed Nov 3, 2023
1 parent 9a60954 commit f8912ff
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public static DynaWaltzParameters load(PlatformConfig platformConfig, FileSystem
// Writes final state IIDM
boolean writeFinalState = config.flatMap(c -> c.getOptionalBooleanProperty("writeFinalState")).orElse(DEFAULT_WRITE_FINAL_STATE);

boolean useModelOptimizers = config.flatMap(c -> c.getOptionalBooleanProperty("useOptimizers")).orElse(DEFAULT_USE_MODEL_OPTIMIZERS);
boolean useModelOptimizers = config.flatMap(c -> c.getOptionalBooleanProperty("useModelOptimizers")).orElse(DEFAULT_USE_MODEL_OPTIMIZERS);

// Load xml files
List<ParametersSet> modelsParameters = ParametersXml.load(parametersPath);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,35 +67,39 @@ public List<Reference> getReferences() {
}

public boolean getBool(String parameterName) {
Parameter parameter = getParameter(parameterName, ParameterType.BOOL);
Parameter parameter = getParameterOrThrows(parameterName, ParameterType.BOOL);
return Boolean.parseBoolean(parameter.value());
}

public double getDouble(String parameterName) {
Parameter parameter = getParameter(parameterName, ParameterType.DOUBLE);
Parameter parameter = getParameterOrThrows(parameterName, ParameterType.DOUBLE);
return Double.parseDouble(parameter.value());
}

public int getInt(String parameterName) {
Parameter parameter = getParameter(parameterName, ParameterType.INT);
Parameter parameter = getParameterOrThrows(parameterName, ParameterType.INT);
return Integer.parseInt(parameter.value());
}

public String getString(String parameterName) {
Parameter parameter = getParameter(parameterName, ParameterType.STRING);
Parameter parameter = getParameterOrThrows(parameterName, ParameterType.STRING);
return parameter.value();
}

public Parameter getParameter(String parameterName) {
return parameters.get(parameterName);
}

public Parameter getParameterOrThrows(String parameterName) {
Parameter parameter = parameters.get(parameterName);
if (parameter == null) {
throw new IllegalArgumentException("Parameter " + parameterName + " not found in set " + id);
}
return parameter;
}

private Parameter getParameter(String parameterName, ParameterType type) {
Parameter parameter = getParameter(parameterName);
private Parameter getParameterOrThrows(String parameterName, ParameterType type) {
Parameter parameter = getParameterOrThrows(parameterName);
if (parameter.type() != type) {
throw new PowsyblException("Invalid parameter type: " + parameter.type() + " (" + type + " expected)");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,23 +65,23 @@ void checkParameters() throws IOException {

assertEquals(networkParametersId, parameters.getNetworkParameters().getId());
ParametersSet networkParameters = parameters.getNetworkParameters();
Parameter loadTp = networkParameters.getParameter("load_Tp");
Parameter loadTp = networkParameters.getParameterOrThrows("load_Tp");
assertEquals("90", loadTp.value());
assertEquals("load_Tp", loadTp.name());
assertEquals(ParameterType.DOUBLE, loadTp.type());
Parameter loadControllable = networkParameters.getParameter("load_isControllable");
Parameter loadControllable = networkParameters.getParameterOrThrows("load_isControllable");
assertEquals("false", loadControllable.value());
assertEquals("load_isControllable", loadControllable.name());
assertEquals(ParameterType.BOOL, loadControllable.type());

ParametersSet solverParameters = parameters.getSolverParameters();
assertEquals(solverParametersId, solverParameters.getId());
assertEquals(solverType, parameters.getSolverType());
Parameter order = solverParameters.getParameter("order");
Parameter order = solverParameters.getParameterOrThrows("order");
assertEquals("1", order.value());
assertEquals("order", order.name());
assertEquals(ParameterType.INT, order.type());
Parameter absAccuracy = solverParameters.getParameter("absAccuracy");
Parameter absAccuracy = solverParameters.getParameterOrThrows("absAccuracy");
assertEquals("1e-4", absAccuracy.value());
assertEquals("absAccuracy", absAccuracy.name());
assertEquals(ParameterType.DOUBLE, absAccuracy.type());
Expand Down Expand Up @@ -164,11 +164,11 @@ void checkException() throws IOException {
}

private static void checkModelParameters(DynaWaltzParameters dynaWaltzParameters) {
Parameter booleanParameter = dynaWaltzParameters.getModelParameters("test").getParameter("boolean");
Parameter booleanParameter = dynaWaltzParameters.getModelParameters("test").getParameterOrThrows("boolean");
assertEquals("true", booleanParameter.value());
assertEquals("boolean", booleanParameter.name());
assertEquals(ParameterType.BOOL, booleanParameter.type());
Parameter stringParameter = dynaWaltzParameters.getModelParameters("test").getParameter("string");
Parameter stringParameter = dynaWaltzParameters.getModelParameters("test").getParameterOrThrows("string");
assertEquals("aString", stringParameter.value());
assertEquals("string", stringParameter.name());
assertEquals(ParameterType.STRING, stringParameter.type());
Expand Down

0 comments on commit f8912ff

Please sign in to comment.