I intend to refactor the current coupled ode system object. For one reason I would like to align ODE codes (rk45 and bdf) and for two I would like to route execution through the ode_system object. The reason to do so is that we can plug into the system analytic Jacobians of the ODE wrt to states and parameters using partial template specialization's.
To illustrate what I mean, I prepared a "test" which has the sole purpose to show the execution time for the two cases (with AD and without AD):
The speed gain for the specific case is close to 2x. This always depends on the ODE system, parameters, etc.. the speed gain will be larger for stiffer systems and for ODE systems with many states (this is my personal guess; the cases with many Jacobian evaluations). Applying this during model inference gave me 2-3x speedups.
Supplying the analytic Jacobians won't be something regular users will, rather only advanced users. Making this user friendly is a different topic (I can share some R codes which help already a lot).
I hold on for the moment with a pull request until the design is settled.
Best,
Sebastian
--
You received this message because you are subscribed to the Google Groups "stan development mailing list" group.
To unsubscribe from this group and stop receiving emails from it, send an email to stan-dev+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
- If the goal is to have people write sensitivities and dense Jacobians in the Stan language, then what do you expect it to generate? Right now, we don't even allow users to specify gradients on their own functions and I think this is a good thing. Experts will be able to get into the C++ directly. I think it's hard to implement gradients correctly and not allowing users to try has saved us a lot of effort.
You received this message because you are subscribed to a topic in the Google Groups "stan development mailing list" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/stan-dev/vjM5siFfxwY/unsubscribe.
To unsubscribe from this group and all its topics, send an email to stan-dev+u...@googlegroups.com.
Hi Daniel,My main goal is to have ODEs in Stan at maximum speed. I fully agree that AD is amazingly fast! However, in my field (any I guess many others as well) I need to solve essentially the same ODE in many projects such that it is very reasonable to work out Jacobians for those often used ODE systems. For the current stage I just would like to have an easy C++ way to make the analytic Jacobians possible for ODEs. It is in fact not so magic to do this - there are lots of tools out there to do automatic code generation already. So it comes down to knowing these tools and a bit of copy and paste. No magic. That does not mean this should be worked on in the future, i.e. having some Stan language features which help users with this, but we need to go in steps here.The change I have put up does two things:1. Use the ode_system for calculating the Jacobians. Doing so enables that specifying analytic Jacobians once will be beneficial for bdf and rk45 integrators in Stan2. I made the coupled_ode_system work with an unshifted sensitivity system. Up to now the shifting was done whenever the initials vary. However, this is not needed at all and I aligned this with the CVODES code. This may lead to a minor speedup, not sure.To be clear on this - yes there is no speed gain of the rk45 integrator by now using the ode_system (if at all only a very minor).
You appear to be very confused by the naming of ode_system - we did have a discussion on stab-dev about this (https://groups.google.com/forum/m/?fromgroups#!searchin/stan-dev/ode_system$20name/stan-dev/Bi4D_2YSrjI). Bob and Michael supported the name for it. The design of the ode_system object was aligned with Bob who suggested to use function name overloading. I myself like the ode_system name - it does reflect that this is the ODE plus needed facilities which is the Jacobian in this case.
Now, ode_system should really only provide the Jacobian and not the sensitivity system. The reason is that with the Jacobian it is straightforward to generate the sensitivity system which is needed (which depends on the case var/double and var/double for inits and parameters). Moreover, the CVODES code needs the Jacobian wrt to the states to do its stiff integration. I am not sure if renaming to dense_jacobian makes sense for a Stan object. I mean CVODES makes the distinction between sparse and dense jacobians while Stan always gives you a dense version of it as far as I am aware. So changing to dense_jacobian the function calls - I don’t know.
Moreover, the need to use the MatrixBase Eigen functionality is coming from the fact that I can then pass into the function Matrix and Map objects. The Map functionality enables to write directly into memory chunks, this is used here:or here:If you require a Matrix to be passed around then this leads to extra copies which have to be created. From my experience this leads to a ~2-5% performance degradation.
So here is what I would suggest to do:1. We move the coupled_ode_system to use the ode_system AND to not anymore do a shifting operation (which is on the branch for feature 310)
2. We make cvodes_ode_data use the couple_ode_system which would then be possible as no more shifting is done. Now, this will lead to a minor performance hit for the bdf integrator whenever users supply the analytic Jacobians. The reason is that then the coupled_ode_system cannot be instructed to calculate only the sensitivity system, but not evaluate the function itself. As this is not the major use case of coupled_ode_system and probably the performance hit is not too large, this would be ok. This would lead to a removal of all the rhs_sens function floating around in cvodes_ode_data.However, we will still need the cvodes_ode_data object around as this is needed for the CVODES integrator for the static callback. The name of the object stems from the CVODES notion here which refers to this callback „thing“ as user data.
Best,Sebastian
To unsubscribe from this group and all its topics, send an email to stan-dev+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
The only issue with users specifying wrong gradients is that
they'll get lots of divergences and either live with the wrong
answer or clog our mailing lists. We do have checks that they've
defined it properly, but they're slow.
We could remove the requirement that functions are defined if
they are declared, but then there would be Stan programs that
translate to C++ but don't link. I don't know how to catch the
error at that point and do something reasonable for the user.
> To unsubscribe from this group and stop receiving emails from it, send an email to stan-dev+unsubscribe@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "stan development mailing list" group.
To unsubscribe from this group and stop receiving emails from it, send an email to stan-dev+unsubscribe@googlegroups.com.