Dear all,
I have encountered a somewhat unintuitive error in creating the following semidefinte constraint in JuMP.jl. Sample code is as follows:
# Create a JuMP model
model = Model(optimizer_with_attributes(Mosek.Optimizer))
# Add the variables
@variable(model, G[1:13, 1:13], PSD)
A = [0.0 0.0 0.0 0.0 0.0; 0.0 0.0 0.0 0.0 0.0; 0.0 0.0 0.0 0.0 0.0; 0.0 0.0 0.0 0.0 0.0; 0.0 0.0 0.0 0.0 0.0; 0.0 0.0 0.0 0.0 0.0; 0.0 0.0 0.0 0.0 0.0; 0.0 0.0 0.0 0.0 0.0; 1.0 0.0 0.0 0.0 0.0; 0.0 1.0 0.0 0.0 0.0; 0.0 0.0 1.0 0.0 0.0; 0.0 0.0 0.0 1.0 0.0; 0.0 0.0 0.0 0.0 1.0]
# Want to enforce the constraint -A'GA ⪰ 0
@constraint(model, -A' * G * A >= 0, PSDCone())
The last line results in the following error:
ERROR: DimensionMismatch: array could not be broadcast to match destination
Stacktrace:
[1] check_broadcast_shape
@ .\broadcast.jl:579 [inlined]
[2] check_broadcast_shape
@ .\broadcast.jl:580 [inlined]
[3] check_broadcast_axes
@ .\broadcast.jl:582 [inlined]
[4] instantiate
@ .\broadcast.jl:309 [inlined]
[5] materialize!
@ .\broadcast.jl:914 [inlined]
[6] materialize!
@ .\broadcast.jl:911 [inlined]
[7] operate!(::typeof(*), x::Matrix{AffExpr}, y::Matrix{Float64})
@ MutableArithmetics C:\Users\shuvo\.julia\packages\MutableArithmetics\2vhhw\src\rewrite_generic.jl:9
[8] operate_fallback!!
@ MutableArithmetics C:\Users\username\.julia\packages\MutableArithmetics\2vhhw\src\interface.jl:601 [inlined]
[9] operate!!(::typeof(*), ::Matrix{AffExpr}, ::Matrix{Float64})
@ MutableArithmetics C:\Users\username\.julia\packages\MutableArithmetics\2vhhw\src\interface.jl:585
[10] macro expansion
@ C:\Users\username\.julia\packages\MutableArithmetics\2vhhw\src\rewrite.jl:321 [inlined]
[11] macro expansion
@ C:\Users\username\.julia\packages\JuMP\kSaGf\src\macros.jl:257 [inlined]
[12] macro expansion
@ C:\Users\username\.julia\packages\JuMP\kSaGf\src\macros\@constraint.jl:131 [inlined]
[13] macro expansion
@ C:\Users\username\.julia\packages\JuMP\kSaGf\src\macros.jl:393 [inlined]
[14] top-level scope
@ c:\Users\username\test.jl:147
The error goes away if I explicitly describe what -A
means by rewriting the constraint:
@constraint(model, ((-1) .* A' * G * A) >= 0, PSDCone())
My question is if this DimensionMismatch
error is expected behavior or not. I would assume that intuitively JuMP
or Julia
should interpret -A
as (-1).*A
. Please let me know if I am missing something.