Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Shooting method fail when specified line search algorithm from LineSearches.jl for nonlinear solvers #210

Open
ErikQQY opened this issue Sep 9, 2024 · 0 comments
Labels

Comments

@ErikQQY
Copy link
Member

ErikQQY commented Sep 9, 2024

Describe the bug 🐞

Report from SciML/DiffEqBase.jl#1079, after further investigation, I found out that when using Shooting methods with NonlinearSolve.jl solvers NewtonRaphson(or other methods utilize line search) that specified line search algorithms from LineSearches.jl, this kind of error would occur, not sure whether it's an error from BoundaryValueDiffEq.jl or NonlinearSolve.jl, since changing to native line search algorithms or other nonlinear solvers would fix this kind error.

Expected behavior

A clear and concise description of what you expected to happen.

Minimal Reproducible Example 👇

Without MRE, we would only be able to help you to a limited extent, and attention to the issue would be limited. to know more about MRE refer to wikipedia and stackoverflow.

tspan = (0.0, pi / 2)
function simplependulum!(du, u, p, t)
    θ = u[1]
    dθ = u[2]
    du[1] = dθ
    du[2] = -9.81 * sin(θ)
end
function bc!(residual, u, p, t)
    residual[1] = u[:, end ÷ 2][1] + pi / 2
    residual[2] = u[:, end][1] - pi / 2
end
prob = BVProblem(simplependulum!, bc!, [pi / 2, pi / 2], tspan)
sol = solve(prob, Shooting(Tsit5(), NewtonRaphson(; linesearch = BackTracking())))

Error & Stacktrace ⚠️

ERROR: MethodError: no method matching Float64(::ForwardDiff.Dual{ForwardDiff.Tag{SciMLBase.JacobianWrapper{true, NonlinearFunction{}, SciMLBase.NullParameters}, Float64}, Float64, 1})

Closest candidates are:
  (::Type{T})(::Real, ::RoundingMode) where T<:AbstractFloat
   @ Base rounding.jl:207
  (::Type{T})(::T) where T<:Number
   @ Core boot.jl:792
  Float64(::IrrationalConstants.Sqrt2)
   @ IrrationalConstants D:\Julia\.julia\packages\IrrationalConstants\vp5v4\src\macro.jl:112
  ...

Stacktrace:
  [1] convert(::Type{Float64}, x::ForwardDiff.Dual{ForwardDiff.Tag{SciMLBase.JacobianWrapper{…}, Float64}, Float64, 1})
    @ Base .\number.jl:7
  [2] setindex!(A::Vector{Float64}, x::ForwardDiff.Dual{ForwardDiff.Tag{SciMLBase.JacobianWrapper{…}, Float64}, Float64, 1}, i1::Int64)
    @ Base .\array.jl:1021
  [3] _unsafe_copyto!(dest::Vector{Float64}, doffs::Int64, src::Vector{ForwardDiff.Dual{ForwardDiff.Tag{…}, Float64, 1}}, soffs::Int64, n::Int64)
    @ Base .\array.jl:299
  [4] unsafe_copyto!
    @ .\array.jl:353 [inlined]
  [5] _copyto_impl!
    @ .\array.jl:376 [inlined]
  [6] copyto!
    @ .\array.jl:363 [inlined]
  [7] copyto!
    @ .\array.jl:385 [inlined]
  [8] recursivecopy!
    @ D:\Julia\.julia\packages\RecursiveArrayTools\xGKIm\src\utils.jl:62 [inlined]
  [9] reinit!(integrator::OrdinaryDiffEqCore.ODEIntegrator{…}, u0::Vector{…}; t0::Float64, tf::Float64, erase_sol::Bool, tstops::Tuple{}, saveat::Tuple{}, d_discontinuities::Tuple{}, reset_dt::Bool, reinit_callbacks::Bool, initialize_save::Bool, reinit_cache::Bool, reinit_retcode::Bool)
    @ OrdinaryDiffEqCore D:\Julia\.julia\packages\OrdinaryDiffEqCore\hCoet\src\integrators\integrator_interface.jl:334
 [10] reinit!
    @ D:\Julia\.julia\packages\OrdinaryDiffEqCore\hCoet\src\integrators\integrator_interface.jl:321 [inlined]
 [11] __single_shooting_loss!(resid_::Vector{…}, u0_::Vector{…}, p::SciMLBase.NullParameters, cache::OrdinaryDiffEqCore.ODEIntegrator{…}, bc::typeof(bc!), u0_size::Tuple{…}, pt::SciMLBase.StandardBVProblem, resid_size::Tuple{…})
    @ BoundaryValueDiffEq D:\SciML\BVP\Fix_Shooting\BoundaryValueDiffEq.jl\src\solve\single_shooting.jl:107
 [12] #106
    @ D:\SciML\BVP\Fix_Shooting\BoundaryValueDiffEq.jl\src\solve\single_shooting.jl:30 [inlined]
 [13] NonlinearFunction
    @ D:\Julia\.julia\packages\SciMLBase\jU6iu\src\scimlfunctions.jl:2336 [inlined]
 [14] JacobianWrapper
    @ D:\Julia\.julia\packages\SciMLBase\jU6iu\src\function_wrappers.jl:108 [inlined]
 [15] auto_jacvec!(dy::Vector{…}, f::SciMLBase.JacobianWrapper{…}, x::Vector{…}, v::Vector{…}, cache1::Vector{…}, cache2::Vector{…})
    @ SparseDiffTools D:\Julia\.julia\packages\SparseDiffTools\jpC2n\src\differentiation\jaches_products.jl:17
 [16] #90
    @ D:\Julia\.julia\packages\NonlinearSolve\sETeN\src\internal\operators.jl:112 [inlined]
 [17] JacobianOperator
    @ D:\Julia\.julia\packages\NonlinearSolve\sETeN\src\internal\operators.jl:196 [inlined]
 [18] (::NonlinearSolve.var"#157#169"{})(du::Vector{…}, u::Vector{…}, fu::Vector{…}, p::SciMLBase.NullParameters)
    @ NonlinearSolve D:\Julia\.julia\packages\NonlinearSolve\sETeN\src\globalization\line_search.jl:163
 [19] (::NonlinearSolve.var"#161#173"{})(f::Function, p::SciMLBase.NullParameters, u::Vector{…}, du::Vector{…}, α::Float64, u_cache::Vector{…}, fu_cache::Vector{…}, deriv_op::NonlinearSolve.var"#157#169"{})
    @ NonlinearSolve D:\Julia\.julia\packages\NonlinearSolve\sETeN\src\globalization\line_search.jl:191
 [20] #177
    @ D:\Julia\.julia\packages\NonlinearSolve\sETeN\src\globalization\line_search.jl:205 [inlined]
 [21] #__internal_solve!#174
    @ D:\Julia\.julia\packages\NonlinearSolve\sETeN\src\globalization\line_search.jl:212 [inlined]
 [22] __internal_solve!
    @ D:\Julia\.julia\packages\NonlinearSolve\sETeN\src\globalization\line_search.jl:200 [inlined]
 [23] __step!(cache::NonlinearSolve.ApproximateJacobianSolveCache{…}; recompute_jacobian::Nothing)
    @ NonlinearSolve D:\Julia\.julia\packages\NonlinearSolve\sETeN\src\core\approximate_jacobian.jl:320
 [24] __step!
    @ D:\Julia\.julia\packages\NonlinearSolve\sETeN\src\core\approximate_jacobian.jl:222 [inlined]
 [25] #step!#218
    @ D:\Julia\.julia\packages\NonlinearSolve\sETeN\src\core\generic.jl:50 [inlined]
 [26] step!
    @ D:\Julia\.julia\packages\NonlinearSolve\sETeN\src\core\generic.jl:45 [inlined]
 [27] solve!(cache::NonlinearSolve.ApproximateJacobianSolveCache{…})
    @ NonlinearSolve D:\Julia\.julia\packages\NonlinearSolve\sETeN\src\core\generic.jl:13
 [28] #__solve#217
    @ D:\Julia\.julia\packages\NonlinearSolve\sETeN\src\core\generic.jl:4 [inlined]
 [29] __solve(prob::BVProblem{…}, alg_::Shooting{…}; odesolve_kwargs::@NamedTuple{}, nlsolve_kwargs::@NamedTuple{}, verbose::Bool, kwargs::@Kwargs{})
    @ BoundaryValueDiffEq D:\SciML\BVP\Fix_Shooting\BoundaryValueDiffEq.jl\src\solve\single_shooting.jl:77
 [30] __solve
    @ D:\SciML\BVP\Fix_Shooting\BoundaryValueDiffEq.jl\src\solve\single_shooting.jl:1 [inlined]
 [31] #solve_call#44
    @ D:\Julia\.julia\packages\DiffEqBase\slKc5\src\solve.jl:612 [inlined]
 [32] solve_call
    @ D:\Julia\.julia\packages\DiffEqBase\slKc5\src\solve.jl:569 [inlined]
 [33] #solve_up#53
    @ D:\Julia\.julia\packages\DiffEqBase\slKc5\src\solve.jl:1080 [inlined]
 [34] solve_up
    @ D:\Julia\.julia\packages\DiffEqBase\slKc5\src\solve.jl:1066 [inlined]
 [35] solve(prob::BVProblem{…}, args::Shooting{…}; sensealg::Nothing, u0::Nothing, p::Nothing, wrap::Val{…}, kwargs::@Kwargs{})
    @ DiffEqBase D:\Julia\.julia\packages\DiffEqBase\slKc5\src\solve.jl:1003
 [36] solve(prob::BVProblem{…}, args::Shooting{…})
    @ DiffEqBase D:\Julia\.julia\packages\DiffEqBase\slKc5\src\solve.jl:993
 [37] top-level scope
    @ REPL[59]:1
Some type information was truncated. Use `show(err)` to see complete types.

Environment (please complete the following information):

  • Output of using Pkg; Pkg.status()
  [47edcb42] ADTypes v1.7.1
  [79e6a3ab] Adapt v4.0.4
  [4fba245c] ArrayInterface v7.16.0
  [aae01518] BandedMatrices v1.7.4
  [2569d6c7] ConcreteStructs v0.2.3
  [2b5f629d] DiffEqBase v6.155.0
  [9d29842c] FastAlmostBandedMatrices v0.1.3
  [9aa1b823] FastClosures v0.3.2
  [f6369f11] ForwardDiff v0.10.36
  [7ed4a6bd] LinearSolve v2.34.0
  [8913a72c] NonlinearSolve v3.14.0
  [1dea7af3] OrdinaryDiffEq v6.89.0
  [d236fae5] PreallocationTools v0.4.24
  [aea7be01] PrecompileTools v1.2.1
  [21216c6a] Preferences v1.4.3
  [731186ca] RecursiveArrayTools v3.27.0
  [189a3867] Reexport v1.2.2
  [0bca4576] SciMLBase v2.52.2
  [efcf1570] Setfield v1.1.1
  [47a9eef4] SparseDiffTools v2.20.0
  [37e2e46d] LinearAlgebra
  [56ddb016] Logging
  [2f01184e] SparseArrays v1.10.0
  • Output of versioninfo()
Julia Version 1.10.4
Commit 48d4fd4843 (2024-06-04 10:41 UTC)
Build Info:
  Official https://julialang.org/ release
Platform Info:
  OS: Windows (x86_64-w64-mingw32)
  CPU: 8 × Intel(R) Core(TM) i5-10210U CPU @ 1.60GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-15.0.7 (ORCJIT, skylake)

Additional context

Add any other context about the problem here.

@ErikQQY ErikQQY added the bug label Sep 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant