</div> * provisional name
zvode solver used internally (1980s-1990s)
| small (N<20) | big (N>100) | time dependent |
|---|---|---|
| **Bad** - Severe overhead from python calls | **Depends** - Оverhead from memory allocation (can be worked around) | **Depends** - Any python function works, but python functions are very slow |
In [ ]:
ts = np.linspace(...)
op = -1j*np.array(...)
f_prime = lambda t, state: op*(... t).dot(state)
state0_num = np.array(...)
ode = scipy.integrate.ode(f_prime) ...
res = [state0_num]
for t in ts[1:]:
ode.integrate(t)
res.append(ode.y)
print(res[-1])
In [ ]:
qutip.sesolve(H,init,ts,[])
if timedependent, H has to be:
sesolvemesolve and mcsolveTo run $\hat{H} = \hat{H}_0 + \operatorname{sin}(t)\hat{H}_1$ you write
In [ ]:
H = [H0, [H1, 'sin(t)']]
zvode (from Scipy)| small (N<20) | big (N>100) | time dependent |
|---|---|---|
| **Bad** - Severe overhead from theano/python calls | **Good** - Minor overhead from theano/python calls | **Great** - Symbolic optimizations (and in-place operations!) |
| small (N<20) | big (N>100) | time dependent | |
|---|---|---|---|
| Numpy/Scipy | **Bad** - Severe overhead from python calls | **Depends** - Оverhead from memory allocation (can be worked around) | **Depends** - Any python function works, but python functions are very slow |
| Qutip | **Good** - Noticeable overhead from cython/python calls | **Good** - Minor overhead from cython/python calls | **Bad** - Severely limited in scope and Inconsistent |
| Theano | **Bad** - Severe overhead from theano/python calls | **Good** - Minor overhead from theano/python calls | **Great** - Symbolic optimizations (and in-place operations!) |
| Cutiepy | ? | ? | ? |
In [1]:
from cutiepy import *
k = Ket('psi', 4)
k
Out[1]:
In [2]:
H = Operator('H', 4)
H
Out[2]:
In [3]:
tensor(H,H)
Out[3]:
In [4]:
k2 = Ket('psi_2', [2,2])
k2
Out[4]:
In [5]:
sin(2*t)*H*k
Out[5]:
In [6]:
import numpy as np
Ket('phi', 4, np.array([0,0,0,1], dtype=complex))
Out[6]:
In [7]:
sigmax()
Out[7]:
In [8]:
num(3)
Out[8]:
In [9]:
expression = sigmax()*sigmay()
expression
Out[9]:
In [10]:
evalf(expression)
Out[10]:
In [11]:
numerical(destroy(3))
Out[11]:
In [12]:
y = Ket.anon(2)
op = -1j*num(2)
y_prime = op*y
y_prime
Out[12]:
In [13]:
f = generate_cython(y_prime, # Expression
NDArrayFunction(), # Type of compilation
# (whether to couple to an ODE solver)
[y]) # Arguments for the function
In [14]:
codegen.DEBUG = True
cf = f.compiled()
codegen.DEBUG = False
In [15]:
arg = np.ones((2,1), dtype=complex)
arg
Out[15]:
In [16]:
cf.pythoncall(arg)
Out[16]:
In [17]:
initial_state = basis(2, 0)
initial_state
Out[17]:
In [18]:
ω0 = 1
Δ = 0.002
Ω = 0.005
H = ω0/2 * sigmaz() + Ω * sigmax() * sin((ω0+Δ)*t)
H
Out[18]:
In [19]:
ts = 2*np.pi/Ω*np.linspace(0,1,40)
res = sesolve(H, initial_state, ts)
In [20]:
%matplotlib inline
import matplotlib.pyplot as plt
σz_expect = expect(sigmaz(), res)
plt.plot(ts*Ω/np.pi, σz_expect, 'r.', label='numerical result')
Ωp = (Ω**2+Δ**2)**0.5
plt.plot(ts*Ω/np.pi, 1-(Ω/Ωp)**2*2*np.sin(Ωp*ts/2)**2, 'b-',
label=r'$1-2(\Omega^\prime/\Omega)^2\sin^2(\Omega^\prime t/2)$')
plt.title(r'$\langle\sigma_z\rangle$-vs-$t\Omega/\pi$ at '
r'$\Delta/\Omega=%.2f$, $\omega_0/\Omega=%.2f$'%(Δ/Ω, ω0/Ω))
plt.ylim(-1,1)
plt.legend(loc=3);