mehdi-karimi-math / DDS

Domain-Driven Solver (DDS): a MATLAB-based software package for convex optimization problems
MIT License
3 stars 0 forks source link

Unrecognized field name "SDP_P" when constructing a basic SDP #3

Open JBurniston opened 8 months ago

JBurniston commented 8 months ago

Source code:

rhoR = [1,1i;-1i,1]/2;
rhoL = [1,-1i;1i,1]/2;

objective = blkdiag(2/3*rhoR+1/3*rhoL,0);

constraintA = eye(3);
constraintb = 1;

%% cvx
cvx_begin sdp

variable rho(3,3) hermitian semidefinite

maximize(trace(objective*rho))

trace(constraintA*rho) == constraintb;

cvx_end

A= cell(0);
b=cell(0);
c=cell(0);
cons=cell(0);

%% DDS

hermBasis = hermitianBasis(3).';

% LP
cons{1,1} = "LP";
cons{1,2} = [1,1];

tempA = cellfun(@(x)trace(constraintA*x),hermBasis);

A{1} = [tempA;-tempA];
b{1} = [-constraintb;constraintb];

%SDP >=0
cons{2,1} = "SDP";
cons{2,2} = 3;

tempA = cell2mat(cellfun(@sm2vec,hermBasis,"UniformOutput",false));

A{2,1} = tempA;
b{2,1} = sm2vec(zeros(3));

% objective
c{1,1} = cellfun(@(x) -trace(objective*x),hermBasis);

[rhoVec,y,info] = DDS(c,A,b,cons);

rhoDDS = sum(cat(3,hermBasis{:}),3);

Error message:

Unrecognized field name "SDP_P".

Error in hessian_V

Error in predictor_corrector_3

Error in DDS

Error in problemDDSSDP (line 55)
[rhoVec,y,info] = DDS(c,A,b,cons);

the hermitianBasis function is:

function basis = hermitianBasis(dim)
% hermitianBasis Creates a basis of hermitian observables of dimension dim.
%
% Inputs:
% * dim: The dimension of the matrices in the basis

    basis = cell(dim,dim);
    % diagonal entries
    for i = 1:dim
        vec = zeros(dim);
        vec(i,i) = 1;
        basis{i,i} = vec;
    end

    % other entries
    for i = 2:dim
        for j = 1:i-1
            vec = zeros(dim);
            vec(i,j) = 1;
            vec(j,i) = 1;
            basis{i,j} = vec/sqrt(2);

            vec = zeros(dim);
            vec(i,j) = 1i;
            vec(j,i) = -1i;
            basis{j,i} = vec/sqrt(2);
        end
    end

    basis = basis(:);

end
mehdi-karimi-math commented 8 months ago

@JBurniston thanks for the comments. The error is because the current version of DDS does not accept Hermitian complex matrices. You have to reformulate your problem into a real version. I will add an error message to check this in the input.

JBurniston commented 8 months ago

@mehdi-karimi-math Do you have any plans to support complex variables?

mehdi-karimi-math commented 8 months ago

@JBurniston, We do not plan to change the algorithms yet, but we plan to add DDS to one of the modeling languages, such as YALMIP, so they transform a given problem with complex data into the DDS format. Similar to using CVX; as far as I know, SDPT3, for example, does not accept complex matrices, but CVX reformulates the problem into a real-valued one.