-
-
Notifications
You must be signed in to change notification settings - Fork 58
Eisenstat-Walker Newton-Krylov solver #738
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
Draft
termi-official
wants to merge
16
commits into
SciML:master
Choose a base branch
from
termi-official:do/eisenstat-walker
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
ef8c58f
Eisenstat-Walker Newton-Krylov solver
termi-official 8cbe2be
Missing default
termi-official 8d0f0c4
Fix typos
termi-official c5e8aee
Add missing dispatch
termi-official e315dce
Add verbosity
termi-official 6e0861a
Add maximum eta to params.
termi-official 251f8cc
More parameters
termi-official adc159e
Lower initial eta
termi-official 9770292
Derp
termi-official 910d1cd
Derp again
termi-official a2f3071
Debug instability
termi-official 3ddabe5
Verbosity
termi-official 5d026f7
Export forcing
termi-official 5aef765
Bump LinearSolve to reflect that the new API is used
termi-official 1ff888f
Remove export of helper constructor
termi-official 06d1d1a
Docstring for forcing alg
termi-official File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,111 @@ | ||
| """ | ||
| EisenstatWalkerForcing2(; η₀ = 0.5, ηₘₐₓ = 0.9, γ = 0.9, α = 2, safeguard = true, safeguard_threshold = 0.1) | ||
|
|
||
| Algorithm 2 from the classical work by Eisenstat and Walker (1996) as described by formula (2.6): | ||
| ηₖ = γ * (||rₖ|| / ||rₖ₋₁||)^α | ||
|
|
||
| Here the variables denote: | ||
| rₖ residual at iteration k | ||
| η₀ ∈ [0,1) initial value for η | ||
| ηₘₐₓ ∈ [0,1) maximum value for η | ||
| γ ∈ [0,1) correction factor | ||
| α ∈ [1,2) correction exponent | ||
|
|
||
| Furthermore, the proposed safeguard is implemented: | ||
| ηₖ = max(ηₖ, γ*ηₖ₋₁^α) if γ*ηₖ₋₁^α > safeguard_threshold | ||
| to prevent ηₖ from shrinking too fast. | ||
| """ | ||
| @concrete struct EisenstatWalkerForcing2 | ||
| η₀ | ||
| ηₘₐₓ | ||
| γ | ||
| α | ||
| safeguard | ||
| safeguard_threshold | ||
| end | ||
|
|
||
| function EisenstatWalkerForcing2(; η₀ = 0.5, ηₘₐₓ = 0.9, γ = 0.9, α = 2, safeguard = true, safeguard_threshold = 0.1) | ||
| EisenstatWalkerForcing2(η₀, ηₘₐₓ, γ, α, safeguard, safeguard_threshold) | ||
| end | ||
|
|
||
|
|
||
| @concrete mutable struct EisenstatWalkerForcing2Cache | ||
| p::EisenstatWalkerForcing2 | ||
| η | ||
| rnorm | ||
| rnorm_prev | ||
| internalnorm | ||
| verbosity | ||
| end | ||
|
|
||
|
|
||
|
|
||
| function pre_step_forcing!(cache::EisenstatWalkerForcing2Cache, descend_cache::NonlinearSolveBase.NewtonDescentCache, J, u, fu, iter) | ||
| @SciMLMessage("Eisenstat-Walker forcing residual norm $(cache.rnorm) with rate estimate $(cache.rnorm / cache.rnorm_prev).", cache.verbosity, :forcing) | ||
|
|
||
| # On the first iteration we initialize η with the default initial value and stop. | ||
| if iter == 0 | ||
| cache.η = cache.p.η₀ | ||
| @SciMLMessage("Eisenstat-Walker initial iteration to η=$(cache.η).", cache.verbosity, :forcing) | ||
| LinearSolve.update_tolerances!(descend_cache.lincache; reltol=cache.η) | ||
| return nothing | ||
| end | ||
|
|
||
| # Store previous | ||
| ηprev = cache.η | ||
|
|
||
| # Formula (2.6) | ||
| # ||r|| > 0 should be guaranteed by the convergence criterion | ||
| (; rnorm, rnorm_prev) = cache | ||
| (; α, γ) = cache.p | ||
| cache.η = γ * (rnorm / rnorm_prev)^α | ||
|
|
||
| # Safeguard 2 to prevent over-solving | ||
| if cache.p.safeguard | ||
| ηsg = γ*ηprev^α | ||
| if ηsg > cache.p.safeguard_threshold && ηsg > cache.η | ||
| cache.η = ηsg | ||
| end | ||
| end | ||
|
|
||
| # Far away from the root we also need to respect η ∈ [0,1) | ||
| cache.η = clamp(cache.η, 0.0, cache.p.ηₘₐₓ) | ||
termi-official marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| @SciMLMessage("Eisenstat-Walker iter $iter update to η=$(cache.η).", cache.verbosity, :forcing) | ||
|
|
||
| # Communicate new relative tolerance to linear solve | ||
| LinearSolve.update_tolerances!(descend_cache.lincache; reltol=cache.η) | ||
|
|
||
| return nothing | ||
| end | ||
|
|
||
|
|
||
|
|
||
| function post_step_forcing!(cache::EisenstatWalkerForcing2Cache, J, u, fu, δu, iter) | ||
| # Cache previous residual norm | ||
| cache.rnorm_prev = cache.rnorm | ||
| cache.rnorm = cache.internalnorm(fu) | ||
|
|
||
| # @SciMLMessage("Eisenstat-Walker sanity check: $(cache.internalnorm(fu + J*δu)) ≤ $(cache.η * cache.internalnorm(fu)).", cache.verbosity, :linear_verbosity) | ||
| end | ||
|
|
||
|
|
||
|
|
||
| function InternalAPI.init( | ||
| prob::AbstractNonlinearProblem, alg::EisenstatWalkerForcing2, f, fu, u, p, | ||
| args...; verbose, internalnorm::F = L2_NORM, kwargs... | ||
| ) where {F} | ||
| fu_norm = internalnorm(fu) | ||
|
|
||
| return EisenstatWalkerForcing2Cache( | ||
| alg, alg.η₀, fu_norm, fu_norm, internalnorm, verbose | ||
| ) | ||
| end | ||
|
|
||
|
|
||
|
|
||
| function InternalAPI.reinit!( | ||
| cache::EisenstatWalkerForcing2Cache; p = cache.p, kwargs... | ||
| ) | ||
| cache.p = p | ||
| end | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.