Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DiffEqFlux.sciml_train fails with save_idxs keyword #534

Closed
moesphere opened this issue Apr 20, 2021 · 0 comments · Fixed by SciML/SciMLSensitivity.jl#408
Closed

DiffEqFlux.sciml_train fails with save_idxs keyword #534

moesphere opened this issue Apr 20, 2021 · 0 comments · Fixed by SciML/SciMLSensitivity.jl#408

Comments

@moesphere
Copy link

moesphere commented Apr 20, 2021

Training via DiffEqFlux fails when save_idxs keyword is used within the loss function. Differentiation seems to be the problem. Evaluation of the loss function works fine.

MWE is taken from the docs.
Discussion on julia discourse is here.

using DifferentialEquations, Flux, Optim, DiffEqFlux

function lotka_volterra!(du, u, p, t)
  x, y = u
  α, β, δ, γ = p
  du[1] = dx = α*x - β*x*y
  du[2] = dy = -δ*y + γ*x*y
end

# Initial condition
u0 = [1.0, 1.0]

# Simulation interval and intermediary points
tspan = (0.0, 10.0)
tsteps = 0.0:0.1:10.0

# LV equation parameter. p = [α, β, δ, γ]
p = [1.5, 1.0, 3.0, 1.0]

# Setup the ODE problem, then solve
prob = ODEProblem(lotka_volterra!, u0, tspan, p)

function loss(p)
  sol = solve(prob, Tsit5(), p=p, save_idxs=[2], saveat = tsteps)
  loss = sum(abs2, sol.-1)
  return loss, sol
end


result_ode = DiffEqFlux.sciml_train(loss, p, ADAM(0.1), maxiters = 100)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant