Skip to content

fix: initial objective for termination conditions #579

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

Merged
merged 3 commits into from
Apr 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -104,14 +104,14 @@ NonlinearSolveSpectralMethods = "1.1"
OrdinaryDiffEqTsit5 = "1.1.0"
PETSc = "0.3"
Pkg = "1.10"
PolyesterForwardDiff = "0.1"
PolyesterForwardDiff = "0.1.3"
PrecompileTools = "1.2"
Preferences = "1.4"
Random = "1.10"
ReTestItems = "1.24"
Reexport = "1.2"
SIAMFANLEquations = "1.0.1"
SciMLBase = "2.58"
SciMLBase = "2.68.1"
SimpleNonlinearSolve = "2.1"
SparseArrays = "1.10"
SparseConnectivityTracer = "0.6.5"
Expand All @@ -121,7 +121,7 @@ StableRNGs = "1"
StaticArrays = "1.9"
StaticArraysCore = "1.4"
Sundials = "4.23.1"
SymbolicIndexingInterface = "0.3.31"
SymbolicIndexingInterface = "0.3.36"
Test = "1.10"
Zygote = "0.6.69, 0.7"
julia = "1.10"
Expand Down
2 changes: 1 addition & 1 deletion docs/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ OrdinaryDiffEqTsit5 = "1.1.0"
PETSc = "0.3"
Plots = "1"
Random = "1.10"
SciMLBase = "2.58"
SciMLBase = "2.68.1"
SciMLJacobianOperators = "0.1"
SimpleNonlinearSolve = "2"
SparseConnectivityTracer = "0.6.5"
Expand Down
2 changes: 1 addition & 1 deletion lib/BracketingNonlinearSolve/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ InteractiveUtils = "<0.0.1, 1"
NonlinearSolveBase = "1.1"
PrecompileTools = "1.2"
Reexport = "1.2"
SciMLBase = "2.58"
SciMLBase = "2.68.1"
Test = "1.10"
TestItemRunner = "1"
julia = "1.10"
Expand Down
6 changes: 3 additions & 3 deletions lib/NonlinearSolveBase/Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "NonlinearSolveBase"
uuid = "be0214bd-f91f-a760-ac4e-3421ce2b2da0"
authors = ["Avik Pal <avikpal@mit.edu> and contributors"]
version = "1.5.2"
version = "1.5.3"

[deps]
ADTypes = "47edcb42-4c32-4615-8424-f2b9edc5f35b"
Expand Down Expand Up @@ -70,11 +70,11 @@ Printf = "1.10"
RecursiveArrayTools = "3"
SciMLBase = "2.68.1"
SciMLJacobianOperators = "0.1.1"
SciMLOperators = "0.3.10"
SciMLOperators = "0.3.13"
SparseArrays = "1.10"
SparseMatrixColorings = "0.4.5"
StaticArraysCore = "1.4"
SymbolicIndexingInterface = "0.3.31"
SymbolicIndexingInterface = "0.3.36"
Test = "1.10"
TimerOutputs = "0.5.23"
julia = "1.10"
Expand Down
12 changes: 6 additions & 6 deletions lib/NonlinearSolveBase/src/termination_conditions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@ function CommonSolve.init(

if mode isa AbstractSafeNonlinearTerminationMode
if mode isa AbsNormSafeTerminationMode || mode isa AbsNormSafeBestTerminationMode
initial_objective = Linf_NORM(du)
initial_objective = Utils.apply_norm(mode.internalnorm, du)
u0_norm = nothing
else
initial_objective = Linf_NORM(du) /
(Utils.nonallocating_maximum(+, du, u) + eps(TT))
initial_objective = Utils.apply_norm(mode.internalnorm, du) /
(Utils.apply_norm(mode.internalnorm, du, u) + eps(reltol))
u0_norm = mode.max_stalled_steps === nothing ? nothing : L2_NORM(u)
end
objectives_trace = Vector{TT}(undef, mode.patience_steps)
Expand Down Expand Up @@ -107,10 +107,10 @@ function SciMLBase.reinit!(

if mode isa AbstractSafeNonlinearTerminationMode
if mode isa AbsNormSafeTerminationMode || mode isa AbsNormSafeBestTerminationMode
cache.initial_objective = Linf_NORM(du)
cache.initial_objective = Utils.apply_norm(mode.internalnorm, du)
else
cache.initial_objective = Linf_NORM(du) /
(Utils.nonallocating_maximum(+, du, u) + eps(TT))
cache.initial_objective = Utils.apply_norm(mode.internalnorm, du) /
(Utils.apply_norm(mode.internalnorm, du, u) + eps(TT))
cache.max_stalled_steps !== nothing && (cache.u0_norm = L2_NORM(u))
end
cache.best_objective_value = cache.initial_objective
Expand Down
2 changes: 1 addition & 1 deletion lib/NonlinearSolveFirstOrder/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ PrecompileTools = "1.2"
Random = "1.10"
ReTestItems = "1.24"
Reexport = "1"
SciMLBase = "2.58"
SciMLBase = "2.68.1"
SciMLJacobianOperators = "0.1.0"
Setfield = "1.1.1"
SparseArrays = "1.10"
Expand Down
4 changes: 2 additions & 2 deletions lib/NonlinearSolveQuasiNewton/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ Pkg = "1.10"
PrecompileTools = "1.2"
ReTestItems = "1.24"
Reexport = "1"
SciMLBase = "2.58"
SciMLOperators = "0.3.11"
SciMLBase = "2.68.1"
SciMLOperators = "0.3.13"
StableRNGs = "1"
StaticArrays = "1.9.8"
StaticArraysCore = "1.4.3"
Expand Down
2 changes: 1 addition & 1 deletion lib/NonlinearSolveSpectralMethods/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ Pkg = "1.10"
PrecompileTools = "1.2"
ReTestItems = "1.24"
Reexport = "1"
SciMLBase = "2.58"
SciMLBase = "2.68.1"
StableRNGs = "1"
StaticArrays = "1.9.8"
Test = "1.10"
Expand Down
4 changes: 2 additions & 2 deletions lib/SCCNonlinearSolve/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ Pkg = "1.10"
PrecompileTools = "1.2"
ReTestItems = "1.24"
Reexport = "1"
SciMLBase = "2.60"
SciMLBase = "2.68.1"
StableRNGs = "1"
StaticArrays = "1.9.8"
SymbolicIndexingInterface = "0.3.30"
SymbolicIndexingInterface = "0.3.36"
Test = "1.10"
julia = "1.10"

Expand Down
4 changes: 2 additions & 2 deletions lib/SciMLJacobianOperators/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ ForwardDiff = "0.10.36, 1"
InteractiveUtils = "<0.0.1, 1"
LinearAlgebra = "1.10"
ReverseDiff = "1.15"
SciMLBase = "2.58"
SciMLOperators = "0.3"
SciMLBase = "2.68.1"
SciMLOperators = "0.3.13"
Test = "1.10"
TestItemRunner = "1"
Tracker = "0.2.35"
Expand Down
4 changes: 2 additions & 2 deletions lib/SimpleNonlinearSolve/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,12 @@ MaybeInplace = "0.1.4"
NonlinearProblemLibrary = "0.1.2"
NonlinearSolveBase = "1.4"
Pkg = "1.10"
PolyesterForwardDiff = "0.1"
PolyesterForwardDiff = "0.1.3"
PrecompileTools = "1.2"
Random = "1.10"
Reexport = "1.2"
ReverseDiff = "1.15"
SciMLBase = "2.58"
SciMLBase = "2.68.1"
Setfield = "1.1.1"
StaticArrays = "1.9"
StaticArraysCore = "1.4.3"
Expand Down
20 changes: 20 additions & 0 deletions test/issue_tests.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
@testitem "Correct Best Solution: #565" tags=[:core] begin
using NonlinearSolve, StableRNGs

x = collect(0:0.1:10)

line_fct(x, p) = p[1] .+ p[2] .* x

y_line = line_fct(x, [1, 3])
y_line_n = line_fct(x, [1, 3]) + randn(StableRNG(0), length(x))

res(β, (x, y)) = line_fct(x, β) .- y

prob = NonlinearLeastSquaresProblem(res, [1, 3], p = (x, y_line_n))
sol1 = solve(prob; maxiters = 1000)

prob = NonlinearLeastSquaresProblem(res, [1, 5], p = (x, y_line_n))
sol2 = solve(prob; maxiters = 1000)

@test sol1.u ≈ sol2.u
end
Loading