Skip to content

ModelicaSystem cannot instantiate model, but sendExpression works #478

Description

@cbu-hw

I am encountering puzzling behaviour trying to instantiate a simple model that is located at some path (not the current directory), which gets me an exception with exit status 3221225781 (google suggests this is "dll not found") in check_model_executable:

model MyModel
equation
end MyModel;
from OMPython import ModelicaSystem, OMCSessionZMQ
import sys
print(f'{sys.path=}')

print("works")
omc = OMCSessionZMQ()
print(omc.sendExpression("getVersion()"))
omc.sendExpression('loadFile("C:\\Users\\myuser\\Software_local\\Modelica\\Issues\\MyModel.mo")')
omc.sendExpression("instantiateModel(MyModel)")

print("broken")
model = ModelicaSystem(
    fileName='C:\\Users\\myuser\\Software_local\\Modelica\\Issues\\MyModel.mo',
    modelName='MyModel',
)

Output:

> python .\load_package.py
sys.path=['C:\\Users\\myuser\\Software_local\\Modelica\\Issues\\dll_find_problems', 'C:\\Users\\myuser\\AppData\\Local\\miniforge3\\envs\\modelica\\python312.zip', 'C:\\Users\\myuser\\AppData\\Local\\miniforge3\\envs\\modelica\\DLLs', 'C:\\Users\\myuser\\AppData\\Local\\miniforge3\\envs\\modelica\\Lib', 'C:\\Users\\myuser\\AppData\\Local\\miniforge3\\envs\\modelica', 'C:\\Users\\myuser\\AppData\\Local\\miniforge3\\envs\\modelica\\Lib\\site-packages', 'C:\\Users\\myuser\\AppData\\Local\\miniforge3\\envs\\modelica\\Lib\\site-packages\\win32', 'C:\\Users\\myuser\\AppData\\Local\\miniforge3\\envs\\modelica\\Lib\\site-packages\\win32\\lib', 'C:\\Users\\myuser\\AppData\\Local\\miniforge3\\envs\\modelica\\Lib\\site-packages\\Pythonwin']
works
C:\Users\myuser\Software_local\Modelica\Issues\dll_find_problems\load_package.py:6: DeprecationWarning: The class OMCSessionZMQ is depreciated and will be removed in future versions! Please use OMCSession* classes instead!
  omc = OMCSessionZMQ()
v1.28.0-dev.836+gca0c61d2c7.cmake
[OMC log for 'sendExpression(expr=loadFile("C:\Users\myuser\Software_local\Modelica\Issues\MyModel.mo"), parsed=True)']: [syntax:warning:2] Lexer treating \ as \\, since \U is not a valid Modelica escape sequence.
[OMC log for 'sendExpression(expr=loadFile("C:\Users\myuser\Software_local\Modelica\Issues\MyModel.mo"), parsed=True)']: [syntax:warning:2] Lexer treating \ as \\, since \u is not a valid Modelica escape sequence.
[OMC log for 'sendExpression(expr=loadFile("C:\Users\myuser\Software_local\Modelica\Issues\MyModel.mo"), parsed=True)']: [syntax:warning:2] Lexer treating \ as \\, since \S is not a valid Modelica escape sequence.
[OMC log for 'sendExpression(expr=loadFile("C:\Users\myuser\Software_local\Modelica\Issues\MyModel.mo"), parsed=True)']: [syntax:warning:2] Lexer treating \ as \\, since \M is not a valid Modelica escape sequence.
[OMC log for 'sendExpression(expr=loadFile("C:\Users\myuser\Software_local\Modelica\Issues\MyModel.mo"), parsed=True)']: [syntax:warning:2] Lexer treating \ as \\, since \I is not a valid Modelica escape sequence.
[OMC log for 'sendExpression(expr=loadFile("C:\Users\myuser\Software_local\Modelica\Issues\MyModel.mo"), parsed=True)']: [syntax:warning:2] Lexer treating \ as \\, since \M is not a valid Modelica escape sequence.
broken
Traceback (most recent call last):
  File "C:\Users\myuser\AppData\Local\miniforge3\envs\modelica\Lib\site-packages\OMPython\model_execution.py", line 80, in run
    cmdres = subprocess.run(
             ^^^^^^^^^^^^^^^
  File "C:\Users\myuser\AppData\Local\miniforge3\envs\modelica\Lib\subprocess.py", line 571, in run
    raise CalledProcessError(retcode, process.args,
subprocess.CalledProcessError: Command '['C:/Users/myuser/AppData/Local/Temp/b956fe61-9405-4aa1-b400-649fe415d817/MyModel.exe', '-help=help']' returned non-zero exit status 3221225781.

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "C:\Users\myuser\AppData\Local\miniforge3\envs\modelica\Lib\site-packages\OMPython\modelica_system_abc.py", line 205, in check_model_executable
    returncode = cmd_definition.run()
                 ^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\myuser\AppData\Local\miniforge3\envs\modelica\Lib\site-packages\OMPython\model_execution.py", line 101, in run
    raise ModelExecutionException(f"Error running model executable {repr(cmdl)}: {ex}") from ex
OMPython.model_execution.ModelExecutionException: Error running model executable ['C:/Users/myuser/AppData/Local/Temp/b956fe61-9405-4aa1-b400-649fe415d817/MyModel.exe', '-help=help']: Command '['C:/Users/myuser/AppData/Local/Temp/b956fe61-9405-4aa1-b400-649fe415d817/MyModel.exe', '-help=help']' returned non-zero exit status 3221225781.

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "C:\Users\myuser\Software_local\Modelica\Issues\dll_find_problems\load_package.py", line 12, in <module>
    model = ModelicaSystem(
            ^^^^^^^^^^^^^^^
  File "C:\Users\myuser\AppData\Local\miniforge3\envs\modelica\Lib\site-packages\OMPython\compatibility_v400.py", line 35, in __init__
    super().__init__(*args, **kwargs)
  File "C:\Users\myuser\AppData\Local\miniforge3\envs\modelica\Lib\site-packages\OMPython\ModelicaSystem.py", line 68, in __init__
    self.model(
  File "C:\Users\myuser\AppData\Local\miniforge3\envs\modelica\Lib\site-packages\OMPython\modelica_system_omc.py", line 157, in model
    self.buildModel(variable_filter)
  File "C:\Users\myuser\AppData\Local\miniforge3\envs\modelica\Lib\site-packages\OMPython\modelica_system_omc.py", line 218, in buildModel
    self.check_model_executable()
  File "C:\Users\myuser\AppData\Local\miniforge3\envs\modelica\Lib\site-packages\OMPython\modelica_system_abc.py", line 207, in check_model_executable
    raise ModelicaSystemError(f"Cannot execute model: {exc}") from exc
OMPython.modelica_system_abc.ModelicaSystemError: Cannot execute model: Error running model executable ['C:/Users/myuser/AppData/Local/Temp/b956fe61-9405-4aa1-b400-649fe415d817/MyModel.exe', '-help=help']: Command '['C:/Users/myuser/AppData/Local/Temp/b956fe61-9405-4aa1-b400-649fe415d817/MyModel.exe', '-help=help']' returned non-zero exit status 3221225781.

I expect that this instantiation with ModelicaSystem works.
By the way, OMPython should really define a __version__ attribute so that one can easily report its version.

I suspect some path/environment problems, so I printed the PATH that Python sees. Please advise what I can do to add more diagnostics on the OMPython side.
The MyModel.bat content in the temporary directory is

@echo off
SET PATH=;C:/OpenModelica1.28.0-dev-64bit/bin/;C:/OpenModelica1.28.0-dev-64bit/lib/x86_64-windows-gnu/omc;%PATH%;
SET ERRORLEVEL=
CALL "%CD%/MyModel.exe" %*
SET RESULT=%ERRORLEVEL%

EXIT /b %RESULT%

Version and OS

  • Python Version 3.12.13 (via conda)
  • OMPython Version 4.1.0
  • OpenModelica Version v1.28.0-dev.836+gca0c61d2c7.cmake
  • OS: Windows 11

Activity

  1. cbu-hw commented on Sep 22, 2026

    @cbu-hw
    Author

    because dlls are not being found, possibly related OpenModelica/OpenModelica#16846?

  2. AnHeuermann commented on Sep 22, 2026

    @AnHeuermann
    Member

    Yes, same issue. Fixing it now. I guess the new installer is online in around 2 hours.

  3. self-assigned this
    on Sep 22, 2026
  4. AnHeuermann commented on Sep 22, 2026

    @AnHeuermann
    Member

    @arun3688 the installer now installs static libraries into lib/x86_64-windows-gnu/omc. You might need to check if that directory is already on the search path. But they should be hardcoded in the executables, so probably this will work out of the box.

  5. cbu-hw commented on Sep 22, 2026

    @cbu-hw
    Author

    It would be appreciated if the error could inform about which libraries are missing. I don't know if that's technically possible? I was under the assumption that for some reason it's shared libraries that are missing, not static ones, apparently that's wrong?

  6. cbu-hw commented on Sep 22, 2026

    @cbu-hw
    Author

    Yes, same issue. Fixing it now. I guess the new installer is online in around 2 hours.

    Where will that be available in 2 hrs? Nightly installers are normally appearing during the night, no?

  7. arun3688 commented on Sep 22, 2026

    @arun3688
    Collaborator

    @cbu-hw i think the above issue might not be related to dll missing error i guess because that is related to github actions in the OpenModelicaSetuo, but this PR https://github.com/OpenModelica/OMPython/pull/476 should fix your issue i guess , i tested your model and it worked for me. we need to wait for the github action to pass

    (base) c:\OPENMODELICAGIT\OpenModelica\OMPython>python
    Python 3.13.5 | packaged by Anaconda, Inc. | (main, Jun 12 2025, 16:37:03) [MSC v.1929 64 bit (AMD64)] on win32
    Type "help", "copyright", "credits" or "license" for more information.
    >>> from OMPython import ModelicaSystem
    >>> mod = ModelicaSystem("C:/OPENMODELICAGIT/OMEditDir/mymodel/MyModel.mo", "MyModel")
    >>>
    
  8. cbu-hw commented on Sep 22, 2026

    @cbu-hw
    Author

    this PR https://github.com/OpenModelica/OMPython/pull/476 should fix your issue i guess ,

    Why do you think that? #476 is about directory-based packages, but my MWE is a single-file model? 🤷

  9. arun3688 commented on Sep 22, 2026

    @arun3688
    Collaborator

    @cbu-hw i tested your model in my computer and it worked, i am not using the latest nightly builds, so that is why it worked i guess

  10. adeas31 commented on Sep 22, 2026

    @adeas31
    Member

    ModelicaSystem simulates the model as well so if you try to simulate the model via sendExpression then it will fail as well.

  11. cbu-hw commented on Sep 23, 2026

    @cbu-hw
    Author

    ModelicaSystem simulates the model as well so if you try to simulate the model via sendExpression then it will fail as well.

    I cannot confirm that, it does not fail. Adding a line of print(omc.sendExpression("simulate(MyModel, stopTime=3.0)")) to the sendexpression section works as expected.

  12. adeas31 commented on Sep 23, 2026

    @adeas31
    Member

    ModelicaSystem simulates the model as well so if you try to simulate the model via sendExpression then it will fail as well.

    I cannot confirm that, it does not fail. Adding a line of print(omc.sendExpression("simulate(MyModel, stopTime=3.0)")) to the sendexpression section works as expected.

    OK. We moved around binaries and we need to set PATH for running simulation via ModelicaSystem. I will push in a fix for it.

  13. cbu-hw commented on Sep 23, 2026

    @cbu-hw
    Author

    Yes, same issue. Fixing it now. I guess the new installer is online in around 2 hours.

    Where will that be available in 2 hrs? Nightly installers are normally appearing during the night, no?

    It seems today's nightly did not run sucessfully, the Windows nightly is still from yesterday morning, so I can't test if Andreas' fix resolved the problem.

  14. adeas31 commented on Sep 23, 2026

    @adeas31
    Member

    Yes, we had some issues with signing release executable. We are working on it.

  15. cbu-hw commented on Sep 23, 2026

    @cbu-hw
    Author

    I just installed 1.28.0-dev.857+g5fee2cdbad.cmake that landed today, but that one seems to be just broken 🤷

    Image
  16. cbu-hw commented on Sep 23, 2026

    @cbu-hw
    Author

    Using v1.28.0-dev-429-g1819321c0f-cmake from late August, I don't get the exception, and simulation completes orderly AFAICT. So this is confirmed to be a regression now.

  17. adeas31 commented on Sep 23, 2026

    @adeas31
    Member

    That is a known issue. @AnHeuermann is working on it. We will let you know once a working nightly is available.

  18. AnHeuermann commented on Sep 23, 2026

    @AnHeuermann
    Member

    The installer dev-861 should now be updated and online.

  19. adeas31 commented on Sep 23, 2026

    @adeas31
    Member

    @cbu-hw to my surprise even the windows test passed in #476

    This issue still persists on my local machine. Can you test again and see if it works for you.

  20. cbu-hw commented on Sep 24, 2026

    @cbu-hw
    Author

    This issue still persists on my local machine. Can you test again and see if it works for you.

    I still observe the crash with v1.28.0-dev.861+gec7b922228.cmake

    Also let me remark that OpenModelica/OpenModelica#5809 would be very appreciated. Losing ~1h+ of productivity to switch from a working OM version to a fresh nightly as asked, then back to the working one to be able to continue to work is...frustrating and approaches being prohibitive.

    I'd offer to git bisect on an OM source build (in a devcontainer) to find what introduced the problem, but there's a similar story here -- a fresh compilation takes ~hours, incremental ones I don't know yet, as the current master does not even Configure successfully on my machine.🤷 (edit: Ah I see now that that CMake kit is actually not supported)

  21. adeas31 commented on Sep 24, 2026

    @adeas31
    Member

    I still observe the crash with v1.28.0-dev.861+gec7b922228.cmake

    Should work fine with OpenModelica/OpenModelica#16870

  22. cbu-hw commented on Sep 25, 2026

    @cbu-hw
    Author

    I still observe the crash with v1.28.0-dev.861+gec7b922228.cmake

    Should work fine with OpenModelica/OpenModelica#16870

    We'll see. I'm not sure if that will work, AFAICT as detailed above the .bat file already has the correct paths (so I don't know what the tweaks in OpenModelica/OpenModelica#16870 should improve there), but for some reason ModelicaSystem does not seem to observe that?

  23. adeas31 commented on Sep 25, 2026

    @adeas31
    Member

    No, there were some paths missing in the .bat file e.g., the C compiler path. OpenModelica/OpenModelica#16870 sets that.

  24. cbu-hw commented on Sep 28, 2026

    @cbu-hw
    Author

    With v1.28.0-dev.1026+gb748b1d61d.cmake I don't get the crash with exit status 3221225781 anymore.
    However, now it crashes with exit status 1

    OMPython.modelica_system_abc.ModelicaSystemError: Cannot execute model: Error running model executable ['C:/Users/myuser/AppData/Local/Temp/4e088cf1-03f0-42e5-9f76-2fd38c279baf/MyModel.exe', '-help=help']: Command '['C:/Users/myuser/AppData/Local/Temp/4e088cf1-03f0-42e5-9f76-2fd38c279baf/MyModel.exe', '-help=help']' returned non-zero exit status 1.

    Running .\MyModel.bat -help=help, which should be equivalent to running the exe + path setting gives

    LOG_STDOUT | error | -help: not implemented by this runtime

    which is not surfaced by ModelicaSystem, but might be the reason behind the non-zero exit status.

    Curiously enough, the (powershell) $LastExitCode of that call is 0 -- make of that what you will 🤪

  25. adeas31 commented on Oct 2, 2026

    @adeas31
    Member

    This should work now as expected.

    There were issues with simulation command line arguments when we switched from C to Rust runtime. Just update your OM.

  26. cbu-hw commented on Oct 2, 2026

    @cbu-hw
    Author

    Confirmed fixed with v1.28.0-dev.1157, thank you!

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

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions