DiffEqSensitivity.jl: Issues with ReverseDiffAdjoint sensealg

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

using ReverseDiff
using OrdinaryDiffEq
using DiffEqSensitivity

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

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

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)

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:

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

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.

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 that currently mentions:


This functionality does not come standard with DifferentialEquations.jl. To use this functionality, you must install DiffEqSensitivity.jl:

]add DiffEqSensitivity
using DiffEqSensitivity

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

aha, it looks like that page never updated to its dev version: Local Sensitivity Analysis (Automatic Differentiation) · DifferentialEquations.jl . I’ll fix that.

Oh jeez, Actions · SciML/DiffEqDocs.jl · GitHub 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.

1 Like

Your issue here is fixed in Filter sensealg to stop infinite recursion of ReverseDiff -> RD by ChrisRackauckas · Pull Request #742 · SciML/SciMLSensitivity.jl · GitHub . A patch with this fix should be out tonight.

Thanks so much for the instant fix!