Hi, I’m trying to solve a SDP with quadratic constraints and I get the following error
Unable to transform a quadratic constraint into a second-order cone constraint because the quadratic constraint is not strongly convex.
and my code is
using JuMP
using SCS
function anticommutator(ps1, ps2)
pstr = []
msigns = 0
m = 1
for (i, j) in zip(ps1, ps2)
if i == j
push!(pstr, 'I')
elseif i == 'I'
push!(pstr, j)
elseif j == 'I'
push!(pstr, i)
elseif i == 'X' && j == 'Y'
push!(pstr, 'Z')
msigns += 1
elseif i == 'X' && j == 'Z'
push!(pstr, 'Y')
msigns += 1
m += 1
elseif i == 'Y' && j == 'Z'
push!(pstr, 'X')
msigns += 1
elseif i == 'Y' && j == 'X'
push!(pstr, 'Z')
msigns += 1
m += 1
elseif i == 'Z' && j == 'X'
push!(pstr, 'Y')
msigns += 1
elseif i == 'Z' && j == 'Y'
push!(pstr, 'X')
msigns += 1
m += 1
end
end
if msigns % 2 == 0
m % 2, reduce(*, pstr)
else
(0, "")
end
end
function matrix_element(idx1, idx2, xm)
pstr1, s1 = idx1
pstr2, s2 = idx2
k = length(pstr1)
if s1 > s2
s1, s2 = s2, s1
pstr1, pstr2, = pstr2, pstr1
end
dist = s2 - s1
if k < dist
return -(xm[idx2] * xm[idx1])
end
relstr1 = rpad(pstr1[1+dist:end], k, 'I')
relstr2 = lpad(pstr2[1:k-dist], k, 'I')
sgn, str = anticommutator(relstr1, relstr2)
if str == "" || all(split(str, "") .== "I")
return -(xm[idx1] * xm[idx2])
end
if str[1] == 'I'
str = rpad(str[2:end], k, 'I')
end
sgn = (-1) ^ sgn
sgn * xm[(str, s2)] -(xm[idx1] * xm[idx2])
end
N = 3
K = 2
J = 0.3
h = 0.1
model = Model(SCS.Optimizer)
operators = ['X', 'Y', 'Z', 'I']
sites = [i for i=1:N]
indices = collect(
Iterators.product(map(x -> reduce(*, x), collect(Iterators.product([i == 1 ? operators[1:3] : operators for i=1:K]...))), sites)
)
indices = reshape(indices, :)
n_ops = N * ((length(operators) - 1) * length(operators) ^(K-1))
if length(indices) != n_ops
ArgumentError("The indices do not match the number of operators")
end
@variable(model, X[1:n_ops])
@variable(model, M[1:n_ops, 1:n_ops], PSD)
Xm = Containers.DenseAxisArray(X, indices)
Mm = Containers.DenseAxisArray(M, indices, indices)
@constraint(model, c[i in indices, j in indices], Mm[i, j] == matrix_element(i, j, Xm))
@objective(model, Min, h * sum(Xm[("XI", i)] for i=1:N) + J * sum(Xm[("ZZ", i)] for i=1:N-1))
optimize!(model)
I saw here that it is not possible to express non-convex terms as convex.
Is there a transformation I can do so that I’d be able to optimize the model?
Thanks for any help!