Skip to content

Conversation

@joewa
Copy link

@joewa joewa commented Dec 27, 2025

Related Issues

This pull request is a re-implementation of issue #165 because of a new library architecture @adeas31

Purpose

  • Enable the usage of a pre-built model executable when instantiating ModelicaSystemRunner. This will gain some efficiency e.g. when only the parameters or the input data changes between different simulation runs.
  • Avoid the unnecessary overhead of using an OMCSession (with ZeroMQ connection).
  • Slim (conda) environments, suited for efficient "simulation only" workflows.
  • Applying different variableFilter's (or overrides in general) when calling the pre-built model executables.

Approach

ModelicaSystemRunner will simulate pre-built models with customized parameters or inputs.

from OMPython.OMRunner import ModelicaSystemRunner
mod = ModelicaSystemRunner(modelname='BouncingBall', runpath='.')

The simulation can be executed (with a customized set of output variables) like this:

res_vars = ['h', 'v']
log_str += str(mod.simulate(
    resultfile=resfilepathname,
    overrideaux='variableFilter="'+'|'.join(list(res_vars))+'"'
))

The log_str contains the models output from stdout and stderr.

The Strategy: "Duck Typing" (ModelicaSystemRunner)

Instead of modifying all OMPython modules, I created a standalone class (ModelicaSystemRunner) that mimics the API of OMPython. It will run purely on standard Python libraries (xml.etree, subprocess), making it zero-dependency and perfect for efficient use in slim environments.

Idea for way forward

Create a module + class ModelicaSystemBase that has all functions that are common for ModelicaSystem, ModelicaSystemRunner and probably ModelicaSystemCmd but without dependency on OMCSession. This might reduce the need to duplicate code in all classes.

@joewa
Copy link
Author

joewa commented Dec 27, 2025

@adeas31

@syntron
Copy link
Contributor

syntron commented Dec 27, 2025

@joewa I think it would be possible to use os.PathLike instead of OMCPath to define ModelicaSystemBase - this should be quite simple and would allow to use it - as suggested - as a common base for ModelicaSystemRunner as well as ModelicaSystem

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants