This question describes a particular AD application, I am either looking for a solution, someone telling me why it is not a good idea, or potential collaborators who are interested in the same problem, which comes up frequently whenever one needs multiple specific partial derivatives of a function (eg PDEs).
Consider a multivariate function, eg call it f(x, y, z, ...), which has real arguments and is composed of a set of βelementaryβ functions of (+
, *
, cos
, etc), implemented in Julia.
I am interested in obtaining a user-specified set of derivatives via AD. This is how the (imaginary) API could work. Letβs say f(::Tuple{Real,Real})
is bivariate and takes x and y in a tuple.
# specify what I need, as a NamedTuple of variable indices
D = derivatives_I_want((fval = (), Dx = (1,), Dxy = (1, 2)))
# seeds with the relevant multivariate generalization of dual numbers
# D determines the order implicitly
lifted_xy = seed(D, (1.0, 2.0))
# arranges what I need in a NamedTuple
(; fval, Dx, Dxy) = extract(D, f(lifted_xy))
The idea is a straightforward extension of ForwardDiff.jl, but the only package I could find that implements something like this is
where I would have to supply the wrapper API (derivatives_I_want
, seed
, extract
) but that is straightforward. The only disadvantage is that the package uses Vector
s and hash tables internally, so it is allocation-heavy. There was an attempt to make it static at
but it seems stalled.
Also note that while TaylorSeries.jl could be used to implement this kind of API, it is a bit different because it starts from the derivatives the user wants.
Thoughts appreciated. (@dpsanders, if you have the time I would especially value your opinion)