Skip to content

Commit

Permalink
Add support for Hermitian PSD in conic inequality (#3705)
Browse files Browse the repository at this point in the history
  • Loading branch information
blegat authored Mar 9, 2024
1 parent a024e28 commit d7c45a9
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/macros/@constraint.jl
Original file line number Diff line number Diff line change
Expand Up @@ -674,6 +674,12 @@ function _functionize(
return LinearAlgebra.Symmetric(_functionize(v.data))
end

function _functionize(
v::LinearAlgebra.Hermitian{V},
) where {V<:AbstractVariableRef}
return LinearAlgebra.Hermitian(_functionize(v.data))
end

_functionize(x) = x

_functionize(::_MA.Zero) = false
Expand Down
2 changes: 2 additions & 0 deletions src/sd.jl
Original file line number Diff line number Diff line change
Expand Up @@ -774,6 +774,7 @@ function build_constraint(
MOI.AbstractSymmetricMatrixSetTriangle,
MOI.AbstractSymmetricMatrixSetSquare,
PSDCone,
HermitianPSDCone,
},
)
return build_constraint(error_fn, f, extra)
Expand All @@ -787,6 +788,7 @@ function build_constraint(
MOI.AbstractSymmetricMatrixSetTriangle,
MOI.AbstractSymmetricMatrixSetSquare,
PSDCone,
HermitianPSDCone,
},
)
new_f = _MA.operate!!(*, -1, f)
Expand Down
17 changes: 17 additions & 0 deletions test/test_complex.jl
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,23 @@ function test_complex_hermitian_constraint()
return
end

function test_complex_hermitian_inequality_constraint()
model = Model()
@variable(model, x[1:2, 1:2])
H = LinearAlgebra.Hermitian(x)
@test vectorize(H, HermitianMatrixShape(2)) ==
[x[1, 1], x[1, 2], x[2, 2], 0.0]
@constraint(model, c, H >= 0, HermitianPSDCone())
@test constraint_object(c).func == [x[1, 1], x[1, 2], x[2, 2], 0.0]
@test function_string(MIME("text/plain"), constraint_object(c)) ==
"[x[1,1] x[1,2];\n x[1,2] x[2,2]]"
@constraint(model, c2, 0 <= H, HermitianPSDCone())
@test constraint_object(c2).func == [x[1, 1], x[1, 2], x[2, 2], 0.0]
@test function_string(MIME("text/plain"), constraint_object(c2)) ==
"[x[1,1] x[1,2];\n x[1,2] x[2,2]]"
return
end

function test_isreal()
model = Model()
@variable(model, x[1:2])
Expand Down

0 comments on commit d7c45a9

Please sign in to comment.