RandomStateVector
From QETLAB
RandomStateVector | |
Generates a random pure state vector | |
Other toolboxes required | none |
---|---|
Related functions | RandomDensityMatrix RandomProbabilities RandomSuperoperator RandomUnitary |
Function category | Random things |
RandomStateVector is a function that generates a random pure state vector, uniformly distributed on the unit hypersphere (sometimes said to be uniformly distributed according to Haar measure).
Contents
Syntax
- V = RandomStateVector(DIM)
- V = RandomStateVector(DIM,RE)
- V = RandomStateVector(DIM,RE,K)
Argument descriptions
- DIM: The dimension of the Hilbert space in which V lives. If K > 0 (see optional arguments below) then DIM is the local dimension rather than the total dimension. If different local dimensions are desired, DIM should be a 1-by-2 vector containing the desired local dimensions.
- RE (optional, default 0): A flag (either 0 or 1) indicating that V should only have real entries (RE = 1) or that it is allowed to have complex entries (RE = 0).
- K (optional, default 0): If equal to 0 then V will be generated without considering its Schmidt rank. If K > 0 then a random pure state with Schmidt rank ≤ K will be generated (and with probability 1, its Schmidt rank will equal K). Note that when K = 1 the states on the two subsystems are generated uniformly and independently according to Haar measure on those subsystems. When K = DIM, the usual Haar measure on the total space is used. When 1 < K < DIM, a natural measure that interpolates between these two extremes is used (more specifically, the direct sum of the left (similarly, right) Schmidt vectors is chosen according to Haar measure on $\mathbb{C}^K \otimes \mathbb{C}^{DIM}$).
Examples
A random qubit
To generate a random qubit, use the following code:
>> RandomStateVector(2) ans = -0.1025 - 0.5498i -0.5518 + 0.6186i
If you want it to only have real entries, set RE = 1:
>> RandomStateVector(2,1) ans = -0.4487 0.8937
Random states with fixed Schmidt rank
To generate a random product qutrit-qutrit state and verify that it is indeed a product state, use the following code:
>> v = RandomStateVector(3,0,1) v = 0.0400 - 0.3648i 0.1169 - 0.0666i 0.0465 + 0.0016i -0.1910 + 0.0524i -0.0566 - 0.0455i -0.0084 - 0.0236i -0.4407 + 0.7079i -0.3050 + 0.0214i -0.0936 - 0.0489i >> SchmidtRank(v) ans = 1
You could create a random pure state with Schmidt rank 2 in $\mathbb{C}^3 \otimes \mathbb{C}^4$, and verify its Schmidt rank, using the following lines of code:
>> v = RandomStateVector([3,4],0,2) v = -0.2374 + 0.1984i 0.1643 + 0.0299i -0.0499 + 0.0376i -0.0689 - 0.0005i 0.7740 - 0.0448i -0.1290 - 0.2224i -0.0514 - 0.1565i 0.2195 + 0.2478i -0.1636 + 0.1276i 0.0581 + 0.0608i 0.0482 - 0.0178i -0.1050 + 0.0014i >> SchmidtRank(v,[3,4]) ans = 2
Source code
Click on "expand" to the right to view the MATLAB source code for this function.
%% RANDOMSTATEVECTOR Generates a random pure state vector
% This function has one required argument:
% DIM: the dimension of the Hilbert space that the pure state lives in
%
% V = RandomStateVector(DIM) generates a DIM-dimensional state vector,
% uniformly distributed on the (DIM-1)-sphere. Equivalently, these pure
% states are uniformly distributed according to Haar measure.
%
% This function has two optional input arguments:
% RE (default 0)
% K (default 0)
%
% V = RandomStateVector(DIM,RE,K) generates a random pure state vector as
% above. If RE=1 then all coordinates of V will be real. If K=0 then a
% pure state is generated without considering its Schmidt rank at all. If
% K>0 then a random bipartite pure state with Schmidt rank <= K is
% generated (and with probability 1, the Schmidt rank will equal K). If
% K>0 then DIM is no longer the dimension of the space on which V lives,
% but rather is the dimension of the *local* systems on which V lives. If
% these two systems have unequal dimension, you can specify them both by
% making DIM a 1-by-2 vector containing the two dimensions.
%
% URL: http://www.qetlab.com/RandomStateVector
% requires: iden.m MaxEntangled.m, opt_args.m, PermuteSystems.m, Swap.m
% author: Nathaniel Johnston (nathaniel@njohnston.ca)
% package: QETLAB
% last updated: November 12, 2014
function v = RandomStateVector(dim,varargin)
% set optional argument defaults: re=0, k=0
[re,k] = opt_args({ 0, 0 },varargin{:});
if(k > 0 && k < min(dim)) % Schmidt rank plays a role
% allow the user to enter a single number for dim
if(length(dim) == 1)
dim = [dim,dim];
end
% if you start with a separable state on a larger space and multiply
% the extra k dimensions by a maximally entangled state, you get a
% Schmidt rank <= k state
psi = MaxEntangled(k,1,0);
a = randn(dim(1)*k,1);
b = randn(dim(2)*k,1);
if(~re)
a = a + 1i*randn(dim(1)*k,1);
b = b + 1i*randn(dim(2)*k,1);
end
v = kron(psi',speye(prod(dim)))*Swap(kron(a,b),[2,3],[k,dim(1),k,dim(2)]);
v = v/norm(v);
else % Schmidt rank is full, so ignore it
v = randn(dim,1);
if(~re)
v = v + 1i*randn(dim,1);
end
v = v/norm(v);
end