OpenModelica / OMPython

A Python interface to OpenModelica communicating via CORBA or ZeroMQ
Other
107 stars 58 forks source link

mod.linearize() returns wrong matrix on second call #212

Closed martinscripts closed 6 months ago

martinscripts commented 6 months ago

Description

If two models are loaded and linearized, only the first call of linearize() returns the correct result. All following calls will return the first call's result.

Steps to Reproduce

from OMPython import OMCSessionZMQ
omc = OMCSessionZMQ()
model_path=omc.sendExpression("getInstallationDirectoryPath()") + "/share/doc/omc/testmodels/"
from OMPython import ModelicaSystem

mod1 = ModelicaSystem(model_path + "BouncingBall.mo","BouncingBall")
mod1.linearize()
# returns [[[0, 1], [0, 0]], [], [], []]

mod2 = ModelicaSystem(model_path + "VanDerPol.mo","VanDerPol")
mod2.linearize()
# returns [[[0, 1], [0, 0]], [], [], []]

Expected Behavior

The result of the second linearization (mod2.linearize) should be [[[0, 1], [-0.730936067860485, -0.248180066111424]], [], [], []] but it only returns that after a kernel restart and when mod2 is executed first.

Version and OS

arun3688 commented 6 months ago

@martinscripts the issue is fixed with this commit 891528c8009348881019c81d8d7420c1a8d3ee14, now i can get the correct results

>>> from OMPython import ModelicaSystem
>>> mod1 = ModelicaSystem("C:/OPENMODELICAGIT/OpenModelica/OMCompiler/Examples/BouncingBall.mo", "BouncingBall")
>>> mod2 = ModelicaSystem("C:/OPENMODELICAGIT/OpenModelica/OMCompiler/Examples/VanDerPol.mo", "VanDerPol")
>>> mod1.linearize()
[[[0, 1], [0, 0]], [], [], []]
>>> mod2.linearize()
[[[0, 1], [-0.730936067860485, -0.248180066111424]], [], [], []]
>>>

please update your pip package by python -m pip install -U https://github.com/OpenModelica/OMPython/archive/master.zip

martinscripts commented 6 months ago

Thanks @arun3688.

I had to

pip uninstall OMPython

and then

pip install git+https://github.com/OpenModelica/OMPython.git/@master

and now it works.