From 98feff2926142bff2d5d0cd8e6af84ada76be8f3 Mon Sep 17 00:00:00 2001 From: Adrian Pop Date: Wed, 30 Oct 2024 14:11:51 +0100 Subject: [PATCH] Fix hardcoded number of intervals (#149) * 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: https://github.com/OpenModelica/OpenModelica/issues/13027#issuecomment-2432714963 * output timeout to file, missed one --- README.md | 6 +++++- library.html.tpl | 3 ++- shared.py | 3 ++- test.py | 6 ++++-- testmodel.py | 8 ++++---- 5 files changed, 17 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 812df04..d76396d 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/library.html.tpl b/library.html.tpl index a975a13..4f43d50 100644 --- a/library.html.tpl +++ b/library.html.tpl @@ -42,7 +42,8 @@ OpenModelicaLibraryTesting Changes

BuildModel time limit: #ulimitOmc#s
Simulation time limit: #ulimitExe#s
-Default tolerance: #default_tolerance#
+Default tolerance: #defaultTolerance#
+Default number of intervals: #defaultNumberOfIntervals#
Optimization level: #optlevel#

#referenceFiles# #referenceTool# diff --git a/shared.py b/shared.py index 8a3f462..27e100b 100644 --- a/shared.py +++ b/shared.py @@ -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) diff --git a/test.py b/test.py index 6880ca8..b7753c7 100755 --- a/test.py +++ b/test.py @@ -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"])), @@ -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#", ('

Reference Files: %s

%s' % ((conf["referenceFilesURL"].replace(os.path.dirname(os.path.realpath(__file__)),"")), gitReferenceFilesVersion)) if ((conf.get("referenceFilesURL") or "") != "") else ""), (u"#referenceTool#", ('

Verified using: %s (diffSimulationResults)

' % html.escape(ompython_omc_version)) if ((conf.get("referenceFiles") or "") != "") else ""), diff --git a/testmodel.py b/testmodel.py index 3ddcb87..a1c9705 100755 --- a/testmodel.py +++ b/testmodel.py @@ -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) @@ -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() @@ -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": @@ -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: