import qutip as qt
import numpy as np
import matplotlib.pyplot as plt
omega = 1
V0 = 1
J = 50
a = 20
Hs = qt.Qobj(np.zeros([2, 2]), dims=qt.sigmaz().dims, )
Hc = qt.Qobj(omega* qt.jmat(J, "z"))
Vs = V0 *(qt.sigmaz() + qt.sigmax())
Vc = qt.jmat(J, "x")
dimSys = Hs.shape[0]
dimEnv = Hc.shape[0]
def Xi_gauss(t, J, a):
state_ = np.exp(-J**2/a**2)*qt.spin_state(J, -J)*np.exp(-1j*J*t*omega)
for m in range(-J+1, J+1):
state_ += np.exp(-m**2/a**2)*np.exp(-1j*m*t*omega)*qt.spin_state(J, m)
return state_.unit()
H = qt.tensor(Hs, qt.qeye(dimEnv))+ qt.tensor(qt.qeye(dimSys), Hc) + qt.tensor(Vs, Vc)
eigenenergies, eigenstates = H.eigenstates()
glob_ket = eigenstates[20]
def psi_lambda(t, J, a):
"""
makes a density matrix of the form |psi(t)> <psi(t)|
then traces out the env state
then finds the eigenstate corresponding to the maximum eigenvalue
that's the state of the system
"""
psi_dm = qt.tensor(qt.qeye(dimSys), Xi_gauss(t, J, a).proj()) * glob_ket.proj().tidyup()
psi_dm = (psi_dm.unit()).ptrace(0).tidyup().unit() ## we need to keep system 0 after tracing
valeig_, valstate_ = psi_dm.eigenstates()
index_of_max_eigenvalue = np.abs(np.round(valeig_, 5)).argmax()
print(f"Eigenvalue of the system at t = {t}: ", np.abs(np.round(valeig_, 5)))
return valstate_[index_of_max_eigenvalue].unit()
time = np.linspace(0, 4*np.pi, 1000)
oper = qt.sigmax() + qt.sigmax()
psi_lambda_list = [qt.expect(oper, psi_lambda(t, J, a = a)) for t in time]
plt.figure(figsize=(12, 8))
plt.plot(time, psi_lambda_list, "-.", label = "Numerical")
for x in [np.pi/2, 3*np.pi/2, 5*np.pi/2, 7*np.pi/2]:
plt.axvline(x, color='r', linestyle='--', label=f'x={x}')
plt.axvline(x, color='r', linestyle='--', label=f'x={x}')
plt.xlabel("Time")
plt.ylabel("<Operator>")
plt.grid(True)
plt.legend()
plt.show()