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.65059092+0.j 0.48575167+0.37493153j 0.66557238+0.08941232j
0. +0.j -0.19892853-0.58575629j]
[ 0.48575167-0.37493153j 0. +0.j 0.049938 +0.01111378j
-0.15309387-0.63961294j -0.55094397-0.6883588j ]
[ 0.66557238-0.08941232j 0.049938 -0.01111378j 0.55027224+0.j
0. +0.j 0.66793421+0.20401768j]
[ 0. +0.j -0.15309387+0.63961294j 0. +0.j
0.52646769+0.j 0.80389708+0.60961187j]
[-0.19892853+0.58575629j -0.55094397+0.6883588j 0.66793421-0.20401768j
0.80389708-0.60961187j 0.22957225+0.j ]]
Random Variable Type |
Sampling Functions |
Dimensions |
---|---|---|
State vector ( |
rand_ket, rand_ket_haar |
\(N \times 1\) |
Hermitian operator ( |
rand_herm |
\(N \times 1\) |
Density operator ( |
rand_dm, rand_dm_hs, rand_dm_ginibre |
\(N \times N\) |
Unitary operator ( |
rand_unitary, rand_unitary_haar |
\(N \times N\) |
CPTP channel ( |
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)
[[[7], [7]], [[7], [7]]]
In [3]: print(rand_super_bcsz(6, dims=[[[2, 3], [2, 3]], [[2, 3], [2, 3]]]).dims)
[[[2, 3], [2, 3]], [[2, 3], [2, 3]]]
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.15368954+0.j 0.02289932+0.07581781j -0.10187028-0.03564124j
0.07986184+0.0760688j 0.00818362+0.02591344j]
[ 0.02289932-0.07581781j 0.33601194+0.j 0.00373162+0.039117j
0.00701675-0.00786148j 0.05444308+0.1058045j ]
[-0.10187028+0.03564124j 0.00373162-0.039117j 0.25159057+0.j
-0.11899427-0.02380852j 0.01628486-0.02572504j]
[ 0.07986184-0.0760688j 0.00701675+0.00786148j -0.11899427+0.02380852j
0.13231089+0.j 0. +0.j ]
[ 0.00818362-0.02591344j 0.05444308-0.1058045j 0.01628486+0.02572504j
0. +0.j 0.12639704+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.24981331-5.32276452e-18j 0.06078516+2.10144581e-02j
0.10694037-7.08650832e-02j -0.18665661-7.55319937e-02j
-0.08737016+5.77374826e-02j]
[ 0.06078516-2.10144581e-02j 0.10032809+1.76771327e-18j
0.09125196-4.06025328e-02j -0.01707306+1.58191952e-02j
-0.16139606-4.02613485e-02j]
[ 0.10694037+7.08650832e-02j 0.09125196+4.06025328e-02j
0.12884739+1.84382025e-18j -0.03216067-6.36145385e-02j
-0.16643111-7.73312681e-02j]
[-0.18665661+7.55319937e-02j -0.01707306-1.58191952e-02j
-0.03216067+6.36145385e-02j 0.18076068-1.41693757e-18j
-0.02584792-6.30832476e-02j]
[-0.08737016-5.77374826e-02j -0.16139606+4.02613485e-02j
-0.16643111+7.73312681e-02j -0.02584792+6.30832476e-02j
0.34025052+3.12816858e-18j]]
See the API documentation: Quantum Objects 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. +0.00000000e+00j 0. +0.00000000e+00j
0. +0.00000000e+00j 0. +0.00000000e+00j
0. +0.00000000e+00j]
[ 0. +0.00000000e+00j 2.5 +0.00000000e+00j
0.2555248 +2.44350317e-01j 0. -2.22044605e-16j
-0.76657439+7.33050952e-01j]
[ 0. +0.00000000e+00j 0.2555248 -2.44350317e-01j
2.5 +2.77555756e-17j -0.2555248 +2.44350317e-01j
0. +0.00000000e+00j]
[ 0. +0.00000000e+00j 0. -2.22044605e-16j
-0.2555248 -2.44350317e-01j 2.5 +0.00000000e+00j
-0.76657439+7.33050952e-01j]
[ 0. +0.00000000e+00j -0.76657439-7.33050952e-01j
0. +0.00000000e+00j -0.76657439-7.33050952e-01j
2.5 +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.12892006+0.j 0.00139387-0.00215584j 0. +0.j
-0.11078961-0.07366462j]
[ 0.00139387+0.00215584j 0.26627187+0.j 0.06362809+0.1146888j
0.00224883-0.17521814j]
[ 0. +0.j 0.06362809-0.1146888j 0.12528746+0.j
-0.14312245-0.08182227j]
[-0.11078961+0.07366462j 0.00224883+0.17521814j -0.14312245+0.08182227j
0.47952061+0.j ]]