-
Notifications
You must be signed in to change notification settings - Fork 233
Add iterator interface #745
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
Open
tkf
wants to merge
24
commits into
JuliaNLSolvers:master
Choose a base branch
from
tkf:iterator
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.
Open
Changes from 5 commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
b10f27e
Add iterator interface
tkf cc594a8
Don't use at-eval
tkf d6a6d75
Simplify OptimizationResults(istate)
tkf 2117364
Add accessor functions
tkf b7b63e8
Directly define accessor functions
tkf 8a64efb
Merge branch 'master' into iterator
tkf 0826be0
Merge branch 'master' into iterator
pkofod b0e5c30
Apply suggestions from code review
pkofod a22346a
Apply suggestions from code review
pkofod 2310160
Fix breaks and types in trace api
pkofod 15c8b62
Update optimize.jl
pkofod 75ece54
Update interface.jl
pkofod 54a8542
Fix trust region
pkofod bc42ad8
Use tkf advice on explicitly requiring iter
pkofod afaa7e9
Update optimize.jl
pkofod cc5ebfc
Update optimize.jl
pkofod 56e0795
Fix interface (though we may want to change it) and update an nmgres …
pkofod dc03af8
Get rid of after_while!
pkofod 3daa277
Update interior.jl
pkofod 35ffc80
change how the api functions are used ot include os some places becau…
pkofod e027fe9
Update optimize.jl
pkofod ea17c1c
Update api.jl
pkofod 9faa883
Update api.jl
pkofod 7620e4f
erge remote-tracking branch 'upstream/master' into iterator
pkofod 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -54,84 +54,94 @@ promote_objtype(method::FirstOrderOptimizer, x, autodiff::Symbol, inplace::Bool | |
| promote_objtype(method::SecondOrderOptimizer, x, autodiff::Symbol, inplace::Bool, td::TwiceDifferentiable) = td | ||
|
|
||
| # if no method or options are present | ||
| function optimize(f, initial_x::AbstractArray; inplace = true, autodiff = :finite, kwargs...) | ||
| function optimizing(f, initial_x::AbstractArray; inplace = true, autodiff = :finite, kwargs...) | ||
| method = fallback_method(f) | ||
| checked_kwargs, method = check_kwargs(kwargs, method) | ||
| d = promote_objtype(method, initial_x, autodiff, inplace, f) | ||
| add_default_opts!(checked_kwargs, method) | ||
|
|
||
| options = Options(; checked_kwargs...) | ||
| optimize(d, initial_x, method, options) | ||
| optimizing(d, initial_x, method, options) | ||
| end | ||
| function optimize(f, g, initial_x::AbstractArray; inplace = true, autodiff = :finite, kwargs...) | ||
| function optimizing(f, g, initial_x::AbstractArray; inplace = true, autodiff = :finite, kwargs...) | ||
|
|
||
| method = fallback_method(f, g) | ||
| checked_kwargs, method = check_kwargs(kwargs, method) | ||
| d = promote_objtype(method, initial_x, autodiff, inplace, f, g) | ||
| add_default_opts!(checked_kwargs, method) | ||
|
|
||
| options = Options(; checked_kwargs...) | ||
| optimize(d, initial_x, method, options) | ||
| optimizing(d, initial_x, method, options) | ||
| end | ||
| function optimize(f, g, h, initial_x::AbstractArray; inplace = true, autodiff = :finite, kwargs...) | ||
| function optimizing(f, g, h, initial_x::AbstractArray; inplace = true, autodiff = :finite, kwargs...) | ||
|
|
||
| method = fallback_method(f, g, h) | ||
| checked_kwargs, method = check_kwargs(kwargs, method) | ||
| d = promote_objtype(method, initial_x, autodiff, inplace, f, g, h) | ||
| add_default_opts!(checked_kwargs, method) | ||
|
|
||
| options = Options(; checked_kwargs...) | ||
| optimize(d, initial_x, method, options) | ||
| optimizing(d, initial_x, method, options) | ||
| end | ||
|
|
||
| # no method supplied with objective | ||
| function optimize(d::T, initial_x::AbstractArray, options::Options) where T<:AbstractObjective | ||
| optimize(d, initial_x, fallback_method(d), options) | ||
| function optimizing(d::T, initial_x::AbstractArray, options::Options) where T<:AbstractObjective | ||
| optimizing(d, initial_x, fallback_method(d), options) | ||
| end | ||
| # no method supplied with inplace and autodiff keywords becauase objective is not supplied | ||
| function optimize(f, initial_x::AbstractArray, options::Options; inplace = true, autodiff = :finite) | ||
| function optimizing(f, initial_x::AbstractArray, options::Options; inplace = true, autodiff = :finite) | ||
| method = fallback_method(f) | ||
| d = promote_objtype(method, initial_x, autodiff, inplace, f) | ||
| optimize(d, initial_x, method, options) | ||
| optimizing(d, initial_x, method, options) | ||
| end | ||
| function optimize(f, g, initial_x::AbstractArray, options::Options; inplace = true, autodiff = :finite) | ||
| function optimizing(f, g, initial_x::AbstractArray, options::Options; inplace = true, autodiff = :finite) | ||
|
|
||
| method = fallback_method(f, g) | ||
| d = promote_objtype(method, initial_x, autodiff, inplace, f, g) | ||
| optimize(d, initial_x, method, options) | ||
| optimizing(d, initial_x, method, options) | ||
| end | ||
| function optimize(f, g, h, initial_x::AbstractArray{T}, options::Options; inplace = true, autodiff = :finite) where {T} | ||
| function optimizing(f, g, h, initial_x::AbstractArray{T}, options::Options; inplace = true, autodiff = :finite) where {T} | ||
|
|
||
| method = fallback_method(f, g, h) | ||
| d = promote_objtype(method, initial_x, autodiff, inplace, f, g, h) | ||
|
|
||
| optimize(d, initial_x, method, options) | ||
| optimizing(d, initial_x, method, options) | ||
| end | ||
|
|
||
| # potentially everything is supplied (besides caches) | ||
| function optimize(f, initial_x::AbstractArray, method::AbstractOptimizer, | ||
| function optimizing(f, initial_x::AbstractArray, method::AbstractOptimizer, | ||
| options::Options = Options(;default_options(method)...); inplace = true, autodiff = :finite) | ||
|
|
||
| d = promote_objtype(method, initial_x, autodiff, inplace, f) | ||
| optimize(d, initial_x, method, options) | ||
| optimizing(d, initial_x, method, options) | ||
| end | ||
| function optimize(f, g, initial_x::AbstractArray, method::AbstractOptimizer, | ||
| function optimizing(f, g, initial_x::AbstractArray, method::AbstractOptimizer, | ||
| options::Options = Options(;default_options(method)...); inplace = true, autodiff = :finite) | ||
|
|
||
| d = promote_objtype(method, initial_x, autodiff, inplace, f, g) | ||
|
|
||
| optimize(d, initial_x, method, options) | ||
| optimizing(d, initial_x, method, options) | ||
| end | ||
| function optimize(f, g, h, initial_x::AbstractArray{T}, method::AbstractOptimizer, | ||
| function optimizing(f, g, h, initial_x::AbstractArray{T}, method::AbstractOptimizer, | ||
| options::Options = Options(;default_options(method)...); inplace = true, autodiff = :finite) where T | ||
|
|
||
| d = promote_objtype(method, initial_x, autodiff, inplace, f, g, h) | ||
|
|
||
| optimize(d, initial_x, method, options) | ||
| optimizing(d, initial_x, method, options) | ||
| end | ||
|
|
||
| function optimize(d::D, initial_x::AbstractArray, method::SecondOrderOptimizer, | ||
| function optimizing(d::D, initial_x::AbstractArray, method::SecondOrderOptimizer, | ||
| options::Options = Options(;default_options(method)...); autodiff = :finite, inplace = true) where {D <: Union{NonDifferentiable, OnceDifferentiable}} | ||
| d = promote_objtype(method, initial_x, autodiff, inplace, d) | ||
| optimize(d, initial_x, method, options) | ||
| optimizing(d, initial_x, method, options) | ||
| end | ||
|
|
||
| function optimize(args...; kwargs...) | ||
| local istate | ||
| for istate′ in optimizing(args...; kwargs...) | ||
| istate = istate′ | ||
| end | ||
| # We can safely assume that `istate` is defined at this point. That is to say, | ||
| # `OptimIterator` guarantees that `iterate(::OptimIterator) !== nothing`. | ||
|
Comment on lines
+334
to
+335
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think JET won't agree with this comment 😄 Generally, the code above seems a bit unfortunate... Maybe I also wonder, is there no utility in Julia for directly obtaining the last state of an iterator? |
||
| return OptimizationResults(istate) | ||
| end | ||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suppose
tr = trace(r)should be added here? I think it'll throwUndefVarErrorotherwise. There are two more places I did this change.I'm including these changes (adding
tr = trace(r)) although they are not directly related to PR.