Test the use of e_ops parameter in dictionary form

Copyright (C) 2011 and later, Paul D. Nation & Robert J. Johansson

In [1]:
%matplotlib inline
In [2]:
from scipy import *
In [3]:
from qutip import *
In [4]:
H = 0.5 * 2 * pi * sigmax()
In [5]:
psi0 = basis(2, 0)
In [6]:
tlist = linspace(0, 10, 1000)
In [7]:
e_ops = [sigmax(), sigmay(), sigmaz()]
In [8]:
e_ops_dict = {r'$\sigma_x$': sigmax(), r'$\sigma_y$': sigmay(), r'$\sigma_z$': sigmaz()}

Test mesolve

In [9]:
c_ops = [sqrt(0.1) * sigmaz()]
In [10]:
result = mesolve(H, psi0, tlist, c_ops, e_ops)
In [11]:
fig, ax = plt.subplots(1,1)

for n, e in enumerate(result.expect):
    ax.plot(tlist, e, label=["sx", "sy", "sz"][n])
    
ax.legend();
In [12]:
result = mesolve(H, psi0, tlist, c_ops, e_ops_dict)
In [13]:
fig, ax = plt.subplots(1,1)

for key, e in result.expect.items():
    ax.plot(tlist, e, label=key)
    
ax.legend();

Test sesolve

In [14]:
result = sesolve(H, psi0, tlist, e_ops)
In [15]:
fig, ax = plt.subplots(1,1)

for n, e in enumerate(result.expect):
    ax.plot(tlist, e, label=["sx", "sy", "sz"][n])
    
ax.legend();
/usr/local/lib/python3.3/dist-packages/numpy/core/numeric.py:460: ComplexWarning: Casting complex values to real discards the imaginary part
  return array(a, dtype, copy=False, order=order)
In [16]:
result = sesolve(H, psi0, tlist, e_ops_dict)
In [17]:
fig, ax = plt.subplots(1,1)

for key, e in result.expect.items():
    ax.plot(tlist, e, label=key)
    
ax.legend();

Test mcsolve

In [18]:
result = mcsolve(H, psi0, tlist, c_ops, e_ops, ntraj=15, options=Odeoptions(gui=False))
In [19]:
fig, ax = plt.subplots(1,1)

for n, e in enumerate(result.expect):
    ax.plot(tlist, e, label=["sx", "sy", "sz"][n])
    
ax.legend();
In [20]:
result = mcsolve(H, psi0, tlist, c_ops, e_ops_dict, ntraj=5, options=Odeoptions(gui=False))
In [21]:
fig, ax = plt.subplots(1,1)

for key, e in result.expect.items():
    ax.plot(tlist, e, label=key)
    
ax.legend();
In [ ]: