PartialMap

From QETLAB
Jump to: navigation, search
PartialMap
Applies a superoperator to a subsystem of an operator

Other toolboxes required none
Related functions ApplyMap
PartialTrace
PartialTranspose
Function category Superoperators

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

Syntax

  • PHIX = PartialMap(X,PHI)
  • PHIX = PartialMap(X,PHI,SYS)
  • PHIX = PartialMap(X,PHI,SYS,DIM)

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).
  • SYS (optional, default 2): The subsystem that the superoperator will be applied to.
  • DIM (optional, default has X acting on two subsystems of equal dimension): A vector containing the dimensions of the (possibly more than 2) subsystems on which X acts.

Examples

A random example

The following code applies the completely depolarizing channel to the second subsystem of a random density matrix:

>> rho = RandomDensityMatrix(4)
 
rho =
 
   0.3101            -0.0220 - 0.0219i  -0.0671 - 0.0030i  -0.0170 - 0.0694i
  -0.0220 + 0.0219i   0.1008            -0.0775 + 0.0492i  -0.0613 + 0.0529i
  -0.0671 + 0.0030i  -0.0775 - 0.0492i   0.1361             0.0602 + 0.0062i
  -0.0170 + 0.0694i  -0.0613 - 0.0529i   0.0602 - 0.0062i   0.4530          
 
>> Phi = {[1 0;0 0]/sqrt(2);[0 1;0 0]/sqrt(2);[0 0;1 0]/sqrt(2);[0 0;0 1]/sqrt(2)};
>> PartialMap(rho,Phi)
 
ans =
 
   0.2054                  0            -0.0642 + 0.0250i        0          
        0             0.2054                  0            -0.0642 + 0.0250i
  -0.0642 - 0.0250i        0             0.2946                  0          
        0            -0.0642 - 0.0250i        0             0.2946

And the following code instead applies the same map to the first subsystem:

>> PartialMap(rho,Phi,1)
 
ans =
 
   0.2231             0.0191 - 0.0079i        0                  0          
   0.0191 + 0.0079i   0.2769                  0                  0          
        0                  0             0.2231             0.0191 - 0.0079i
        0                  0             0.0191 + 0.0079i   0.2769

Source code

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

  1. %%  PARTIALMAP    Applies a superoperator to a subsystem of an operator
  2. %   This function has two required arguments:
  3. %     X: a matrix
  4. %     PHI: a superoperator
  5. %
  6. %   PHIX = PartialMap(X,PHI) is the operator (id \otimes PHI)(X). That is,
  7. %   it is the result of applying the superoperator PHI to the second
  8. %   subsystem of X, which is assumed to act on two subsystems of equal
  9. %   dimension (if this is not the case, see the optional arguments below).
  10. %   PHI should be provided either as a Choi matrix, or as a cell with
  11. %   either 1 or 2 columns whose entries are its Kraus operators (see full
  12. %   QETLAB documentation for details).
  13. %
  14. %   This function has two optional arguments:
  15. %     SYS (default 2)
  16. %     DIM (default has two subsystems of equal dimension)
  17. %
  18. %   PHIX = PartialMap(X,PHI,SYS,DIM) is the result of applying the
  19. %   superoperator PHI to the SYS subsystem of X, where the dimensions of
  20. %   the (possibly more than 2) subsystems that X acts on are given in the
  21. %   vector DIM.
  22. %
  23. %   URL: http://www.qetlab.com/PartialMap
  24.  
  25. %   requires: ApplyMap.m, iden.m, MaxEntangled.m, opt_args.m,
  26. %             PermuteSystems.m, Swap.m
  27. %
  28. %   author: Nathaniel Johnston (nathaniel@njohnston.ca)
  29. %   package: QETLAB
  30. %   last updated: February 21, 2014
  31.  
  32. function PhiX = PartialMap(X,Phi,varargin)
  33.  
  34. dX = size(X);
  35.  
  36. % Set optional argument defaults: sys=2, dim=sqrt(length(X))
  37. [sys,dim] = opt_args({ 2, round(sqrt(dX)).'*ones(1,2) },varargin{:});
  38.  
  39. % allow the user to enter a single number for dim
  40. if(length(dim) == 1)
  41.     dim = [dim,dX(1)/dim];
  42.     if abs(dim(2) - round(dim(2))) >= 2*dX(1)*eps
  43.         error('PartialMap:InvalidDim','If DIM is a scalar, X must be square and DIM must evenly divide length(X); please provide the DIM array containing the dimensions of the subsystems.');
  44.     end
  45.     dim(2) = round(dim(2));
  46. end
  47.  
  48. % allow the user to enter a vector for dim if X is square
  49. if(min(size(dim)) == 1)
  50.     dim = dim(:)'; % force dim to be a row vector
  51.     dim = [dim;dim];
  52. end
  53.  
  54. % Compute the dimensions of the auxiliary subsystems.
  55. prod_dim_r1 = prod(dim(1,1:sys-1));
  56. prod_dim_c1 = prod(dim(2,1:sys-1));
  57. prod_dim_r2 = prod(dim(1,sys+1:end));
  58. prod_dim_c2 = prod(dim(2,sys+1:end));
  59.  
  60. if(iscell(Phi)) % the superoperator was provided as a cell of Kraus operators
  61.     % Compute the Kraus operators on the full system.
  62.     sPhi = size(Phi);
  63.     if(sPhi(2) == 1 || (sPhi(1) == 1 && sPhi(2) > 2)) % map is CP
  64.         Phi = Phi(:);
  65.         Phi = cellfun(@(x) kron(kron(speye(prod_dim_r1),x),speye(prod_dim_r2)),Phi,'UniformOutput',false);
  66.     else
  67.         Phi(:,1) = cellfun(@(x) kron(kron(speye(prod_dim_r1),x),speye(prod_dim_r2)),Phi(:,1),'UniformOutput',false);
  68.         Phi(:,2) = cellfun(@(x) kron(kron(speye(prod_dim_c1),x),speye(prod_dim_c2)),Phi(:,2),'UniformOutput',false);
  69.     end
  70.  
  71.     PhiX = ApplyMap(X,Phi);
  72. else % the superoperator was provided as a Choi matrix
  73.     dPhi = size(Phi);
  74.     dim = [prod_dim_r1,prod_dim_r1,dPhi(1)/dim(1,sys),dim(1,sys),prod_dim_r2,prod_dim_r2;prod_dim_c1,prod_dim_c1,dPhi(2)/dim(2,sys),dim(2,sys),prod_dim_c2,prod_dim_c2];
  75.     psi_r1 = MaxEntangled(prod_dim_r1,1,0);
  76.     psi_c1 = MaxEntangled(prod_dim_c1,1,0);
  77.     psi_r2 = MaxEntangled(prod_dim_r2,1,0);
  78.     psi_c2 = MaxEntangled(prod_dim_c2,1,0);
  79.  
  80.     Phi = PermuteSystems(kron(kron(psi_r1*psi_c1.',Phi),psi_r2*psi_c2.'),[1,3,5,2,4,6],dim);
  81.     PhiX = ApplyMap(X,Phi);
  82. end