Skip to content

Trivial (length 0 state) NonlinearLeastSquaresProblem always returns success #387

New issue

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

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

Already on GitHub? # to your account

Closed
ChrisRackauckas opened this issue Feb 28, 2024 · 2 comments · Fixed by SciML/DiffEqBase.jl#1015

Comments

@ChrisRackauckas
Copy link
Member

Here's a fun edge case:

using NonlinearSolve
function unsat(du,u,p)
    du[1] = 1
end
unsatprob = NonlinearLeastSquaresProblem(f, nothing)
sol = solve(unsatprob) # Success
@avik-pal
Copy link
Member

It is not even hitting NonlinearSolve for some reason. If we do:

julia> SciMLBase.__solve(unsatprob, GaussNewton())
ERROR: MethodError: no method matching __maybe_unaliased(::Nothing, ::Bool)

Closest candidates are:
  __maybe_unaliased(::NonlinearSolve.AbstractNonlinearSolveOperator, ::Bool)
   @ NonlinearSolve /mnt/research/ongoing/nlsolve/NonlinearSolve.jl/src/utils.jl:50
  __maybe_unaliased(::Union{Number, StaticArraysCore.SArray}, ::Bool)
   @ NonlinearSolve /mnt/research/ongoing/nlsolve/NonlinearSolve.jl/src/utils.jl:44
  __maybe_unaliased(::AbstractArray, ::Bool)
   @ NonlinearSolve /mnt/research/ongoing/nlsolve/NonlinearSolve.jl/src/utils.jl:45

Stacktrace:
  [1] __init(::NonlinearLeastSquaresProblem{…}, ::GeneralizedFirstOrderAlgorithm{…}; alias_u0::Bool, maxiters::Int64, abstol::Nothing, reltol::Nothing, maxtime::Nothing, termination_condition::Nothing, internalnorm::Function, linsolve_kwargs::@NamedTuple{}, kwargs::@Kwargs{})
    @ NonlinearSolve /mnt/research/ongoing/nlsolve/NonlinearSolve.jl/src/core/generalized_first_order.jl:152
  [2] __init(::NonlinearLeastSquaresProblem{Nothing, true, SciMLBase.NullParameters, NonlinearFunction{…}, @Kwargs{}}, ::GeneralizedFirstOrderAlgorithm{nothing, :GaussNewton, Missing, Missing, NewtonDescent{…}, Nothing, Nothing, Nothing})
    @ NonlinearSolve /mnt/research/ongoing/nlsolve/NonlinearSolve.jl/src/core/generalized_first_order.jl:144
  [3] init_call(_prob::NonlinearLeastSquaresProblem{…}, args::GeneralizedFirstOrderAlgorithm{…}; merge_callbacks::Bool, kwargshandle::Nothing, kwargs::@Kwargs{})
    @ DiffEqBase ~/.julia/packages/DiffEqBase/4084R/src/solve.jl:530
  [4] init_call(_prob::NonlinearLeastSquaresProblem{Nothing, true, SciMLBase.NullParameters, NonlinearFunction{…}, @Kwargs{}}, args::GeneralizedFirstOrderAlgorithm{nothing, :GaussNewton, Missing, Missing, NewtonDescent{…}, Nothing, Nothing, Nothing})
    @ DiffEqBase ~/.julia/packages/DiffEqBase/4084R/src/solve.jl:503
  [5] init_up(prob::NonlinearLeastSquaresProblem{…}, sensealg::Nothing, u0::Nothing, p::SciMLBase.NullParameters, args::GeneralizedFirstOrderAlgorithm{…}; kwargs::@Kwargs{})
    @ DiffEqBase ~/.julia/packages/DiffEqBase/4084R/src/solve.jl:556
  [6] init_up(prob::NonlinearLeastSquaresProblem{…}, sensealg::Nothing, u0::Nothing, p::SciMLBase.NullParameters, args::GeneralizedFirstOrderAlgorithm{…})
    @ DiffEqBase ~/.julia/packages/DiffEqBase/4084R/src/solve.jl:551
  [7] init(prob::NonlinearLeastSquaresProblem{…}, args::GeneralizedFirstOrderAlgorithm{…}; sensealg::Nothing, u0::Nothing, p::Nothing, kwargs::@Kwargs{})
    @ DiffEqBase ~/.julia/packages/DiffEqBase/4084R/src/solve.jl:544
  [8] init(prob::NonlinearLeastSquaresProblem{Nothing, true, SciMLBase.NullParameters, NonlinearFunction{…}, @Kwargs{}}, args::GeneralizedFirstOrderAlgorithm{nothing, :GaussNewton, Missing, Missing, NewtonDescent{…}, Nothing, Nothing, Nothing})
    @ DiffEqBase ~/.julia/packages/DiffEqBase/4084R/src/solve.jl:534
  [9] __solve(::NonlinearLeastSquaresProblem{Nothing, true, SciMLBase.NullParameters, NonlinearFunction{…}, @Kwargs{}}, ::GeneralizedFirstOrderAlgorithm{nothing, :GaussNewton, Missing, Missing, NewtonDescent{…}, Nothing, Nothing, Nothing}; kwargs::@Kwargs{})
    @ NonlinearSolve /mnt/research/ongoing/nlsolve/NonlinearSolve.jl/src/core/generic.jl:3
 [10] __solve(::NonlinearLeastSquaresProblem{Nothing, true, SciMLBase.NullParameters, NonlinearFunction{…}, @Kwargs{}}, ::GeneralizedFirstOrderAlgorithm{nothing, :GaussNewton, Missing, Missing, NewtonDescent{…}, Nothing, Nothing, Nothing})
    @ NonlinearSolve /mnt/research/ongoing/nlsolve/NonlinearSolve.jl/src/core/generic.jl:1
 [11] top-level scope
    @ REPL[14]:1
 [12] top-level scope
    @ ~/.julia/packages/Infiltrator/TNlCu/src/Infiltrator.jl:798
Some type information was truncated. Use `show(err)` to see complete types.

@ChrisRackauckas
Copy link
Member Author

It's hitting a short circuit here https://github.com/SciML/DiffEqBase.jl/blob/master/src/solve.jl#L682-L694, which made sense for NonlinearProblem since that would also need 0 equations, but now NonlinearLeastSquaresProblem we need to make sure it's satisfied.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants