# Automatic differentiation of spline functions

**URL:** https://discourse.julialang.org/t/automatic-differentiation-of-spline-functions/86182
**Category:** Performance
**Tags:** question
**Created:** [August 23, 2022, 10:39am UTC](https://discourse.julialang.org/t/automatic-differentiation-of-spline-functions/86182 "2022-08-23T10:39:37Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![compleat](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/compleat/32/8958_2.png) [@compleat](https://discourse.julialang.org/u/compleat)
#### Post date: [August 23, 2022, 10:39am UTC](https://discourse.julialang.org/t/automatic-differentiation-of-spline-functions/86182/1 "2022-08-23T10:39:37Z")

</div>

Splines are a common fitting tool and there are a number of versions in Julia, but I can’t seem to find any versions which are auto-differentiable (i.e., for use in JuMP, NLopt, ODE’s, Integration, etc.).  
[I’m guessing that the issue is that the resulting Arrays are mutating due to the nature of the bases, which Zygote doesn’t like?]  
I would appreciate any help or hints, as I hope to make use of this in classes I am due to teach.  
Thanks!

---

<div class="post-metadata">

### Author: ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)
#### Post date: [August 23, 2022, 11:03am UTC](https://discourse.julialang.org/t/automatic-differentiation-of-spline-functions/86182/2 "2022-08-23T11:03:29Z")

</div>

DataInterpolations.jl seems fine, and even has special overloads. Can you be more specific about your issue?

[https://github.com/PumasAI/DataInterpolations.jl](https://github.com/PumasAI/DataInterpolations.jl)

[https://github.com/PumasAI/DataInterpolations.jl/blob/master/src/DataInterpolations.jl#L27-L35](https://github.com/PumasAI/DataInterpolations.jl/blob/master/src/DataInterpolations.jl#L27-L35)

[https://github.com/PumasAI/DataInterpolations.jl/blob/master/src/derivatives.jl](https://github.com/PumasAI/DataInterpolations.jl/blob/master/src/derivatives.jl)

---

<div class="post-metadata">

### Author: ![compleat](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/compleat/32/8958_2.png) [@compleat](https://discourse.julialang.org/u/compleat)
#### Post date: [August 23, 2022, 1:35pm UTC](https://discourse.julialang.org/t/automatic-differentiation-of-spline-functions/86182/3 "2022-08-23T13:35:39Z")

</div>

> [@ChrisRackauckas](#):
>
> DataInterpolations.jl seems fine, and even has special overloads. Can you be more specific about your issue?

Thanks - That was one I didn’t look at but will try.

About the specific issue, it seems here that derivatives are calculated for some of the spline routines (which is helpful) but for instance if I try to register a spline function into JuMP, it requires that autodiff=true (automatic differentiation) but automatic differentiation does not work for any of the numerous Julia spline routines I tried. Other nonlinear optimisation routines I tried fall over with a similar error. This seems to imply that I cannot use spline functions with any of the various optimisation packages I tried. [I could write one that would probably work, but that seems wasteful]  
Thanks again for your help.

---

<div class="post-metadata">

### Author: ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)
#### Post date: [August 23, 2022, 2:37pm UTC](https://discourse.julialang.org/t/automatic-differentiation-of-spline-functions/86182/4 "2022-08-23T14:37:39Z")

</div>

DataInterpolations.jl is used all of the time in optimization packages. There’s tutorials in SciMLSensitivity.jl which use Optimization.jl with ODEs and splines in them IIRC. I recommend sticking to the standard maintained packages [The SciML Open Souce Software Ecosystem · SciML](https://docs.sciml.ai/stable/)

---

<div class="post-metadata">

### Author: ![compleat](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/compleat/32/8958_2.png) [@compleat](https://discourse.julialang.org/u/compleat)
#### Post date: [August 23, 2022, 2:39pm UTC](https://discourse.julialang.org/t/automatic-differentiation-of-spline-functions/86182/5 "2022-08-23T14:39:56Z")

</div>

Great! That sounds like just what I need.

Thanks!  
[I’ll mark as ‘solved’ when I get a toy example running]
