RandomDensityMatrix

RandomDensityMatrix is a function that generates a random density matrix, uniformly according to the Hilbert-Schmidt measure (equivalently, by generating a pure state according to Haar measure on a larger system and then tracing out the ancillary space) or the Bures measure.

Syntax

 * RHO = RandomDensityMatrix(DIM)
 * RHO = RandomDensityMatrix(DIM,RE)
 * RHO = RandomDensityMatrix(DIM,RE,K)
 * RHO = RandomDensityMatrix(DIM,RE,K,DIST)

Argument descriptions

 * DIM: The number of rows (or equivalently, columns) that RHO will have.
 * RE (optional, default 0): A flag (either 0 or 1) indicating that RHO</tt> should only have real entries (RE = 1</tt>) or that it is allowed to have complex entries (RE = 0</tt>).
 * K</tt> (optional, default DIM</tt>): The maximal rank of the density matrix to be produced. With probability 1, rank(RHO) = K</tt> (if K &le; DIM</tt>).
 * DIST</tt> (optional, default 'haar'</tt>): A string indicating the desired distribution that RHO</tt> should be chosen from. It can take on one of three values:
 * 'haar' or 'hs'</tt>: The density matrix is generated by generating a Haar-uniform pure state in $\mathbb{C}^K \otimes \mathbb{C}^{DIM}$ and then tracing out the first subsystem. In the special case when K = DIM</tt>, this is sometimes called the Hilbert-Schmidt measure.
 * 'bures'</tt>: The Bures measure.

Random mixed qubits
The following code generates a random mixed state on a 2-level system:

We can verify that this is indeed a valid density matrix as follows:

The following code generates a density matrix with all real entries, chosen according to the Bures measure:

A larger example of specified rank
To generate a 6-by-6 density matrix with rank at most 4, you could use the following code:

Purity of random density matrices
It is known that the expected purity of a random $n \times n$ density matrix, generated according to Haar measure with an ancillary space of dimension $m$, is $(n+m)/(nm+1)$. We can verify this numerically as follows: