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.85238103+0.j          0.00473610-0.26899532j  0.00000000+0.j
   0.00000000+0.j          0.19439792-0.46184373j]
 [ 0.00473610+0.26899532j  0.00000000+0.j          0.21699323-0.14122294j
  -0.12734561+0.05322338j  0.00000000+0.j        ]
 [ 0.00000000+0.j          0.21699323+0.14122294j  0.00000000+0.j
  -0.11379132+0.23186375j  0.00000000+0.j        ]
 [ 0.00000000+0.j         -0.12734561-0.05322338j -0.11379132-0.23186375j
   0.00000000+0.j         -0.21668267-0.1563881j ]
 [ 0.19439792+0.46184373j  0.00000000+0.j          0.00000000+0.j
  -0.21668267+0.1563881j   0.49328238+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.08726712+0.j         -0.03362172+0.00303434j -0.00473776+0.0098806j
   0.02409785+0.02057042j -0.02694881-0.00077172j]
 [-0.03362172-0.00303434j  0.54505183+0.j         -0.11020859+0.18506214j
  -0.06926802-0.0708372j   0.00000000+0.j        ]
 [-0.00473776-0.0098806j  -0.11020859-0.18506214j  0.20934553+0.j
   0.00000000+0.j          0.01079379+0.02426893j]
 [ 0.02409785-0.02057042j -0.06926802+0.0708372j   0.00000000+0.j
   0.09298637+0.j          0.00000000+0.j        ]
 [-0.02694881+0.00077172j  0.00000000+0.j          0.01079379-0.02426893j
   0.00000000+0.j          0.06534915+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.23471657+0.j          0.10820614-0.02145801j  0.12163628+0.01851836j
  -0.05838879-0.06850493j -0.09856997+0.06653353j]
 [ 0.10820614+0.02145801j  0.13793106+0.j          0.24031280+0.07369358j
  -0.00222394-0.08333132j -0.03390061+0.02083971j]
 [ 0.12163628-0.01851836j  0.24031280-0.07369358j  0.49999443+0.j
  -0.02498869-0.14270603j -0.00828407+0.02941982j]
 [-0.05838879+0.06850493j -0.00222394+0.08333132j -0.02498869+0.14270603j
   0.06348763+0.j          0.00931797-0.0359943j ]
 [-0.09856997-0.06653353j -0.03390061-0.02083971j -0.00828407-0.02941982j
   0.00931797+0.0359943j   0.06387031+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 =
[[ 0.75000000 +1.38777878e-17j -0.34999221 -5.00545000e-02j
  -0.75000000 -1.38777878e-17j  0.00000000 +0.00000000e+00j
   0.00000000 +0.00000000e+00j]
 [-0.34999221 +5.00545000e-02j  1.50000000 +0.00000000e+00j
   0.34999221 -5.00545000e-02j  0.00000000 +0.00000000e+00j
   0.00000000 +0.00000000e+00j]
 [-0.75000000 -1.38777878e-17j  0.34999221 +5.00545000e-02j
   0.75000000 +1.38777878e-17j  0.00000000 +0.00000000e+00j
   0.00000000 +0.00000000e+00j]
 [ 0.00000000 +0.00000000e+00j  0.00000000 +0.00000000e+00j
   0.00000000 +0.00000000e+00j  3.50000000 +0.00000000e+00j
   0.50000000 +0.00000000e+00j]
 [ 0.00000000 +0.00000000e+00j  0.00000000 +0.00000000e+00j
   0.00000000 +0.00000000e+00j  0.50000000 +0.00000000e+00j
   3.50000000 +0.00000000e+00j]]

In [9]: H.eigenenergies()
Out[9]: 
array([  6.60925904e-17,   1.00000000e+00,   2.00000000e+00,
         3.00000000e+00,   4.00000000e+00])

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.17001195+0.j         -0.01646742+0.14280935j  0.00000000+0.j
   0.00000000+0.j        ]
 [-0.01646742-0.14280935j  0.32998805+0.j          0.00000000+0.j
   0.00000000+0.j        ]
 [ 0.00000000+0.j          0.00000000+0.j          0.39261361+0.j
  -0.05203202-0.06338613j]
 [ 0.00000000+0.j          0.00000000+0.j         -0.05203202+0.06338613j
   0.10738639+0.j        ]]