when trying to call Implicit Euler for solving an ODE, I receive the following error:
MethodError: no method matching OrdinaryDiffEq.NLNewtonConstantCache(::Float32, ::Array{Float64,2}, ::LinearAlgebra.LU{Float64,Array{Float64,2}}, ::Bool, ::Bool, ::Bool, ::Float32, ::DiffEqBase.UDerivativeWrapper{ODEFunction{false,DiffEqFlux.var"#dudt_#50"{NeuralODE{Chain{Tuple{Dense{typeof(tanh),Array{Float32,2},Array{Float32,1}},Dense{typeof(identity),Array{Float32,2},Array{Float32,1}}}},Array{Float32,1},Flux.var"#12#14"{Chain{Tuple{Dense{typeof(tanh),Array{Float32,2},Array{Float32,1}},Dense{typeof(identity),Array{Float32,2},Array{Float32,1}}}}},Tuple{Float32,Float32},ImplicitEuler{0,false,DefaultLinSolve,NLNewton{Rational{Int64},Rational{Int64},Rational{Int64}},DataType},Tuple{},Base.Iterators.Pairs{Symbol,Any,NTuple{4,Symbol},NamedTuple{(:dt, :saveat, :reltol, :abstol),Tuple{Float64,StepRangeLen{Float32,Float64,Float64},Float64,Float64}}}}},LinearAlgebra.UniformScaling{Bool},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing},Float32,Array{Float32,1}}, ::Float64, ::Float32, ::Float32)
Closest candidates are:
OrdinaryDiffEq.NLNewtonConstantCache(::tType, ::J, ::W, ::Bool, ::Bool, ::Bool, ::tType, ::ufType, !Matched::tType, ::tType, ::tType) where {tType, J, W, ufType} at /Users/sdoneva/.julia/packages/OrdinaryDiffEq/nV9bA/src/nlsolve/type.jl:62
And this is how I called the solver:
using Flux, DiffEqFlux, DifferentialEquations, Plots
u0 = [1.0,1.0]
solver = ImplicitEuler(autodiff = false)
tspan_train = (0.0f0,4.00f0)
train_size = 32
t_train = range(tspan_train[1],tspan_train[2],length = train_size)
function create_neural_ode(solver, tspan, t_saveat)
dudt = Chain(
Dense(2,50,tanh),
Dense(50,2))
ps = Flux.params(dudt)
n_ode = NeuralODE(dudt, tspan, solver, dt=1/2^4, saveat = t_saveat, reltol=1e-7, abstol=1e-9)
n_ode
end
n_ode = create_neural_ode(solver, tspan_train, t_train)
plot(n_ode(u0))
What is the right way to call ImplicitEuler?
Your state was Float64 while time was Float32, and it just wasn't able to initialize the implicit tooling with that combination. I'd labelled it as a bug and hope to fix it soon, but in the meantime I recommend just using both Float32 or both Float64. Example:
using Flux, DiffEqFlux, DifferentialEquations, Plots
u0 = Float32[1.0,1.0]
solver = ImplicitEuler(autodiff = false)
tspan_train = (0.0f0,4.00f0)
train_size = 32
t_train = range(tspan_train[1],tspan_train[2],length = train_size)
function create_neural_ode(solver, tspan, t_saveat)
dudt = Chain(
Dense(2,50,tanh),
Dense(50,2))
ps = Flux.params(dudt)
n_ode = NeuralODE(dudt, tspan, solver, dt=1/2^4, saveat = t_saveat, reltol=1e-7, abstol=1e-9)
n_ode
end
n_ode = create_neural_ode(solver, tspan_train, t_train)
plot(n_ode(u0))
works just fine.