ApplyMap

From QETLAB
Jump to: navigation, search
ApplyMap
Applies a superoperator to an operator

Other toolboxes required none
Related functions PartialMap
Function category Superoperators

ApplyMap is a function that applies a superoperator to an operator. Both the superoperator and the operator may be either full or sparse.

Syntax

  • PHIX = ApplyMap(X,PHI)

Argument descriptions

  • X: A matrix.
  • PHI: A superoperator. Should be provided as either a Choi matrix, or as a cell with either 1 or 2 columns (see the tutorial page for more details about specifying superoperators within QETLAB).

Examples

A random example

The following code computes $\Phi(X)$, where $X = \begin{bmatrix}1 & 2 \\ 3 & 4\end{bmatrix}$ and $\Phi$ is the superoperator defined by $$ \Phi(X) = \begin{bmatrix}1 & 5 \\ 1 & 0 \\ 0 & 2\end{bmatrix}X\begin{bmatrix}0 & 1 \\ 2 & 3 \\ 4 & 5\end{bmatrix}^\dagger - \begin{bmatrix}1 & 0 \\ 0 & 0 \\ 0 & 1\end{bmatrix}X\begin{bmatrix}0 & 0 \\ 1 & 1 \\ 0 & 0\end{bmatrix}^\dagger. $$

>> X = [1 2;3 4];
>> Phi = {[1 5;1 0;0 2] [0 1;2 3;4 5];[-1 0;0 0;0 -1] [0 0;1 1;0 0]};
>> ApplyMap(X,Phi)
 
ans =
 
    22    95   174
     2     8    14
     8    29    64

Transpose map

The swap operator is the Choi matrix of the transpose map. Thus, the following code is a (rather slow and ugly) way of computing the transpose of a matrix:

>> X = reshape(1:9,3,3)
 
X =
 
     1     4     7
     2     5     8
     3     6     9
 
>> ApplyMap(X,SwapOperator(3))
 
ans =
 
     1     2     3
     4     5     6
     7     8     9

Of course, in practice you should just use MATLAB's built-in transposition operator X.'.

Source code

Click on "expand" to the right to view the MATLAB source code for this function.

  1. %%  APPLYMAP    Applies a superoperator to an operator
  2. %   This function has two required arguments:
  3. %     X: a matrix
  4. %     PHI: a superoperator
  5. %
  6. %   PHIX = ApplyMap(X,PHI) is the operator PHI(X). That is, it is the
  7. %   result of applying the superoperator PHI to the operator X. PHI should
  8. %   be provided either as a Choi matrix, or as a cell with either 1 or 2
  9. %   columns whose entries are its Kraus operators (see full QETLAB
  10. %   documentation for details).
  11. %
  12. %   This function has no optional arguments.
  13. %
  14. %   URL: http://www.qetlab.com/ApplyMap
  15.  
  16. %   requires: opt_args.m, PermuteSystems.m, Swap.m
  17. %   author: Nathaniel Johnston (nathaniel@njohnston.ca)
  18. %   package: QETLAB
  19. %   last updated: November 12, 2014
  20.  
  21. function PhiX = ApplyMap(X,Phi)
  22.  
  23. % Both of the following methods of applying the superoperator are much
  24. % faster than naively looping through Kraus operators or constructing
  25. % eigenvectors of a Choi matrix.
  26. if(iscell(Phi)) % the superoperator was given as a cell of Kraus operators
  27.     sPhi = size(Phi);
  28.     if(sPhi(2) == 1 || (sPhi(1) == 1 && sPhi(2) > 2)) % map is CP
  29.         Phi = Phi(:);
  30.         Phi(:,2) = cellfun(@ctranspose,Phi(:,1),'UniformOutput',false);
  31.     else
  32.         Phi(:,2) = cellfun(@ctranspose,Phi(:,2),'UniformOutput',false);
  33.     end
  34.     PhiX = cell2mat(Phi(:,1).')*kron(speye(size(Phi,1)),X)*cell2mat(Phi(:,2));
  35. else % the superoperator was given as a Choi matrix
  36.     sX = size(X);
  37.     sNX = size(Phi)./sX;
  38.     PhiX = kron(reshape(X,1,prod(sX)),speye(sNX(1)))*reshape(Swap(Phi.',[1,2],[sX(2) sNX(2);sX(1) sNX(1)],1).',sNX(1)*prod(sX),sNX(2));
  39. end
  40. if(~issparse(X))
  41.     PhiX = full(PhiX);
  42. end