Fidelity
Fidelity | |
Computes the fidelity of two density matrices | |
Other toolboxes required | none |
---|---|
Related functions | TraceNorm |
Function category | Norms and distance measures |
Fidelity is a function that computes the fidelity between two quantum states $\rho$ and $\sigma$, defined as follows: \[F(\rho,\sigma) := \mathrm{Tr}\Big( \sqrt{ \sqrt{\rho}\sigma\sqrt{\rho}}\Big).\]
Note that, in some sources, "fidelity" refers to the square of this quantity.
Contents
Syntax
- FID = Fidelity(RHO,SIGMA)
Argument descriptions
- RHO: A density matrix.
- SIGMA: A density matrix.
Examples
Pure states
If $\rho = |v\rangle\langle v|$ and $\sigma = |w\rangle\langle w|$ are both pure states then their fidelity simply equals $\big|\langle v|w \rangle\big|$:
>> v = RandomStateVector(4); >> w = RandomStateVector(4); >> Fidelity(v*v',w*w') ans = 0.6486 >> abs(v'*w) ans = 0.6486
Can be used with CVX
The fidelity function is a jointly concave function, and it can be used in the objective function or constraints of a CVX optimization problem. For example, the following code computes the maximum output fidelity of two quantum channels:
>> Phi = RandomSuperoperator(3); % generate a random channel >> Psi = RandomSuperoperator(3); % generate another one >> cvx_begin sdp quiet variable rho(3,3) hermitian; variable sigma(3,3) hermitian; maximize Fidelity(ApplyMap(rho,Phi),ApplyMap(sigma,Psi)) subject to % the constraints here just force rho and sigma to be density matrices trace(rho) == 1; trace(sigma) == 1; rho >= 0; sigma >= 0; cvx_end >> cvx_optval cvx_optval = 0.9829
Of course, in this case it is more convenient to just use the MaximumOutputFidelity function directly:
>> MaximumOutputFidelity(Phi,Psi) ans = 0.9829
Source code
Click on "expand" to the right to view the MATLAB source code for this function.
%% FIDELITY Computes the fidelity of two density matrices
% This function has two required input arguments:
% RHO,SIGMA: density matrices
%
% FID = Fidelity(RHO,SIGMA) is the fidelity between the two density
% matrices RHO and SIGMA, defined by ||sqrt(RHO)*sqrt(SIGMA)||_1, where
% ||.||_1 denotes the trace norm. FID is a value between 0 and 1, with 0
% corresponding to matrices RHO and SIGMA with orthogonal support, and 1
% corresponding to the case RHO = SIGMA.
%
% URL: http://www.qetlab.com/Fidelity
% requires: nothing (only uses CVX if called as an input to CVX)
% authors: Vincent Russo (vrusso@uwaterloo.ca)
% Nathaniel Johnston (nathaniel@njohnston.ca)
% package: QETLAB
% last updated: November 21, 2014
function fid = Fidelity(rho,sigma)
sz_rho = size(rho);
% Do some error checking.
if(~all(sz_rho == size(sigma)))
error('Fidelity:InvalidDims','RHO and SIGMA must be matrices of the same size.');
elseif(sz_rho(1) ~= sz_rho(2))
error('Fidelity:InvalidDims','RHO and SIGMA must be square.');
end
% If rho or sigma is a CVX variable then compute fidelity via semidefinite
% programming, so that this function can be used in the objective function
% or constraints of other CVX optimization problems.
if(isa(rho,'cvx') || isa(sigma,'cvx'))
cvx_begin sdp quiet
variable X(sz_rho(1),sz_rho(1)) complex;
maximize trace(X) + trace(X');
subject to
cons = [rho,X;X',sigma];
cons + cons' >= 0; % avoid some numerical problems: CVX often thinks things aren't symmetric without this
cvx_end
fid = cvx_optval/2;
% If rho and sigma are *not* CVX variables, compute fidelity normally,
% since this is much faster.
else
[sq_rho,res] = sqrtm(rho); % need "res" parameter to suppress MATLAB singularity warning
[sq_fid,res] = sqrtm(sq_rho*sigma*sq_rho);
fid = real(trace(sq_fid)); % finally, compute the fidelity
end