Copyright (C) 2011 and later, Paul D. Nation & Robert J. Johansson
%pylab inline
from qutip import *
def visualize(result):
fig, ax = subplots(figsize=(12,6))
for idx, e in enumerate(result.expect):
ax.plot(result.times, e, label="%d" % idx)
ax.legend()
Consider two coupled qubits:
H0 = -2*pi*(tensor(sigmaz(), identity(2)) + tensor(identity(2), sigmaz()))
Hint = 2*pi*0.1 * tensor(sigmax(), sigmax())
H = H0 + Hint
H
energy_level_diagram([H], figsize=(6,6), show_ylabels=True);
If the highest energy state is not initially occupied, and if we neglect thermal excitations, it will never be occupied, and therefore not really necessary to include in a calculation of for example the dynamics of the three lowest states.
psi_gg = tensor(basis(2, 0), basis(2, 0))
psi_eg = tensor(basis(2, 1), basis(2, 0))
psi_ge = tensor(basis(2, 0), basis(2, 1))
psi_ee = tensor(basis(2, 1), basis(2, 1))
c_op1 = tensor(destroy(2), identity(2))
c_op2 = tensor(identity(2), destroy(2))
psi0 = psi_eg
tlist = linspace(0, 15, 100)
result = mesolve(H, psi0, tlist,
[sqrt(0.1) * c_op1, sqrt(0.25) * c_op2],
[ket2dm(psi_gg), ket2dm(psi_ge), ket2dm(psi_eg), ket2dm(psi_ee)])
visualize(result)
Note that the fourth state is not included in the dynamics at all. So...
# We are only interested in these states
keep_states = [0, 1, 2]
# or equivalently, not interested in these states
remove_states = [3]
H_sub = H.eliminate_states(remove_states)
H_sub
H_sub = H.extract_states(keep_states)
H_sub
energy_level_diagram([H_sub], figsize=(6,6), show_ylabels=True);
psi0_sub = psi0.extract_states(keep_states, normalize=True)
psi0_sub
c_op1_sub = c_op1.extract_states(keep_states)
c_op2_sub = c_op2.extract_states(keep_states)
psi_gg_sub = psi_gg.extract_states(keep_states)
psi_eg_sub = psi_eg.extract_states(keep_states)
psi_ge_sub = psi_ge.extract_states(keep_states)
tlist = linspace(0, 15, 100)
result = mesolve(H_sub, psi0_sub, tlist,
[sqrt(0.1) * c_op1_sub, sqrt(0.25) * c_op2_sub],
[ket2dm(psi_gg_sub), ket2dm(psi_ge_sub), ket2dm(psi_eg_sub)])
visualize(result)
Voila! Same results with fewer quantum states in the calculation, and therefore potentially more efficient.
from qutip.ipynbtools import version_table
version_table()
Software | Version |
---|---|
Cython | 0.19-dev |
SciPy | 0.13.0.dev-38ad5d2 |
QuTiP | 2.3.0.dev-9e45c8d |
Python | 2.7.3 (default, Sep 26 2012, 21:51:14) [GCC 4.7.2] |
IPython | 0.13 |
OS | posix [linux2] |
Numpy | 1.8.0.dev-bd7104c |
matplotlib | 1.3.x |
Wed Mar 13 16:25:43 2013 |