second order cone constraint in JuMP 0.19 with gurobi solver

I failed to add SOCP constraint to my model with gurobi solver after updating JuMP to 0.19.

Since norm is no longer supported, I tried the example provided in documentation,

using JuMP,Gurobi,MathOptInterface

env = Gurobi.Env()

model = Model(with_optimizer(Gurobi.Optimizer, env))

@variable(model, x)

@variable(model, t)

#@constraint(model, norm([x-1, x-2]) <= t)

@constraint(model, [t, x-1, x-2] in SecondOrderCone())

print(model)

JuMP.optimize!(model)

But the error message says

ERROR: LoadError: Constraints of type MathOptInterface.VectorAffineFunction{Float64}-in-MathOptIInterface.SecondOrderCone are not supported by the solver and there are no bridges that can refrormulate it into supported constraints.

Please help on this.

For Gurobi you need to enter it as a quadratic constraint. The transformation from SOC to quadratic is currently discussed here:

We try to make a decision about this during this afternoon collaboration time at JuMP-dev.

Hi, new to Julia and JuMP here, but really enjoying it so far.

Unfortunately, I am a bit stuck with this issue and would be happy to know how the dev plan for SOCtoQuadBridge look like at the moment?

As I try to convert an old (but working fine) Python code to Julia, I run into the issue that Gurobi in JuMP cannot automatically reformulate constraints of form x^2 + y^2 <= z^2, z >= 0 (“Q-matrix” is not PSD but has only 1 negative eigenvalue, so I believe this constraint should be SOC representable). It throws the error that “Q-matrix is not PSD”.The equivalent constraint in the GurobiPy API does result in an “optimal” solution.

A minimal example is posted below. For my larger problem, unfortunately, MOSEK with the SecondOrderCone() constraint is not working well as Mosek solver stalls (JuMP status: SLOW_PROGRESS, Mosek status: Mosek.MSK_RES_TRM_STALL).

It is possible that I am doing something wrong.
Many thanks in advance for your help.

using JuMP, Mosek, MosekTools, Gurobi

#Uncomment for Gurobi
m = Model(with_optimizer(Gurobi.Optimizer, Presolve=0, OutputFlag=1, DualReductions=0))

#Uncomment for Mosek
#m = Model(with_optimizer(Mosek.Optimizer,MSK_IPAR_LOG=1,MSK_DPAR_INTPNT_CO_TOL_REL_GAP=1.0e-10))

@variable(m, x)
@variable(m, y)
@variable(m, z)

@constraint(m, z >= 0)
@constraint(m, 1 <= x <= 3)
@constraint(m, 1 <= y <= 3)

#Uncomment for Gurobi
@constraint(m, x*x + y*y <= z*z)

#Uncomment for Mosek
#@constraint(m, [z,x,y] in SecondOrderCone())


@objective(m, Min, x+y)

optimize!(m)
status = termination_status(m)

println(status)
println(JuMP.value(x))
println(JuMP.value(y))
println(JuMP.value(z))

You should use bounds instead of constraints.

@variable(m, 1 <= x <= 3)
@variable(m, 1 <= y <= 3)
@variable(m, z >= 0)

Gurobi can’t preserve your constraints to prove z >= 0 .

SecondOrderCone support is coming. See https://github.com/JuliaOpt/Gurobi.jl/pull/231

1 Like

Thanks so much, Oscar. It works now for my larger problem too. Looking forward to and following updates on the SecondOrderCone support for Gurobi.

Hi Oscar, is SecondOrderCone supported by Gurobi now?
As you said " Gurobi can’t preserve constraints to prove z >= 0 ", I have a similar issue. But my constraint z >= 0 is in a loop, so I cannot use bound since I cannot attach same name variable to my model. If so, any better way to solve this problem? Thanks in advance.

Yes. It just needs a new tag: Bump version by odow · Pull Request #259 · jump-dev/Gurobi.jl · GitHub

For now, you could try ] add Gurobi#master.

But my constraint z >= 0 is in a loop, so I cannot use bound since I cannot attach same name variable to my model. If so, any better way to solve this problem?

You want to use the anonymous syntax:

z = @variable(model, lower_bound = 0)

See: Variables · JuMP

I am sorry. I am new here. What do you mean ] add Gurobi#master here? Can you explain more? Thanks!

Open the Julia REPL and type

julia> ] add Gurobi#master

This will install the latest version of Gurobi.jl. E.g.,

1 Like

Thanks but julia return this:


and here is my Pkg.status():
image
What should I do?

Try running ] up first. You need JuMP 0.20

1 Like

It works now! Thank you so much, Oscar.