I used CVode solver followed the example on discontinuities (https://jmodelica.org/assimulo/_modules/assimulo/examples/cvode_with_disc.html#run_example), meaning that I subclassed the 'Explicit_Problem' class.
For integration of my ode system (that has discontinuities), I did override the method 'rhs', which encodes my ode system. More specifically, I used the following signature: def rhs(self, t, y, sw)
.
Then, to also get the parametric sensitivities, I just modified the signature like this def rhs(self, t, y, sw, p)
, note the additional argument p
! I needed also to assign p0
with the parameter values, as seen for the initial values assignment y0
in the example. It was just as easy as that.
Be aware that also calculating the parametric sensitivities may need considerably more computation time (I found 5 to 10 times more, but my ode systems are typically not that big).
Unfortunately, the sensitivities are calculated using finite differences (forward or central). To my understanding, the SUNDIALS solvers are able to do state-of-the-art algorithmic differentation to get the sensitivity equations for solving them along with the original ode. Would love to see this in next releases :-)