Download Matlab file:
The computation of the fidelity of one-shot distillation of a single bit of coherence under SIO corresponds to evaluating a semidefinite program, as per the manuscript. The implementation below uses CVX and returns both the primal and dual optimal variables, with notation consistent with the paper.
function [fid,X,D,N] = fid_sio(rho)
d = size(rho,2);
if d==1
rho=rho*rho';
d=size(rho,1);
end
rho=(rho+rho')/2; % to avoid numerical problems
cvx_begin sdp quiet
variable X(d,d) hermitian
dual variable D
dual variable N
X>= -eye(d)
X<= eye(d)
D: diag(X) == 0
N: X(:) == nonnegative(d^2)
maximize (trace(abs(rho)*X))
cvx_end
fid = (cvx_optval+1)/2;
D = sparse(diag(D));
N = reshape(N, [d,d]);
N = (N + N')/2;
end