def test_thermal(): N = 10 beta = 0.5 assert qutip.thermal_dm(N, 0) == qutip.fock_dm(N, 0) thermal_operator = qutip.thermal_dm(N, beta) thermal_analytic = qutip.thermal_dm(N, beta, method="analytic") np.testing.assert_allclose(thermal_operator.full(), thermal_analytic.full(), atol=2e-5) with pytest.raises(ValueError) as e: qutip.thermal_dm(N, beta, method="other") assert str(e.value) == ("The method option can only take " "values 'operator' or 'analytic'")
def __init__(self, EC=10, EJ=0.3, f01=None, alpha=None, N=10, Nq=3, Temp=20e-3): # Unit in [GHz] if f01 is None and alpha is None: self.EC = EC self.EJ = EJ self.N = N self.enes = self.calcChargeQubitLevels(self.EC, self.EJ, self.N) self.f01 = self.enes[1] self.anh = self.enes[2] - 2 * self.enes[1] else: self.f01 = f01 self.anh = -abs(alpha) self.enes = [0] + [ i * self.f01 + (i - 1) * self.anh for i in range(1, N) ] self.nth_q = Maxwell_Boltzmann_distributon(self.enes, Temp, N) self.P0 = iniState1Qsys(Nq, 0, mode='rho') self.P1 = iniState1Qsys(Nq, 1, mode='rho') # Thermal_state_ket = 0 # for i in range(Nq): # Thermal_state_ket += ket(Nq, i)*self.nth_q[i] # self.Thermal_state_ket = Thermal_state_ket # self.Thermal_state_dm = self.Thermal_state_ket*self.Thermal_state_ket.dag() self.Thermal_state_dm = qt.thermal_dm(Nq, self.nth_q[1]) if Nq != None: self.Q_duffingOscillator(Nq)
def testThermalDensityMatrix(self): """ states: thermal density matrix """ N = 40 rho = thermal_dm(N, 1) # make sure rho has trace close to 1.0 assert_(abs(rho.tr() - 1.0) < 1e-12)
def test_thermal_distribution(cls): ''' compares the result of the computed distribution with the same result obtained through qutip ''' nbar = 3 * np.random.ranf() test_entries = 10 computed = cls.thermal(nbar, test_entries) from qutip import thermal_dm thermal_qutip = thermal_dm(test_entries, nbar, method = 'analytic').diag() return np.allclose(thermal_qutip, computed)
def test_thermal_distribution(cls): ''' compares the result of the computed distribution with the same result obtained through qutip ''' nbar = 3 * np.random.ranf() test_entries = 10 computed = cls.thermal(nbar, test_entries) from qutip import thermal_dm #using a much higher dimension of 100 than the end result thermal_qutip = thermal_dm(100, nbar).diag()[0:test_entries] return np.allclose(thermal_qutip, computed)
def set_environment(self, reflectance, nth): """ Set up the thermal noise bath Parameters ---------- reflectance: float reflectance of the possibly-exciting target object nth: float average photon number of the thermal noise Returns ------- no return, alternate self.thermal_0 and self.thermal_1 inplace """ self.reflectance = reflectance self.nth = nth self.thermal_0 = qu.thermal_dm(self.n_max, nth) self.thermal_1 = qu.thermal_dm(self.n_max, nth / (1 - self.reflectance))
def __init__(self, fr, Qc, Nf=5, Temp=20e-3): self.fr = fr self.Nf = Nf self.Qc = Qc self.a = qt.destroy(Nf) self.ad = self.a.dag() self.na = self.ad * self.a self.Hr = fr * self.na self.Ir = qt.qeye(Nf) self.kappa = fr / Qc self.nth_a = Bose_distributon(fr, Temp) self.Thermal_state_dm = qt.thermal_dm(Nf, self.nth_a)
def test_thermal_distribution(cls): """ compares the result of the computed distribution with the same result obtained through qutip """ nbar = 3 * np.random.ranf() test_entries = 10 computed = cls.thermal(nbar, test_entries) from qutip import thermal_dm # using a much higher dimension of 100 than the end result thermal_qutip = thermal_dm(100, nbar).diag()[0:test_entries] return np.allclose(thermal_qutip, computed)
def test_displaced_thermal(cls): ''' compares the result of the computed distribution with the same result obtained through qutip ''' alpha = np.sqrt(5) * np.random.ranf() nbar = 5 * np.random.ranf() test_entries = 100 computed = cls.displaced_thermal(alpha, nbar, test_entries) from qutip import thermal_dm, displace thermal_dm = thermal_dm(test_entries, nbar, method = 'analytic') displace_operator = displace(test_entries, alpha) displaced_dm = displace_operator * thermal_dm * displace_operator.dag() qutip_result = displaced_dm.diag() return np.allclose(qutip_result, computed)
def __init__(self, isLindblad): """ Construct an instance of class ThermalState. """ super(ThermalQM, self).__init__(isLindblad) # #Some physical constants #The number of average photons in thermal equilibrium for the resonator #with the given frequency and temperature. # print("nHO=%.5g at thermal equilibrium" % pars['nHO']) # Density matrix of HO at thermal equlibrium self.rho_HO = thermal_dm(pars['N'], pars['nHO'])
def test_enr_thermal_dm2(): "Excitation-number-restricted state space: thermal density operator (II)" dims, excitations = [3, 4, 5], 2 n_vec = 0.1 rho = enr_thermal_dm(dims, excitations, n_vec) rho_ref = tensor([thermal_dm(d, n_vec) for idx, d in enumerate(dims)]) gonners = [idx for idx, state in enumerate(state_number_enumerate(dims)) if sum(state) > excitations] rho_ref = rho_ref.eliminate_states(gonners) rho_ref = rho_ref / rho_ref.tr() assert_(abs((rho.data - rho_ref.data).data).max() < 1e-12)
def test_displaced_thermal(cls): ''' compares the result of the computed distribution with the same result obtained through qutip ''' alpha = np.sqrt(3) * np.random.ranf() nbar = 3 * np.random.ranf() test_entries = 10 computed = cls.displaced_thermal(alpha, nbar, test_entries) from qutip import thermal_dm, displace #using a much higher dimension of 100 than the end result thermal_dm = thermal_dm(100, nbar) displace_operator = displace(100, alpha) displaced_dm = displace_operator * thermal_dm * displace_operator.dag() qutip_result = displaced_dm.diag()[0:test_entries] return np.allclose(qutip_result, computed)
def test_displaced_thermal(cls): """ compares the result of the computed distribution with the same result obtained through qutip """ alpha = np.sqrt(3) * np.random.ranf() nbar = 3 * np.random.ranf() test_entries = 10 computed = cls.displaced_thermal(alpha, nbar, test_entries) from qutip import thermal_dm, displace # using a much higher dimension of 100 than the end result thermal_dm = thermal_dm(100, nbar) displace_operator = displace(100, alpha) displaced_dm = displace_operator * thermal_dm * displace_operator.dag() qutip_result = displaced_dm.diag()[0:test_entries] return np.allclose(qutip_result, computed)
def _reference_dm(dimensions, n_excitations, nbars): """ Get the reference density matrix using `Qobj.eliminate_states` explicitly, to compare to the direct ENR construction. """ if np.isscalar(nbars): nbars = [nbars] * len(dimensions) out = qutip.tensor([ qutip.thermal_dm(dimension, nbar) for dimension, nbar in zip(dimensions, nbars) ]) eliminate = [ i for i, state in enumerate(qutip.state_number_enumerate(dimensions)) if sum(state) > n_excitations ] out = out.eliminate_states(eliminate) return out / out.tr()
def do_gate(self, nT=2): if self.two_loops: times = np.linspace(0, self.T / 2, nT) else: times = np.linspace(0, self.T, nT) # initialize result vector final_rhos = [] # GATE # ------------------------------------------------------------------------- # initial state rhoInitial = tensor(self.dn_dn, self.dn_dn, thermal_dm(self.nHO, self.nbar_mode)) # apply pi/2 rho_after_piB2 = self.U_rot( pi / 2 * self.sq_factor) * rhoInitial * self.U_rot( pi / 2 * self.sq_factor).dag() # do gate after_wobble = self.wobble_force(rho_after_piB2, times) # finish Ramsey interferometer/ do second part of gate for ii in range(len(times)): rho_t = after_wobble.states[ii] if self.two_loops: rho_after_pi = self.U_rot( pi * self.sq_factor) * rho_t * self.U_rot( pi * self.sq_factor).dag() phi = pi #delta_g*times[ii]+pi after_wobble_two = self.wobble_force(rho_after_pi, [0, times[ii]], phi_0=phi) rho_final = self.U_rot( pi / 2 * self.sq_factor) * after_wobble_two.states[-1] * self.U_rot( pi / 2 * self.sq_factor).dag() else: # only one loop rho_final = self.U_rot( pi / 2 * self.sq_factor) * rho_t * self.U_rot( pi / 2 * self.sq_factor).dag() # final results final_rhos.append(rho_final) if self.two_loops: times *= 2 return times, final_rhos
def initialise_TLS(init_sys, init_RC, states, w0, T_ph, H_RC=np.ones((2, 2))): # allows specific state TLS-RC states to be constructed easily G = qt.ket([0]) E = qt.ket([1]) ground_list, excited_list = ground_and_excited_states(states) concat_list = [ground_list, excited_list] N = states[1].shape[0] / 2 if init_sys == 'coherence': rho_left = (states[concat_list[0][init_RC]] + states[concat_list[1][init_RC]]) / np.sqrt(2) rho_right = rho_left.dag() init_rho = rho_left * rho_right elif type(init_sys) == tuple: #coherence state if type(init_RC) == tuple: # take in a 2-tuple to initialise in coherence state. print((init_sys, init_RC)) rho_left = states[concat_list[init_sys[0]][init_RC[0]]] rho_right = states[concat_list[init_sys[1]][init_RC[1]]].dag() init_rho = rho_left * rho_right else: raise ValueError elif init_sys == 0: # population state init_rho = states[ground_list[init_RC]] * states[ ground_list[init_RC]].dag() elif init_sys == 1: init_rho = states[excited_list[init_RC]] * states[ excited_list[init_RC]].dag() elif init_sys == 2: Therm = qt.thermal_dm(N, Occupation(w0, T_ph)) init_rho = qt.tensor(E * E.dag(), Therm) # if in neither ground or excited # for the minute, do nothing. This'll be fixed below. else: # finally, if not in either G or E, initialise as thermal num = (-H_RC * beta_f(T_ph)).expm() init_rho = num / num.tr() return init_rho
# Fock state (as a density matrix) print( "Fock State as a Density Matrix with hilbert space size = {dim} and occupied state = {n} \n" .format(dim=5, n=2), fock_dm(5, 2)) print() print( "Coherent State as a Density Matrix with number of fock states = {N} and eigenvalue = {alpha}" .format(N=8, alpha=1.0), coherent_dm(N=8, alpha=1.0)) print() n = 1 # average number of thermal photons print( "Thermal State as Density Matrix with with number of basis states in hilbert space = {N} and expectation value for number of particles in thermal state = {n}\n" .format(N=8, n=n), thermal_dm(8, n)) wait() """ --------------- </Operators> --------------- """ # Qubit Operators (2 level system) print("Sigma x:\n", sigmax()) print("Sigma y:\n", sigmay()) print("Sigma z:\n", sigmaz()) wait() # Harmonic Oscillator Operators print(
def get_rho(dim, T, omega): """ diagonal density matrix at temperature T for equidistant eigenstates """ n = 1.0/(np.exp(omega/T)-1.0) return q.thermal_dm(dim, n)
def do_gate(self, nT=2): if self.two_loops: times = np.linspace(0, self.T / 2, nT) else: times = np.linspace(0, self.T, nT) # initialize result vector final_rhos = [] # GATE # ------------------------------------------------------------------------- # initial state rhoInitial = tensor(self.dn_dn, self.dn_dn, thermal_dm(self.nHO, self.nbar_mode)) if self.phase_insensitive: rho_after_uw_piB2 = self.U_rot(pi/2*self.sq_factor,ion_index=[1,0],phi=self.mw_offset_phase_1)*\ self.U_rot(pi/2*self.sq_factor,ion_index=[0,1],phi=self.mw_offset_phase_2)*\ rhoInitial* \ self.U_rot(pi/2*self.sq_factor,ion_index=[1,0],phi=self.mw_offset_phase_1).dag() *\ self.U_rot(pi/2*self.sq_factor,ion_index=[0,1],phi=self.mw_offset_phase_2).dag() rho_after_laser_piB2 = self.U_rot(pi/2*self.sq_factor,ion_index=[1,0],phi=-self.phi_sum_1)* \ self.U_rot(pi/2*self.sq_factor,ion_index=[0,1],phi=-self.phi_sum_2)* \ rho_after_uw_piB2* \ self.U_rot(pi/2*self.sq_factor,ion_index=[1,0],phi=-self.phi_sum_1).dag() *\ self.U_rot(pi/2*self.sq_factor,ion_index=[0,1],phi=-self.phi_sum_2).dag() rho_before_MS_interaction = rho_after_laser_piB2 elif self.ms_ls_exp: rho_after_piB2 = self.U_rot(pi/2*self.sq_factor,ion_index=[1,0],phi=-self.phi_sum_1)* \ self.U_rot(pi/2*self.sq_factor,ion_index=[0,1],phi=-self.phi_sum_2)* \ rhoInitial* \ self.U_rot(pi/2*self.sq_factor,ion_index=[1,0],phi=-self.phi_sum_1).dag() *\ self.U_rot(pi/2*self.sq_factor,ion_index=[0,1],phi=-self.phi_sum_2).dag() rho_before_MS_interaction = rho_after_piB2 else: rho_before_MS_interaction = rhoInitial # do gate after_ms = self.ms_force_asym(rho_before_MS_interaction, times) #after_ms = self.ms_force(rho_before_MS_interaction, times) # finish Ramsey interferometer/ do second part of gate for ii in range(len(times)): rho_t = after_ms.states[ii] if self.two_loops: if self.do_center_pi: rho_after_pi = self.U_rot(pi*self.sq_factor,ion_index=[1,0],phi=-self.phi_sum_1)*\ self.U_rot(pi*self.sq_factor,ion_index=[0,1],phi=-self.phi_sum_2)*\ rho_t*\ self.U_rot(pi*self.sq_factor,ion_index=[1,0],phi=-self.phi_sum_1).dag() *\ self.U_rot(pi*self.sq_factor,ion_index=[0,1],phi=-self.phi_sum_2).dag() else: rho_after_pi = rho_t if self.do_Walsh: phi = pi + self.second_loop_phase_error + self.delta_LS * times[ -1] #delta_g*times[ii]+pi else: phi = 0 + self.second_loop_phase_error + self.delta_LS * times[ -1] after_second_loop = self.ms_force_asym(rho_after_pi, [0, times[ii]], phi_offset=phi, scnd_loop=True) #after_second_loop = self.ms_force(rho_after_pi, [0,times[ii]], phi_offset=phi) if self.phase_insensitive: rho_after_2nd_laser_piB2 = self.U_rot(pi/2*self.sq_factor,ion_index=[1,0],phi=-self.phi_sum_1)* \ self.U_rot(pi/2*self.sq_factor,ion_index=[0,1],phi=-self.phi_sum_2)* \ after_second_loop.states[-1]* \ self.U_rot(pi/2*self.sq_factor,ion_index=[1,0],phi=-self.phi_sum_1).dag() *\ self.U_rot(pi/2*self.sq_factor,ion_index=[0,1],phi=-self.phi_sum_2).dag() rho_after_2nd_uw_piB2 = self.U_rot(pi/2*self.sq_factor,ion_index=[1,0],phi=self.mw_offset_phase_1)*\ self.U_rot(pi/2*self.sq_factor,ion_index=[0,1],phi=self.mw_offset_phase_2)*\ rho_after_2nd_laser_piB2* \ self.U_rot(pi/2*self.sq_factor,ion_index=[1,0],phi=self.mw_offset_phase_1).dag() *\ self.U_rot(pi/2*self.sq_factor,ion_index=[0,1],phi=self.mw_offset_phase_2).dag() final_rho = rho_after_2nd_uw_piB2 elif self.ms_ls_exp: rho_after_2nd_piB2 = self.U_rot(pi/2*self.sq_factor,ion_index=[1,0],phi=-self.phi_sum_1)* \ self.U_rot(pi/2*self.sq_factor,ion_index=[0,1],phi=-self.phi_sum_2)* \ after_second_loop.states[-1]* \ self.U_rot(pi/2*self.sq_factor,ion_index=[1,0],phi=-self.phi_sum_1).dag() *\ self.U_rot(pi/2*self.sq_factor,ion_index=[0,1],phi=-self.phi_sum_2).dag() final_rho = rho_after_2nd_piB2 else: final_rho = after_second_loop.states[-1] else: # only one loop #rho_final = self.U_rot(pi/2)*self.U_rot(pi)*rho_t*self.U_rot(pi).dag()*self.U_rot(pi/2).dag() if self.phase_insensitive: rho_after_2nd_laser_piB2 = self.U_rot(pi/2*self.sq_factor,ion_index=[1,0],phi=pi-self.phi_sum_1)* \ self.U_rot(pi/2*self.sq_factor,ion_index=[0,1],phi=pi-self.phi_sum_2)* \ rho_t* \ self.U_rot(pi/2*self.sq_factor,ion_index=[1,0],phi=pi-self.phi_sum_1).dag() *\ self.U_rot(pi/2*self.sq_factor,ion_index=[0,1],phi=pi-self.phi_sum_2).dag() rho_after_2nd_uw_piB2 = self.U_rot(pi/2*self.sq_factor,ion_index=[1,0],phi=self.mw_offset_phase_1)*\ self.U_rot(pi/2*self.sq_factor,ion_index=[0,1],phi=self.mw_offset_phase_2)*\ rho_after_2nd_laser_piB2* \ self.U_rot(pi/2*self.sq_factor,ion_index=[1,0],phi=self.mw_offset_phase_1).dag() *\ self.U_rot(pi/2*self.sq_factor,ion_index=[0,1],phi=self.mw_offset_phase_2).dag() final_rho = rho_after_2nd_uw_piB2 elif self.ms_ls_exp: rho_after_2nd_piB2 = self.U_rot(pi/2*self.sq_factor,ion_index=[1,0],phi=-self.phi_sum_1+pi/2)* \ self.U_rot(pi/2*self.sq_factor,ion_index=[0,1],phi=-self.phi_sum_2+pi/2)* \ rho_t* \ self.U_rot(pi/2*self.sq_factor,ion_index=[1,0],phi=-self.phi_sum_1+pi/2).dag() *\ self.U_rot(pi/2*self.sq_factor,ion_index=[0,1],phi=-self.phi_sum_2+pi/2).dag() final_rho = rho_after_2nd_piB2 else: final_rho = rho_t # final results # final_rhos.append(rho_final) final_rhos.append(final_rho) if self.two_loops: times *= 2 return times, final_rhos
def undisplaced_initial(init_sys, w0, T, N): n = Occupation(w0, T) return tensor(init_sys, thermal_dm(N, n))
gamma_motion_phi = 1e-3 # motion dephasing rate gamma_atom = 1e0 # atom dissipation rate N_hilbert = 200 # number of motional Fock states in Hilbert space # Atom state atom_up = basis(2,1) atom_down = basis(2,0) # Fock motional states #N_fock = 0 #motionfock = basis(N_hilbert,N_fock) #rho_up = tensor( motionfock*motionfock.dag(), atom_up*atom_up.dag()) #rho_down = tensor( motionfock*motionfock.dag(), atom_down*atom_down.dag()) # Thermal motional state N_motion = 20 # Thermal component of the initial state motion_dm = thermal_dm(N_hilbert, N_motion) alpha = 10. # Coherent displacement amplitude motion_dm = displaced_dm(thermal_dm(N_hilbert, N_motion), alpha) rho_up = tensor(motion_dm, atom_up*atom_up.dag()) rho_down = tensor(motion_dm, atom_down*atom_down.dag()) # collapse operators c_ops = collapse_operators(N_hilbert, N_noise, gamma_motion, gamma_motion_phi, gamma_atom) # return operators r_ops = population_operators(N_hilbert) thetalist = linspace(0, 2*pi, 100) phi = 0. mesolution_c = carrier_flop(rho_down, bare_rabi_freq, eta, detuning, thetalist, phi, c_ops, r_ops) mesolution_b = bsb_flop(rho_down, bare_rabi_freq, eta, detuning, thetalist, phi, c_ops, r_ops)
def rcsolve(Hsys, psi0, tlist, e_ops, Q, wc, alpha, N, w_th, sparse=False, options=None): """ Function to solve for an open quantum system using the reaction coordinate (RC) model. Parameters ---------- Hsys: Qobj The system hamiltonian. psi0: Qobj Initial state of the system. tlist: List. Time over which system evolves. e_ops: list of :class:`qutip.Qobj` / callback function single Single operator or list of operators for which to evaluate expectation values. Q: Qobj The coupling between system and bath. wc: Float Cutoff frequency. alpha: Float Coupling strength. N: Integer Number of cavity fock states. w_th: Float Temperature. sparse: Boolean Optional argument to call the sparse eigenstates solver if needed. options : :class:`qutip.Options` With options for the solver. Returns ------- output: Result System evolution. """ if options is None: options = Options() dot_energy, dot_state = Hsys.eigenstates(sparse=sparse) deltaE = dot_energy[1] - dot_energy[0] if (w_th < deltaE / 2): warnings.warn("Given w_th might not provide accurate results") gamma = deltaE / (2 * np.pi * wc) wa = 2 * np.pi * gamma * wc # reaction coordinate frequency g = np.sqrt(np.pi * wa * alpha / 2.0) # reaction coordinate coupling nb = (1 / (np.exp(wa / w_th) - 1)) # Reaction coordinate hamiltonian/operators dimensions = dims(Q) a = tensor(destroy(N), qeye(dimensions[1])) unit = tensor(qeye(N), qeye(dimensions[1])) Nmax = N * dimensions[1][0] Q_exp = tensor(qeye(N), Q) Hsys_exp = tensor(qeye(N), Hsys) e_ops_exp = [tensor(qeye(N), kk) for kk in e_ops] na = a.dag() * a xa = a.dag() + a # decoupled Hamiltonian H0 = wa * a.dag() * a + Hsys_exp # interaction H1 = (g * (a.dag() + a) * Q_exp) H = H0 + H1 L = 0 PsipreEta = 0 PsipreX = 0 all_energy, all_state = H.eigenstates(sparse=sparse) Apre = spre((a + a.dag())) Apost = spost(a + a.dag()) for j in range(Nmax): for k in range(Nmax): A = xa.matrix_element(all_state[j].dag(), all_state[k]) delE = (all_energy[j] - all_energy[k]) if abs(A) > 0.0: if abs(delE) > 0.0: X = (0.5 * np.pi * gamma * (all_energy[j] - all_energy[k]) * (np.cosh( (all_energy[j] - all_energy[k]) / (2 * w_th)) / (np.sinh( (all_energy[j] - all_energy[k]) / (2 * w_th)))) * A) eta = (0.5 * np.pi * gamma * (all_energy[j] - all_energy[k]) * A) PsipreX = PsipreX + X * all_state[j] * all_state[k].dag() PsipreEta = PsipreEta + (eta * all_state[j] * all_state[k].dag()) else: X = 0.5 * np.pi * gamma * A * 2 * w_th PsipreX = PsipreX + X * all_state[j] * all_state[k].dag() A = a + a.dag() L = ((-spre(A * PsipreX)) + (sprepost(A, PsipreX)) + (sprepost(PsipreX, A)) + (-spost(PsipreX * A)) + (spre(A * PsipreEta)) + (sprepost(A, PsipreEta)) + (-sprepost(PsipreEta, A)) + (-spost(PsipreEta * A))) # Setup the operators and the Hamiltonian and the master equation # and solve for time steps in tlist rho0 = (tensor(thermal_dm(N, nb), psi0)) output = mesolve(H, rho0, tlist, [L], e_ops_exp, options=options) return output
def rcsolve(Hsys, psi0, tlist, e_ops, Q, wc, alpha, N, w_th, sparse=False, options=None): """ Function to solve for an open quantum system using the reaction coordinate (RC) model. Parameters ---------- Hsys: Qobj The system hamiltonian. psi0: Qobj Initial state of the system. tlist: List. Time over which system evolves. e_ops: list of :class:`qutip.Qobj` / callback function single Single operator or list of operators for which to evaluate expectation values. Q: Qobj The coupling between system and bath. wc: Float Cutoff frequency. alpha: Float Coupling strength. N: Integer Number of cavity fock states. w_th: Float Temperature. sparse: Boolean Optional argument to call the sparse eigenstates solver if needed. options : :class:`qutip.Options` With options for the solver. Returns ------- output: Result System evolution. """ if options is None: options = Options() dot_energy, dot_state = Hsys.eigenstates(sparse=sparse) deltaE = dot_energy[1] - dot_energy[0] if (w_th < deltaE/2): warnings.warn("Given w_th might not provide accurate results") gamma = deltaE / (2 * np.pi * wc) wa = 2 * np.pi * gamma * wc # reaction coordinate frequency g = np.sqrt(np.pi * wa * alpha / 2.0) # reaction coordinate coupling nb = (1 / (np.exp(wa/w_th) - 1)) # Reaction coordinate hamiltonian/operators dimensions = dims(Q) a = tensor(destroy(N), qeye(dimensions[1])) unit = tensor(qeye(N), qeye(dimensions[1])) Nmax = N * dimensions[1][0] Q_exp = tensor(qeye(N), Q) Hsys_exp = tensor(qeye(N), Hsys) e_ops_exp = [tensor(qeye(N), kk) for kk in e_ops] na = a.dag() * a xa = a.dag() + a # decoupled Hamiltonian H0 = wa * a.dag() * a + Hsys_exp # interaction H1 = (g * (a.dag() + a) * Q_exp) H = H0 + H1 L = 0 PsipreEta = 0 PsipreX = 0 all_energy, all_state = H.eigenstates(sparse=sparse) Apre = spre((a + a.dag())) Apost = spost(a + a.dag()) for j in range(Nmax): for k in range(Nmax): A = xa.matrix_element(all_state[j].dag(), all_state[k]) delE = (all_energy[j] - all_energy[k]) if abs(A) > 0.0: if abs(delE) > 0.0: X = (0.5 * np.pi * gamma*(all_energy[j] - all_energy[k]) * (np.cosh((all_energy[j] - all_energy[k]) / (2 * w_th)) / (np.sinh((all_energy[j] - all_energy[k]) / (2 * w_th)))) * A) eta = (0.5 * np.pi * gamma * (all_energy[j] - all_energy[k]) * A) PsipreX = PsipreX + X * all_state[j] * all_state[k].dag() PsipreEta = PsipreEta + (eta * all_state[j] * all_state[k].dag()) else: X = 0.5 * np.pi * gamma * A * 2 * w_th PsipreX = PsipreX + X * all_state[j] * all_state[k].dag() A = a + a.dag() L = ((-spre(A * PsipreX)) + (sprepost(A, PsipreX)) + (sprepost(PsipreX, A)) + (-spost(PsipreX * A)) + (spre(A * PsipreEta)) + (sprepost(A, PsipreEta)) + (-sprepost(PsipreEta, A)) + (-spost(PsipreEta * A))) # Setup the operators and the Hamiltonian and the master equation # and solve for time steps in tlist rho0 = (tensor(thermal_dm(N, nb), psi0)) output = mesolve(H, rho0, tlist, [L], e_ops_exp, options=options) return output
gamma_motion_phi = 1e-3 # motion dephasing rate gamma_atom = 1e0 # atom dissipation rate N_hilbert = 200 # number of motional Fock states in Hilbert space # Atom state atom_up = basis(2, 1) atom_down = basis(2, 0) # Fock motional states #N_fock = 0 #motionfock = basis(N_hilbert,N_fock) #rho_up = tensor( motionfock*motionfock.dag(), atom_up*atom_up.dag()) #rho_down = tensor( motionfock*motionfock.dag(), atom_down*atom_down.dag()) # Thermal motional state N_motion = 20 # Thermal component of the initial state motion_dm = thermal_dm(N_hilbert, N_motion) alpha = 10. # Coherent displacement amplitude motion_dm = displaced_dm(thermal_dm(N_hilbert, N_motion), alpha) rho_up = tensor(motion_dm, atom_up * atom_up.dag()) rho_down = tensor(motion_dm, atom_down * atom_down.dag()) # collapse operators c_ops = collapse_operators(N_hilbert, N_noise, gamma_motion, gamma_motion_phi, gamma_atom) # return operators r_ops = population_operators(N_hilbert) thetalist = linspace(0, 2 * pi, 100) phi = 0. mesolution_c = carrier_flop(rho_down, bare_rabi_freq, eta, detuning, thetalist, phi, c_ops, r_ops)
def test_thermal_type(): "State CSR Type: thermal_dm" st = thermal_dm(25,5) assert_equal(isspmatrix_csr(st.data), True) st = thermal_dm(25,5, method='analytic') assert_equal(isspmatrix_csr(st.data), True)
import numpy as np import matplotlib.pyplot as plt import qutip N = 25 taus = np.linspace(0, 25.0, 200) a = qutip.destroy(N) H = 2 * np.pi * a.dag() * a kappa = 0.25 n_th = 2.0 # bath temperature in terms of excitation number c_ops = [np.sqrt(kappa * (1 + n_th)) * a, np.sqrt(kappa * n_th) * a.dag()] states = [ {'state': qutip.coherent_dm(N, np.sqrt(2)), 'label': "coherent state"}, {'state': qutip.thermal_dm(N, 2), 'label': "thermal state"}, {'state': qutip.fock_dm(N, 2), 'label': "Fock state"}, ] fig, ax = plt.subplots(1, 1) for state in states: rho0 = state['state'] # first calculate the occupation number as a function of time n = qutip.mesolve(H, rho0, taus, c_ops, [a.dag() * a]).expect[0] # calculate the correlation function G2 and normalize with n(0)n(t) to # obtain g2 G2 = qutip.correlation_3op_1t(H, rho0, taus, c_ops, a.dag(), a.dag()*a, a) g2 = G2 / (n[0] * n)