Stan compiler warnings in IPython

Operating System: 10.12.4
Interface Version: PyStan, 2.17.0.0

When I try to compile models in PyStan using IPython, I get numerous compiler warnings, beginning with…

In file included from /Library/Python/2.7/site-packages/numpy/core/include/numpy/arrayobject.h:4:
In file included from /Library/Python/2.7/site-packages/numpy/core/include/numpy/ndarrayobject.h:18:
In file included from /Library/Python/2.7/site-packages/numpy/core/include/numpy/ndarraytypes.h:1809:
/Library/Python/2.7/site-packages/numpy/core/include/numpy/npy_1_7_deprecated_api.h:15:2: warning: "Using deprecated NumPy
API, disable it by " “#defining NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION” [-W#warnings]

and then continuing for hundreds of lines, eg

/Library/Python/2.7/site-packages/pystan/stan/lib/stan_math/stan/math/prim/mat/meta/seq_view.hpp:183:19: warning:
implicit conversion loses integer precision: ‘size_type’ (aka ‘unsigned long’) to ‘int’ [-Wshorten-64-to-32]
return x_.size();

I do not get these errors when running in Python as opposed to IPython. Any help on how to remove them is welcome!

I’m not sure if this would help, but perhaps you should see what happens if you use Python 3 instead of Python 2.7. Try using Anaconda Python. As far as I know, Python 2.7 should work, but it may be enlightening to see if you get the same problems with a different Python installation.

These are there in a normal python too. Nothing to worry about.

sm = pystan.StanModel(..., verbose=True)

It is just the IPython handles the stdin and stdout differently. This is also the case with Jupyter Notebooks (the errors are printed in terminal).

There are ways to redirect IPython stdout but I don’t remember how, but it should be some command written in IPython.

Ok, I did test this IPython 6.2.0 + PyStan 2.17.0 and the warnings are visible only if the verbose=True.

So maybe as a first step try to update IPython and PyStan and see if that will fix the problem.

Hi guys!

Thanks so much for these helpful replies! I upgraded my Python with Conda and I’m now on Python 2.7.14, IPython 5.4.1, PyStan 2.17.0. Can’t upgrade any further for IPython on Python 2.7. I’m still getting warnings when I compile, but they’re somewhat reduced – full printout –

In file included from /var/folders/xz/45bxl3d12wz15ds352gsl0yr0000gn/T/tmpiUGODN/stanfit4anon_model_1521910521946302af05b50fa606e2ea_6169241267858442418.cpp:559:
In file included from /Users/epierson/anaconda2/lib/python2.7/site-packages/numpy/core/include/numpy/arrayobject.h:4:
In file included from /Users/epierson/anaconda2/lib/python2.7/site-packages/numpy/core/include/numpy/ndarrayobject.h:18:
In file included from /Users/epierson/anaconda2/lib/python2.7/site-packages/numpy/core/include/numpy/ndarraytypes.h:1809:
/Users/epierson/anaconda2/lib/python2.7/site-packages/numpy/core/include/numpy/npy_1_7_deprecated_api.h:15:2: warning:
"Using deprecated NumPy API, disable it by " “#defining NPY_NO_DEPRECATED_API
NPY_1_7_API_VERSION” [-W#warnings]
#warning "Using deprecated NumPy API, disable it by "
^
In file included from /Users/epierson/anaconda2/lib/python2.7/site-packages/pystan/stan_fit.hpp:22:
In file included from /Users/epierson/anaconda2/lib/python2.7/site-packages/pystan/stan/src/stan/services/diagnose/diagnose.hpp:10:
In file included from /Users/epierson/anaconda2/lib/python2.7/site-packages/pystan/stan/src/stan/model/test_gradients.hpp:7:
In file included from /Users/epierson/anaconda2/lib/python2.7/site-packages/pystan/stan/src/stan/model/log_prob_grad.hpp:4:
In file included from /Users/epierson/anaconda2/lib/python2.7/site-packages/pystan/stan/lib/stan_math/stan/math/rev/mat.hpp:12:
In file included from /Users/epierson/anaconda2/lib/python2.7/site-packages/pystan/stan/lib/stan_math/stan/math/prim/mat.hpp:298:
In file included from /Users/epierson/anaconda2/lib/python2.7/site-packages/pystan/stan/lib/stan_math/stan/math/prim/arr.hpp:38:
In file included from /Users/epierson/anaconda2/lib/python2.7/site-packages/pystan/stan/lib/stan_math/stan/math/prim/arr/functor/integrate_ode_rk45.hpp:17:
In file included from /Users/epierson/anaconda2/lib/python2.7/site-packages/pystan/stan/lib/stan_math/lib/boost_1.64.0/boost/numeric/odeint.hpp:61:
In file included from /Users/epierson/anaconda2/lib/python2.7/site-packages/pystan/stan/lib/stan_math/lib/boost_1.64.0/boost/numeric/odeint/util/multi_array_adaption.hpp:29:
In file included from /Users/epierson/anaconda2/lib/python2.7/site-packages/pystan/stan/lib/stan_math/lib/boost_1.64.0/boost/multi_array.hpp:21:
In file included from /Users/epierson/anaconda2/lib/python2.7/site-packages/pystan/stan/lib/stan_math/lib/boost_1.64.0/boost/multi_array/base.hpp:28:
/Users/epierson/anaconda2/lib/python2.7/site-packages/pystan/stan/lib/stan_math/lib/boost_1.64.0/boost/multi_array/concept_checks.hpp:42:43: warning:
unused typedef ‘index_range’ [-Wunused-local-typedef]
typedef typename Array::index_range index_range;
^
/Users/epierson/anaconda2/lib/python2.7/site-packages/pystan/stan/lib/stan_math/lib/boost_1.64.0/boost/multi_array/concept_checks.hpp:43:37: warning:
unused typedef ‘index’ [-Wunused-local-typedef]
typedef typename Array::index index;
^
/Users/epierson/anaconda2/lib/python2.7/site-packages/pystan/stan/lib/stan_math/lib/boost_1.64.0/boost/multi_array/concept_checks.hpp:53:43: warning:
unused typedef ‘index_range’ [-Wunused-local-typedef]
typedef typename Array::index_range index_range;
^
/Users/epierson/anaconda2/lib/python2.7/site-packages/pystan/stan/lib/stan_math/lib/boost_1.64.0/boost/multi_array/concept_checks.hpp:54:37: warning:
unused typedef ‘index’ [-Wunused-local-typedef]
typedef typename Array::index index;

And the code seems to run fine, so maybe this isn’t anything to worry about?

Also, I do not get these warnings when I run the same code in Python, not IPython.

Best,
Emma

Try this to avoid compiler warnings:
sm = pystan.StanModel(...,extra_compile_args=["-w"])

You can redirect stderror from the terminal to the jupyter notebook using the wurlitzer extension:
https://github.com/minrk/wurlitzer

Install the extension, and then use this in jupyter notebook:
%load_ext wurlitzer