Repository navigation
ModelicaSystem cannot instantiate model, but sendExpression works #478
Copy link
Copy link
Closed
OpenModelica/OpenModelicaSetup
#88Description
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
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels
Activity
cbu-hw commentedon Sep 22, 2026
because dlls are not being found, possibly related OpenModelica/OpenModelica#16846?
AnHeuermann commentedon Sep 22, 2026
Yes, same issue. Fixing it now. I guess the new installer is online in around 2 hours.
AnHeuermann commentedon Sep 22, 2026
@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.cbu-hw commentedon Sep 22, 2026
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?
cbu-hw commentedon Sep 22, 2026
Where will that be available in 2 hrs? Nightly installers are normally appearing during the night, no?
arun3688 commentedon Sep 22, 2026
@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/476should fix your issue i guess , i tested your model and it worked for me. we need to wait for the github action to passcbu-hw commentedon Sep 22, 2026
Why do you think that? #476 is about directory-based packages, but my MWE is a single-file model? 🤷
arun3688 commentedon Sep 22, 2026
@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
adeas31 commentedon Sep 22, 2026
ModelicaSystemsimulates the model as well so if you try to simulate the model viasendExpressionthen it will fail as well.cbu-hw commentedon Sep 23, 2026
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.adeas31 commentedon Sep 23, 2026
OK. We moved around binaries and we need to set PATH for running simulation via ModelicaSystem. I will push in a fix for it.
cbu-hw commentedon Sep 23, 2026
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.
adeas31 commentedon Sep 23, 2026
Yes, we had some issues with signing release executable. We are working on it.
cbu-hw commentedon Sep 23, 2026
I just installed 1.28.0-dev.857+g5fee2cdbad.cmake that landed today, but that one seems to be just broken 🤷
cbu-hw commentedon Sep 23, 2026
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.
adeas31 commentedon Sep 23, 2026
That is a known issue. @AnHeuermann is working on it. We will let you know once a working nightly is available.
AnHeuermann commentedon Sep 23, 2026
The installer
dev-861should now be updated and online.adeas31 commentedon Sep 23, 2026
@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.
cbu-hw commentedon Sep 24, 2026
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)
adeas31 commentedon Sep 24, 2026
Should work fine with OpenModelica/OpenModelica#16870
cbu-hw commentedon Sep 25, 2026
We'll see. I'm not sure if that will work, AFAICT as detailed above the
.batfile already has the correct paths (so I don't know what the tweaks in OpenModelica/OpenModelica#16870 should improve there), but for some reasonModelicaSystemdoes not seem to observe that?adeas31 commentedon Sep 25, 2026
No, there were some paths missing in the
.batfile e.g., the C compiler path. OpenModelica/OpenModelica#16870 sets that.cbu-hw commentedon Sep 28, 2026
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
Running
.\MyModel.bat -help=help, which should be equivalent to running the exe + path setting giveswhich is not surfaced by ModelicaSystem, but might be the reason behind the non-zero exit status.
Curiously enough, the (powershell)
$LastExitCodeof that call is0-- make of that what you will 🤪adeas31 commentedon Oct 2, 2026
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.
cbu-hw commentedon Oct 2, 2026
Confirmed fixed with v1.28.0-dev.1157, thank you!