Closed daviehh closed 5 years ago
also, looks like NaN returned by the problem function is handled correctly, e.g. with
function f(du, u,p,t)
du = t>1 ? NaN : 0.1
end
It will be almost impossible to help you here without seeing any code. That said,
function f(du, u,p,t)
du = t>1 ? NaN : 0.1
end
Note that the code you wrote there doesn't do anything. du = ...
overrides the input, so no mutation occurs. Instead, you should be doing something like du[1] = ...
or du .= ...
.
But a bigger question.
ODE: around 500 coupled odes (written in complex-valued matrices), involves some random numbers. They are hierarchical equations, where higher orders are supposed to be close to zero. (unable to share full equation set for now, so this is just a general query)
Are you sure it's an ODE? If you have random numbers in your derivative function, it is not an ODE. It might be a stochastic differential equation or a random ordinary differential equation. If you are taking new random numbers each time f
is called, then the adaptive algorithm will sense that f
is not defined and will reject the step, and keep doing so until the simulation ends or it goes unstable. Problems with stochasticity should use the SDE or RODE solvers for this purpose, or use adaptive=false
to turn off adaptivity. But note that these methods are not guaranteed the same order of convergence when there's randomness anyways, whereas the SDE and RODE methods are made to converge (with higher order) in cases with randomness.
So anyways your issue is either because du
isn't actually updated since you're shadowing instead of mutating it, or it's because of taking random numbers in your derivative function.
Thanks! Sorry, that du =
is a typo, in my actual code I have things like du[1:n1] = ...
; the random number is generated and saved in p
, then passes on to f
(something like ODEProblem(f,u0,tspan,p)
) so f is not changed every time it's called (no explicit random numbers in f
). I'll look into using the SODE solvers, we are using a non-standard complex-valued noise process but it looks like there's a NoiseGrid
function in the package that allows one to use arbitrarily noise process. Thanks! closing the issue now.
ODE: around 500 coupled odes (written in complex-valued matrices), involves some random numbers. They are hierarchical equations, where higher orders are supposed to be close to zero. (unable to share full equation set for now, so this is just a general query)
[it is understood that the solver provided may fail for some problems; the main purpose of this issue is to discuss/report that some errors makes more logical sense for the ode solver to handle, rather than a NaN error reported by julia]
Solver: AutoVern8(Rosenbrock23()) or AutoTsit5(Rosenbrock23()), with autodiff=false (for complex numbers)
Problem encountered:
for problem function f(du, u,p,t), I got an error message that I'm accessing t=NaN. Turns out both t and u have become NaN, while du sometimes is NaN, sometimes is a very, very big number (20-digit or so?) while in reality it should be around 0~5.
on the other hand, when I manually convert the equation by splitting the complex into real and imaginary part, I normally get
while occasionally also getting the accessing t at NaN error message from julia, full message at the end. The warning message and
sol.retcode
being not:Success
is the "correct" behavior, while the t=NaN error comes from julia and seems to be not handle by the differential equation solver. Is there some checks in the solver to make sure that the timestep/final time does not go over tspan, or, handle NaN returned by the problem function (and return the error/warning as expected)? Thanks!full error message: