In [1]:
import cutiepy
cutiepy.interactive.INTERACTIVE = False
import qutip
import numpy as np
import scipy
N = 100
ts = np.linspace(0,1000,100)
In [2]:
init = qutip.coherent(N,2)
H = qutip.num(N)
opt = qutip.Options(rhs_reuse=True)
%time res = qutip.sesolve(H,init,ts,[], options=opt)
%time res = qutip.sesolve(H,init,ts,[], options=opt)
print(res.states[-1].data.A[:4], res.states[-1].norm())
In [3]:
init = cutiepy.coherent(N,2)
H = cutiepy.num(N)
%time res = cutiepy.sesolve(H, init, np.linspace(0,1000,100))
%time res = cutiepy.sesolve(H, init, np.linspace(0,1000,100))
print(res[-1].numerical[:4], np.linalg.norm(res[-1].numerical))
In [4]:
%%time
H = qutip.num(N).data.A
op = -1j*H
f = lambda t, state: op.dot(state)
ode = scipy.integrate.ode(f)
ode.set_integrator('zvode', method='adams', rtol=1e-6, atol=1e-8, nsteps=1000)
state0_num = qutip.coherent(N,2).data.A
ode.set_initial_value(state0_num, ts[0])
res = [state0_num]
for t in ts[1:]:
ode.integrate(t)
if not ode.successful():
RuntimeError('The ODE solver failed.')
#y = ode.y
#n = scipy.linalg.norm(y)
#y /= n
#ode.set_initial_value(y, t)
res.append(ode.y)
print(res[-1][:4], np.linalg.norm(res[-1]))