Status of CVODES in PyStan

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) (3.9 KB)
function in 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 "", line 92, in compile_model
    sm = pystan.StanModel(model_code=model_code)
  File "/Users/Betancourt/anaconda/lib/python2.7/site-packages/pystan/", line 317, in __init__
    self.module = load_module(self.module_name, lib_dir)
  File "/Users/Betancourt/anaconda/lib/python2.7/site-packages/pystan/", line 54, in load_module
    return imp.load_module(module_name, *module_info)
ImportError: dlopen(/var/folders/bb/67q6n75n13xcq3tcqt9mn44h0000gn/T/tmp0Py2yw/, 2): Symbol not found: _CVDense
  Referenced from: /var/folders/bb/67q6n75n13xcq3tcqt9mn44h0000gn/T/tmp0Py2yw/
  Expected in: flat namespace
 in /var/folders/bb/67q6n75n13xcq3tcqt9mn44h0000gn/T/tmp0Py2yw/

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

You need to install from this PR.

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?

Does the building of the CVODES library not get cached?

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

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.

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.

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?

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

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

pip install git+
1 Like

It works. Thanks a lot, very helpful.

I was trying to install this but got this error, did I do anything wrong?

Collecting git+
  Cloning (to revision feature/cvodes-support) to /tmp/pip-req-build-lkbkqfa8
  Running command git clone -q /tmp/pip-req-build-lkbkqfa8
  WARNING: Did not find branch or tag 'feature/cvodes-support', assuming revision or ref.
  Running command git checkout -q feature/cvodes-support
  error: pathspec 'feature/cvodes-support' did not match any file(s) known to git
WARNING: Discarding git+ Command errored out with exit status 1: git checkout -q feature/cvodes-support Check the logs for full command output.                                                                                                         
ERROR: Command errored out with exit status 1: git checkout -q feature/cvodes-support Check the logs for full command output.

Hi, pystan is currently i 3.x (these instructions were made for 2.x).

3.x version supports cvodes by default so no need to do anything special.