Archived OpenModelica forums. Posting is disabled.

Alternative forums include GitHub discussions or StackOverflow (make sure to read the Stack Overflow rules; you need to have well-formed questions)


Forgot password? | Forgot username? | Register

Cannot run OMPython in Google Colab

Cannot run OMPython in Google Colab

Hello All!

I am trying to run OpenModelica using OMPython in a Google Colab notebook. I can install OpenModelica and OMPython using these commands:

Code:


! for deb in deb deb-src; do echo "$deb http://build.openmodelica.org/apt `lsb_release -cs` release"; done | sudo tee /etc/apt/sources.list.d/openmodelica.list
! wget -q http://build.openmodelica.org/apt/openmodelica.asc -O- | sudo apt-key add -
! apt update && apt install openmodelica
! pip install ompython

But then when I try to use it with

Code:


from OMPython import OMCSessionZMQ
omc = OMCSessionZMQ()
omc.sendExpression("getVersion()")

I get the following error:

2020-11-19 18:00:50,085 - OMPython - ERROR - OMC Server did not start. Please start it! Log-file says:
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!

Now the problem is that I cannot change the user on the notebook (I can create a new user and switch to it temporarily, but not permanently for the notebook). Is there a way to disable that warning or start OpenModelica some other way that?

Miklos

Re: Cannot run OMPython in Google Colab

You could perhaps chown /usr/bin/omc to a non-root user and then chmod 4755 /usr/bin/omc

But still, running omc as the root user is a bad idea.

Re: Cannot run OMPython in Google Colab

Thanks for the quick reply and suggestion! That does not seem to work either, I get the following error:

Code:


2020-11-20 14:23:01,652 - OMPython - ERROR - OMC Server did not start. Please start it! Log-file says:
Created ZeroMQ Server.
Dumped server port in file: /tmp/openmodelica.nobody.port.927da77d9a9147e1a6ecf29a0d758836

I assume that OMPython cannot find the OMC server because one is running under root and the other is under another user. I got further with this hack (suggested by Peter Volgyesi):

Code:


!useradd modelica
!mv /usr/bin/omc /usr/bin/omc_orig
!echo 'sudo -u modelica USER=root /usr/bin/omc_orig $*' >/usr/bin/omc
!chmod +x /usr/bin/omc

This gets me execute "getVersion()", but "simulate(BouncingBall)" just hangs. Any idea how to properly use OpenModelica in Google Colab?

There are 0 guests and 0 other users also viewing this topic
You are here: