snopt / SNOPT7.jl

Julia interface for SNOPT7
MIT License
10 stars 6 forks source link

Support JuMP.@constraint #4

Open lassepe opened 3 years ago

lassepe commented 3 years ago

First of all, thank you for making SNOPT available in Julia!

I was able to run the JuMP example in example/hs72.jl. However, I am not able to run an equivalent formulation in which the last constraint is encoded via JuMP.@constraint rather than JuMP.@NLconstraint:

import JuMP
import SNOPT7

m = JuMP.Model(JuMP.optimizer_with_attributes(
        SNOPT7.Optimizer,
        "print_level" => 0,
        "system_information" => "yes",
))

JuMP.@variable(m, 1 <= x[i = 1:4] <= 5)
JuMP.@NLobjective(m, Min, x[1] * x[4] * (x[1] + x[2] + x[3]) + x[3])
JuMP.@NLconstraint(m, x[1] * x[2] * x[3] * x[4] >= 25)
JuMP.@constraint(m, sum(el -> el^2, x) == 40)

JuMP.optimize!(m)

println(JuMP.value.(x))

objval = JuMP.objective_value(m)
println("Final objective: $objval")

println(JuMP.termination_status(m))

I am getting the following error message (truncated)

ERROR: LoadError: `MOI.ScalarQuadraticFunction{Float64}`-in-`MOI.EqualTo{Float64}` constraints are not supported and cannot be bridged into supported constrained variables and constraints. See details below:
 [1] constrained variables in `MOI.RotatedSecondOrderCone` are not supported because:
   Cannot use `MOIB.Variable.RSOCtoSOCBridge{Float64}` because:
   [2] constrained variables in `MOI.SecondOrderCone` are not supported
   Cannot use `MOIB.Variable.RSOCtoPSDBridge{Float64}` because:
   [5] constrained variables in `MOI.PositiveSemidefiniteConeTriangle` are not supported
   Cannot add free variables and then constrain them because:
   (9) `MOI.VectorOfVariables`-in-`MOI.RotatedSecondOrderCone` constraints are not supported
 [2] constrained variables in `MOI.SecondOrderCone` are not supported because:
   Cannot use `MOIB.Variable.SOCtoRSOCBridge{Float64}` because:
   [1] constrained variables in `MOI.RotatedSecondOrderCone` are not supported
   Cannot add free variables and then constrain them because:
   (11) `MOI.VectorOfVariables`-in-`MOI.SecondOrderCone` constraints are not supported
 [5] constrained variables in `MOI.PositiveSemidefiniteConeTriangle` are not supported because no added bridge supports bridging it.
   Cannot add free variables and then constrain them because:
   (18) `MOI.VectorOfVariables`-in-`MOI.PositiveSemidefiniteConeTriangle` constraints are not supported
 (1) `MOI.ScalarQuadraticFunction{Float64}`-in-`MOI.EqualTo{Float64}` constraints are not supported because:
   Cannot use `MOIB.Constraint.VectorizeBridge{Float64,MOI.VectorQuadraticFunction{Float64},MOI.Zeros,MOI.ScalarQuadraticFunction{Float64}}` because:
   (2) `MOI.VectorQuadraticFunction{Float64}`-in-`MOI.Zeros` constraints are not supported
   Cannot use `MOIB.Constraint.SplitIntervalBridge{Float64,MOI.ScalarQuadraticFunction{Float64},MOI.EqualTo{Float64},MOI.GreaterThan{Float64},MOI.LessThan{Float64}}` because:
[...]

Tl;DR Is it not possible to use any JuMP.@contraint calls with SNOPT7.jl; i.e. do I have to convert all of them to JuMP.@NLconstraint? If so, are there any plans to support JuMP.@constraint in the future?

gnowzil commented 3 years ago

Hi, I think this is in-line with the JuMP documentation (https://jump.dev/JuMP.jl/v0.21.1/nlp). "Note that the @objective and @constraint macros (and corresponding functions) do not currently support nonlinear expressions."

I haven't kept up with recent JuMP developments though so if this isn't accurate, I can look into updating to support @constraint.

lassepe commented 3 years ago

Hi, thank you for your quick reply!

Hi, I think this is in-line with the JuMP documentation (https://jump.dev/JuMP.jl/v0.21.1/nlp). "Note that the @objective and @constraint macros (and corresponding functions) do not currently support nonlinear expressions."

I think the use of the term "nonlinear" is a bit confusing in the JuMP documentation. JuMP allows affine and quadratic expressions in @constraint and @objective. Thus, the formulation above should be valid. In fact, Ipopt and other JuMP enabled solvers are able to solve this problem.

I haven't kept up with recent JuMP developments though so if this isn't accurate, I can look into updating to support @constraint.

It would certainly be good to have support for @constraint and @objective in SNOPT7.jl because they are perhaps the main workhorses in JuMP at the moment. Unfortunately, I am not too familiar with the backend of either JuMP or SNOPT7 at this point. However, I'd be happy to help with the implementation of this feature if you can provide some rough guidance of what would be needed for this.