Opened 4 years ago

Last modified 4 years ago

#6337 reopened defect

OMPython openning files associates with non default OM libraries

Reported by: jeduapf@… Owned by: arunkumar palanisamy
Priority: high Milestone: NeedsInput
Component: OMPython Version: 1.16.2
Keywords: OMPython, libraries Cc:

Description

Hello,

I am trying to open one file VSC_Test.mo that I developed using three default Modelica libraries (Modelica 3.2.3,Complex 3.2.3,ModelicaServices 3.2.3) and 2 other libraries (OpenIPSL,HVDCcomponents). However when I try to create the model mod using the function ModelicaSystem(), several errors pop up. If I load the model only using the name of the file and its path :



from OMPython import OMCSessionZMQ
from OMPython import ModelicaSystem

path = 'C:/Users/j.alves/Desktop/Stage/Python_CODES/Modele_HVDC_simplifie'
# path = 'C:/OpenModelica/lib/omlibrary/HVDCcomponents/Examples'
within = 'HVDCcomponents.Examples'
name = 'Test_VSC'

file ='"'+ path + '/' + name + '.mo'+'"'
mod_file = path + '/' + name + '.mo'
load_file = "loadFile(" + file + ")"
within_name = within + '.' + name


# To create the modelica session and execute action 
omc = OMCSessionZMQ()

# To set variables, and change the model 
mod = ModelicaSystem(mod_file)
mod.buildModel()

# Loading the model file 
Load = omc.sendExpression(load_file)
if (not Load):
    raise NameError("Coudn't load file")



2021-01-08 10:58:55,995 - OMPython - INFO - OMC Server is up and running at file:///C:/Users/J5046~1.ALV/AppData/Local/Temp/openmodelica.port.01c776f1a0d049748d371c59fde5c76e pid=2436
2021-01-08 10:58:56,323 - OMPython - INFO - OMC Server is up and running at file:///C:/Users/J5046~1.ALV/AppData/Local/Temp/openmodelica.port.c90c19bd229547c4abbc8c7f7570a383 pid=3316
Notification: Automatically loaded package Modelica 3.2.3 due to uses annotation.
Notification: Automatically loaded package Complex 3.2.3 due to uses annotation.
Notification: Automatically loaded package ModelicaServices 3.2.3 due to uses annotation.
Notification: Skipped loading package OpenIPSL (1.5.0) using MODELICAPATH C:/OpenModelica/lib/omlibrary (uses-annotation may be wrong).
Notification: Skipped loading package HVDCcomponents (1.0) using MODELICAPATH C:/OpenModelica/lib/omlibrary (uses-annotation may be wrong).

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-13-e4c24ceb511d> in <module>
      9 
     10 # To set variables, and change the model
---> 11 mod = ModelicaSystem(mod_file)
     12 mod.buildModel()
     13 

c:\python38\lib\site-packages\OMPython\__init__.py in __init__(self, fileName, modelName, lmodel, useCorba, commandLineOptions)
    718             if (self.fileName_):  # execution from different path
    719                 os.chdir(self.currDir)
--> 720                 self.__loadingModel()
    721             else:
    722                 print("Error: File does not exist!!!")

c:\python38\lib\site-packages\OMPython\__init__.py in __loadingModel(self)
    758                 if loadmodelError:
    759                     print(loadmodelError)
--> 760         self.buildModel()
    761 
    762     def buildModel(self):

c:\python38\lib\site-packages\OMPython\__init__.py in buildModel(self)
    764         buildModelResult = self.requestApi("buildModel", self.modelName)
    765         buildModelError = self.requestApi("getErrorString")
--> 766         if ('' in buildModelResult):
    767             print(buildModelError)
    768             return

TypeError: argument of type 'NoneType' is not iterable

1

If instead of using only the name I put "within" in "mod = ModelicaSystem(mod_file,within_name)" since there is a commented within in the VSC_Test file (Image 1) I get:

Notification: Automatically loaded package Modelica 3.2.3 due to uses annotation.
Notification: Automatically loaded package Complex 3.2.3 due to uses annotation.
Notification: Automatically loaded package ModelicaServices 3.2.3 due to uses annotation.
Notification: Skipped loading package OpenIPSL (1.5.0) using MODELICAPATH C:/OpenModelica/lib/omlibrary (uses-annotation may be wrong).
Notification: Skipped loading package HVDCcomponents (1.0) using MODELICAPATH C:/OpenModelica/lib/omlibrary (uses-annotation may be wrong).

[C:/OpenModelica/lib/omlibrary/HVDCcomponents/Examples/Test_VSC.mo:3:1-81:13:writable] Error: Expected the package to have within HVDCcomponents.Examples; but got within ;.
Error: Failed to load package HVDCcomponents (default) using MODELICAPATH C:/OpenModelica/lib/omlibrary.
Notification: Automatically loaded package OpenIPSL 1.5.0 due to uses annotation.
Warning: Requested package Modelica of version 3.2.2, but this package was already loaded with version 3.2.3. You might experience problems if these versions are incompatible.
Warning: Requested package Complex of version 3.2.2, but this package was already loaded with version 3.2.3. You might experience problems if these versions are incompatible.
[C:/OpenModelica/lib/omlibrary/HVDCcomponents/Examples/Test_VSC.mo:3:1-81:13:writable] Error: Expected the package to have within HVDCcomponents.Examples; but got within ;.
Notification: Skipped loading package HVDCcomponents (1.0,default) using MODELICAPATH C:/OpenModelica/lib/omlibrary (uses-annotation may be wrong).
Error: Class HVDCcomponents.Examples.Test_VSC not found in scope <TOP>.

[C:/OpenModelica/lib/omlibrary/HVDCcomponents/Examples/Test_VSC.mo:3:1-81:13:writable] Error: Expected the package to have within HVDCcomponents.Examples; but got within ;.
Error: Failed to load package HVDCcomponents (default) using MODELICAPATH C:/OpenModelica/lib/omlibrary.
[C:/OpenModelica/lib/omlibrary/HVDCcomponents/Examples/Test_VSC.mo:3:1-81:13:writable] Error: Expected the package to have within HVDCcomponents.Examples; but got within ;.
Notification: Skipped loading package HVDCcomponents (1.0,default) using MODELICAPATH C:/OpenModelica/lib/omlibrary (uses-annotation may be wrong).
Warning: Requested package Modelica of version 3.2.2, but this package was already loaded with version 3.2.3. You might experience problems if these versions are incompatible.
Warning: Requested package Complex of version 3.2.2, but this package was already loaded with version 3.2.3. You might experience problems if these versions are incompatible.
Error: Class HVDCcomponents.Examples.Test_VSC not found in scope <TOP>.

Also, the paths were those libraries are is the same as the path of all default libraries in MODELICAPATH (added to environmental variables Image 2)

2


The libraries are located as in Image 3

3


Basically I want to open the VSC_Test.mo file and run simulations to get the results in real time with python to then change the inputs and run more simulations and so on... I will update the inputs of the system based on the result outputs.

Moreover, using only the library Modelica I can run all the simulations I want using the "mod", but with these other 2 libraries I always get one kind of error. Please help me with this issue...

Attachments (3)

1.png (66.0 KB ) - added by jeduapf@… 4 years ago.
1
2.png (34.9 KB ) - added by jeduapf@… 4 years ago.
2
3.png (22.8 KB ) - added by jeduapf@… 4 years ago.
3

Download all attachments as: .zip

Change History (7)

by jeduapf@…, 4 years ago

Attachment: 1.png added

1

by jeduapf@…, 4 years ago

Attachment: 2.png added

2

by jeduapf@…, 4 years ago

Attachment: 3.png added

3

comment:1 by arunkumar palanisamy, 4 years ago

@jeduapf, you are using the ModelicaSystem Constructor with wrong arguments see the documentation for more information https://www.openmodelica.org/doc/OpenModelicaUsersGuide/latest/ompython.html

the first two arguments are compulsory, and the third argument is optional, when you want to specify third party libraries, So your arguments should look like below,

from OMPython import ModelicaSystem
mod = ModelicaSystem("VSC_Test.mo", VSC_Test, ["OpenISL", "HVDCComponents"])

comment:2 by Francesco Casella, 4 years ago

Resolution: invalid
Status: newclosed

Please reopen if you need further feedback.

in reply to:  1 comment:3 by anonymous, 4 years ago

Resolution: invalid
Status: closedreopened

Replying to arun3688:

@jeduapf, you are using the ModelicaSystem Constructor with wrong arguments see the documentation for more information https://www.openmodelica.org/doc/OpenModelicaUsersGuide/latest/ompython.html

the first two arguments are compulsory, and the third argument is optional, when you want to specify third party libraries, So your arguments should look like below,

from OMPython import ModelicaSystem
mod = ModelicaSystem("VSC_Test.mo", VSC_Test, ["OpenISL", "HVDCComponents"])

I tried this way too, but even though I have the same results.

"Notification: Skipped loading package OpenIPSL (1.5.0) using MODELICAPATH C:/OpenModelica/lib/omlibrary (uses-annotation may be wrong).
Notification: Skipped loading package HVDCcomponents (1.0) using MODELICAPATH C:/OpenModelica/lib/omlibrary (uses-annotation may be wrong).
"
...

comment:4 by arunkumar palanisamy, 4 years ago

@jeduapf the third argument for loading libraries, must be defined with path to the library package e.g.

mod = ModelicaSystem("VSC_Test.mo", VSC_Test, ["c:/OpenISL/package.mo", "c:/HVDCComponents/package.mo"])

Note: See TracTickets for help on using tickets.