Inerfacing cmdstan 2.18 with C++ code to solve system of ODEs

Hi,

I wonder if somebody wrote an interface from cmdstan 2.18 to C++ code that solves system of ODEs (or system of nonlinear equations etc - something bit complicated) and passes Jacobians to stan’s AD. At least pointer where such interface is described would be appreciated. I found some description in https://cran.r-project.org/web/packages/rstan/vignettes/external.html but it seems it is for stan 2.17.

That hasn’t changed for 2.18. But it is a bit different in CmdStan than in RStan, as explained in the CmdStan PDF.

FYI: I played in the last few days with this. So what I did is defined the ODE functor in a way that it has the analytic Jacobian available (but this info would be injected into the AD tree). However, things got 2x-3x slower vs doing the brute force autodiff.

This means that we will have to specialize the coupled_ode_system to get performance gains. That is a bit more work to do, but at least this is my plan to do.

My idea was to go official way and use stan’s interface to external C++ function f(y,theta). In the external code I call the CVODES directly and supply Jy at the specified values of theta. Somehow I have to supply stan’s AD the Jtheta at the specified values of y. Is this feasible? In reality I also want to use the solver for a system of nonlinear equtions.