Code accompanying the manuscripts Phys. Rev. Lett. **128**, 110505 (2022) (arXiv:2109.04481) and Quantum **6**, 817 (2022) (arXiv:2112.11321).

We show how the computation of the projective robustness $\Omega_{\mathbb{F}}$ as well as the optimisation problems $\Xi_{\varepsilon}$ and $\Theta_{\varepsilon}$ that appear in the latter manuscript can be implemented in MATLAB using CVX. We consider a few representative resource theories.

The free states $\mathbb{F}$ here are all quantum states with a positive partial transpose. The projective robustness $\Omega_{\mathbb{F}}$ is then implemented as follows. The code uses the helper function `PartialTranspose`

from QETLAB, and for simplicity we assume that the two constituent subsystems are of equal dimension. In addition to the optimal value and an optimal primal solution, the program returns optimal dual variables `A`

and `B`

(following notation in the manuscript).

```
function [cvx_optval,F,A,B] = ProjRobPPT(rho)
d = size(rho,1);
cvx_begin sdp quiet
variable F(d,d) hermitian semidefinite
variable gam nonnegative
dual variable A
dual variable B
A: rho <= F
B: F <= gam*rho
PartialTranspose(F) >= 0;
minimize gam
cvx_end
end
```

One can similarly implement the problems $\Xi_\varepsilon$ (maximal probability of success for a fixed distillation error $\varepsilon$) and $\Theta_p$ (minimal distillation error for a fixed probability of success). We denote them by `XiPPT`

and `ThetaPPT`

, respectively.

```
function [cvx_optval,W,Z] = XiPPT(rho, k, err)
d = size(rho,1);
cvx_begin sdp quiet
variable W(d,d) hermitian semidefinite
variable Z(d,d) hermitian semidefinite
variable Q(d,d) hermitian semidefinite
W <= Z <= eye(d)
trace(W*rho) == (1-err)*trace(Z*rho)
Z/k - W >= PartialTranspose(Q)
maximize trace(Z*rho)
cvx_end
end
```

```
function [cvx_optval,W,Z] = ThetaPPT(rho, k, p)
d = size(rho,1);
cvx_begin sdp quiet
variable W(d,d) hermitian semidefinite
variable Z(d,d) hermitian semidefinite
variable Q(d,d) hermitian semidefinite
W <= Z <= eye(d)
trace(Z*rho) == p
Z/k - W >= PartialTranspose(Q)
maximize trace(W*rho)/p
cvx_end
end
```

Here, we used the fact that the dual cone of the set of all PPT states — the union of the dual cones of the set of all states and the set of all PPT (Hermitian) operators — is formed by operators of the form `P + Q`

, where `P`

is a PSD matrix and `Q`

is a matrix such that `PartialTranspose(Q)`

is PSD.

Let us begin with the resource theory of coherence, where the free states $\mathbb{F}$ are all states whose density matrix is diagonal in the given basis. The implementation of the projective robustness is done very similarly.

```
function [cvx_optval,F,A,B] = ProjRobCoh(rho)
d = size(rho,1);
cvx_begin sdp quiet
variable F(d,d) hermitian semidefinite
variable gam nonnegative
dual variable A
dual variable B
A: rho <= F
B: F <= gam*rho
F == diag(diag(F))
minimize gam
cvx_end
end
```

To apply the above to the resource theory of imaginarity (where the free states are those whose density matrix has only real elements in the given basis), it suffices to replace `diag(diag(...))`

with `real(...)`

.

In the quantification of achievable probabilities/errors, care needs to be taken to impose strict equality in line with the definition of the problems $\Xi_\varepsilon^{\mathrm{aff}}$ and $\Theta_p^{\mathrm{aff}}$.

```
function [cvx_optval,W,Z] = XiCoh(rho, k, err)
d = size(rho,1);
cvx_begin sdp quiet
variable W(d,d) hermitian semidefinite
variable Z(d,d) hermitian semidefinite
W <= Z <= eye(d)
trace(W*rho) >= (1-err)*trace(Z*rho)
diag(diag(Z/k - W)) == 0
maximize trace(Z*rho)
cvx_end
end
```

```
function [cvx_optval,W,Z] = ThetaCoh(rho, k, p)
d = size(rho,1);
cvx_begin sdp quiet
variable W(d,d) hermitian semidefinite
variable Z(d,d) hermitian semidefinite
W <= Z <= eye(d)
trace(Z*rho) == p
diag(diag(Z/k - W)) == 0
maximize trace(W*rho)/p
cvx_end
end
```

Evaluating the projective robustness for the theory of magic states proceeds slightly differently. Here, in addition to the input state `rho`

, the function takes as an input argument a matrix `T`

whose columns are the pure stabiliser states of the same dimension as the input state. Any free state can then be written as `T*X*T'`

where `X`

is a diagonal matrix whose diagonal entries $x_{ii}$ satisfy $x_{ii} \geq 0$, $\sum_i x_{ii} = 1$.

The `T`

matrices for systems of 1-4 qubits can be downloaded here:

The following MATLAB program then computes $\Omega_{\mathbb{F}}(\rho)$.

```
function [cvx_optval,F,A,B,x] = ProjRobMag(rho, T)
d = size(rho,1);
cvx_begin sdp quiet
variable x(size(T,2)) nonnegative
variable gam nonnegative
dual variable A
dual variable B
F = T*diag(x)*T';
A: rho <= F
B: F <= gam*rho
minimize gam
cvx_end
end
```

The quantities $\Xi_\varepsilon$ (maximal probability of success for a fixed distillation error $\varepsilon$) and $\Theta_p$ (minimal distillation error for a fixed probability of success) are computed analogously. Note once again the additional argument `T`

.

```
function [cvx_optval,W,Z] = XiMag(rho, k, err, T)
d = size(rho,1);
cvx_begin sdp quiet
variable W(d,d) hermitian semidefinite
variable Z(d,d) hermitian semidefinite
variable Q(d,d) hermitian semidefinite
W <= Z <= eye(d)
trace(W*rho) >= (1-err)*trace(Z*rho)
for j=1:size(T,2)
T(:,j)'*(Z/k - W)*T(:,j) >= 0
end
maximize trace(Z*rho)
cvx_end
end
```

```
function [cvx_optval,W,Z] = ThetaMag(rho, k, p, T)
d = size(rho,1);
cvx_begin sdp quiet
variable W(d,d) hermitian semidefinite
variable Z(d,d) hermitian semidefinite
variable Q(d,d) hermitian semidefinite
W <= Z <= eye(d)
trace(Z*rho) == p
for j=1:size(T,2)
T(:,j)'*(Z/k - W)*T(:,j) >= 0
end
maximize trace(W*rho)/p
cvx_end
end
```