You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I would like to use OMPython, installed on Windows, to interact with OpenModelica, installed on WSL. Is it possible?
If I understand correctly, this possibility is not considered by the current implementation. I guess it should be possible, since I can launch OMC with Popen, for exemple with Popen(["wsl","omc", ...])...
the process to run OMPython.OMCSessionZMQ is slighly modified as it still defaults to local usage
try to run in WSL using something as follows:
import OMPython
def run_wsl():
omcp = OMPython.OMCProcessWSL()
om = OMPython.OMCSessionZMQ(omc_process=omcp)
print(om.sendExpression("getVersion()"))
if __name__ == '__main__':
run_wsl()
print('DONE')
if needed provide the location of omc in WSL as wsl_omc: omcp = OMPython.OMCProcessWSL(wsl_cmd=...)
please keep in mind, that this will not allow you to use ModelicaSystem! - this would need local access to the files to read the content or to run the executable
untested from my side; thus, your feedback is welcome!
>>>omcp=OMPython.OMCProcessWSL()
Traceback (mostrecentcalllast):
File"<stdin>", line1, in<module>File"C:\Users\D24676\Documents\depots\OMPython\OMPython\OMCSession.py", line1000, in__init__self._omc_port=self._omc_port_get()
^^^^^^^^^^^^^^^^^^^^File"C:\Users\D24676\Documents\depots\OMPython\OMPython\OMCSession.py", line1040, in_omc_port_getraiseOMCSessionException(f"WSL based OMC Server did not start (timeout={self._timeout}). "OMPython.OMCSession.OMCSessionException: WSLbasedOMCServerdidnotstart (timeout=10.0). CouldnotopenportfileNone. Log-filesays:
Using the wsl_omc argument (not wsl_cmd 😉 ) with wsl omc as value (which is the command I can enter in the windows cmd to launch OpenModelica) changes nothing.
Using the wsl_omc argument (not wsl_cmd 😉 ) with wsl omc as value (which is the command I can enter in the windows cmd to launch OpenModelica) changes nothing.
wsl_omc = 'omc' - the wsl part is added by the class!
I had errors running OMC in wsl since the default user is root, which is not allowed by OMC:
Error: You are trying to run OpenModelica as a server using the root user.
This is a very bad idea:
* The socket interface does not authenticate the user.
* OpenModelica allows execution of arbitrary commands.
Execution failed!
I suppose this is a quite common setup for WSL, so a generic issue. I then create a new user (with its own home!):
sudo useradd -d /home/USER_NAME USER_NAME
Two solutions to use it then:
Change the default user for wsl &rarr, wsl --manage DISTRO_NAME --set-default-user USER_NAME
Or specify a user name in the wsl call → wsl --user USER_NAME -- omc --locale=C --interactive=zmq -z=abcdefg123
I would prefer the second option, but I will go with the first one for the moment (waiting for the additional user argument in the class). 😉
With that done, the tests pass and I get the tcp address.
However I still had the original error message... but trying to change the timeout to 30 (indeed the wsl startup itself take some time (with a quite random delay...especially in an interactive python shell, it looks better once in a script)...so 10 seconds timeout looked to me quite short) it is now working and I get the OpenModelica version printed out.
Wonderful!
I am now getting some error while trying to load some libraries, but maybe this is my fault (I am not familiar with the whole OMPython):
perhaps, this should be enforced, i.e. a values != root must be defined?
At the same point, you can increase the timeout as needed.
The errors you get now seems to be related to internet connection (curl). I think that this could be more related to local WSL problems ... Is it working if you use OMC directly in WSL?
Have you tested some simple OMC functionality (from test_ZMQ)?
om.sendExpression("""loadString(\"model M
Real r = time;
end M;
\")""")
om.sendExpression('res:=simulate(M, stopTime=2.0)')
om.sendExpression('res.resultFile')
@Sonyoyo thanks for the feedback - all further questions are perhaps related to OMPython but more focused on using it - WSL is working! as you confirmed this issue could be closed
Activity
syntron commentedon Jun 12, 2025
@Sonyoyo could you please test PR #302 - this could work ...
Sonyoyo commentedon Jun 13, 2025
Thanks for your support. However, it looks like it can't yet find the OpenModelica installation:
Maybe I have to provide some arguments for
omc = OMCSessionZMQ()or set some specific environment variables?syntron commentedon Jun 14, 2025
@Sonyoyo it is not as simple ;-)
omcp = OMPython.OMCProcessWSL(wsl_cmd=...)untested from my side; thus, your feedback is welcome!
Sonyoyo commentedon Jun 16, 2025
I still have errors:
Using the
wsl_omcargument (notwsl_cmd😉 ) withwsl omcas value (which is the command I can enter in the windowscmdto launch OpenModelica) changes nothing.syntron commentedon Jun 16, 2025
@Sonyoyo Lets go one step back and just test if it is possible to run OMC; could you please execute the following commands to check if it is working?
These are the commands which would be executed by OMCSessionZMQ/OMCProcessWSL:
(1) start OMC in WSL:
(2) Get the content of the port file:
You should get something like:
If this is working, then we can continue ;-) Else we should tweak these commands first to find working versions ...
The error message indicates that step (1) fails, i.e. OMC is not started / the path to the port file is not available.
syntron commentedon Jun 17, 2025
@Sonyoyo
Just noted an important point:
wsl_omc = 'omc'- thewslpart is added by the class!Sonyoyo commentedon Jun 17, 2025
Result of tests (quite good advances!):
I had errors running OMC in
wslsince the default user isroot, which is not allowed by OMC:I suppose this is a quite common setup for WSL, so a generic issue. I then create a new user (with its own home!):
Two solutions to use it then:
wsl --manage DISTRO_NAME --set-default-user USER_NAMEwsl --user USER_NAME -- omc --locale=C --interactive=zmq -z=abcdefg123I would prefer the second option, but I will go with the first one for the moment (waiting for the additional
userargument in the class). 😉With that done, the tests pass and I get the tcp address.
However I still had the original error message... but trying to change the timeout to
30(indeed the wsl startup itself take some time (with a quite random delay...especially in an interactive python shell, it looks better once in a script)...so 10 seconds timeout looked to me quite short) it is now working and I get the OpenModelica version printed out.Wonderful!
I am now getting some error while trying to load some libraries, but maybe this is my fault (I am not familiar with the whole OMPython):
Here it does not recognize
loadFile... I do not understand why...syntron commentedon Jun 18, 2025
@Sonyoyo user and distribution can be defined as option to OMCProcessWSL
perhaps, this should be enforced, i.e. a values != root must be defined?
At the same point, you can increase the timeout as needed.
The errors you get now seems to be related to internet connection (curl). I think that this could be more related to local WSL problems ... Is it working if you use OMC directly in WSL?
Have you tested some simple OMC functionality (from test_ZMQ)?
It should output you a file name ...
Sonyoyo commentedon Jun 19, 2025
Thank you for pointing out that the
wsl_userargument already exist. Excellent! 😄With your example, everything works fine. So I guess I just need to understand how to load existing libraries and models with OMPython.
syntron commentedon Jun 19, 2025
@Sonyoyo thanks for the feedback - all further questions are perhaps related to OMPython but more focused on using it - WSL is working! as you confirmed this issue could be closed
@adeas31 this means PR #302 is working ;-)
adeas31 commentedon Jun 25, 2025
@syntron I also got your example working with 2 different distros.