8000 Optim.jl's IPNewton should not require constraints · Issue #629 · SciML/Optimization.jl · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Optim.jl's IPNewton should not require constraints #629

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

Closed
sebapersson opened this issue Nov 18, 2023 · 4 comments
Closed

Optim.jl's IPNewton should not require constraints #629

sebapersson opened this issue Nov 18, 2023 · 4 comments

Comments

@sebapersson
Copy link

Interior point Newton methods such as IPNewton or Ipopt are capable of handling non-linear constraints, but it is also possible to run them with just box-constraints. In our benchmarks for ODE models we have found IPNewton to perform well for smaller models. However, currently when trying to use either IPNewton or Ipopt Optimization requests constraints (MVE below).

The problem can be worked around by providing an empty constraint function, but, to make it easier for the user it would be nice if this is not necessary. In particular, we have just wrapped Optmization for PEtab.jl (and it is great to gain access to so many algorithms via one interface!) - and it would be great if the user would not have to provide a flag that they want to use an interior-point method when creating the OptmizationProblem.

MVE

using Optimization, ForwardDiff, OptimizationOptimJL

rosenbrock(x, p) = (p[1] - x[1])^2 + p[2] * (x[2] - x[1]^2)^2
x0 = zeros(2)
_p = [1.0, 100.0]

f = OptimizationFunction(rosenbrock, Optimization.AutoForwardDiff())
prob = OptimizationProblem(f, x0, _p, lb = [-1.0, -1.0], ub = [0.8, 0.8])
sol = solve(prob, IPNewton())

Error message :

ERROR: The algorithm IPNewton{typeof(Optim.backtrack_constrained_grad), Symbol} requires constraints, pass them with the `cons` kwarg in `OptimizationFunction`.
Stacktrace:
 [1] _check_opt_alg(prob::OptimizationProblem{true, OptimizationFunction{true, AutoForwardDiff{nothing, Nothing}, typeof(rosenbrock), Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT_OBSERVED_NO_TIME), Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing}, Vector{Float64}, Vector{Float64}, Vector{Float64}, Vector{Float64}, Nothing, Nothing, Nothing, Nothing, Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}}, alg::IPNewton{typeof(Optim.backtrack_constrained_grad), Symbol}; kwargs::Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
   @ SciMLBase ~/.julia/packages/SciMLBase/LRUtn/src/solve.jl:112
 [2] _check_opt_alg(prob::OptimizationProblem{true, OptimizationFunction{true, AutoForwardDiff{nothing, Nothing}, typeof(rosenbrock), Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT_OBSERVED_NO_TIME), Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing}, Vector{Float64}, Vector{Float64}, Vector{Float64}, Vector{Float64}, Nothing, Nothing, Nothing, Nothing, Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}}, alg::IPNewton{typeof(Optim.backtrack_constrained_grad), Symbol})
   @ SciMLBase ~/.julia/packages/SciMLBase/LRUtn/src/solve.jl:105
 [3] init(::OptimizationProblem{true, OptimizationFunction{true, AutoForwardDiff{nothing, Nothing}, typeof(rosenbrock), Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT_OBSERVED_NO_TIME), Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing}, Vector{Float64}, Vector{Float64}, Vector{Float64}, Vector{Float64}, Nothing, Nothing, Nothing, Nothing, Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}}, ::IPNewton{typeof(Optim.backtrack_constrained_grad), Symbol}; kwargs::Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
   @ SciMLBase ~/.julia/packages/SciMLBase/LRUtn/src/solve.jl:162
 [4] init(::OptimizationProblem{true, OptimizationFunction{true, AutoForwardDiff{nothing, Nothing}, typeof(rosenbrock), Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT_OBSERVED_NO_TIME), Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing}, Vector{Float64}, Vector{Float64}, Vector{Float64}, Vector{Float64}, Nothing, Nothing, Nothing, Nothing, Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}}, ::IPNewton{typeof(Optim.backtrack_constrained_grad), Symbol})
   @ SciMLBase ~/.julia/packages/SciMLBase/LRUtn/src/solve.jl:161
 [5] solve(::OptimizationProblem{true, OptimizationFunction{true, AutoForwardDiff{nothing, Nothing}, typeof(rosenbrock), Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT_OBSERVED_NO_TIME), Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing}, Vector{Float64}, Vector{Float64}, Vector{Float64}, Vector{Float64}, Nothing, Nothing, Nothing, Nothing, Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}}, ::IPNewton{typeof(Optim.backtrack_constrained_grad), Symbol}; kwargs::Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
   @ SciMLBase ~/.julia/packages/SciMLBase/LRUtn/src/solve.jl:94
 [6] solve(::OptimizationProblem{true, OptimizationFunction{true, AutoForwardDiff{nothing, Nothing}, typeof(rosenbrock), Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT_OBSERVED_NO_TIME), Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing}, Vector{Float64}, Vector{Float64}, Vector{Float64}, Vector{Float64}, Nothing, Nothing, Nothing, Nothing, Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}}, ::IPNewton{typeof(Optim.backtrack_constrained_grad), Symbol})
   @ SciMLBase ~/.julia/packages/SciMLBase/LRUtn/src/solve.jl:91
 [7] top-level scope
   @ ~/Dropbox/PhD/Projects/tmp/Optim_fail/Example_crash.jl:9
@Vaibhavdixit02
Copy link
Member

Do you see the error with Ipopt as well?

@sebapersson
Copy link
Author

Sorry my fault, with Ipopt I do not see the error, so this code works:

using Optimization, ForwardDiff, OptimizationMOI, Ipopt

rosenbrock(x, p) = (p[1] - x[1])^2 + p[2] * (x[2] - x[1]
8000
^2)^2
x0 = zeros(2)
_p = [1.0, 100.0]

f = OptimizationFunction(rosenbrock, Optimization.AutoForwardDiff())
prob = OptimizationProblem(f, x0, _p, lb = [-1.0, -1.0], ub = [0.8, 0.8])
sol = solve(prob, Ipopt.Optimizer())

@Vaibhavdixit02
Copy link
Member

No worries, wanted to confirm.

@ChrisRackauckas ChrisRackauckas changed the title Interior point Newton optimizers should not require constraints Optim.jl's IPNewton should not require constraints Nov 19, 2023
@ChrisRackauckas
Copy link
Member

Fixed the title

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants
0