# DiffEqSensitivity.jl: Issues with ReverseDiffAdjoint sensealg

**URL:** <https://discourse.julialang.org/t/diffeqsensitivity-jl-issues-with-reversediffadjoint-sensealg/88774>\
**Category:** General Usage\
**Created:** [October 15, 2022, 11:49am UTC](https://discourse.julialang.org/t/diffeqsensitivity-jl-issues-with-reversediffadjoint-sensealg/88774 "2022-10-15T11:49:20Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![nrontsis](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nrontsis/32/38535_2.png) [@nrontsis](https://discourse.julialang.org/u/nrontsis)\
**Post date:** [October 15, 2022, 11:49am UTC](https://discourse.julialang.org/t/diffeqsensitivity-jl-issues-with-reversediffadjoint-sensealg/88774/1 "2022-10-15T11:49:20Z")

</div>

Hi all, I am starting out in `DiffEqSensitivity`, and I ran into the following issue.

When computing gradients as per the following example I get StackOverFlow

```julia
using ReverseDiff
using OrdinaryDiffEq
using DiffEqSensitivity

function ode!(derivative, state, parameters, t)
    derivative .= parameters
end

function ode(state, parameters, t)
    return ode!(similar(state), state, parameters, t)
end

function solve_euler(state, times, parameters)
    problem = ODEProblem{true}(ode!, state, times[[1, end]], parameters; saveat=times, sensealg=ReverseDiffAdjoint())
    return solve(problem, Euler(); dt=1e-1)
end

const initial_state = ones(2)
const solution_times = [1.0, 2.0]
ReverseDiff.gradient(p -> sum(sum(solve_euler(initial_state, solution_times, p))), zeros(2))

```

Passing a non-mutating ode (i.e. `ODEProblem{false}(ode,..)` instead of `ODEProblem{true}(ode!,...)`) results in no StackOverflow, but then the execution never finishes.

Any ideas what’s happening? Thanks!

I am on intel-based MacOS 12.6, Julia 1.7.3 (2022-05-06) and:

```julia

  [41bf760c] DiffEqSensitivity v6.79.0
  [0c46a032] DifferentialEquations v7.2.0
  [37e2e3b7] ReverseDiff v1.14.1

```

---

<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:** [October 15, 2022, 8:09pm UTC](https://discourse.julialang.org/t/diffeqsensitivity-jl-issues-with-reversediffadjoint-sensealg/88774/2 "2022-10-15T20:09:56Z")

</div>

> [@nrontsis](#):
>
> I am starting out in `DiffEqSensitivity`

Is there any reason you can’t update this to `SciMLSensitivity`? All of the tutorials and such have deprecated DiffEqSensitivity long ago IIRC, and the upgrade path is just a name change for most things.

---

<div class="post-metadata">

**Author:** ![nrontsis](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nrontsis/32/38535_2.png) [@nrontsis](https://discourse.julialang.org/u/nrontsis)\
**Post date:** [October 15, 2022, 11:44pm UTC](https://discourse.julialang.org/t/diffeqsensitivity-jl-issues-with-reversediffadjoint-sensealg/88774/3 "2022-10-15T23:44:43Z")

</div>

Thanks, I was not aware of SciMLSensitivity! Unfortunately, even after using it, instead of DiffEqSensitivity, I still end up with the above issues.

For what its worth I started using DiffEqSensitivity due to [this](https://diffeq.sciml.ai/stable/analysis/sensitivity/#Installation) that currently mentions:

> [Installation](https://diffeq.sciml.ai/stable/analysis/sensitivity/#Installation)
> 
> This functionality does not come standard with DifferentialEquations.jl. To use this functionality, you must install DiffEqSensitivity.jl:
> 
> ```julia
> ]add DiffEqSensitivity
> using DiffEqSensitivity
> 
> ```

The above link was the first google result that came up on the search “differentialequations.jl sensitivity”

---

<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:** [October 16, 2022, 5:33am UTC](https://discourse.julialang.org/t/diffeqsensitivity-jl-issues-with-reversediffadjoint-sensealg/88774/4 "2022-10-16T05:33:50Z")

</div>

aha, it looks like that page never updated to its dev version: [Local Sensitivity Analysis (Automatic Differentiation) · DifferentialEquations.jl](https://diffeq.sciml.ai/dev/analysis/sensitivity/) . I’ll fix that.

---

<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:** [October 16, 2022, 5:51am UTC](https://discourse.julialang.org/t/diffeqsensitivity-jl-issues-with-reversediffadjoint-sensealg/88774/5 "2022-10-16T05:51:39Z")

</div>

Oh jeez, [Actions · SciML/DiffEqDocs.jl · GitHub](https://github.com/SciML/DiffEqDocs.jl/actions/workflows/pages/pages-build-deployment) the docs got over some size limit so they weren’t deploying for months (but they were passing all doc build tests!). So sorry about that: that explains the uptick in questions! Thanks for helping to point this out.

---

<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:** [October 16, 2022, 11:53am UTC](https://discourse.julialang.org/t/diffeqsensitivity-jl-issues-with-reversediffadjoint-sensealg/88774/6 "2022-10-16T11:53:34Z")

</div>

Your issue here is fixed in [Filter sensealg to stop infinite recursion of ReverseDiff -\> RD by ChrisRackauckas · Pull Request #742 · SciML/SciMLSensitivity.jl · GitHub](https://github.com/SciML/SciMLSensitivity.jl/pull/742) . A patch with this fix should be out tonight.

---

<div class="post-metadata">

**Author:** ![nrontsis](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nrontsis/32/38535_2.png) [@nrontsis](https://discourse.julialang.org/u/nrontsis)\
**Post date:** [October 17, 2022, 9:00am UTC](https://discourse.julialang.org/t/diffeqsensitivity-jl-issues-with-reversediffadjoint-sensealg/88774/7 "2022-10-17T09:00:50Z")

</div>

Thanks so much for the instant fix!
