SciML / DifferentialEquations.jl

Multi-language suite for high-performance solvers of differential equations and scientific machine learning (SciML) components. Ordinary differential equations (ODEs), stochastic differential equations (SDEs), delay differential equations (DDEs), differential-algebraic equations (DAEs), and more in Julia.
https://docs.sciml.ai/DiffEqDocs/stable/
Other
2.85k stars 226 forks source link

Error using Rodas4() #744

Closed hurricane007 closed 3 years ago

hurricane007 commented 3 years ago

Hello,

when I solve a PDE (basically dC/dt = -usgdC/dz + Dgd^2C/dz^2 + S) with alg_hints=[:stiff], I learnt the algorithm was Rodas4(), but I have never been able to solve the PDE with Rodas4() (also not possible with other algorithms such as KenCarp*()). anyone know the reason? image

hurricane007 commented 3 years ago

The only thing working is CVODE_BDF(), but this algorithm doesn't support "save_idxs" that I need for parameter estimation.

anandijain commented 3 years ago

can you post the reproducer so i can mess around with it?

ChrisRackauckas commented 3 years ago

That means your code is not ForwardDiff differentiable. You'll need to do Rodas4(autodiff=false) or KenCarp4(autodiff=false) to turn off automatic differentiation. See the FAQ for more details: https://diffeq.sciml.ai/stable/basics/faq/#Native-Julia-solvers-compatibility-with-autodifferentiation . Likely you're doing something like Array{Float64}(...) in your code, which of course will fail with this message.

anandijain commented 3 years ago

i suspect chris just enjoys the 1up...

hurricane007 commented 3 years ago

can you post the reproducer so i can mess around with it?

It's a simulation of a fixed bed reactor, so the whole code to make it work is too long so I didn't post it. If you are interested I can post it. But Christ's method helped. Actually, I got this problem quite a lot of times. This time it seems to be due to:

for ii = 1:nGrid
    # usg = FA/CA [mo/m²⋅s]/[mol/m³] = Finert/(C_tot - C_CO2 - C_NO)
    usg[ii, ii] = Finert/(C_tot - u[ii, 1])
end

That means your code is not ForwardDiff differentiable. You'll need to do Rodas4(autodiff=false) or KenCarp4(autodiff=false) to turn off automatic differentiation. See the FAQ for more details: https://diffeq.sciml.ai/stable/basics/faq/#Native-Julia-solvers-compatibility-with-autodifferentiation . Likely you're doing something like Array{Float64}(...) in your code, which of course will fail with this message.

Thanks Chris, this solved the problem.