All of the examples can be found in Jupyter notebook form here.

# Fidelity in quantum information theory

This example is inspired from a lecture of John Watrous in the course on Theory of Quantum Information.

The Fidelity between two Hermitian semidefinite matrices P and Q is defined as:

$F(P, Q) = \|P^{1/2}Q^{1/2}\|_{\text{tr}} = \max_U \mathrm{tr}(P^{1/2}U Q^{1/2})$

where the trace norm $\|\cdot\|_{\text{tr}}$ is the sum of the singular values, and the maximization goes over the set of all unitary matrices U. This quantity can be expressed as the optimal value of the following complex-valued SDP:

$\begin{array}{ll} \mbox{maximize} & \frac{1}{2}\text{tr}(Z+Z^\dagger) \\ \mbox{subject to} &\\ & \left[\begin{array}{cc}P&Z\\{Z}^{\dagger}&Q\end{array}\right] \succeq 0\\ & Z \in \mathbf {C}^{n \times n}\\ \end{array}$
using Convex, SCS, LinearAlgebra
if VERSION < v"1.2.0-DEV.0"
LinearAlgebra.diagm(v::AbstractVector) = diagm(0 => v)
end

n = 20
P = randn(n,n) + im*randn(n,n)
P = P*P'
Q = randn(n,n) + im*randn(n,n)
Q = Q*Q'
Z = ComplexVariable(n,n)
objective = 0.5*real(tr(Z+Z'))
constraint = [P Z;Z' Q] ⪰ 0
problem = maximize(objective,constraint)
solve!(problem, SCSSolver(verbose=0))
computed_fidelity = evaluate(objective)
580.3070861227797
# Verify that computer fidelity is equal to actual fidelity
P1,P2 = eigen(P)
sqP = P2 * diagm([p1^0.5 for p1 in P1]) * P2'
Q1,Q2 = eigen(Q)
sqQ = Q2 * diagm([q1^0.5 for q1 in Q1]) * Q2'
20×20 Array{Complex{Float64},2}:
5.61705+1.11022e-16im  …    0.700195+0.60619im
0.49492+0.185839im          0.313627+0.196467im
0.481404+0.115272im         -0.364561+0.843019im
-0.0974573+0.189815im         -0.279087+0.715268im
-0.00589191+0.720583im         -0.115346-1.01428im
0.149646-0.730849im     …   -0.271959-0.318572im
0.903574-0.464682im          0.602452-0.345557im
0.0731664-0.0349363im        -0.146864+0.630165im
-0.263928-0.090138im         -0.239118-0.364574im
0.20019+0.350791im         -0.882568+0.846959im
0.230249-0.608196im     …   -0.247886+0.832007im
-0.645344-0.0114094im         0.379073+0.429442im
0.495238+0.317661im        -0.0670969+0.160112im
-0.562143-0.0413663im        -0.700676+0.265533im
0.546403+0.944105im         -0.622406-0.438829im
-0.360621-0.92215im      …    0.299766+0.865221im
-0.0432292-0.207528im          0.589368+0.384068im
-0.288301+0.20771im          -0.313043+0.461881im
0.736124-0.5545im            0.517316+0.284041im
0.700195-0.60619im            5.58108+0.0im     
actual_fidelity = sum(svdvals(sqP * sqQ))
580.3076315691303

We can see that the actual fidelity value is very close the computed fidelity value.