Skip to content

Commit

Permalink
Don't warn about vendor experiment options (#11544)
Browse files Browse the repository at this point in the history
- Clean up CevalScriptBackend.populateSimulationOptions.
- Don't print warnings about unknown experiment options in they're
  vendor-specific options that begin with `__`.
- Spelling defaulSimOpt => defaultSimOpt.
  • Loading branch information
perost committed Nov 10, 2023
1 parent d3d5d8f commit 05db175
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 108 deletions.
153 changes: 48 additions & 105 deletions OMCompiler/Compiler/Script/CevalScriptBackend.mo
Expand Up @@ -499,108 +499,51 @@ algorithm
end getConst;

protected function populateSimulationOptions
"@auhtor: adrpo
populate simulation options"
input GlobalScript.SimulationOptions inSimOpt;
input list<Absyn.NamedArg> inExperimentSettings;
output GlobalScript.SimulationOptions outSimOpt;
algorithm
outSimOpt := matchcontinue(inSimOpt, inExperimentSettings)
local
Absyn.Exp exp;
list<Absyn.NamedArg> rest;
GlobalScript.SimulationOptions simOpt;
DAE.Exp startTime;
DAE.Exp stopTime;
DAE.Exp numberOfIntervals;
DAE.Exp stepSize;
DAE.Exp tolerance;
DAE.Exp method;
DAE.Exp fileNamePrefix;
DAE.Exp options;
DAE.Exp outputFormat;
DAE.Exp variableFilter, cflags, simflags;
Real rStepSize, rStopTime, rStartTime;
Integer iNumberOfIntervals;
String name,msg;

case (_, {}) then inSimOpt;

case (GlobalScript.SIMULATION_OPTIONS(startTime, stopTime, numberOfIntervals, stepSize, tolerance, method, fileNamePrefix, options, outputFormat, variableFilter, cflags, simflags),
Absyn.NAMEDARG(argName = "Tolerance", argValue = exp)::rest)
equation
tolerance = getConst(exp, DAE.T_REAL_DEFAULT);
simOpt = populateSimulationOptions(
GlobalScript.SIMULATION_OPTIONS(startTime,stopTime,numberOfIntervals,stepSize,tolerance,method,
fileNamePrefix,options,outputFormat,variableFilter,cflags,simflags),
rest);
then
simOpt;

case (GlobalScript.SIMULATION_OPTIONS(startTime, stopTime, numberOfIntervals, stepSize, tolerance, method, fileNamePrefix, options, outputFormat, variableFilter, cflags, simflags),
Absyn.NAMEDARG(argName = "StartTime", argValue = exp)::rest)
equation
startTime = getConst(exp, DAE.T_REAL_DEFAULT);
simOpt = populateSimulationOptions(
GlobalScript.SIMULATION_OPTIONS(startTime,stopTime,numberOfIntervals,stepSize,tolerance,method,
fileNamePrefix,options,outputFormat,variableFilter,cflags,simflags),
rest);
then
simOpt;

case (GlobalScript.SIMULATION_OPTIONS(startTime, stopTime, numberOfIntervals, stepSize, tolerance, method, fileNamePrefix, options, outputFormat, variableFilter, cflags, simflags),
Absyn.NAMEDARG(argName = "StopTime", argValue = exp)::rest)
equation
stopTime = getConst(exp, DAE.T_REAL_DEFAULT);
simOpt = populateSimulationOptions(
GlobalScript.SIMULATION_OPTIONS(startTime,stopTime,numberOfIntervals,stepSize,tolerance,method,
fileNamePrefix,options,outputFormat,variableFilter,cflags,simflags),
rest);
then
simOpt;

case (GlobalScript.SIMULATION_OPTIONS(startTime, stopTime, numberOfIntervals, stepSize, tolerance, method, fileNamePrefix, options, outputFormat, variableFilter, cflags, simflags),
Absyn.NAMEDARG(argName = "NumberOfIntervals", argValue = exp)::rest)
equation
numberOfIntervals = getConst(exp, DAE.T_INTEGER_DEFAULT);
simOpt = populateSimulationOptions(
GlobalScript.SIMULATION_OPTIONS(startTime,stopTime,numberOfIntervals,stepSize,tolerance,method,
fileNamePrefix,options,outputFormat,variableFilter,cflags,simflags),
rest);
then
simOpt;

case (GlobalScript.SIMULATION_OPTIONS(startTime, stopTime, numberOfIntervals, stepSize, tolerance, method, fileNamePrefix, options, outputFormat, variableFilter, cflags, simflags),
Absyn.NAMEDARG(argName = "Interval", argValue = exp)::rest)
equation
DAE.RCONST(rStepSize) = getConst(exp, DAE.T_REAL_DEFAULT);
// a bit different for Interval, handle it LAST!!!!
GlobalScript.SIMULATION_OPTIONS(startTime,stopTime,numberOfIntervals,stepSize,tolerance,method,
fileNamePrefix,options,outputFormat,variableFilter,cflags,simflags) =
populateSimulationOptions(inSimOpt, rest);

DAE.RCONST(rStartTime) = startTime;
DAE.RCONST(rStopTime) = stopTime;
iNumberOfIntervals = realInt(realDiv(realSub(rStopTime, rStartTime), rStepSize));

numberOfIntervals = DAE.ICONST(iNumberOfIntervals);
stepSize = DAE.RCONST(rStepSize);

simOpt = GlobalScript.SIMULATION_OPTIONS(startTime,stopTime,numberOfIntervals,stepSize,tolerance,method,
fileNamePrefix,options,outputFormat,variableFilter,cflags,simflags);
then
simOpt;
input output GlobalScript.SimulationOptions options;
input list<Absyn.NamedArg> args;
protected
String name;
Absyn.Exp value;
Option<DAE.Exp> interval = NONE();
algorithm
for arg in args loop
Absyn.NAMEDARG(argName = name, argValue = value) := arg;

() := match name
case "Tolerance" algorithm options.tolerance := getConst(value, DAE.T_REAL_DEFAULT); then ();
case "StartTime" algorithm options.startTime := getConst(value, DAE.T_REAL_DEFAULT); then ();
case "StopTime" algorithm options.stopTime := getConst(value, DAE.T_REAL_DEFAULT); then ();
case "NumberOfIntervals" algorithm options.numberOfIntervals := getConst(value, DAE.T_INTEGER_DEFAULT); then ();
case "Interval" algorithm interval := SOME(getConst(value, DAE.T_REAL_DEFAULT)); then ();
else
algorithm
if not StringUtil.startsWith(name, "__") then
Error.addCompilerWarning("Ignoring unknown experiment annotation option: " +
name + " = " + Dump.printExpStr(value));
end if;
then
();
end match;
end for;

case (_,Absyn.NAMEDARG(argName = name, argValue = exp)::rest)
equation
msg = "Ignoring unknown experiment annotation option: " + name + " = " + Dump.printExpStr(exp);
Error.addCompilerWarning(msg);
simOpt = populateSimulationOptions(inSimOpt, rest);
then
simOpt;
end matchcontinue;
// Interval needs to be handled last since it depends on the start and stop time.
if isSome(interval) then
options := setSimulationOptionsInterval(options, Expression.toReal(Util.getOption(interval)));
end if;
end populateSimulationOptions;

function setSimulationOptionsInterval
input output GlobalScript.SimulationOptions options;
input Real interval;
protected
Real start_time, stop_time;
algorithm
start_time := Expression.toReal(options.startTime);
stop_time := Expression.toReal(options.stopTime);
options.stepSize := DAE.RCONST(interval);
options.numberOfIntervals := DAE.ICONST(realInt((stop_time - start_time) / interval));
end setSimulationOptionsInterval;

protected function simOptionsAsString
"@author: adrpo
Gets the simulation options as string"
Expand Down Expand Up @@ -3457,15 +3400,15 @@ algorithm
list<String> args;
Boolean haveAnnotation;
SimCode.SimulationSettings simSettings;
GlobalScript.SimulationOptions defaulSimOpt;
GlobalScript.SimulationOptions defaultSimOpt;
case (cache,env,_,fileNamePrefix,_)
algorithm
if isSome(inSimSettingsOpt) then
SOME(simSettings) := inSimSettingsOpt;
else
defaulSimOpt := buildSimulationOptionsFromModelExperimentAnnotation(className, fileNamePrefix, SOME(defaultSimulationOptions));
simSettings := convertSimulationOptionsToSimCode(defaulSimOpt);
defaultSimOpt := buildSimulationOptionsFromModelExperimentAnnotation(className, fileNamePrefix, SOME(defaultSimulationOptions));
simSettings := convertSimulationOptionsToSimCode(defaultSimOpt);
end if;
if Config.ignoreCommandLineOptionsAnnotation() then
Expand Down Expand Up @@ -3999,7 +3942,7 @@ protected
Boolean staticSourceCodeFMU, success;
String filenameprefix, fmutmp, logfile, configureLogFile, dir, cmd;
String fmuTargetName;
GlobalScript.SimulationOptions defaulSimOpt;
GlobalScript.SimulationOptions defaultSimOpt;
SimCode.SimulationSettings simSettings;
list<String> libs;
Boolean isWindows;
Expand Down Expand Up @@ -4034,8 +3977,8 @@ algorithm
if isSome(inSimSettings) then
SOME(simSettings) := inSimSettings;
else
defaulSimOpt := buildSimulationOptionsFromModelExperimentAnnotation(className, filenameprefix, SOME(defaultSimulationOptions));
simSettings := convertSimulationOptionsToSimCode(defaulSimOpt);
defaultSimOpt := buildSimulationOptionsFromModelExperimentAnnotation(className, filenameprefix, SOME(defaultSimulationOptions));
simSettings := convertSimulationOptionsToSimCode(defaultSimOpt);
end if;
FlagsUtil.setConfigBool(Flags.BUILDING_FMU, true);
FlagsUtil.setConfigString(Flags.FMI_VERSION, FMUVersion);
Expand Down
3 changes: 0 additions & 3 deletions testsuite/flattening/modelica/connectors/Ticket4062.mo
Expand Up @@ -486,7 +486,4 @@ end Ticket4062;
// serialReceive.pkgOut.userPkgBitSize = unpackInt.pkgIn.userPkgBitSize;
// integerToReal.u = unpackInt.y;
// end Ticket4062;
// Warning: Ignoring unknown experiment annotation option: __Dymola_fixedstepsize = 0.001
// Warning: Ignoring unknown experiment annotation option: __Dymola_Algorithm = "Euler"
//
// endResult

0 comments on commit 05db175

Please sign in to comment.