OrdinaryDiffEq.jl icon indicating copy to clipboard operation
OrdinaryDiffEq.jl copied to clipboard

TerminalLogger Progress bar breaks for array of arrays

Open jlchan opened this issue 3 years ago • 2 comments

using OrdinaryDiffEq
using StaticArrays, StructArrays
using Logging: global_logger
using TerminalLoggers: TerminalLogger
global_logger(TerminalLogger())

u0 = VectorOfArray([ones(4),2*ones(4)]) # works for VectorOfArray
u0 = StructArray{SVector{2,Float64}}((ones(4),2*ones(4))) # does not work for StructArray array of arrays
function rhs!(du, u, p, t)
    du .= u
end

tspan = (0.,10.)
solve(ODEProblem(rhs!, u0, tspan), Euler(), dt = 0.5, save_everystep = false, 
                progress = true, progress_steps = 1)

The logging error I get when running with StructArrays is

┌ Error: Exception while generating log record in module OrdinaryDiffEq at
│ /Users/jessechan/.julia/packages/OrdinaryDiffEq/IOPED/src/integrators/integrator_utils.jl:225
│   exception =
│    MethodError: no method matching abs(::SVector{2, Float64})
...

Not sure if this is related to https://github.com/SciML/DiffEqBase.jl/issues/619, but has some similarities?

jlchan avatar May 17 '21 20:05 jlchan

The problem seems to be maximum(abs.(u)) in https://github.com/SciML/DiffEqBase.jl/blob/2daa81bfeb3df95c43469b96c058877a9cc240da/src/common_defaults.jl#L22. Maybe one should use ODE_DEFAULT_NORM or better the norm used by the integrator (which would have to be provided when calling progress_message)? Or some other recursive definition of abs?

devmotion avatar May 17 '21 20:05 devmotion

Yeah defaulting to the norm might be good. I threw that into the message because usually a good thing to track would be divergence, which the norm would also tell you, but the maximum would be best at telling you divergence.

ChrisRackauckas avatar May 17 '21 22:05 ChrisRackauckas