From 6f580a860ceb438b93704ed21b28cd8693fd84e8 Mon Sep 17 00:00:00 2001 From: Mohamed Tarek Date: Fri, 21 Jan 2022 08:37:06 +1100 Subject: [PATCH 1/5] Update Project.toml --- Project.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Project.toml b/Project.toml index c58629a..0208cc9 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "NonconvexIpopt" uuid = "bf347577-a06d-49ad-a669-8c0e005493b8" authors = ["Mohamed Tarek and contributors"] -version = "0.1.2" +version = "0.1.3" [deps] Ipopt = "b6b21f68-93f8-5de0-b562-5493be1d77c9" @@ -14,7 +14,7 @@ Zygote = "e88e6eb3-aa80-5325-afca-941959d7151f" [compat] Ipopt = "0.6, 0.7" -NonconvexCore = "0.1.3" +NonconvexCore = "1.0.0" Parameters = "0.12" Reexport = "1" Zygote = "0.6" From d42ff9448e3ba2a72000e92fdf1bed5aba424987 Mon Sep 17 00:00:00 2001 From: Mohamed Tarek Date: Thu, 20 Jan 2022 23:42:57 +0200 Subject: [PATCH 2/5] bump Ipopt --- Project.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Project.toml b/Project.toml index 0208cc9..edea24d 100644 --- a/Project.toml +++ b/Project.toml @@ -13,7 +13,7 @@ SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf" Zygote = "e88e6eb3-aa80-5325-afca-941959d7151f" [compat] -Ipopt = "0.6, 0.7" +Ipopt = "0.6, 0.7, 0.8, 0.9" NonconvexCore = "1.0.0" Parameters = "0.12" Reexport = "1" From 20b12f022c4ebceca72697537b68081edf48f06e Mon Sep 17 00:00:00 2001 From: Mohamed Tarek Date: Fri, 21 Jan 2022 00:24:20 +0200 Subject: [PATCH 3/5] Ipopt 0.9 --- Project.toml | 3 ++- src/ipopt.jl | 15 ++++++++++++--- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/Project.toml b/Project.toml index edea24d..9778dcb 100644 --- a/Project.toml +++ b/Project.toml @@ -5,6 +5,7 @@ version = "0.1.3" [deps] Ipopt = "b6b21f68-93f8-5de0-b562-5493be1d77c9" +Ipopt_jll = "9cc047cb-c261-5740-88fc-0cf96f7bdcc7" LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" NonconvexCore = "035190e5-69f1-488f-aaab-becca2889735" Parameters = "d96e819e-fc66-5662-9728-84c9c7592b0a" @@ -13,7 +14,7 @@ SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf" Zygote = "e88e6eb3-aa80-5325-afca-941959d7151f" [compat] -Ipopt = "0.6, 0.7, 0.8, 0.9" +Ipopt = "0.9" NonconvexCore = "1.0.0" Parameters = "0.12" Reexport = "1" diff --git a/src/ipopt.jl b/src/ipopt.jl index aeee4ac..2cd81ff 100644 --- a/src/ipopt.jl +++ b/src/ipopt.jl @@ -47,14 +47,23 @@ function optimize!(workspace::IpoptWorkspace) counter[] = 0 foreach(keys(options.nt)) do k v = options.nt[k] - Ipopt.addOption(problem, string(k), v) + addOption(problem, string(k), v) end - solvestat = Ipopt.solveProblem(problem) + solvestat = Ipopt.IpoptSolve(problem) return IpoptResult( copy(problem.x), getobjective(model)(problem.x), problem, solvestat, counter[] ) end +function addOption(prob, name, val::Int) + return Ipopt.AddIpoptIntOption(prob, name, val) +end +function addOption(prob, name, val::String) + return Ipopt.AddIpoptStrOption(prob, name, val) +end +function addOption(prob, name, val) + return Ipopt.AddIpoptNumOption(prob, name, val) +end struct IpoptAlg <: AbstractOptimizer end @@ -177,7 +186,7 @@ function get_ipopt_problem(obj, ineq_constr, eq_constr, x0, xlb, xub, first_orde return Inf end end - prob = Ipopt.createProblem( + prob = Ipopt.CreateIpoptProblem( nvars, xlb, xub, ineq_nconstr + eq_nconstr, clb, cub, nvalues(ineqJ0) + nvalues(eqJ0), Hnvalues, _obj, eval_g, eval_grad_f, eval_jac_g, eval_h, From b18eac8c3412f5a25da06f57f533c59d8ccc133f Mon Sep 17 00:00:00 2001 From: Mohamed Tarek Date: Fri, 21 Jan 2022 01:36:22 +0200 Subject: [PATCH 4/5] minor changes --- Project.toml | 1 - src/ipopt.jl | 12 +++++++----- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/Project.toml b/Project.toml index 9778dcb..41a9f2f 100644 --- a/Project.toml +++ b/Project.toml @@ -5,7 +5,6 @@ version = "0.1.3" [deps] Ipopt = "b6b21f68-93f8-5de0-b562-5493be1d77c9" -Ipopt_jll = "9cc047cb-c261-5740-88fc-0cf96f7bdcc7" LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" NonconvexCore = "035190e5-69f1-488f-aaab-becca2889735" Parameters = "d96e819e-fc66-5662-9728-84c9c7592b0a" diff --git a/src/ipopt.jl b/src/ipopt.jl index 2cd81ff..9c530d0 100644 --- a/src/ipopt.jl +++ b/src/ipopt.jl @@ -50,10 +50,12 @@ function optimize!(workspace::IpoptWorkspace) addOption(problem, string(k), v) end solvestat = Ipopt.IpoptSolve(problem) - return IpoptResult( + res = IpoptResult( copy(problem.x), getobjective(model)(problem.x), problem, solvestat, counter[] ) + finalize(problem) + return res end function addOption(prob, name, val::Int) return Ipopt.AddIpoptIntOption(prob, name, val) @@ -139,8 +141,8 @@ function get_ipopt_problem(obj, ineq_constr, eq_constr, x0, xlb, xub, first_orde grad_f .= grad end end - function eval_jac_g(x::Vector{Float64}, mode, rows::Vector{Int32}, cols::Vector{Int32}, values::Vector{Float64}) - if mode == :Structure + function eval_jac_g(x::Vector{Float64}, rows::Vector{Int32}, cols::Vector{Int32}, values::Union{Nothing, Vector{Float64}}) + if values === nothing ineqJ0 === nothing || fill_indices!(rows, cols, ineqJ0) eqJ0 === nothing || fill_indices!(rows, cols, eqJ0, offset = Joffset, row_offset = ineq_nconstr) else @@ -166,8 +168,8 @@ function get_ipopt_problem(obj, ineq_constr, eq_constr, x0, xlb, xub, first_orde x0, ), ) - eval_h = function (x::Vector{Float64}, mode, rows::Vector{Int32}, cols::Vector{Int32}, obj_factor::Float64, lambda::Vector{Float64}, values::Vector{Float64}) - if mode == :Structure + eval_h = function (x::Vector{Float64}, rows::Vector{Int32}, cols::Vector{Int32}, obj_factor::Float64, lambda::Vector{Float64}, values::Union{Nothing, Vector{Float64}}) + if values === nothing fill_indices!(rows, cols, HL0) else HL = LowerTriangular( From 91e1882edff8b4f025a0606d194d51feb4159320 Mon Sep 17 00:00:00 2001 From: Mohamed Tarek Date: Fri, 21 Jan 2022 01:37:31 +0200 Subject: [PATCH 5/5] no finalize --- src/ipopt.jl | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/ipopt.jl b/src/ipopt.jl index 9c530d0..c7d852a 100644 --- a/src/ipopt.jl +++ b/src/ipopt.jl @@ -50,12 +50,10 @@ function optimize!(workspace::IpoptWorkspace) addOption(problem, string(k), v) end solvestat = Ipopt.IpoptSolve(problem) - res = IpoptResult( + return IpoptResult( copy(problem.x), getobjective(model)(problem.x), problem, solvestat, counter[] ) - finalize(problem) - return res end function addOption(prob, name, val::Int) return Ipopt.AddIpoptIntOption(prob, name, val)