SciML / DiffEqBase.jl

The lightweight Base library for shared types and functionality for defining differential equation and scientific machine learning (SciML) problems
Other
302 stars 106 forks source link

fix: fallback to empty vector when resid_prototype is nothing for NonlinearLeastSquaresProblem #1026

Closed sathvikbhagavan closed 2 months ago

sathvikbhagavan commented 2 months ago

Found this coming from NonlinearSystems where structural_simplify reduces the equations to 0, hence u0 becomes nothing and resid_prototype becomes nothing.

MWE:

@variables u1
@parameters k=1.0 r=1.0 u2=1.0
eq = [0 ~ -u2 + (k - u1)/r]
@named n = NonlinearSystem(eq, [u1], [u2, k, r])
sys = structural_simplify(n)
np = NonlinearLeastSquaresProblem(sys, [], [u2 => 1.0, k => 1.0, r => 1.0])
sol = solve(np)
sol[u1]