Skip to content

Commit f052940

Browse files
sjoelundclaude
andcommitted
Apply __OpenModelica_simulationFlags to wasm-jit
The annotation was only read for `simCodeTarget=C`, so a model asking for a specific solver got it in the C run and the default `dassl` in the wasm-jit one. That is not a like-for-like comparison, and where the annotation exists it is usually there because the default solver copes badly: ScalableTestSuite's CocurrentHeatExchangerEquations asks for `ida` (sparse, KLU), and dassl's dense factorization made the wasm-jit runs scale cubically instead of linearly. | N | dassl | ida (annotation) | C, ida | | ---- | ------ | ---------------- | ------ | | 320 | 3.7s | 0.34s | 0.4s | | 640 | 31.9s | 1.01s | 0.85s | | 1280 | >600s | 2.82s | 1.9s | The C path validates each flag by running the HelloWorld executable with it. wasm-jit builds no executable — the runtime is inside omc — so probe it there instead, by simulating a trivial model through the session that is already open. Co-authored-by: Claude <noreply@anthropic.com>
1 parent 65f890e commit f052940

1 file changed

Lines changed: 14 additions & 4 deletions

File tree

testmodel.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -410,23 +410,33 @@ def sendExpressionOldOrNew(cmd):
410410
loadLibraryInNewOM()
411411
return omc_new.sendExpression(cmd)
412412

413+
haveFlagCheckModel=False
414+
def wasmJitAcceptsFlag(flagVal):
415+
# There is no HelloWorld executable to probe: the wasm-jit runtime lives in
416+
# omc, so ask it directly whether a trivial model still simulates.
417+
global haveFlagCheckModel
418+
if not haveFlagCheckModel:
419+
sendExpressionOldOrNew('loadString("model OMLibTestFlagCheck Real x(start = 1, fixed = true); equation der(x) = -x; end OMLibTestFlagCheck;")')
420+
haveFlagCheckModel=True
421+
return bool((sendExpressionOldOrNew('simulate(OMLibTestFlagCheck,simflags="%s")' % flagVal) or {}).get("resultFile"))
422+
413423
annotationSimFlags=""
414424
(startTime,stopTime,tolerance,numberOfIntervals,stepSize)=sendExpressionOldOrNew('getSimulationOptions(%s,defaultTolerance=%s,defaultNumberOfIntervals=%s)' % (conf["modelName"], conf["defaultTolerance"], max(conf["defaultNumberOfIntervals"], numberOfIntervalsInReference)))
415-
if conf["simCodeTarget"]=="C" and sendExpressionOldOrNew('classAnnotationExists(%s, __OpenModelica_simulationFlags)' % conf["modelName"]):
425+
if conf["simCodeTarget"] in ("C","wasm-jit") and sendExpressionOldOrNew('classAnnotationExists(%s, __OpenModelica_simulationFlags)' % conf["modelName"]):
416426
for flag in sendExpressionOldOrNew('getAnnotationNamedModifiers(%s,"__OpenModelica_simulationFlags")' % conf["modelName"]):
417427
if flag=="The searched annotation name not found":
418428
# Old, stupid API
419429
continue
420430
val=sendExpressionOldOrNew('getAnnotationModifierValue(%s,"__OpenModelica_simulationFlags","%s")' % (conf["modelName"],flag))
421431
flagVal=" -noemit -%s=%s" % (flag,val)
422-
if shared.simulationAcceptsFlag(flagVal, checkOutput=False, cwd="..", isWin=isWin):
432+
if wasmJitAcceptsFlag("-%s=%s" % (flag,val)) if isWasmJit else shared.simulationAcceptsFlag(flagVal, checkOutput=False, cwd="..", isWin=isWin):
423433
annotationSimFlags+=" -%s=%s" % (flag,val)
424434
else:
425435
with open(errFile, 'a+') as fp:
426-
fp.write("Ignoring simflag %s since it seems broken on HelloWorld\n" % flagVal)
436+
fp.write("Ignoring simflag %s since the simulation runtime does not accept it\n" % flagVal)
427437

428438
def simulateCmd(resimulate):
429-
simflags = ("%s %s -lv LOG_STATS" % (conf["simFlags"],emit_protected)).strip()
439+
simflags = ("%s %s %s -lv LOG_STATS" % (annotationSimFlags,conf["simFlags"],emit_protected)).strip()
430440
return 'simulate(%s,startTime=%g,stopTime=%g,tolerance=%g,numberOfIntervals=%d,outputFormat="%s",variableFilter="%s",fileNamePrefix="%s",simflags="%s"%s)' % (conf["modelName"],startTime,stopTime,tolerance,numberOfIntervals,outputFormat,variableFilter,conf["fileName"],simflags,(',resimulateExecutable="%s"' % conf["fileName"]) if resimulate else "")
431441

432442
# TODO: Detect and handle the case where RT_CLOCK is not available in OMC

0 commit comments

Comments
 (0)