Skip to content

Commit

Permalink
Add a note on the first value
Browse files Browse the repository at this point in the history
  • Loading branch information
avik-pal committed Nov 23, 2023
1 parent 354e080 commit 1a91191
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 9 deletions.
5 changes: 5 additions & 0 deletions docs/src/basics/Logging.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ sol = solve(prob; trace_level = TraceAll(), store_trace = Val(true));
sol.trace
```

!!! note

For `iteration == 0` only the `norm(fu, Inf)` is guaranteed to be meaningful. The other
values being meaningful are solver dependent.

## API

```@docs
Expand Down
2 changes: 1 addition & 1 deletion src/gaussnewton.jl
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ function SciMLBase.__init(prob::NonlinearLeastSquaresProblem{uType, iip}, alg_::
abstol, reltol, tc_cache_1 = init_termination_cache(abstol, reltol, fu1, u,
termination_condition)
_, _, tc_cache_2 = init_termination_cache(abstol, reltol, fu1, u, termination_condition)
trace = init_nonlinearsolve_trace(alg, u, fu1, J, du; kwargs...)
trace = init_nonlinearsolve_trace(alg, u, fu1, apply(zero, J), du; kwargs...)

return GaussNewtonCache{iip}(f, alg, u, copy(u), fu1, fu2, zero(fu1), du, p, uf,
linsolve, J, JᵀJ, Jᵀf, jac_cache, false, maxiters, internalnorm, ReturnCode.Default,
Expand Down
2 changes: 1 addition & 1 deletion src/levenberg.jl
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ function SciMLBase.__init(prob::Union{NonlinearProblem{uType, iip},
tc_cache_2 = nothing
end

trace = init_nonlinearsolve_trace(alg, u, fu1, J, du; kwargs...)
trace = init_nonlinearsolve_trace(alg, u, fu1, apply(zero, J), du; kwargs...)

if _unwrap_val(linsolve_with_JᵀJ)
mat_tmp = zero(JᵀJ)
Expand Down
2 changes: 1 addition & 1 deletion src/pseudotransient.jl
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ function SciMLBase.__init(prob::NonlinearProblem{uType, iip}, alg_::PseudoTransi

abstol, reltol, tc_cache = init_termination_cache(abstol, reltol, fu1, u,
termination_condition)
trace = init_nonlinearsolve_trace(alg, u, fu1, J, du; kwargs...)
trace = init_nonlinearsolve_trace(alg, u, fu1, apply(zero, J), du; kwargs...)

return PseudoTransientCache{iip}(f, alg, u, copy(u), fu1, fu2, du, p, alpha, res_norm,
uf, linsolve, J, jac_cache, false, maxiters, internalnorm, ReturnCode.Default,
Expand Down
2 changes: 1 addition & 1 deletion src/raphson.jl
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ function SciMLBase.__init(prob::NonlinearProblem{uType, iip}, alg_::NewtonRaphso
termination_condition)

ls_cache = init_linesearch_cache(alg.linesearch, f, u, p, fu1, Val(iip))
trace = init_nonlinearsolve_trace(alg, u, fu1, J, du; kwargs...)
trace = init_nonlinearsolve_trace(alg, u, fu1, apply(zero, J), du; kwargs...)

return NewtonRaphsonCache{iip}(f, alg, u, copy(u), fu1, fu2, du, p, uf, linsolve, J,
jac_cache, false, maxiters, internalnorm, ReturnCode.Default, abstol, reltol, prob,
Expand Down
8 changes: 4 additions & 4 deletions src/trace.jl
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,8 @@ function update_trace!(trace::NonlinearSolveTrace{ShT, StT}, iter, u, fu, J, δu
return trace
end

show_now = ShT && (iter % trace.trace_level.print_frequency == 0)
store_now = StT && (iter % trace.trace_level.store_frequency == 0)
show_now = ShT && (iter % trace.trace_level.print_frequency == 1)
store_now = StT && (iter % trace.trace_level.store_frequency == 1)
(show_now || store_now) && (entry = __trace_entry(trace.trace_level, iter, u, fu, J,
δu, α))
store_now && push!(trace.history, entry)
Expand All @@ -226,8 +226,8 @@ function update_trace_with_invJ!(trace::NonlinearSolveTrace{ShT, StT}, iter, u,
return trace
end

show_now = ShT && (iter % trace.trace_level.print_frequency == 0)
store_now = StT && (iter % trace.trace_level.store_frequency == 0)
show_now = ShT && (iter % trace.trace_level.print_frequency == 1)
store_now = StT && (iter % trace.trace_level.store_frequency == 1)
if show_now || store_now
J_ = trace.trace_level isa TraceMinimal ? J : inv(J)
entry = __trace_entry(trace.trace_level, iter, u, fu, J_, δu, α)
Expand Down
2 changes: 1 addition & 1 deletion src/trustRegion.jl
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ function SciMLBase.__init(prob::NonlinearProblem{uType, iip}, alg_::TrustRegion,

abstol, reltol, tc_cache = init_termination_cache(abstol, reltol, fu1, u,
termination_condition)
trace = init_nonlinearsolve_trace(alg, u, fu1, J, du; kwargs...)
trace = init_nonlinearsolve_trace(alg, u, fu1, apply(zero, J), du; kwargs...)

return TrustRegionCache{iip}(f, alg, u_prev, u, fu_prev, fu1, fu2, p, uf, linsolve, J,
jac_cache, false, maxiters, internalnorm, ReturnCode.Default, abstol, reltol, prob,
Expand Down

0 comments on commit 1a91191

Please sign in to comment.