# Parameter sensitivities of ParametricNDSolveValue involving numerical function

This is a followup of my former question from here. Consider the code

pfun = ParametricNDSolveValue[{x'[t] == a*x[t], x[0] == 1}, {x}, {t,0, 10}, {a}];
part[l_List, n_Integer] := Part[l, n];
qfun = ParametricNDSolveValue[{y'[s] == a^2*y[s], y[0] == part[pfun[a], 1][2]}, {y}, {s, 0, 10}, {a}];


The goal is to calculate the sensitivity of the parameter $a$, $\partial_a y(t;a)$. However,

Derivative[1][qfun][2]


gives ParametricFunction[<>][2] instead of an InterpolatingFunction -object. It seems that this is a general issue for functions of the parameter $a$, which only allow numeric arguments:

f[a_] := a^2;
rfun = ParametricNDSolveValue[{y'[s] == a^2*y[s], y[0] == f[a]}, {y}, {s, 0, 10}, {a}];
Derivative[1][rfun][2]


gives {InterpolatingFunction[{{0.,10.}},<>]}, while

g[a_?NumericQ] := a^2;
sfun = ParametricNDSolveValue[{y'[s] == a^2*y[s], y[0] == g[a]}, {y}, {s, 0, 10}, {a}];
Derivative[1][sfun][2]


also not works and results in ParametricFunction[<>][2].

How can this issue be resolved?

-
I've no idea how to solve this and think it is a bug. You should have in mind that this functionality is new in version 9 and my guess is that nesting ParametricFunction hasn't been on the focus and probably never has been tested. I could imagine that that case simply can't be handled by the underlying routines and the correct behavior would be a warning about that. Of course that is all just speculating and I could be completely off... –  Albert Retey Oct 12 '13 at 10:28