Nonconvex.jl icon indicating copy to clipboard operation
Nonconvex.jl copied to clipboard

DictModel cannot convert a JuMP model with quadratic objective

Open odow opened this issue 3 years ago • 2 comments

julia> using JuMP

julia> import Nonconvex

julia> Nonconvex.@load Ipopt
[ Info: Attempting to load the package NonconvexIpopt.
[ Info: Loading succesful.

julia> model = JuMP.Model();

julia> @variable(model, x >= 0)
x

julia> @objective(model, Min, x^2)
x²

julia> ncvx_model = DictModel(model)
ERROR: AssertionError: obj isa AffExpr
Stacktrace:
 [1] get_objective_info(model::JuMP.Model, nvars::Int64)
   @ NonconvexCore ~/.julia/packages/NonconvexCore/YjDSM/src/models/jump.jl:184
 [2] DictModel(model::JuMP.Model)
   @ NonconvexCore ~/.julia/packages/NonconvexCore/YjDSM/src/models/jump.jl:204
 [3] top-level scope
   @ REPL[7]:1

cc @ccoffrin

odow avatar Feb 24 '22 07:02 odow

Adding an epigraph variable also fails:

julia> using JuMP

julia> import Nonconvex

julia> Nonconvex.@load Ipopt
[ Info: Attempting to load the package NonconvexIpopt.
[ Info: Loading succesful.

julia> model = JuMP.Model();

julia> @variable(model, x >= 0)
x

julia> @variable(model, t)
t

julia> @constraint(model, t >= x^2)
-x² + t ≥ 0.0

julia> @objective(model, Min, t)
t

julia> ncvx_model = DictModel(model)
ERROR: AssertionError: obj isa AffExpr
Stacktrace:
 [1] get_objective_info(model::JuMP.Model, nvars::Int64)
   @ NonconvexCore ~/.julia/packages/NonconvexCore/YjDSM/src/models/jump.jl:184
 [2] DictModel(model::JuMP.Model)
   @ NonconvexCore ~/.julia/packages/NonconvexCore/YjDSM/src/models/jump.jl:204
 [3] top-level scope
   @ REPL[17]:1

odow avatar Feb 24 '22 07:02 odow

Yes currently I only support linear expressions because this is the main utility of using JuMP over Nonconvex directly to define objectives or constraints. Extending this is possible but it will need to add support for more expression types in https://github.com/JuliaNonconvex/NonconvexCore.jl/blob/master/src/models/jump.jl.

mohamed82008 avatar Feb 24 '22 08:02 mohamed82008