Problem importing Jmodelica.org models to CasADI

370 views
Skip to first unread message

Andres Codas Duarte

unread,
Oct 10, 2013, 9:05:23 AM10/10/13
to casadi...@googlegroups.com
Hi all,

  I just installed JModellica, I guess version r5327, that comes along with CasADi.  I also downloaded and installed CasADi (I think this cab582cb106f9be8d462e10f843e5db75001eb2a is the git reference).  I'm running on a linux machine

  I tryed to run the example ('fritzson_application_examples'), from the JModelica installation, and the line 54:

    jmu_name = compile_jmu(name, curr_dir+"/thermodynamics_example.mo",'modelica','ipopt',{'generate_xml_equations':True, 'generate_fmi_me_xml':False})

  returns an error.  I believe it is because the option 'ipopt' is not longer supported.  So, I removed that option and tried to run again, this time successfully.  But then, the command line 66:
 
    ocp.parseFMI('BasicVolumeMassConservation.xml')

   Gives the following error:

  File "thermodynamics_example.py", line 66, in <module>
    ocp.parseFMI('BasicVolumeMassConservation.xml')
  File "/usr/lib/python2.7/dist-packages/casadi/casadi.py", line 21908, in parseFMI
    return _casadi.SymbolicOCP_parseFMI(self, *args)
RuntimeError: Error in XMLNode::operator[]: could not find QualifiedName

  The same error appears if I use the casadi installation from JModelica

   Is there a solution for this problem.  How do I import now Jmodelica models to casadi?

   Regards,
   Andres

Joel Andersson

unread,
Oct 14, 2013, 6:03:05 AM10/14/13
to casadi...@googlegroups.com
Hello Andres!

Did you install JModelica.org and CasADi separate from each other? JModelica.org comes with CasADi, so there is no reason to install it separately. What you have is probably a version mismatch. I'd recommend you to only use the CasADi version which comes with JModelica.org.

Greetings,
Joel

Andres Codas Duarte

unread,
Oct 14, 2013, 6:25:26 AM10/14/13
to casadi...@googlegroups.com
Hi Joel,

  Thanks your answer.

   I believe that it is not just a simple version mismatch.  I believe it has to do with functionalities that were updated/changed and now are generating bugs.  But of course in a previous version it worked.  But anyway answering your question:

   --Did you install JModelica.org and CasADi separate from each other?

   Yes.  First I installed JModelica, together with Casadi, and I tried to run some old code I have.  It returned exactly the same error reported above .  So then I tried updating CasADi, by installing it separately, and happened the same.

   If you tried to run the example, and it returned successfully, maybe the reason why is because you are using the pre-compiled version of the Modelica model (you are not parsing the model with the new version of Modelica).

   So... What do you recommend me to do?  Is there any fix with the latest versions or should I download a previous version (which) that is working?

   Regards,
   Andres

Joel Andersson

unread,
Oct 14, 2013, 6:42:53 AM10/14/13
to casadi...@googlegroups.com
Hello again,

Did you try to run the CasADi-based solvers in JModelica? I don't believe that the JModelica people would release a JModelica version that is incompatible with CasADi. I think that either there is a version conflict with multiple CasADi installations, or that you're trying to use an outdated XML instead of generating a new one.

Joel

Andres Codas Duarte

unread,
Oct 14, 2013, 6:48:03 AM10/14/13
to casadi...@googlegroups.com
Hi Joel,

   As I said in my previous e-mail.  First I tried just with the CasADi version within the JModelica.org package.  So, yes I tried the CasADi-based solvers in JModelica.

   Andres

Joel Andersson

unread,
Oct 14, 2013, 6:55:12 AM10/14/13
to casadi...@googlegroups.com
The "fritzson_application_examples" stuff is just something I coded myself, it doesn't use the CasADi-based solvers in JModelica. The JModelica devs don't use or test it, so it might very well become broken. I mean, do examples like vdp_casadi work? I would be surprised if they didn't.

Joel

Andres Codas Duarte

unread,
Oct 14, 2013, 10:56:06 AM10/14/13
to casadi...@googlegroups.com
If I run vdp_casadi with the CasADi version installed within JModelica it runs without problems.  If I run it with the version installed separately it returns the error at the bottom of this message.

However, an important remark.  I want to get the 'SymbolicOCP' object out of the modelica/optimica model.  In the example vdp_casadi you are using other structure "CasadiModel" to solve the OCP with collocation (I actually want to use Single shooting or Multiple shooting).

Thanks,
Andres


-----------------------------------------------------------------------------------------------

In [1]: run vdp_casadi.py
JVM started.
Warning: Skipped TiXmlNode::DECLARATION
Adding model variables.
Adding binding equations.
... parsing complete after 0 seconds
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
/usr/lib/python2.7/dist-packages/IPython/utils/py3compat.pyc in execfile(fname, *where)
    173             else:
    174                 filename = fname
--> 175             __builtin__.execfile(filename, *where)

/home/codas/JModelica.org/JModelica-r5327/Python/pyjmi/examples/vdp_casadi.py in <module>()
     74
     75 if __name__ == "__main__":
---> 76     run_demo()

/home/codas/JModelica.org/JModelica-r5327/Python/pyjmi/examples/vdp_casadi.py in run_demo(with_plots)
     41
     42     # Optimize

---> 43     res = model.optimize(algorithm="LocalDAECollocationAlg", options=opts)
     44
     45     # Extract variable profiles


/home/codas/JModelica.org/JModelica-r5327/Python/pyjmi/casadi_interface.pyc in optimize(self, algorithm, options)
    361         """
    362         return self._exec_algorithm('pyjmi.jmi_algorithm_drivers',
--> 363                                     algorithm, options)
    364
    365     def get_casadi_ocp(self):

/home/codas/JModelica.org/JModelica-r5327/Python/pyjmi/common/core.pyc in _exec_algorithm(self, module, algorithm, options)
    166
    167         # initialize algorithm

--> 168         alg = algorithm(self, options)
    169         # solve optimization problem/initialize

    170         alg.solve()

/home/codas/JModelica.org/JModelica-r5327/Python/pyjmi/jmi_algorithm_drivers.pyc in __init__(self, model, options)
   1489                     'Could not find CasADi. Check pyjmi.check_packages()')
   1490
-> 1491         self.nlp = LocalDAECollocator(model, self.options)
   1492
   1493         # set solver options


/home/codas/JModelica.org/JModelica-r5327/Python/pyjmi/optimization/casadi_collocation.pyc in __init__(self, model, options)
    771
    772         # Get to work

--> 773         self._create_nlp()
    774
    775     def _create_nlp(self):

/home/codas/JModelica.org/JModelica-r5327/Python/pyjmi/optimization/casadi_collocation.pyc in _create_nlp(self)
    784         self._create_cost()
    785         self._compute_bounds_and_init()
--> 786         self._create_solver()
    787
    788     def _get_ocp_expressions(self):

/home/codas/JModelica.org/JModelica-r5327/Python/pyjmi/optimization/casadi_collocation.pyc in _create_solver(self)
   2643                                     casadi.nlpOut(f=self.cost, g=constraints))
   2644         elif self.graph == "SX":
-> 2645             nlp = casadi.SXFunction(casadi.nlpIn(x=self.xx),
   2646                                     casadi.nlpOut(f=self.cost, g=constraints))
   2647         else:

AttributeError: 'module' object has no attribute 'nlpIn'

Joel Andersson

unread,
Oct 14, 2013, 11:50:52 AM10/14/13
to casadi...@googlegroups.com
It looks like the CasADi version in JModelica is newer than the one you've installed separately. Checking the commit id you sent it looks like your version if from April. I'd try either updating CasADi or using the CasADi version that comes with JModelica. Both CasADi and JModelica are being developed, so a version mismatch can mean that it doesn't work.

The CasADi distribution that comes with JModelica should be pretty complete. You can always create "SymbolicOCP" objects using it (JModelica does this internally).

Greetings,
Joel

Andres Codas Duarte

unread,
Oct 14, 2013, 1:26:10 PM10/14/13
to casadi...@googlegroups.com
Hi Joel,

  Thanks for your advice.  I took a look inside the implementation, and I realized that if compile the files with FMUX instead of JMU it works.

  (For those having the same problem) Find attached a working example for me.

  The CasADi version I installed is what you call 'official release' in the installation instructions: (git clone https://github.com/casadi/casadi.git casadi && cd casadi && git checkout 1.6.x)

  Regards,
  Andres
thermodynamics_example.py

Joel Andersson

unread,
Oct 14, 2013, 2:59:55 PM10/14/13
to casadi...@googlegroups.com
Good that it worked out! Note that the latest release is 1.7 from June this year and JModelica probably uses that one.

Greatings,
Joel

Duc Doan

unread,
Oct 2, 2015, 4:54:16 AM10/2/15
to CasADi
Dear Andres,

I followed your post about importing XML file to CasADi, and you solved these problems. In my case, I can create XML file, but I can not parse XML file in CasADi (I am using CasADi integrated in Jmodelica). The erros are as follows:

==========================================================================
Traceback (most recent call last):
  File "C:\JModelica.org-SDK-1.11\install\Python\pyjmi\examples\EV_test4.py", line 66, in <module>
    ocp.parseFMI('EV_pack.EV_Energy_Opt.xml')
  File "C:\JModelica.org-SDK-1.11\install\Python\casadi\casadi_core.py", line 37624, in parseFMI
    return _casadi_core.SymbolicOCP_parseFMI(self, *args)
RuntimeError: The assertion "handle!=0" on line 153 of file "c:/JModelica.org-SDK-1.11/src/ThirdParty/CasADi/CasADi/casadi/core/misc/../function/plugin_interface.hpp" failed. 
PluginInterface::loadPlugin: Cannot load shared library:
  Tried libcasadi_xmlfile_tinyxml.dll:
    Error code (WIN32): 126
  Tried: c:/JModelica.org-SDK-1.11/install/ThirdParty/CasADi/lib\libcasadi_xmlfile_tinyxml.dll:
    Error code (WIN32): 126
  Tried: .\libcasadi_xmlfile_tinyxml.dll:
    Error code (WIN32): 126
=========================================================================================

I spent one week to adjust the program following instructions in the internet, but it is still not working. Do you have any advice?

Thank you very much for your reading.

Joel Andersson

unread,
Oct 3, 2015, 2:45:26 AM10/3/15
to CasADi
Hi Duc,

Please note that the above posts are almost two years old and lots of things have changed since then.

In general, if you get the CasADi expressions from JModelica, you should ask in the JModelica.org forum. They maintain a pretty complete way of doing so and I know that they are working right now in bringing it up-to-date with the latest CasADi version.

The Modelica support in the DaeBuilder class, previously SymbolicOCP, is not actively maintained, so better use the approach recommended by JModelica.

Joel

Andres Codas Duarte

unread,
Oct 3, 2015, 8:54:17 AM10/3/15
to CasADi
Hi Duc,

   As Joel says, there has been a lot of time since this post and I don't even remember anymore the details. Maybe they are not relevant anymore.

   However, I would suggest you to follow the procedures of working test examples from Jmodelica first before you try your model.  The error seems to be related to a faulty installation rather than a coding error on your side.

   Further than that, I'm not into the details of the installation and configuration of these softwares.

   Andres
Reply all
Reply to author
Forward
0 new messages