Code accompanying the manuscript Nature Communications 12, 4411 (2021) (arXiv:2010.11942).
The MATLAB code below serves as an example of how the measures $R_{\mathbb{O}}$ and $W_{\mathbb{O}}$ can be computed in relevant settings. The implementation requires CVX.
In the case of communication assisted by no-signalling correlations, $\mathbb{O}$ is the set of replacement (constant) channels. The example code below takes as an input the (unnormalized) Choi matrix J
of a channel and a vector dim
of the form [dA, dB]
indicating the input and output dimensions of the given channel. The dimensions are assumed to be equal if not provided.
function [cvx_optval,X] = Rob_NS(J, dim)
if nargin < 2
dim = [1,1]*sqrt(size(J,1));
end
cvx_begin sdp quiet
variable sigm(dim(2),dim(2)) hermitian semidefinite
J <= kron( eye(dim(1)), sigm )
minimize trace(sigm)
cvx_end
X = kron( eye(dim(1)), sigm );
end
function [cvx_optval,X] = Weight_NS(J, dim)
if nargin < 2
dim = [1,1]*sqrt(size(J,1));
end
cvx_begin sdp quiet
variable sigm(dim(2),dim(2)) hermitian semidefinite
J >= kron( eye(dim(1)), sigm )
maximize trace(sigm)
cvx_end
X = kron( eye(dim(1)), sigm );
end
In the case of magic, we choose $\mathbb{O}$ as the set of completely stabilizer-preserving operations, in which case we can compute the measures by optimizing over the set of stabilizer states. The implementations below take three arguments: the (unnormalized) Choi matrix J
of the channel, a matrix T
whose columns are all of the stabilizer states in the given dimension (as pure state vectors), and a vector dim
of the form [dA, dB]
indicating the input and output dimensions of the given channel. The last argument is optional, with the dimension assumed to be equal if not provided. The T
matrices for 1-4 qubits are provided below — this allows the computation of the measures for general channels from $n$ to $m$ qubits where $n+m \leq 4$, or for special cases of channels which can be realized through state injection of a state of up to 4 qubits, such as diagonal Clifford gates from the third level of the Clifford hierarchy (see manuscript).
The code uses the helper function PartialTrace
from QETLAB.
Download auxiliary files:
function [cvx_optval, x] = Rob_mag(J, T, dim)
if nargin < 3
dim = [1,1]*sqrt(size(J,1));
end
k = size(T,2);
cvx_begin sdp quiet
variable x(k) nonnegative
variable t
Z = T*diag(x)*T';
PartialTrace(Z,2,dim) == t*eye(dim(1))
J <= Z
minimize sum(x)/dim(1)
cvx_end
end
function [cvx_optval, x] = Weight_mag(J, T, dim)
if nargin < 3
dim = [1,1]*sqrt(size(J,1));
end
k = size(T,2);
cvx_begin sdp quiet
variable x(k) nonnegative
variable t
Z = T*diag(x)*T';
PartialTrace(Z,2,dim) == t*eye(dim(1))
J >= Z
maximize sum(x)/dim(1)
cvx_end
end
To compute the measures for states, it suffices to remove the constraint PartialTrace(Z,2,dim) == t*eye(dim(1))
and remove dim(1)
from the objective function (see also the code for state-based measures of magic).