I'm just pasting the code from the attached nb, in case that's more the habit here.
there is a function for both array-type and function-type Hamiltonian.
%load_ext watermark
import numpy as np
import matplotlib.pyplot as plt
import qutip
%watermark -v --iversion
N = 300
T=1.5
tlist = np.linspace(0, T, N)
ket0 = qutip.basis(2,0)
ket1 = qutip.basis(2,1)
proj10 = qutip.ket2dm(ket0)
proj01 = qutip.ket2dm(ket1)
def Omega_Cst(times, args):
A = args['ampl']
fi = args['phi']
last = args['Nf']
res = np.empty(len(times), dtype=np.complex128)
for k in range(last):
res[k]=A*np.exp(1.j*fi)
for k in range(last, len(times)):
res[k]=0
return res
def Omega_Cst_f(t, args):
A = args['ampl']
fi = args['phi']
last = args['Nf']
if t<=T*float(last)/N:
return A*np.exp(1.j*fi)
else:
return 0
dict_cst = {'phi': np.pi*0.5, 'ampl':2*np.pi/T, 'Nf':int(N*1.)}
fig, ax = plt.subplots()
ax.set_ylim(0, dict_cst['ampl']*1.05)
om_cst = Omega_Cst(tlist, dict_cst)
ax.plot(tlist, np.absolute(om_cst))
def solve_cst_func(detuning):
H = qutip.QobjEvo([detuning*qutip.sigmaz(), [qutip.sigmax(), Omega_Cst_f]], args=dict_cst)
result = qutip.sesolve(H, ket0, tlist, e_ops=[proj10, proj01])
return result
def solve_cst_arr(detuning):
H = qutip.QobjEvo([detuning*qutip.sigmaz(), [qutip.sigmax(), Omega_Cst(tlist,dict_cst)]], tlist=tlist)
result = qutip.sesolve(H, ket0, tlist, e_ops=[proj10, proj01])
return result
Cst_omega_slv = solve_cst_func(0)
fig,ax=plt.subplots()
ax.set_ylim(0,1)
ax.plot(tlist, Cst_omega_slv.expect[1])