rand.random_density_matrix

Generate random density matrix.

Module Contents

Functions

random_density_matrix(dim[, is_real, k_param, ...])

Generate a random density matrix.

rand.random_density_matrix.random_density_matrix(dim, is_real=False, k_param=None, distance_metric='haar')

Generate a random density matrix.

Generates a random dim-by-dim density matrix distributed according to the Hilbert-Schmidt measure. The matrix is of rank <= k_param distributed according to the distribution distance_metric If is_real = True, then all of its entries will be real. The variable distance_metric must be one of:

  • haar (default):

    Generate a larger pure state according to the Haar measure and trace out the extra dimensions. Sometimes called the Hilbert-Schmidt measure when k_param = dim.

  • bures:

    The Bures measure.

Examples

Using toqito, we may generate a random complex-valued \(n\)- dimensional density matrix. For \(d=2\), this can be accomplished as follows.

>>> from toqito.rand import random_density_matrix
>>> complex_dm = random_density_matrix(2)
>>> complex_dm 
array([[0.83378447+0.j        , 0.25937396-0.12958422j],
       [0.25937396+0.12958422j, 0.16621553+0.j        ]])

We can verify that this is in fact a valid density matrix using the is_denisty function from toqito as follows

>>> from toqito.matrix_props import is_density
>>> is_density(complex_dm)
True

We can also generate random density matrices that are real-valued as follows.

>>> from toqito.rand import random_density_matrix
>>> real_dm = random_density_matrix(2, is_real=True)
>>> real_dm 
array([[0.3686455 , 0.48243625],
       [0.48243625, 0.6313545 ]])

Again, verifying that this is a valid density matrix can be done as follows.

>>> from toqito.matrix_props import is_density
>>> is_density(real_dm)
True

By default, the random density operators are constructed using the Haar measure. We can select to generate the random density matrix according to the Bures metric instead as follows.

>>> from toqito.rand import random_density_matrix
>>> bures_mat = random_density_matrix(2, distance_metric="bures")
>>> bures_mat 
array([[0.73969055+0.j        , 0.09494426-0.15279342j],
       [0.09494426+0.15279342j, 0.26030945+0.j        ]])

As before, we can verify that this matrix generated is a valid density matrix.

>>> from toqito.matrix_props import is_density
>>> is_density(bures_mat)
True
Parameters:
  • dim (int) – The number of rows (and columns) of the density matrix.

  • is_real (bool) – Boolean denoting whether the returned matrix will have all real entries or not.

  • k_param (list[int] | int) – Default value is equal to dim.

  • distance_metric (str) – The distance metric used to randomly generate the density matrix. This metric is either the Haar measure or the Bures measure. Default value is to use the Haar measure.

Returns:

A dim-by-dim random density matrix.

Return type:

numpy.ndarray