-
Notifications
You must be signed in to change notification settings - Fork 1
/
cubitt_RandomDensityMatrix.m
47 lines (41 loc) · 1.75 KB
/
cubitt_RandomDensityMatrix.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
%% RANDOMDENSITYMATRIX Generates a random density matrix
% from http://www.qetlab.com/RandomDensityMatrix
% This function has one required argument:
% DIM: the number of rows (and columns) of the density matrix
%
% RHO = RandomDensityMatrix(DIM) generates a random DIM-by-DIM density
% matrix, distributed according to the Hilbert-Schmidt measure.
%
% This function has three optional arguments:
% RE (default 0)
% K (default DIM)
% DIST (default 'haar')
%
% RHO = RandomDensityMatrix(DIM,RE,K,DIST) generates a random density
% matrix of rank <= K, distributed according to the distribution DIST. If
% RE = 1 then all of its entries will be real. DIST must be one of:
% 'haar' or 'hs' (default) - Generate a larger pure state according to
% Haar measure and trace out the extra dimensions.
% Sometimes called the Hilbert-Schmidt measure when
% K = DIM.
% 'bures' - the Bures measure
%
% URL: http://www.qetlab.com/RandomDensityMatrix
% requires: opt_args.m, RandomUnitary.m
%
% author: Nathaniel Johnston (nathaniel@njohnston.ca)
% package: QETLAB
% last updated: October 10, 2014
function rho = cubitt_RandomDensityMatrix(dim,varargin)
% set optional argument defaults: re=0, k=dim, dist='hs'
[re,k,dist] = opt_args({ 0, dim, 'haar' },varargin{:});
% Haar/Hilbert-Schmidt measure
gin = randn(dim,k);
if(~re)
gin = gin + 1i*randn(dim,k);
end
if(strcmpi(dist,'bures')) % Bures measure
gin = (cubitt_randU(dim) + eye(dim))*gin;
end
rho = gin*gin';
rho = rho/trace(rho);