Fix support for BigFloat u0#202
Conversation
Signed-off-by: ErikQQY <2283984853@qq.com>
Benchmark Results
Benchmark PlotsA plot of the benchmark results have been uploaded as an artifact to the workflow run for this PR. |
|
|
We should just use a LazyBufferCache then? |
Signed-off-by: ErikQQY <2283984853@qq.com>
|
Implemented a special diff cache for the BigFloat case, which may not be the best solution, and some improvement is still necessary, the BigFloat support for MIRK is working now!! |
|
I don't understand the need for |
We only build the BigFloat cache when the input |
|
SciML/PreallocationTools.jl#112 should be all you need? |
|
Hopefully this can close 🤞 and BVP needs to do nothing special. |
Signed-off-by: ErikQQY <2283984853@qq.com>
Signed-off-by: ErikQQY <2283984853@qq.com>
Signed-off-by: ErikQQY <2283984853@qq.com>
src/utils.jl
Outdated
| @inline function __fill_like(v, x, args...) | ||
| @inline function __similar(x, args...) | ||
| y = similar(x, args...) | ||
| eltype(y) <: BigFloat && fill!(y, BigFloat(0)) |
There was a problem hiding this comment.
is there a reason to not always fill with zeros?
There was a problem hiding this comment.
zeros is better, just change them all. While NonlinearSolve is doing the similar thing like specialize on bigfloat and do __similar things in SciML/NonlinearSolve.jl#438, maybe we can change to zeros everywhere in NonlinearSolve.jl as well?
There was a problem hiding this comment.
There was a problem hiding this comment.
Note this will also fix issues with non-fully defined functions. For example, if a user doesn't write to du[i], we should still converge now, while before you'd get something random. So a few bugs should be fixed, some bugs avoided, etc. Avoiding uninitialized memory is just a good idea all around and NonlinearSolve needs to do this change too.
Signed-off-by: ErikQQY <2283984853@qq.com>
Fix #43
Unblock #178
Possibly need SciML/PreallocationTools.jl#72
I think
get_tmpin PreallocationTools.jl doesn't support BigFloat and would causecannot reinterpret `BigFloat` as `ForwardDiff.Dual`, type `ForwardDiff.Dual` is not a bits typeerror, similar issue is SciML/PreallocationTools.jl#72@avik-pal
Full stacktrace
ERROR: ArgumentError: cannot reinterpret `BigFloat` as `ForwardDiff.Dual{ForwardDiff.Tag{BoundaryValueDiffEq.__Fix3{BoundaryValueDiffEq.var"#131#137"{SciMLBase.StandardBVProblem, BoundaryValueDiffEq.MIRKCache{true, BigFloat, Tuple{Int64}, BVPFunction{true, SciMLBase.FullSpecialize, false, typeof(simplependulum!), typeof(bc!), LinearAlgebra.UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT_OBSERVED), Nothing, Nothing, SymbolicIndexingInterface.SymbolCache{Nothing, Nothing, Nothing, Nothing, Dict{Any, Any}}}, typeof(bc!), BVProblem{Vector{BigFloat}, Tuple{Float64, Float64}, true, Nothing, SciMLBase.NullParameters, BVPFunction{true, SciMLBase.FullSpecialize, false, typeof(simplependulum!), typeof(bc!), LinearAlgebra.UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT_OBSERVED), Nothing, Nothing, SymbolicIndexingInterface.SymbolCache{Nothing, Nothing, Nothing, Nothing, Dict{Any, Any}}}, SciMLBase.StandardBVProblem, Base.Pairs{Symbol, Union{}, Tuple{}, @NamedTuple{}}}, SciMLBase.StandardBVProblem, SciMLBase.NullParameters, MIRK4{Nothing, BVPJacobianAlgorithm{AutoForwardDiff{nothing, Nothing}, AutoSparse{AutoForwardDiff{nothing, Nothing}, ADTypes.NoSparsityDetector, ADTypes.NoColoringAlgorithm}, AutoSparse{AutoForwardDiff{nothing, Nothing}, ADTypes.NoSparsityDetector, ADTypes.NoColoringAlgorithm}}, Float64}, BoundaryValueDiffEq.MIRKTableau{Int64, Vector{BigFloat}, Vector{BigFloat}, Vector{BigFloat}, Matrix{BigFloat}}, BoundaryValueDiffEq.MIRKInterpTableau{Int64, Vector{BigFloat}, Vector{BigFloat}, Vector{BigFloat}, BigFloat}, Vector{BigFloat}, Vector{Float64}, Vector{Float64}, Vector{PreallocationTools.DiffCache{Matrix{BigFloat}, Vector{BigFloat}}}, Vector{Matrix{BigFloat}}, Vector{PreallocationTools.DiffCache{Vector{BigFloat}, Vector{BigFloat}}}, Vector{Vector{BigFloat}}, Vector{PreallocationTools.DiffCache{Vector{BigFloat}, Vector{BigFloat}}}, PreallocationTools.DiffCache{Vector{BigFloat}, Vector{BigFloat}}, Vector{BigFloat}, Vector{Vector{BigFloat}}, Vector{Vector{BigFloat}}, Tuple{Int64}, @NamedTuple{abstol::Float64, dt::Float64, adaptive::Bool}}}, SciMLBase.NullParameters}, BigFloat}, BigFloat, 11}`, type `ForwardDiff.Dual{ForwardDiff.Tag{BoundaryValueDiffEq.__Fix3{BoundaryValueDiffEq.var"#131#137"{SciMLBase.StandardBVProblem, BoundaryValueDiffEq.MIRKCache{true, BigFloat, Tuple{Int64}, BVPFunction{true, SciMLBase.FullSpecialize, false, typeof(simplependulum!), typeof(bc!), LinearAlgebra.UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT_OBSERVED), Nothing, Nothing, SymbolicIndexingInterface.SymbolCache{Nothing, Nothing, Nothing, Nothing, Dict{Any, Any}}}, typeof(bc!), BVProblem{Vector{BigFloat}, Tuple{Float64, Float64}, true, Nothing, SciMLBase.NullParameters, BVPFunction{true, SciMLBase.FullSpecialize, false, typeof(simplependulum!), typeof(bc!), LinearAlgebra.UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT_OBSERVED), Nothing, Nothing, SymbolicIndexingInterface.SymbolCache{Nothing, Nothing, Nothing, Nothing, Dict{Any, Any}}}, SciMLBase.StandardBVProblem, Base.Pairs{Symbol, Union{}, Tuple{}, @NamedTuple{}}}, SciMLBase.StandardBVProblem, SciMLBase.NullParameters, MIRK4{Nothing, BVPJacobianAlgorithm{AutoForwardDiff{nothing, Nothing}, AutoSparse{AutoForwardDiff{nothing, Nothing}, ADTypes.NoSparsityDetector, ADTypes.NoColoringAlgorithm}, AutoSparse{AutoForwardDiff{nothing, Nothing}, ADTypes.NoSparsityDetector, ADTypes.NoColoringAlgorithm}}, Float64}, BoundaryValueDiffEq.MIRKTableau{Int64, Vector{BigFloat}, Vector{BigFloat}, Vector{BigFloat}, Matrix{BigFloat}}, BoundaryValueDiffEq.MIRKInterpTableau{Int64, Vector{BigFloat}, Vector{BigFloat}, Vector{BigFloat}, BigFloat}, Vector{BigFloat}, Vector{Float64}, Vector{Float64}, Vector{PreallocationTools.DiffCache{Matrix{BigFloat}, Vector{BigFloat}}}, Vector{Matrix{BigFloat}}, Vector{PreallocationTools.DiffCache{Vector{BigFloat}, Vector{BigFloat}}}, Vector{Vector{BigFloat}}, Vector{PreallocationTools.DiffCache{Vector{BigFloat}, Vector{BigFloat}}}, PreallocationTools.DiffCache{Vector{BigFloat}, Vector{BigFloat}}, Vector{BigFloat}, Vector{Vector{BigFloat}}, Vector{Vector{BigFloat}}, Tuple{Int64}, @NamedTuple{abstol::Float64, dt::Float64, adaptive::Bool}}}, SciMLBase.NullParameters}, BigFloat}, BigFloat, 11}` is not a bits type Stacktrace: [1] (::Base.var"#throwbits#333")(S::Type, T::Type, U::Type) @ Base .\reinterpretarray.jl:16 [2] reinterpret(::Type{ForwardDiff.Dual{ForwardDiff.Tag{…}, BigFloat, 11}}, a::SubArray{BigFloat, 1, Vector{BigFloat}, Tuple{UnitRange{…}}, true}) @ Base .\reinterpretarray.jl:62 [3] get_tmp(dc::PreallocationTools.DiffCache{Vector{BigFloat}, Vector{BigFloat}}, u::Vector{ForwardDiff.Dual{ForwardDiff.Tag{…}, BigFloat, 11}}) @ PreallocationTools D:\Julia\.julia\packages\PreallocationTools\vWjVk\src\PreallocationTools.jl:152 [4] (::BoundaryValueDiffEq.var"#3#4"{PreallocationTools.DiffCache{Vector{…}, Vector{…}}, Vector{ForwardDiff.Dual{…}}})() @ BoundaryValueDiffEq D:\SciML\BVP\bc\BoundaryValueDiffEq.jl\src\types.jl:169 [5] with_logstate(f::Function, logstate::Any) @ Base.CoreLogging .\logging.jl:515 [6] with_logger(f::Function, logger::Base.CoreLogging.NullLogger) @ Base.CoreLogging .\logging.jl:627 [7] get_tmp @ D:\SciML\BVP\bc\BoundaryValueDiffEq.jl\src\types.jl:168 [inlined] [8] _broadcast_getindex_evalf @ .\broadcast.jl:709 [inlined] [9] _broadcast_getindex @ .\broadcast.jl:682 [inlined] [10] getindex @ .\broadcast.jl:636 [inlined] [11] copy @ .\broadcast.jl:942 [inlined] [12] materialize @ .\broadcast.jl:903 [inlined]