Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for Hermitian PSD for conic inequality #3705

Merged
merged 3 commits into from
Mar 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading