Skip to content

Commit

Permalink
Fix hardcoded number of intervals (#149)
Browse files Browse the repository at this point in the history
* allow configuration of numberOfIntervals for a library instead of the hardcoded 2500
- change also naming from default_tolerance to defaultTolerance as we use camel case for the other json components
- see also: OpenModelica/OpenModelica#13027 (comment)

* output timeout to file, missed one
  • Loading branch information
adrpo authored Oct 30, 2024
1 parent 350ecc9 commit 98feff2
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 9 deletions.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,16 @@ The scripts from this repository can be used to run regression tests for public,
"referenceFileExtension":"mat",
"referenceFileNameDelimiter":"/",
"referenceFileNameExtraName":"$ClassName",
"referenceFiles":{
"referenceFiles": "/path/to/some/SomeDirectory", // specifies a directory with the files
"referenceFiles": "$ENV_VAR/SomeDirectory", // specifies a directory with the files via an env var
"referenceFiles":{ // specified as an URL, directory destination, git branch and git directory
"giturl":"https://github.com/myName/MyModelicaLibrary-ref",
"destination":"ReferenceFiles/MyModelicaLibrary",
"git-ref": "main",
"git-directory": "ReferenceFiles"
},
"defaultTolerance": 1e-6, // tolerance for tests if not specified by the model, defaults to 1e-6
"defaultNumberOfIntervals": 500, // number of intervals for tests if not specified by the model, defaults to 500
"ulimitOmc":800, // specify a max timeout for a model build
"ulimitExe":300, // specify a max timeout for a model simulation
"ulimitMemory":62000000, // specify a max for the virtual memory of the running process when building a model
Expand Down
3 changes: 2 additions & 1 deletion library.html.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ OpenModelicaLibraryTesting Changes<br>
<p>
BuildModel time limit: #ulimitOmc#s<br>
Simulation time limit: #ulimitExe#s<br>
Default tolerance: #default_tolerance#<br>
Default tolerance: #defaultTolerance#<br>
Default number of intervals: #defaultNumberOfIntervals#<br>
Optimization level: #optlevel#</p>
#referenceFiles#
#referenceTool#
Expand Down
3 changes: 2 additions & 1 deletion shared.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ def fixData(data,abortSimulationFlag,alarmFlag,overrideDefaults,defaultCustomCom
data["simCodeTarget"] = data.get("simCodeTarget") or "C"
data["referenceFileExtension"] = data.get("referenceFileExtension") or "mat"
data["referenceFileNameDelimiter"] = data.get("referenceFileNameDelimiter") or "."
data["default_tolerance"] = float(data.get("default_tolerance") or 1e-6)
data["defaultTolerance"] = float(data.get("defaultTolerance") or 1e-6)
data["defaultNumberOfIntervals"] = int(data.get("defaultNumberOfIntervals") or 500)
data["reference_reltol"] = float(data.get("reference_reltol") or 3e-3)
data["reference_reltolDiffMinMax"] = float(data.get("reference_reltolDiffMinMax") or 3e-3)
data["reference_rangeDelta"] = float(data.get("reference_rangeDelta") or 1e-3)
Expand Down
6 changes: 4 additions & 2 deletions test.py
Original file line number Diff line number Diff line change
Expand Up @@ -726,7 +726,8 @@ def hashReferenceFiles(s):
(u"#customCommands#", conf["customCommands"]),
(u"#modelVersion#", conf["libraryVersion"]),
(u"#ulimitOmc#", str(conf["ulimitOmc"])),
(u"#default_tolerance#", str(conf["default_tolerance"])),
(u"#defaultTolerance#", str(conf["defaultTolerance"])),
(u"#defaultNumberOfIntervals#", str(conf["defaultNumberOfIntervals"])),
(u"#reference_reltol#", str(conf["reference_reltol"])),
(u"#reference_reltolDiffMinMax#", str(conf["reference_reltolDiffMinMax"])),
(u"#reference_rangeDelta#", str(conf["reference_rangeDelta"])),
Expand Down Expand Up @@ -1061,7 +1062,8 @@ def cpu_name():
(u"#metadata#", html.escape(conf["metadata"])),
(u"#ulimitOmc#", html.escape(str(conf["ulimitOmc"]))),
(u"#ulimitExe#", html.escape(str(conf["ulimitExe"]))),
(u"#default_tolerance#", html.escape(str(conf["default_tolerance"]))),
(u"#defaultTolerance#", html.escape(str(conf["defaultTolerance"]))),
(u"#defaultNumberOfIntervals#", html.escape(str(conf["defaultNumberOfIntervals"]))),
(u"#simFlags#", html.escape(conf.get("simFlags") or "")),
(u"#referenceFiles#", ('<p>Reference Files: %s</p>%s' % ((conf["referenceFilesURL"].replace(os.path.dirname(os.path.realpath(__file__)),"")), gitReferenceFilesVersion)) if ((conf.get("referenceFilesURL") or "") != "") else ""),
(u"#referenceTool#", ('<p>Verified using: %s (diffSimulationResults)</p>' % html.escape(ompython_omc_version)) if ((conf.get("referenceFiles") or "") != "") else ""),
Expand Down
8 changes: 4 additions & 4 deletions testmodel.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def writeResultAndExit(exitStatus):

def sendExpressionTimeout(omc, cmd, timeout):
with open(errFile, 'a+') as fp:
fp.write(cmd + "\n")
fp.write("%s [Timeout %s]\n" % (cmd, timeout))
def target(res):
try:
res[0] = omc.sendExpression(cmd)
Expand Down Expand Up @@ -92,7 +92,7 @@ def target(res):

def checkOutputTimeout(cmd, timeout, conf=None):
with open(errFile, 'a+') as fp:
fp.write(cmd + "\n")
fp.write("%s [Timeout %s]\n" % (cmd, timeout))
def target(res):
try:
env = os.environ.copy()
Expand Down Expand Up @@ -322,7 +322,7 @@ def sendExpressionOldOrNew(cmd):
return omc_new.sendExpression(cmd)

annotationSimFlags=""
(startTime,stopTime,tolerance,numberOfIntervals,stepSize)=sendExpressionOldOrNew('getSimulationOptions(%s,defaultTolerance=%s,defaultNumberOfIntervals=2500)' % (conf["modelName"],conf["default_tolerance"]))
(startTime,stopTime,tolerance,numberOfIntervals,stepSize)=sendExpressionOldOrNew('getSimulationOptions(%s,defaultTolerance=%s,defaultNumberOfIntervals=%s)' % (conf["modelName"], conf["defaultTolerance"], conf["defaultNumberOfIntervals"]))
if conf["simCodeTarget"]=="C" and sendExpressionOldOrNew('classAnnotationExists(%s, __OpenModelica_simulationFlags)' % conf["modelName"]):
for flag in sendExpressionOldOrNew('getAnnotationNamedModifiers(%s,"__OpenModelica_simulationFlags")' % conf["modelName"]):
if flag=="The searched annotation name not found":
Expand All @@ -342,7 +342,7 @@ def sendExpressionOldOrNew(cmd):
if conf.get("fmi"):
cmd='"" <> buildModelFMU(%s,fileNamePrefix="%s",fmuType="%s",version="%s",platforms={"static"})' % (conf["modelName"],conf["fileName"].replace(".","_"),conf["fmuType"],conf["fmi"])
else:
cmd='translateModel(%s,tolerance=%g,outputFormat="%s",numberOfIntervals=%d,variableFilter="%s",fileNamePrefix="%s")' % (conf["modelName"],tolerance,outputFormat,2*numberOfIntervals,variableFilter,conf["fileName"])
cmd='translateModel(%s,tolerance=%g,outputFormat="%s",numberOfIntervals=%d,variableFilter="%s",fileNamePrefix="%s")' % (conf["modelName"],tolerance,outputFormat,numberOfIntervals,variableFilter,conf["fileName"])
with open(errFile, 'a+') as fp:
fp.write("Running command: %s\n"%(cmd))
try:
Expand Down

0 comments on commit 98feff2

Please sign in to comment.