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

Revert "Support inequality syntax for HermitianPSDCone (#3256)" #3264

Merged
merged 1 commit into from
Mar 3, 2023
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
5 changes: 5 additions & 0 deletions docs/src/manual/complex.md
Original file line number Diff line number Diff line change
Expand Up @@ -275,3 +275,8 @@ julia> @constraint(model, H in HermitianPSDCone())
[x[1] (0.0 + 1.0im);
(0.0 - 1.0im) (-1.0 - 0.0im) x[2]] ∈ HermitianPSDCone()
```

!!! note
The matrix `H` in `H in HermitianPSDCone()` must be a `LinearAlgebra.Hermitian`
matrix type. A `build_constraint` error will be thrown if the matrix is
a different matrix type.
44 changes: 0 additions & 44 deletions src/sd.jl
Original file line number Diff line number Diff line change
Expand Up @@ -580,47 +580,3 @@ function build_constraint(
shape,
)
end

function build_constraint(
_error::Function,
Q::AbstractMatrix{<:AbstractJuMPScalar},
set::HermitianPSDCone,
)
if !LinearAlgebra.ishermitian(Q)
_error("the matrix is not Hermitian.")
end
return build_constraint(_error, LinearAlgebra.Hermitian(Q), set)
end

function build_constraint(
_error::Function,
Q::AbstractMatrix{<:AbstractJuMPScalar},
set::Union{MOI.GreaterThan,MOI.LessThan},
extra::HermitianPSDCone,
)
if !LinearAlgebra.ishermitian(Q)
_error("the matrix is not Hermitian.")
end
return build_constraint(_error, LinearAlgebra.Hermitian(Q), set, extra)
end

function build_constraint(
_error::Function,
f::LinearAlgebra.Hermitian{V,<:AbstractMatrix{V}},
s::MOI.GreaterThan,
extra::HermitianPSDCone,
) where {V<:AbstractJuMPScalar}
@assert iszero(s.lower)
return build_constraint(_error, f, extra)
end

function build_constraint(
_error::Function,
f::LinearAlgebra.Hermitian{V,<:AbstractMatrix{V}},
s::MOI.LessThan,
extra::HermitianPSDCone,
) where {V<:AbstractJuMPScalar}
@assert iszero(s.upper)
new_f = _MA.operate!!(*, -1, f)
return build_constraint(_error, new_f, extra)
end
56 changes: 2 additions & 54 deletions test/test_complex.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ using JuMP
using Test

import LinearAlgebra
import MutableArithmetics as MA
import MutableArithmetics
import SparseArrays

include(joinpath(@__DIR__, "utilities.jl"))
const MA = MutableArithmetics

function _test_dot(a, b)
@test LinearAlgebra.dot(a, b) == conj(a) * b
Expand Down Expand Up @@ -273,56 +273,4 @@ function test_isreal()
return
end

function test_complex_hermitian_constraint_nonhermitian_syntax()
model = Model()
@variable(model, x[1:2, 1:2])
@test_throws_strip(
ErrorException(
"In `@constraint(model, x in HermitianPSDCone())`: the matrix is " *
"not Hermitian.",
),
@constraint(model, x in HermitianPSDCone()),
)
H = [x[1, 1] x[1, 2]; x[1, 2] x[2, 2]]
@constraint(model, c, H in HermitianPSDCone())
@test constraint_object(c).func == [x[1, 1], x[1, 2], x[2, 2], 0]
return
end

function test_complex_hermitian_constraint_greaterthan_inequality_syntax()
model = Model()
@variable(model, x[1:2, 1:2])
H = LinearAlgebra.Hermitian(x)
@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]]"
@test_throws_strip(
ErrorException(
"In `@constraint(model, x >= 0, HermitianPSDCone())`: the matrix " *
"is not Hermitian.",
),
@constraint(model, x >= 0, HermitianPSDCone()),
)
return
end

function test_complex_hermitian_constraint_lessthan_inequality_syntax()
model = Model()
@variable(model, x[1:2, 1:2])
H = LinearAlgebra.Hermitian(x)
@constraint(model, c, 0 <= H, 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]]"
@test_throws_strip(
ErrorException(
"In `@constraint(model, 0 <= x, HermitianPSDCone())`: the matrix " *
"is not Hermitian.",
),
@constraint(model, 0 <= x, HermitianPSDCone()),
)
return
end

end