Hi community, I am having issues inputting the following problem into Convex.jl
where \Sigma and S_1,...,S_m are positive definite matrices of appropriate dimensions. The syntax diag(x_1S_1,...,x_mS_m) in the constraint specifies a block-diagonal matrix.
My code so far:
using LinearAlgebra
using Convex
using Hypatia
using BlockDiagonals
function solve_SDP(Σ::Matrix{Float64}, S::Vector{Matrix{Float64}})
x = Variable(length(S))
add_constraint!(x, x ≥ 0)
add_constraint!(x, x ≤ 1)
current_blocks = BlockDiagonal(x .* S)
constraint = Symmetric(2Σ - current_blocks) in :SDP
problem = maximize(sum(x), constraint)
solve!(problem, Hypatia.Optimizer)
return evaluate(x)
end
Σ = 0.5 * Matrix(I, 100, 100) + 0.5 * ones(100, 100)
S = [0.5 * Matrix(I, 10, 10) + 0.5 * ones(10, 10) for _ in 1:10]
solve_SDP(Σ, S)
throws this error
MethodError: no method matching ispos(::Vector{Matrix{Float64}})
Closest candidates are:
ispos(::Real) at /home/users/bbchu/.julia/packages/Convex/FQF1R/src/constant.jl:6
ispos(::AbstractVecOrMat{var"#s52"} where var"#s52"<:Real) at /home/users/bbchu/.julia/packages/Convex/FQF1R/src/constant.jl:7
I get the same error if I convert current_blocks to a Matrix{Float64}.
It looks like there’s no good way to achieve this in Convex.jl. It uses an expression-graph representation of the problem, so it seems like it has some problems with using an arbitrary matrix type like BlockDiagonal.
Here’s how I’d write it in JuMP:
using JuMP, LinearAlgebra, BlockDiagonals, Hypatia
m, n = 4, 2
model = Model(Hypatia.Optimizer)
Σ = 0.5 * Matrix(I, m, m) + 0.5 * ones(m, m)
S = [0.5 * Matrix(I, n, n) + 0.5 * ones(n, n) for _ in 1:n]
@variable(model, 0 <= x[1:n] <= 1)
blocks = Matrix(BlockDiagonal([x[i] * S[i] for i in 1:n]))
@constraint(model, Symmetric(2 * Σ - blocks) in PSDCone())