Closed ederag closed 5 months ago
From reading the error, I presume that needs to be: IPNewton(linesearch = Optim.HagerZhang)
The linked optim doc requires an instance rather than the type.
And algo_hz = Newton(linesearch = HagerZhang)
, fails with
MethodError: no method matching LineSearches.HagerZhang(::NLSolversBase.TwiceDifferentiable{Float64, Vector{Float64}, Matrix{Float64}, Vector{Float64}}, ::Vector{Float64}, ::Vector{Float64}, ::Float64, ::Vector{Float64}, ::Float64, ::Float64)
Closest candidates are:
LineSearches.HagerZhang(::T, !Matched::T, !Matched::T, !Matched::T, !Matched::T, !Matched::T, ::Any, !Matched::T, !Matched::Any, !Matched::Tm) where {T, Tm}
@ LineSearches ~/.julia/packages/Parameters/MK0O4/src/Parameters.jl:525
perform_linesearch!(::Optim.NewtonState{Vector{Float64}, Float64, LinearAlgebra.Cholesky{Float64, Matrix{Float64}}}, ::Optim.Newton{LineSearches.InitialStatic{Float64}, UnionAll}, ::NLSolversBase.TwiceDifferentiable{Float64, Vector{Float64}, Matrix{Float64}, Vector{Float64}})@perform_linesearch.jl:58
update_state!(::NLSolversBase.TwiceDifferentiable{Float64, Vector{Float64}, Matrix{Float64}, Vector{Float64}}, ::Optim.NewtonState{Vector{Float64}, Float64, LinearAlgebra.Cholesky{Float64, Matrix{Float64}}}, ::Optim.Newton{LineSearches.InitialStatic{Float64}, UnionAll})@newton.jl:79
optimize(::NLSolversBase.TwiceDifferentiable{Float64, Vector{Float64}, Matrix{Float64}, Vector{Float64}}, ::Vector{Float64}, ::Optim.Newton{LineSearches.InitialStatic{Float64}, UnionAll}, ::Optim.Options{Float64, Nothing}, ::Optim.NewtonState{Vector{Float64}, Float64, LinearAlgebra.Cholesky{Float64, Matrix{Float64}}})@optimize.jl:54
optimize(::NLSolversBase.TwiceDifferentiable{Float64, Vector{Float64}, Matrix{Float64}, Vector{Float64}}, ::Vector{Float64}, ::Optim.Newton{LineSearches.InitialStatic{Float64}, UnionAll}, ::Optim.Options{Float64, Nothing})@optimize.jl:36
var"#optimize#85"(::Bool, ::Symbol, ::Base.Pairs{Symbol, Optim.Newton{LineSearches.InitialStatic{Float64}, UnionAll}, Tuple{Symbol}, @NamedTuple{method::Optim.Newton{LineSearches.InitialStatic{Float64}, UnionAll}}}, ::typeof(Optim.optimize), ::Function, ::Function, ::Function, ::Vector{Float64})@interface.jl:111
top-level scope@[Local: 1](http://localhost:1234/edit?id=f9148700-c19a-11ee-257f-69bdb30e2f94#)[inlined]
We're just passing this onto Optim so whatever Optim wants is what to put there.
Sorry, I typed in a Pluto notebook instead of in the minimum example REPL. Here is the output:
julia> sol = solve(prob, IPNewton(linesearch = Optim.HagerZhang))
ERROR: TypeError: in keyword argument linesearch, expected Function, got Type{LineSearches.HagerZhang}
Stacktrace:
[1] top-level scope
The linked optim doc requires an instance rather than the type.
Then it looks like this is an upstream problem with Optim.jl?
OK, let me try in barebones Optim and report back.
Ah, there isn't any bug anywhere,
but the current documentation linked to an optim doc example
that uses Newton
rather than IPNewton
.
IPNewton
does not accept LineSearches yet:
As of February 2018, the line search algorithm is specialised for constrained interior-point methods. In future we hope to support more algorithms from LineSearches.jl
Hence the errors.
So the current documentation is misleading (IIUC): https://github.com/SciML/Optimization.jl/blob/7c700d0e2b1c5847fffe7e96de4e9c543ce6618f/docs/src/optimization_packages/optim.md?plain=1#L58-L67
One fix could be to remove references to LineSearch and link to the equivalent and more relevant IPNewton example
or find another constrained optimization algorithm that matches those sentences.
I don't know about the latter, but the former I could do if you wish.
I see. Could you make the PR removing the reference?
Specifying
linesearch
forIPNewton
fails withTypeError
.MRE adapted from https://docs.sciml.ai/Optimization/stable/optimization_packages/optim/#Local-Constraint
Error & Stacktrace ⚠️
Environment
using Pkg; Pkg.status()
using Pkg; Pkg.status(; mode = PKGMODE_MANIFEST)
versioninfo()