Generating Random Quantum States & Operators

QuTiP includes a collection of random state, unitary and channel generators for simulations, Monte Carlo evaluation, theorem evaluation, and code testing. Each of these objects can be sampled from one of several different distributions including the default distributions used by QuTiP versions prior to 3.2.0.

For example, a random Hermitian operator can be sampled by calling rand_herm function:

In [1]: rand_herm(5)
Out[1]: 
Quantum object: dims = [[5], [5]], shape = (5, 5), type = oper, isherm = True
Qobj data =
[[ 0.00000000+0.j          0.00000000+0.j          0.20872749-0.04866211j
   0.40209203+0.26704136j -0.40352428-0.41332776j]
 [ 0.00000000+0.j          0.00000000+0.j         -0.40056281+0.05963275j
   0.00000000+0.j          0.00000000+0.j        ]
 [ 0.20872749+0.04866211j -0.40056281-0.05963275j  0.43373541+0.j
   0.00000000+0.j          0.00000000+0.j        ]
 [ 0.40209203-0.26704136j  0.00000000+0.j          0.00000000+0.j
  -0.25290039+0.j          0.25762505-0.0894655j ]
 [-0.40352428+0.41332776j  0.00000000+0.j          0.00000000+0.j
   0.25762505+0.0894655j  -0.23343653+0.j        ]]
Random Variable Type Sampling Functions Dimensions
State vector (ket) rand_ket, rand_ket_haar \(N \times 1\)
Hermitian operator (oper) rand_herm \(N \times 1\)
Density operator (oper) rand_dm, rand_dm_hs, rand_dm_ginibre \(N \times N\)
Unitary operator (oper) rand_unitary, rand_unitary_haar \(N \times N\)
CPTP channel (super) rand_super, rand_super_bcsz \((N \times N) \times (N \times N)\)

In all cases, these functions can be called with a single parameter \(N\) that dimension of the relevant Hilbert space. The optional dims keyword argument allows for the dimensions of a random state, unitary or channel to be broken down into subsystems.

In [2]: print rand_super_bcsz(7).dims
  File "<ipython-input-2-aef77a269b21>", line 1
    print rand_super_bcsz(7).dims
                        ^
SyntaxError: invalid syntax


In [3]: print rand_super_bcsz(6, dims=[[[2, 3], [2, 3]], [[2, 3], [2, 3]]]).dims
  File "<ipython-input-3-fbc42bdd7e86>", line 1
    print rand_super_bcsz(6, dims=[[[2, 3], [2, 3]], [[2, 3], [2, 3]]]).dims
                        ^
SyntaxError: invalid syntax

Several of the distributions supported by QuTiP support additional parameters as well, namely density and rank. In particular, the rand_herm and rand_dm functions return quantum objects such that a fraction of the elements are identically equal to zero. The ratio of nonzero elements is passed as the density keyword argument. By contrast, the rand_dm_ginibre and rand_super_bcsz take as an argument the rank of the generated object, such that passing rank=1 returns a random pure state or unitary channel, respectively. Passing rank=None specifies that the generated object should be full-rank for the given dimension.

For example,

In [4]: rand_dm(5, density=0.5)
Out[4]: 
Quantum object: dims = [[5], [5]], shape = (5, 5), type = oper, isherm = True
Qobj data =
[[ 0.10896859+0.j          0.14864558-0.06577093j  0.00000000+0.j
  -0.01098061-0.05261621j  0.00000000+0.j        ]
 [ 0.14864558+0.06577093j  0.35248856+0.j          0.00000000+0.j
   0.02439276-0.11397767j  0.00000000+0.j        ]
 [ 0.00000000+0.j          0.00000000+0.j          0.03401205+0.j
   0.00000000+0.j         -0.04851665-0.01398429j]
 [-0.01098061+0.05261621j  0.02439276+0.11397767j  0.00000000+0.j
   0.03854286+0.j          0.00000000+0.j        ]
 [ 0.00000000+0.j          0.00000000+0.j         -0.04851665+0.01398429j
   0.00000000+0.j          0.46598795+0.j        ]]

In [5]: rand_dm_ginibre(5, rank=2)
Out[5]: 
Quantum object: dims = [[5], [5]], shape = (5, 5), type = oper, isherm = True
Qobj data =
[[ 0.14444494+0.j         -0.08815439-0.09608178j -0.06900577+0.08447549j
  -0.05764204+0.00337936j -0.00361732-0.04579055j]
 [-0.08815439+0.09608178j  0.18064571+0.j          0.09984492-0.2012697j
   0.01694304-0.07064221j  0.09360399-0.05370721j]
 [-0.06900577-0.08447549j  0.09984492+0.2012697j   0.45983816+0.j
   0.05045130-0.04901256j  0.21598011-0.01894092j]
 [-0.05764204-0.00337936j  0.01694304+0.07064221j  0.05045130+0.04901256j
   0.04167134+0.j          0.02296694+0.06776826j]
 [-0.00361732+0.04579055j  0.09360399+0.05370721j  0.21598011+0.01894092j
   0.02296694-0.06776826j  0.17339985+0.j        ]]

See the API documentation: Random Operators and States for details.

Warning

When using the density keyword argument, setting the density too low may result in not enough diagonal elements to satisfy trace constraints.

Random objects with a given eigen spectrum

Note

New in QuTiP 3.2

It is also possible to generate random Hamiltonian (rand_herm) and densitiy matrices (rand_dm) with a given eigen spectrum. This is done by passing an array of eigenvalues as the first argument to either function. For example,

In [6]: eigs = np.arange(5)

In [7]: H = rand_herm(eigs, density=0.5)

In [8]: H
Out[8]: 
Quantum object: dims = [[5], [5]], shape = (5, 5), type = oper, isherm = True
Qobj data =
[[ 2.00000000 +0.00000000e+00j  0.00000000 +0.00000000e+00j
   0.00000000 +0.00000000e+00j  0.00000000 +0.00000000e+00j
  -2.00000000 +0.00000000e+00j]
 [ 0.00000000 +0.00000000e+00j  1.75000000 -1.11022302e-16j
  -0.22270225 +2.74597359e-01j  0.75000000 -1.11022302e-16j
   0.00000000 +0.00000000e+00j]
 [ 0.00000000 +0.00000000e+00j -0.22270225 -2.74597359e-01j
   2.50000000 -1.38777878e-17j -0.22270225 -2.74597359e-01j
   0.00000000 +0.00000000e+00j]
 [ 0.00000000 +0.00000000e+00j  0.75000000 -1.11022302e-16j
  -0.22270225 +2.74597359e-01j  1.75000000 -1.11022302e-16j
   0.00000000 +0.00000000e+00j]
 [-2.00000000 +0.00000000e+00j  0.00000000 +0.00000000e+00j
   0.00000000 +0.00000000e+00j  0.00000000 +0.00000000e+00j
   2.00000000 +0.00000000e+00j]]

In [9]: H.eigenenergies()
Out[9]: array([ 0.,  1.,  2.,  3.,  4.])

In order to generate a random object with a given spectrum QuTiP applies a series of random complex Jacobi rotations. This technique requires many steps to build the desired quantum object, and is thus suitable only for objects with Hilbert dimensionality \(\lesssim 1000\).

Composite random objects

In many cases, one is interested in generating random quantum objects that correspond to composite systems generated using the qutip.tensor.tensor function. Specifying the tensor structure of a quantum object is done using the dims keyword argument in the same fashion as one would do for a qutip.Qobj object:

In [10]: rand_dm(4, 0.5, dims=[[2,2], [2,2]])
Out[10]: 
Quantum object: dims = [[2, 2], [2, 2]], shape = (4, 4), type = oper, isherm = True
Qobj data =
[[ 0.15264527+0.j         -0.00364106+0.12979889j -0.02838016+0.09702862j
  -0.03965808-0.12296506j]
 [-0.00364106-0.12979889j  0.17104297+0.j          0.05290509-0.05373766j
  -0.15642597+0.00105696j]
 [-0.02838016-0.09702862j  0.05290509+0.05373766j  0.40978099+0.j
   0.02747475+0.10516943j]
 [-0.03965808+0.12296506j -0.15642597-0.00105696j  0.02747475-0.10516943j
   0.26653077+0.j        ]]