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.02899876+0.j         -0.13416343-0.22952874j  0.12840707+0.41050523j
  -0.20370645+0.30698666j  0.00000000+0.j        ]
 [-0.13416343+0.22952874j  0.00000000+0.j          0.09407321+0.10234802j
   0.00000000+0.j          0.00000000+0.j        ]
 [ 0.12840707-0.41050523j  0.09407321-0.10234802j  0.00000000+0.j
   0.40961470-0.26592036j -0.74062964+0.07040012j]
 [-0.20370645-0.30698666j  0.00000000+0.j          0.40961470+0.26592036j
   0.29223638+0.j          0.00000000+0.j        ]
 [ 0.00000000+0.j          0.00000000+0.j         -0.74062964-0.07040012j
   0.00000000+0.j          0.00000000+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.21180855+0.j          0.04540648+0.06118105j -0.07598360+0.02849567j
   0.04776725+0.16115118j  0.00000000+0.j        ]
 [ 0.04540648-0.06118105j  0.25539169+0.j         -0.11587367+0.13290748j
   0.06120300-0.03780905j  0.00000000+0.j        ]
 [-0.07598360-0.02849567j -0.11587367-0.13290748j  0.20161473+0.j
  -0.03706151+0.02662839j  0.00000000+0.j        ]
 [ 0.04776725-0.16115118j  0.06120300+0.03780905j -0.03706151-0.02662839j
   0.33118502+0.j          0.00000000+0.j        ]
 [ 0.00000000+0.j          0.00000000+0.j          0.00000000+0.j
   0.00000000+0.j          0.00000000+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.27113384 -2.52030496e-18j  0.11041622 +1.10157305e-01j
  -0.09362474 -4.65887107e-02j  0.06418789 +7.47838678e-02j
  -0.18650823 -3.64827992e-03j]
 [ 0.11041622 -1.10157305e-01j  0.33661489 +3.46524913e-18j
   0.02712672 +1.98547784e-01j  0.00897342 +1.69034391e-02j
  -0.14502197 +6.60610682e-02j]
 [-0.09362474 +4.65887107e-02j  0.02712672 -1.98547784e-01j
   0.19951476 +8.04832011e-19j -0.04212089 +2.40440682e-02j
   0.03600323 +1.55392180e-02j]
 [ 0.06418789 -7.47838678e-02j  0.00897342 -1.69034391e-02j
  -0.04212089 -2.40440682e-02j  0.04561591 +3.00292833e-19j
  -0.03256089 +5.55928047e-02j]
 [-0.18650823 +3.64827992e-03j -0.14502197 -6.60610682e-02j
   0.03600323 -1.55392180e-02j -0.03256089 -5.55928047e-02j
   0.14712060 -2.05006901e-18j]]

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.00000000+0.j          0.00000000+0.j          0.00000000+0.j
   0.00000000+0.j          0.00000000+0.j        ]
 [ 0.00000000+0.j          3.16669420+0.j         -0.18870571+0.29898186j
   0.25876163+0.35702732j -0.83330580+0.j        ]
 [ 0.00000000+0.j         -0.18870571-0.29898186j  2.00000000+0.j
   0.46421661+0.18574966j -0.18870571-0.29898186j]
 [ 0.00000000+0.j          0.25876163-0.35702732j  0.46421661-0.18574966j
   1.66661160+0.j          0.25876163-0.35702732j]
 [ 0.00000000+0.j         -0.83330580+0.j         -0.18870571+0.29898186j
   0.25876163+0.35702732j  3.16669420+0.j        ]]

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.15913371+0.j          0.04719306+0.03098083j -0.21086285-0.12748706j
  -0.07220161-0.09696794j]
 [ 0.04719306-0.03098083j  0.06780024+0.j         -0.08634093-0.03718852j
   0.00000000+0.j        ]
 [-0.21086285+0.12748706j -0.08634093+0.03718852j  0.52791042+0.j
   0.18747936+0.17295123j]
 [-0.07220161+0.09696794j  0.00000000+0.j          0.18747936-0.17295123j
   0.24515564+0.j        ]]