Thanks Chris for letting me know it should work! The NamedTuple Error was triggered by incorrect behaviour in our code (missing Semicolon), the only surprising part is that the bug doesn’t prevent the normal code to run (as long as no keyword arguments are actually passed):
using DiffEqFlux
using OrdinaryDiffEq
function l1(p; solver_options...)
dd_spec = solve(ODEProblem((dy,y,p,t) -> dy .= p, zeros(2), (0., 10.), p), Tsit5(), saveat=0.:0.1:10.
, solver_options...) # Comma instead of semicolon here
sum(dd_spec[end])
end
l1(ones(2)) # This works despite the missing semicolon
DiffEqFlux.sciml_train(
l1,
ones(2),
DiffEqFlux.ADAM(0.5),
maxiters = 2) # NamedTuple Error.
# Apparently splatted keyword arguments being passed
# splatted into arguments is not so good (and almost
# certainly this is never going to be the intended behaviour).
# The following works as expected:
function l2(p; solver_options...)
dd_spec = solve(ODEProblem((dy,y,p,t) -> dy .= p, zeros(2), (0., 10.), p), Tsit5(), saveat=0.:0.1:10.; solver_options...)
sum(dd_spec[end])
end
l2(ones(2))
DiffEqFlux.sciml_train(
l2,
ones(2),
DiffEqFlux.ADAM(0.5),
maxiters = 2)
While reducing this I also came across the follwoing failure to differentiate. We create a temporary array of arrays, don’t use it, and that throws off the adjoint. Again, this is triggered by having code you don’t want to have in the first place, but that is perfectly valid.
function l3(p)
ps = [p[1 + (n - 1) * 2:n * 2] for n in 1:10] # This is unused
dd_spec = solve(ODEProblem((dy,y,p,t) -> dy .= p, zeros(2), (0., 10.), p[1:2]), Tsit5())
sum(dd_spec[end])
end
l3(ones(20))
DiffEqFlux.sciml_train(
l3,
ones(20),
DiffEqFlux.ADAM(0.5),
maxiters = 2) # MethodError: no method matching iterate(::Nothing)