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

solve fails when passed vectorial tolerances. #525

Open
lte678 opened this issue Jan 13, 2025 · 1 comment
Open

solve fails when passed vectorial tolerances. #525

lte678 opened this issue Jan 13, 2025 · 1 comment
Labels
enhancement New feature or request

Comments

@lte678
Copy link

lte678 commented Jan 13, 2025

Description

solve fails when called on nonlinear systems of equations with vectorial tolerances.
This is for both reltol and abstol.

Since NonlinearSolve is used internally to solve inconsistent DAE initializations in DifferentialEquations.jl, this causes crashes when solving DAEs with a vector supplied for reltol (in fact, this happens for vector-valued abstol as well, if SciML/OrdinaryDiffEq.jl#1214 has been patched out). I think this is a good motivation to consider this a bug either in NonlinearSolve or OrdinaryDiffEqNonlinearSolve.

Reproducable Test

using NonlinearSolve, StaticArrays

f(u, p) = u .* u .- 2
u0 = @SVector[1.0, 1.0]
solver = solve(NonlinearProblem(f, u0), reltol=[1e-3, 1e-4])

Stacktrace

ERROR: MethodError: no method matching Float64(::Vector{Float64})
The type `Float64` exists, but no method is defined for this combination of argument types when trying to construct it.

Closest candidates are:
  Float64(::IrrationalConstants.Halfπ)
   @ IrrationalConstants ~/.julia/packages/IrrationalConstants/vp5v4/src/macro.jl:112
  Float64(::IrrationalConstants.Twoinvπ)
   @ IrrationalConstants ~/.julia/packages/IrrationalConstants/vp5v4/src/macro.jl:112
  Float64(::IrrationalConstants.Inv2π)
   @ IrrationalConstants ~/.julia/packages/IrrationalConstants/vp5v4/src/macro.jl:112
  ...

Stacktrace:
  [1] convert_real(::Type{Float64}, x::Vector{Float64})
    @ NonlinearSolveBase.Utils ~/.julia/packages/NonlinearSolveBase/Kek5u/src/utils.jl:91
  [2] get_tolerance::Vector{Float64}, ::Type{Float64})
    @ NonlinearSolveBase ~/.julia/packages/NonlinearSolveBase/Kek5u/src/common_defaults.jl:37
  [3] get_tolerance(::SVector{2, Float64}, η::Vector{Float64}, ::Type{Float64})
    @ NonlinearSolveBase ~/.julia/packages/NonlinearSolveBase/Kek5u/src/common_defaults.jl:43
  [4] init_termination_cache(prob::NonlinearProblem{…}, abstol::Nothing, reltol::Vector{…}, du::SVector{…}, u::SVector{…}, tc::AbsNormSafeBestTerminationMode{…}, ::Val{…})
    @ NonlinearSolveBase ~/.julia/packages/NonlinearSolveBase/Kek5u/src/termination_conditions.jl:295
  [5] init_termination_cache(prob::NonlinearProblem{…}, abstol::Nothing, reltol::Vector{…}, du::SVector{…}, u::SVector{…}, ::Nothing, callee::Val{…})
    @ NonlinearSolveBase ~/.julia/packages/NonlinearSolveBase/Kek5u/src/termination_conditions.jl:286
  [6] __init(::NonlinearProblem{…}, ::GeneralizedFirstOrderAlgorithm{…}; stats::SciMLBase.NLStats, alias_u0::Bool, maxiters::Int64, abstol::Nothing, reltol::Vector{…}, maxtime::Nothing, termination_condition::Nothing, internalnorm::Function, linsolve_kwargs::@NamedTuple{}, initializealg::NonlinearSolveBase.NonlinearSolveDefaultInit, kwargs::@Kwargs{})
    @ NonlinearSolveFirstOrder ~/.julia/packages/NonlinearSolveFirstOrder/3kzAL/src/solve.jl:156
  [7] __solve(::NonlinearProblem{…}, ::GeneralizedFirstOrderAlgorithm{…}; kwargs::@Kwargs{})
    @ NonlinearSolveBase ~/.julia/packages/NonlinearSolveBase/Kek5u/src/solve.jl:5
  [8] macro expansion
    @ ~/.julia/packages/NonlinearSolveBase/Kek5u/src/solve.jl:173 [inlined]
  [9] __generated_polysolve(::NonlinearProblem{…}, ::NonlinearSolvePolyAlgorithm{…}; stats::SciMLBase.NLStats, alias_u0::Bool, verbose::Bool, initializealg::NonlinearSolveBase.NonlinearSolveDefaultInit, kwargs::@Kwargs{})
    @ NonlinearSolveBase ~/.julia/packages/NonlinearSolveBase/Kek5u/src/solve.jl:130
 [10] __generated_polysolve
    @ ~/.julia/packages/NonlinearSolveBase/Kek5u/src/solve.jl:130 [inlined]
 [11] #__solve#154
    @ ~/.julia/packages/NonlinearSolveBase/Kek5u/src/solve.jl:127 [inlined]
 [12] __solve
    @ ~/.julia/packages/NonlinearSolveBase/Kek5u/src/solve.jl:124 [inlined]
 [13] #__solve#18
    @ ~/.julia/packages/NonlinearSolve/IChU2/src/default.jl:27 [inlined]
 [14] __solve
    @ ~/.julia/packages/NonlinearSolve/IChU2/src/default.jl:24 [inlined]
 [15] #__solve#72
    @ ~/.julia/packages/DiffEqBase/R2Vjs/src/solve.jl:1438 [inlined]
 [16] __solve
    @ ~/.julia/packages/DiffEqBase/R2Vjs/src/solve.jl:1429 [inlined]
 [17] #solve_call#44
    @ ~/.julia/packages/DiffEqBase/R2Vjs/src/solve.jl:634 [inlined]
 [18] solve_call
    @ ~/.julia/packages/DiffEqBase/R2Vjs/src/solve.jl:591 [inlined]
 [19] #solve_up#53
    @ ~/.julia/packages/DiffEqBase/R2Vjs/src/solve.jl:1107 [inlined]
 [20] solve_up
    @ ~/.julia/packages/DiffEqBase/R2Vjs/src/solve.jl:1101 [inlined]
 [21] #solve#52
    @ ~/.julia/packages/DiffEqBase/R2Vjs/src/solve.jl:1095 [inlined]
 [22] top-level scope
    @ ~/Projects/scratchpad/dae_vector_init_bug/nonlinear_solve.jl:5
Some type information was truncated. Use `show(err)` to see complete type

Environment

  • Julia Version 1.11.2
  • NonlinearSolve v4.3.0
@lte678 lte678 added the bug Something isn't working label Jan 13, 2025
@avik-pal
Copy link
Member

This is currently not supported. But should be easy to do with a patch in NonlinearSolveBase

@avik-pal avik-pal added enhancement New feature or request and removed bug Something isn't working labels Jan 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants