Superoperator dims

superoperator_dims is a function that computes all of the dimensions of a given superoperator (i.e., the dimensions of its input space, output space, and environment space). It also serves as an error-checking function that will get cranky if the superoperator passed into it does not really represent a superopertor.

Syntax

 * [DA,DB,DE] = superoperator_dims(PHI)
 * [DA,DB,DE] = superoperator_dims(PHI,ALLOW_RECT)
 * [DA,DB,DE] = superoperator_dims(PHI,ALLOW_RECT,DIM)

Input arguments

 * PHI: A superoperator, represented either as a Choi matrix or as a cell of Kraus operators.
 * ALLOW_RECT (optional, default 1): A flag (either 1 or 0) indicating that the input and output spaces of PHI can or can't be rectangular (non-square). If ALLOW_RECT == 0 and PHI</tt> has non-square input or output space, an error is produced.
 * DIM</tt> (optional): A 1-by-2 vector containing the dimensions of the input and output space of PHI</tt>. If this argument is provided, the function serves only as an error-checking function that makes sure that the computed dimensions agree with these given dimensions (and gives an error otherwise).

Output arguments

 * DA</tt>: A 1-by-2 vector containing the row and column dimensions of the input space of PHI</tt> (if ALLOW_RECT == 0</tt> then DA</tt> is a scalar, not a vector).
 * DB</tt> (optional): A 1-by-2 vector containing the row and column dimensions of the output space of PHI</tt> (if ALLOW_RECT == 0</tt> then DB</tt> is a scalar, not a vector).
 * DE</tt> (optional): A scalar indicating the environment dimension of PHI</tt> (this is sometimes call the "Choi rank" of PHI</tt>: it is the minimal number of Kraus operators in any representation of PHI</tt>).

Examples
The following code generates a random quantum channel from $M_3$ to $M_4$ and then computes its dimensions, and verifies that it cannot be written with fewer than 12 Kraus operators (which happens with probability 1):