No method matching promote_shape

Here is a small example.

using JuMP,Mosek,MosekTools

u=rand(3,1)
M_SDP = Model(Mosek.Optimizer)
#set_silent(model)
#set_optimizer_attribute(M_SDP, "MSK_IPAR_LOG", 0)
@variable(M_SDP,buro[1:3,1])
# Z >= 0, PSD
@variable(M_SDP, P[1:3, 1:3], PSD)
@constraint(M_SDP , P .>= 0)
#@variable(M_SDP, P[1:24,1:24])
#@SDconstraint(M_SDP, X>=0)
@constraint(M_SDP, norm(P*u+buro) .<= 1 )
@objective(M_SDP, Min, log(det(inv(P)))
solve(M_SDP)
P_SDP = getvalue(P)
buro_SDP= getvalue(buro)

But it shows such an error:
MethodError: no method matching promote_shape(::Tuple{Base.OneTo{Int64},Base.OneTo{Int64}}, ::Tuple{Base.OneTo{Int64},Int64})


Error happens in @constraint(M_SDP, norm(P*u+buro) .<= 1 )
The constraint is to constrain the 2-norm of (P*u+buro) small than 1.
What’s wrong with that?

I have changed @variable(M_SDP,buro[1:3,1]) into @variable(M_SDP,buro[1:3]), and @constraint(M_SDP, norm(P*u+buro) .<= 1 ) into @constraint(M_SDP, [1, (P*u+buro)[1], (P*u+buro)[2], (P*u+buro)[3]] in SecondOrderCone()).
Then the error above disappeared.
But when I run @objective(M_SDP, Min, log(det(inv(P))), it shows me such a new error:


I try to add LinearAlgebra,like this: @objective(M_SDP, Min, LinearAlgebra.log(det(inv(P))))
But the same error happen.
How can I solve the problem?

JuMP isn’t like Convex.jl, so you can’t use functions like norm, log and det directly. You need to formulate a conic optimization problem.

I don’t have Mosek so I can’t test, but I think you want something like

using JuMP, MosekTools
u = rand(3)
M_SDP = Model(Mosek.Optimizer)
@variable(M_SDP, buro[1:3])
@variable(M_SDP, P[1:3, 1:3] >= 0, PSD)
# norm(P * u + buro) <= 1
@constraint(M_SDP, [1; P * u + buro] in SecondOrderCone())
# t <= log(det(P))
@variable(M_SDP, t)
@constraint(M_SDP, [t; 1; vec(P)] in MOI.LogDetConeSquare(3))
@objective(M_SDP, Max, t)
optimize!(M_SDP)
P_SDP = value.(P)
buro_SDP = value.(buro)

I add MathOptInterface.jl and using MathOptInterface for MOI.LogDetConeSquare(),but it still appear such an error in @constraint(M_SDP, [t; 1; vec(P)] in MOI.LogDetConeSquare(3)):

ERROR: LoadError: cannot assign a value to variable JuMP.MOI from module Main
Stacktrace:
 [1] top-level scope at untitled-36f70f3d81c9a751a6967ac32d0812fd:2

in expression starting at untitled-36f70f3d81c9a751a6967ac32d0812fd:2
LoadError: `MOI.VectorAffineFunction{Float64}`-in-`MOI.LogDetConeSquare` constraints are not supported and cannot be bridged into supported constrained variables and constraints. See details below:
 [3] constrained variables in `MOI.LogDetConeSquare` are not supported because no added bridge supports bridging it.
   Cannot add free variables and then constrain them because:
   (10) `MOI.VectorOfVariables`-in-`MOI.LogDetConeSquare` constraints are not supported
 (9) `MOI.VectorAffineFunction{Float64}`-in-`MOI.LogDetConeSquare` constraints are not supported because:
   Cannot use `MOIB.Constraint.VectorSlackBridge{Float64,MOI.VectorAffineFunction{Float64},MOI.LogDetConeSquare}` because:     
   [3] constrained variables in `MOI.LogDetConeSquare` are not supported
 (10) `MOI.VectorOfVariables`-in-`MOI.LogDetConeSquare` constraints are not supported because:
   Cannot use `MOIB.Constraint.VectorFunctionizeBridge{Float64,MOI.LogDetConeSquare}` because:
   (9) `MOI.VectorAffineFunction{Float64}`-in-`MOI.LogDetConeSquare` constraints are not supported

What else is missing or wrong?

  1. You don’t need using MathOptInterface. It is already exported by JuMP.

  2. The looks like a bug. We should be able to bridge the LogDet cone into PSD + Exponential. (Edit: here’s the issue: add bridges for logdet/rootdet square -> triangle · Issue #541 · jump-dev/MathOptInterface.jl · GitHub)

Rewriting to use a LogDetConeTriangle, here is what I get with SCS:

julia> using JuMP, SCS

julia> u = rand(3)
3-element Vector{Float64}:
 0.2076471595685787
 0.6577478008368793
 0.4799996513530598

julia> M_SDP = Model(SCS.Optimizer)
A JuMP Model
Feasibility problem with:
Variables: 0
Model mode: AUTOMATIC
CachingOptimizer state: EMPTY_OPTIMIZER
Solver name: SCS

julia> @variable(M_SDP, -1 <= buro[1:3] <= 1)
3-element Vector{VariableRef}:
 buro[1]
 buro[2]
 buro[3]

julia> @variable(M_SDP, P[1:3, 1:3] >= 0, PSD)
3×3 Symmetric{VariableRef, Matrix{VariableRef}}:
 P[1,1]  P[1,2]  P[1,3]
 P[1,2]  P[2,2]  P[2,3]
 P[1,3]  P[2,3]  P[3,3]

julia> @constraint(M_SDP, [1; P * u + buro] in SecondOrderCone())
[1, buro[1] + 0.2076471595685787 P[1,1] + 0.6577478008368793 P[1,2] + 0.4799996513530598 P[1,3], buro[2] + 0.2076471595685787 P[1,2] + 0.6577478008368793 P[2,2] + 0.4799996513530598 P[2,3], buro[3] + 0.2076471595685787 P[1,3] + 0.6577478008368793 P[2,3] + 0.4799996513530598 P[3,3]] ∈ MathOptInterface.SecondOrderCone(4)

julia> @variable(M_SDP, t)
t

julia> lower_triangular(P) = [P[i, j] for i = 1:size(P, 1) for j = 1:i]
lower_triangular (generic function with 1 method)

julia> @constraint(M_SDP, [t; 1; lower_triangular(P)] in MOI.LogDetConeTriangle(3))
[t, 1, P[1,1], P[1,2], P[2,2], P[1,3], P[2,3], P[3,3]] ∈ MathOptInterface.LogDetConeTriangle(3)

julia> @objective(M_SDP, Max, t)
t

julia> optimize!(M_SDP)
----------------------------------------------------------------------------
	SCS v2.1.3 - Splitting Conic Solver
	(c) Brendan O'Donoghue, Stanford University, 2012
----------------------------------------------------------------------------
Lin-sys: sparse-indirect, nnz in A = 55, CG tol ~ 1/iter^(2.00)
eps = 1.00e-05, alpha = 1.50, max_iters = 5000, normalize = 1, scale = 1.00
acceleration_lookback = 10, rho_x = 1.00e-03
Variables n = 19, constraints m = 53
Cones:	linear vars: 13
	soc vars: 4, soc blks: 1
	sd vars: 27, sd blks: 2
	exp vars: 9, dual exp vars: 0
Setup time: 6.76e-05s
----------------------------------------------------------------------------
 Iter | pri res | dua res | rel gap | pri obj | dua obj | kap/tau | time (s)
----------------------------------------------------------------------------
     0| 2.81e+19  2.40e+19  1.00e+00 -1.26e+20  4.84e+19  1.55e+20  7.41e-05 
    80| 3.56e-06  6.66e-06  6.04e-07 -4.09e+00 -4.09e+00  3.50e-17  4.42e-03 
----------------------------------------------------------------------------
Status: Solved
Timing: Solve time: 4.43e-03s
	Lin-sys: avg # CG iterations: 4.86, avg solve time: 1.66e-06s
	Cones: avg projection time: 4.55e-05s
	Acceleration: avg step time: 5.91e-06s
----------------------------------------------------------------------------
Error metrics:
dist(s, K) = 2.1945e-09, dist(y, K*) = 1.7850e-09, s'y/|s||y| = 5.9406e-12
primal res: |Ax + s - b|_2 / (1 + |b|_2) = 3.5589e-06
dual res:   |A'y + c|_2 / (1 + |c|_2) = 6.6559e-06
rel gap:    |c'x + b'y| / (1 + |c'x| + |b'y|) = 6.0362e-07
----------------------------------------------------------------------------
c'x = -4.0921, -b'y = -4.0921
============================================================================

julia> -objective_value(M_SDP), log(det(inv(value.(P))))
(-4.092065768181431, -4.09206772307858)

Everything is OK,but:
Julia> @constraint(M_SDP, [t; 1; lower_triangular(P)] in MOI.LogDetConeTriangle(3))
ERROR: UndefVarError: lower_triangular not defined
Stacktrace:
[1] top-level scope at C:\Users\ipso17.GXU.julia\packages\MutableArithmetics\DcLoq\src\rewrite.jl:279
[2] top-level scope at C:\Users\ipso17.GXU.julia\packages\JuMP\MIPb6\src\macros.jl:607
[3] top-level scope at none:1

Should be LowerTriangular?

Should be LowerTriangular?

No. It’s the function I wrote.

julia> lower_triangular(P) = [P[i, j] for i = 1:size(P, 1) for j = 1:i]

OK! Got it. Thank you very much~

1 Like