SciML/SciMLSensitivity.jl

Allow return code when directly calling adjoint_sensitivities

sebapersson opened this issue · 0 comments

Is your feature request related to a problem? Please describe.

As noted in the docs directly calling adjoint_sensitivities can be more efficient, and it is what we for example do in PEtab.jl. However, as adjoint_sensitivities does not return any retcode for adj_sol it is currently not possible when, for example doing parameter estimation, to catch gradient evaluation failures. As the forward problem can often be easier to solve, being able to catch the error in the forward-solve is not enough.

I have also seen questions about this on Slack in the sciml-bridged channel.

Describe the solution you’d like

I do not know exactly how to solve this, but one option could be to allow _adjoint_sensitivities to also return adj_sol, then for the function adjoint_sensitivities have a kwarg like retadjsol=false that by default is false and return as currently du, dp, but if true also returns adj_sol.

Describe alternatives you’ve considered

An alternative is in for example packages like PEtab.jl to copy in the code from _adjoint_sensitivities for each method, however, this is not feasible to maintain. It is also possible to generally capture if a warning was thrown, but accessing the retcode would be a more convenient and less hacky solution.