SciML / DiffEqFlux.jl

Pre-built implicit layer architectures with O(1) backprop, GPUs, and stiff+non-stiff DE solvers, demonstrating scientific machine learning (SciML) and physics-informed machine learning methods
https://docs.sciml.ai/DiffEqFlux/stable
MIT License
870 stars 157 forks source link

MethodError: no method matching length(::Nothing) #498

Closed praveenyati10 closed 3 years ago

praveenyati10 commented 3 years ago

Was trying to predict parameters for duffing equation using BlackBoxOptim. It worked in julia 1.5.1 but not working in julia 1.5.3 and throwing error-MethodError: no method matching `length(::Nothing)`

using BlackBoxOptim

using Optim

function loss(p)
        tmp_prob=remake(prob,p=p)
        tmp_sol=solve(tmp_prob,MethodOfSteps(Tsit5()),p=p,saveat=0.01)
        sum(abs2,Array(tmp_sol)-dataset),tmp_sol
end

pinit=[1.0,1.0,0.5]
res3=DiffEqFlux.sciml_train(loss,pinit,DiffEqFlux.BBO(),lower_bounds=0.0ones(4),upper_bounds=4.0ones(4))
ChrisRackauckas commented 3 years ago

I can't run that.

praveenyati10 commented 3 years ago

okay let me upload the whole code

using Pkg

Pkg.add("BlackBoxOptim")

using DiffEqFlux

function duffing(du,u,p,t)
 γ,d,ω=p
 du[1] = u[2]
 du[2] = u[1] - u[1]^3 -γ*u[2] + d*cos(ω*t)
end

p=[.1,.1,1.4]
u0 = [1.0; -1.0]
tspan = (0.0,50.0)

Δt = 1e-2
T = tspan[1]:Δt:tspan[end]

prob = ODEProblem(duffing, u0, tspan,p)
sol =solve(prob,MethodOfSteps(Tsit5()),p=p,saveat=0.01)
sol
plot(sol[1,:])
dataset=Array(sol)
dataset
function loss(p)
        tmp_prob=remake(prob,p=p)
        tmp_sol=solve(tmp_prob,MethodOfSteps(Tsit5()),p=p,saveat=0.01)
        sum(abs2,Array(tmp_sol)-dataset),tmp_sol
end

using BlackBoxOptim

using Optim

pinit=[1.0,1.0,0.5]
res3=DiffEqFlux.sciml_train(loss,pinit,DiffEqFlux.BBO(),lower_bounds=0.0ones(4),upper_bounds=4.0ones(4))
res3

`
ChrisRackauckas commented 3 years ago

The fix is in https://github.com/SciML/DiffEqFlux.jl/pull/499 and should merge tomorrow.