Status of CVODES in PyStan


#1

Operating System: 10.12.6
Python Version: 2.7.12
Interface Version: 2.16.0
Compiler/Toolkit: clang

Is CVODES supposed to work in PyStan at the moment? If I try to cache a model that includes intergrate_ode_bdf (using the comple_modelode.stan (559 Bytes)
stan_utility.py (3.9 KB)
function in stan_utility.py) I get the error

>>> model = stan_utility.compile_model('ode.stan')
INFO:pystan:COMPILING THE C++ CODE FOR MODEL anon_model_58a969bf13ae84e1c0fd951cb478e608 NOW.
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "stan_utility.py", line 92, in compile_model
    sm = pystan.StanModel(model_code=model_code)
  File "/Users/Betancourt/anaconda/lib/python2.7/site-packages/pystan/model.py", line 317, in __init__
    self.module = load_module(self.module_name, lib_dir)
  File "/Users/Betancourt/anaconda/lib/python2.7/site-packages/pystan/model.py", line 54, in load_module
    return imp.load_module(module_name, *module_info)
ImportError: dlopen(/var/folders/bb/67q6n75n13xcq3tcqt9mn44h0000gn/T/tmp0Py2yw/stanfit4anon_model_58a969bf13ae84e1c0fd951cb478e608_8865521048563499472.so, 2): Symbol not found: _CVDense
  Referenced from: /var/folders/bb/67q6n75n13xcq3tcqt9mn44h0000gn/T/tmp0Py2yw/stanfit4anon_model_58a969bf13ae84e1c0fd951cb478e608_8865521048563499472.so
  Expected in: flat namespace
 in /var/folders/bb/67q6n75n13xcq3tcqt9mn44h0000gn/T/tmp0Py2yw/stanfit4anon_model_58a969bf13ae84e1c0fd951cb478e608_8865521048563499472.so

Are there extra steps needed to use CVODES or is it known that CVODES doesn’t work with Python? @ariddell @ahartikainen @seantalts


#2

You need to install from this PR.


#3

I’ve been thinking of building a separate set of wheels for CVODES
PyStan users.

@betanalpha if you installed the cvodes version of pystan it would/will
make all your models take ~10-20 seconds longer to compile. How big a
deal is that for you?


#4

Does the building of the CVODES library not get cached?


#5

There is a way to do this with conda, I think, but doing it with
pip/setuptools is not well supported.


#6

It’s just a binary that needs to get built once and then linked during the model build process.

How do people use C++ libraries or C libraries that aren’t header only in Python? I can’t imagine they recompile every time they’re used.


#7

You can build a Python extension module which uses a C/C++ library.
It’s the packaging up of the compiled C/C++ library for future use which
is the difficulty. (If you’re familiar with Python’s distutils /
setuptools you’ll note there’s is a build_clib function but no
install_clib function.)

I’ll take another look at this. I did have it working at one point a
very long time ago (when Stan wasn’t header-only). I recall it’s all
very messy and difficult to maintain.


#8

Sure, but why can’t PyStan build the library the first time a model is compiled (like CmdStan does) then cache it for future use, like the models themselves can be cached?


#10

Hello,
I got the same error using integrate_ode_bdf. Shall I upgrade PyStan or I need to install something? Sorry I didn’t get what to do by reading following links. Thanks a lot in advance for your hint. Best, Sam


#11

Currently, install with this (I recommend that you use virtual environment).

pip install git+https://github.com/stan-dev/pystan.git@feature/cvodes-support

#12

It works. Thanks a lot, very helpful.