{"id":93,"date":"2009-12-21T13:24:00","date_gmt":"2009-12-21T13:24:00","guid":{"rendered":"https:\/\/sandrock.co.za\/carl\/2009\/12\/21\/pysundials-problems\/"},"modified":"2009-12-21T13:24:00","modified_gmt":"2009-12-21T13:24:00","slug":"pysundials-problems","status":"publish","type":"post","link":"https:\/\/sandrock.co.za\/carl\/2009\/12\/pysundials-problems\/","title":{"rendered":"PySUNDIALS problems"},"content":{"rendered":"<p>I&#8217;m still installing JModelica.  I am now in the annoying &#8220;nothing broke during install, but somethings still fail when I use them&#8221; phase.  I am using the instructions <a href=\"http:\/\/www.jmodelica.org\/book\/106\">here<\/a>, and using the example to test if things are working because JModelica doesn&#8217;t seem to have a test suite.  This is what is happening now:<\/p>\n<div><\/div>\n<div><\/p>\n<pre><br \/>In [1]: import jmodelica.examples.cstr as cstr<br \/>\/Library\/Python\/2.6\/site-packages\/jpype\/_pykeywords.py:18: DeprecationWarning: the sets module is deprecated<br \/>import sets<br \/>---------------------------------------------------------------------------<br \/>AttributeError                            Traceback (most recent call last)<br \/><br \/>\/Users\/alchemyst\/ in ()<br \/><br \/>\/usr\/local\/Python\/jmodelica\/examples\/cstr.py in ()<br \/>  9 from jmodelica.initialization.ipopt import NLPInitialization<br \/> 10 from jmodelica.initialization.ipopt import InitializationOptimizer<br \/>---&gt; 11 from jmodelica.simulation.sundials import TrajectoryLinearInterpolation<br \/> 12 from jmodelica.simulation.sundials import SundialsDAESimulator<br \/> 13 from jmodelica.optimization import ipopt<br \/><br \/>\/usr\/local\/Python\/jmodelica\/simulation\/sundials.py in ()<br \/> 14<br \/> 15 try:<br \/>---&gt; 16     from pysundials import cvodes<br \/> 17     from pysundials import ida<br \/> 18     from pysundials import nvecserial<br \/><br \/>\/Library\/Python\/2.6\/site-packages\/pysundials\/cvodes.py in ()<br \/> 39 import ctypes<br \/> 40 import sundials_core<br \/>---&gt; 41 import nvecserial<br \/> 42<br \/> 43 realtype = nvecserial.realtype<br \/><br \/>\/Library\/Python\/2.6\/site-packages\/pysundials\/nvecserial.py in ()<br \/> 56 PVector = ctypes.POINTER(_NVector)<br \/> 57<br \/>---&gt; 58 nvecserial.N_VNew_Serial.restype = PVector<br \/> 59<br \/> 60 nvecserial.N_VLinearSum_Serial.argtypes = [realtype, PVector, realtype, PVector, PVector]<br \/><br \/>\/System\/Library\/Frameworks\/Python.framework\/Versions\/2.6\/lib\/python2.6\/ctypes\/__init__.pyc in __getattr__(self, name)<br \/>356         if name.startswith('__') and name.endswith('__'):<br \/>357             raise AttributeError(name)<br \/>--&gt; 358         func = self.__getitem__(name)<br \/>359         setattr(self, name, func)<br \/>360         return func<br \/><br \/>\/System\/Library\/Frameworks\/Python.framework\/Versions\/2.6\/lib\/python2.6\/ctypes\/__init__.pyc in __getitem__(self, name_or_ordinal)<br \/>361<br \/>362     def __getitem__(self, name_or_ordinal):<br \/>--&gt; 363         func = self._FuncPtr((name_or_ordinal, self))<br \/>364         if not isinstance(name_or_ordinal, (int, long)):<br \/>365             func.__name__ = name_or_ordinal<br \/><br \/>AttributeError: dlsym(0x102e957d0, N_VNew_Serial): symbol not found<br \/><\/pre>\n<p>It&#8217;s clear something is wrong with pysundials.  On closer inspection, it seems that the dynamic library isn&#8217;t loading correctly.  A part of the problem is explained by this:<\/p><\/div>\n<div><\/p>\n<pre><br \/>$ nm \/usr\/local\/lib\/libsundials*dylib<br \/><br \/>\/usr\/local\/lib\/libsundials_cvode.1.0.0.dylib:<br \/>0000000000000000 s __mh_dylib_header<br \/>              U dyld_stub_binder<br \/><\/pre>\n<p><\/div>\n<div>And many more like it.  It seems like the .dylib built by the sundials build process doesn&#8217;t include the correct names.  After much browsing and learning about how .dylibs work, I realise that this can be solved with a simple change to the configure script call (typical &#8211; it was actually documented: use &#8211;enable-shared in the build!):<\/div>\n<div><\/div>\n<p><\/p>\n<div><\/p>\n<pre><br \/>FFLAGS=\"-arch x86_64\" .\/configure --prefix=\/usr\/local --enable-examples --enable-shared<br \/>make<br \/>sudo make install<br \/><\/pre>\n<p>Now nm shows the items in the dylib.<\/p>\n<\/div>\n<div>I know sundials is working right because the examples compile and run fine.  Now for pysundials:<\/div>\n<div><\/div>\n<div><\/p>\n<pre><br \/>In [2]: from pysundials import cvode<br \/>---------------------------------------------------------------------------<br \/>AttributeError                            Traceback (most recent call last)<br \/><br \/>\/Users\/alchemyst\/tmp\/pysundials-2.3.0-rc2\/examples\/cvode\/serial\/ in ()<br \/><br \/>\/Library\/Python\/2.6\/site-packages\/pysundials\/cvode.py in ()<br \/>   350         if ret  352 cvode.CVodeSetFdata.argtypes = [ctypes.c_void_p, ctypes.c_void_p]<br \/>   353 cvode.CVodeSetFdata.restype = ctypes.c_int<br \/>   354<br \/><br \/>\/System\/Library\/Frameworks\/Python.framework\/Versions\/2.6\/lib\/python2.6\/ctypes\/__init__.pyc in __getattr__(self, name)<br \/>   356         if name.startswith('__') and name.endswith('__'):<br \/>   357             raise AttributeError(name)<br \/>--&gt; 358         func = self.__getitem__(name)<br \/>   359         setattr(self, name, func)<br \/>   360         return func<br \/><br \/>\/System\/Library\/Frameworks\/Python.framework\/Versions\/2.6\/lib\/python2.6\/ctypes\/__init__.pyc in __getitem__(self, name_or_ordinal)<br \/>   361<br \/>   362     def __getitem__(self, name_or_ordinal):<br \/>--&gt; 363         func = self._FuncPtr((name_or_ordinal, self))<br \/>   364         if not isinstance(name_or_ordinal, (int, long)):<br \/>   365             func.__name__ = name_or_ordinal<br \/><br \/>AttributeError: dlsym(0x1014d04f0, CVodeSetFdata): symbol not found<br \/><br \/><\/pre>\n<p>And the original thing I was trying to do:<\/p>\n<pre><br \/>In [1]: import jmodelica.examples.cstr as cstr<br \/>\/Library\/Python\/2.6\/site-packages\/jpype\/_pykeywords.py:18: DeprecationWarning: the sets module is deprecated<br \/> import sets<br \/>---------------------------------------------------------------------------<br \/>OSError                                   Traceback (most recent call last)<br \/><br \/>\/Users\/alchemyst\/tmp\/pysundials-2.3.0-rc2\/examples\/cvode\/serial\/ in ()<br \/><br \/>\/usr\/local\/Python\/jmodelica\/examples\/cstr.py in ()<br \/>     9 from jmodelica.initialization.ipopt import NLPInitialization<br \/>    10 from jmodelica.initialization.ipopt import InitializationOptimizer<br \/>---&gt; 11 from jmodelica.simulation.sundials import TrajectoryLinearInterpolation<br \/>    12 from jmodelica.simulation.sundials import SundialsDAESimulator<br \/>    13 from jmodelica.optimization import ipopt<br \/><br \/>\/usr\/local\/Python\/jmodelica\/simulation\/sundials.py in ()<br \/>    14<br \/>    15 try:<br \/>---&gt; 16     from pysundials import cvodes<br \/>    17     from pysundials import ida<br \/>    18     from pysundials import nvecserial<br \/><br \/>\/Library\/Python\/2.6\/site-packages\/pysundials\/cvodes.py in ()<br \/>    44 NVector = nvecserial.NVector<br \/>    45<br \/>---&gt; 46 cvodes = sundials_core.loadlib(\"cvodes\")<br \/>    47<br \/>    48 #Linear Multistep method constants<br \/><br \/><br \/>\/Library\/Python\/2.6\/site-packages\/pysundials\/sundials_core.pyc in loadlib(libname)<br \/>    62                 lib = ctypes.CDLL(libpaths[libname])<br \/>    63         except OSError, e:<br \/>---&gt; 64                 raise OSError(\"%snCannot load shared library %s. Please check you config file and ensure the paths to the shared libraries are correct.\"%(e, libpaths[libname]))<br \/>    65         return lib<br \/>    66<br \/><br \/>OSError: dlopen(\/usr\/local\/libsundials_cvodes.dylib, 6): image not found<br \/>Cannot load shared library \/usr\/local\/libsundials_cvodes.dylib. Please check you config file and ensure the paths to the shared libraries are correct.<br \/><br \/><\/pre>\n<p>So the error has changed to it not finding the library.  Something must be screwy with paths.  Frustrating afternoon.<\/p><\/div>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;m still installing JModelica. I am now in the annoying &#8220;nothing broke during install, but somethings still fail when I use them&#8221; phase. I am using the instructions here, and using the example to test if things are working because JModelica doesn&#8217;t seem to have a test suite. This is what is happening now: In [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_feature_clip_id":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_post_was_ever_published":false},"categories":[1],"tags":[],"class_list":["post-93","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/sandrock.co.za\/carl\/wp-json\/wp\/v2\/posts\/93","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/sandrock.co.za\/carl\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/sandrock.co.za\/carl\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/sandrock.co.za\/carl\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/sandrock.co.za\/carl\/wp-json\/wp\/v2\/comments?post=93"}],"version-history":[{"count":0,"href":"https:\/\/sandrock.co.za\/carl\/wp-json\/wp\/v2\/posts\/93\/revisions"}],"wp:attachment":[{"href":"https:\/\/sandrock.co.za\/carl\/wp-json\/wp\/v2\/media?parent=93"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/sandrock.co.za\/carl\/wp-json\/wp\/v2\/categories?post=93"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/sandrock.co.za\/carl\/wp-json\/wp\/v2\/tags?post=93"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}