def step_when_11(context, t_prop): """ And I propagate with Lindblad form L and PureDephasing D to get RE at time {t_prop} """ t = float(t_prop) # initial density matrix R = context.R HH = context.H RE = qr.ReducedDensityMatrix(dim=HH.dim) RE.data[:, :] = 0.0 time2 = context.time2 t2, dt2 = time2.locate(t) L = context.L D = context.D prop = qr.ReducedDensityMatrixPropagator(timeaxis=time2, Ham=HH, RTensor=L, PDeph=D) prop.setDtRefinement(10) with qr.eigenbasis_of(HH): rhot = prop.propagate(R) RE = qr.ReducedDensityMatrix(data=rhot.data[t2, :, :]) context.RE = RE
def test_dynamics(agg_list, energies): # Adding the energies to the molecules. Neeed to be done before agg with qr.energy_units("1/cm"): for i, mol in enumerate(agg_list): mol.set_energy(1, energies[i]) # Creation of the aggregate for dynamics. multiplicity can be 1 agg = qr.Aggregate(molecules=agg_list) agg.set_coupling_by_dipole_dipole(epsr=1.21) agg.build(mult=1) agg.diagonalize() # Creating a propagation axis length t13_ax plus padding with intervals 1 t2_prop_axis = qr.TimeAxis(0.0, 1000, 1) # Generates the propagator to describe motion in the aggregate prop_Redfield = agg.get_ReducedDensityMatrixPropagator( t2_prop_axis, relaxation_theory="stR", time_dependent=False, secular_relaxation=True ) # Obtaining the density matrix shp = agg.get_Hamiltonian().dim rho_i1 = qr.ReducedDensityMatrix(dim=shp, name="Initial DM") # Setting initial conditions rho_i1.data[shp-1,shp-1] = 1.0 # Propagating the system along the t13_ax_ax time axis rho_t1 = prop_Redfield.propagate(rho_i1, name="Redfield evo from agg") rho_t1.plot(coherences=False, axis=[0,t2_prop_axis.length,0,1.0], show=True)
def test_dynamics(self, en_method = None): # Adding the energies to the molecules. Neeed to be done before agg mol_list_temp = self._temp_assign_energies(method = en_method) aggregate = self._temp_build_agg(agg_list = mol_list_temp) # Propagation axis length t13_ax plus padding with intervals of 1 #t1_len = int(((t13_ax.length+padding-1)*t13_ax.step)+1) t2_prop_axis = qr.TimeAxis(0.0, 1000, 1) # Generates the propagator to describe motion in the aggregate prop_Redfield = aggregate.get_ReducedDensityMatrixPropagator( t2_prop_axis, relaxation_theory="stR", time_dependent=False, secular_relaxation=True ) # Obtaining the density matrix shp = aggregate.get_Hamiltonian().dim rho_i1 = qr.ReducedDensityMatrix(dim=shp, name="Initial DM") # Setting initial conditions rho_i1.data[shp-1,shp-1] = 1.0 # Propagating the system along the t13_ax_ax time axis rho_t1 = prop_Redfield.propagate(rho_i1, name="Redfield evo from agg") rho_t1.plot(coherences=False, axis=[0,t2_prop_axis.length,0,1.0], show=True)
def step_when_4(context, dtime, t_prop): """ And I multiply each coherence element by corresponding exponential decay with dephasing time {dtime} to get RE """ gamma = 1.0 / float(dtime) t = float(t_prop) R = context.R HH = context.H RE = qr.ReducedDensityMatrix(dim=HH.dim) RE.data[:, :] = 0.0 with qr.eigenbasis_of(HH): for i in range(4): for j in range(4): om = HH.data[i, i] - HH.data[j, j] if i != j: RE.data[i, j] = R.data[i, j] * numpy.exp(-1j * om * t - gamma * t) else: RE.data[i, j] = R.data[i, j] * numpy.exp(-1j * om * t) context.RE = RE
def step_given_7(context): """ Given I have a Hamiltonian H, Lidblad form L and initial density matrix R """ # create test aggregatedimer agg = qr.TestAggregate("trimer-2") agg.build() # get the associated time axis and the relaxation tensor and Hamiltonian time = qr.TimeAxis(0, 320, 1.0) time2 = qr.TimeAxis(0, 32, 10.0) context.time = time context.time2 = time2 HH = agg.get_Hamiltonian() context.H = HH SBI = qr.qm.TestSystemBathInteraction(name="trimer-2-lind") LL = qr.qm.LindbladForm(HH, SBI) context.L= LL # initial density matrix R = qr.ReducedDensityMatrix(dim=HH.dim) R.data[2,2] = 1.0 context.R = R
def step_when_7(context, dtime, t_prop): """ And I multiply each coherence element by corresponding Gaussian decay with dephasing time {dtime} to get RE at time {t_prop} """ delta = (1.0 / float(dtime))**2 t = float(t_prop) R = context.R HH = context.H RE = qr.ReducedDensityMatrix(dim=HH.dim) RE.data[:, :] = 0.0 with qr.eigenbasis_of(HH): for i in range(4): for j in range(4): om = HH.data[i, i] - HH.data[j, j] if i != j: RE.data[i, j] = R.data[i, j] * numpy.exp(-1j * om * t - (delta / 2.0) * (t**2)) else: RE.data[i, j] = R.data[i, j] * numpy.exp(-1j * om * t) context.RE = RE
def step_given_14(context, dtime): """ Given I have a Hamiltonian H, Lidblad form L, PureDephasing object D with dephasing time {dtime} and initial density matrix R """ td = float(dtime) print("Dephasing time", td) context.td = td # create test aggregatedimer agg = qr.TestAggregate("trimer-2") with qr.energy_units("1/cm"): agg.set_resonance_coupling(0, 1, 100.0) agg.set_resonance_coupling(1, 2, 50.0) agg.build() HH = agg.get_Hamiltonian() context.H = HH print("Hamiltonian:") print(HH) L = qr.qm.LindbladForm(HH, sbi=None) context.L = L # initial density matrix R = qr.ReducedDensityMatrix(dim=HH.dim) with qr.eigenbasis_of(HH): R.data[1:4, 1:4] = 0.5 context.R = R dd = numpy.zeros((4, 4), dtype=qr.REAL) dd[1, 2] = 1.0 / td dd[2, 1] = 1.0 / td dd[1, 3] = 1.0 / td dd[3, 1] = 1.0 / td dd[2, 3] = 1.0 / td dd[3, 2] = 1.0 / td D = qr.qm.PureDephasing(drates=dd, dtype="Lorentzian") context.D = D
def step_given_1(context): # create test aggregate agg = qr.TestAggregate("dimer-2-env") agg.build() # get the associated time axis and the relaxation tensor and Hamiltonian time = agg.get_SystemBathInteraction().TimeAxis RR, HH = agg.get_RelaxationTensor(time, relaxation_theory="stR") context.H = HH # define and calculate evolution superoperator U = qr.qm.EvolutionSuperOperator(time, ham=HH, relt=RR) U.calculate() context.U = U # initial density matrix R = qr.ReducedDensityMatrix(dim=HH.dim) R.data[2,2] = 1.0 context.R = R
# # calculation of the evolution superoperator # eS = qr.qm.EvolutionSuperOperator(time_so, ham, rt) eS.set_dense_dt(100) eS.calculate() print("...done") print("Reference calculation:") # # Reference calculations: via propagation # rho0 = qr.ReducedDensityMatrix(dim=Ndim) rho0.data[4, 4] = 0.5 rho0.data[3, 3] = 0.5 rho0.data[3, 4] = 0.5 rho0.data[4, 3] = 0.5 prop_tot = qr.ReducedDensityMatrixPropagator(time_tot, ham, rt) rhot = prop_tot.propagate(rho0) # # Reconstruct density matrix by applying evolution superoperator # rhoc1 = qr.qm.DensityMatrixEvolution(time_so) rhoc1.set_initial_condition(rho0)
from quantarhei.qm.liouvillespace.integrodiff.integrodiff \ import IntegrodiffPropagator timea = qr.TimeAxis(0.0, 200, 0.5) Nt = timea.length ham = qr.Hamiltonian(data=[[0.0, 0.1], [0.1, 0.01]]) # # Propagation without relaxation # ip1 = IntegrodiffPropagator(timea, ham, timefac=3, decay_fraction=2.0) np = qr.ReducedDensityMatrixPropagator(timea, ham) rhoi = qr.ReducedDensityMatrix(data=[[0.0, 0.0], [0.0, 1.0]]) t1 = time.time() rhot_i = ip1.propagate(rhoi) t2 = time.time() print("Propagated in frequency domain in:", t2 - t1) t1 = time.time() rhot_n = np.propagate(rhoi) t2 = time.time() print("Propagated in time domain in:", t2 - t1) if _show_plots_: plt.plot(timea.data, numpy.real(rhot_n.data[:, 0, 0]), "-b") plt.plot(timea.data, numpy.real(rhot_n.data[:, 1, 1]), "-r") plt.plot(timea.data, numpy.real(rhot_i.data[:, 0, 0]), "--g")
def test_LindbladWithVibrations_dynamics_comp(self): """Compares Lindblad dynamics of a system with vibrations calculated from propagator and superoperator """ # Aggregate import quantarhei as qr time = qr.TimeAxis(0.0, 1000, 1.0) # create a model with qr.energy_units("1/cm"): me1 = qr.Molecule([0.0, 12100.0]) me2 = qr.Molecule([0.0, 12000.0]) me3 = qr.Molecule([0.0, 12900.0]) agg_el = qr.Aggregate([me1, me2, me3]) agg_el.set_resonance_coupling(0, 1, qr.convert(150, "1/cm", to="int")) agg_el.set_resonance_coupling(1, 2, qr.convert(50, "1/cm", to="int")) m1 = qr.Molecule([0.0, 12100.0]) m2 = qr.Molecule([0.0, 12000.0]) m3 = qr.Molecule([0.0, 12900.0]) mod1 = qr.Mode(frequency=qr.convert(100, "1/cm", "int")) m1.add_Mode(mod1) mod1.set_HR(1, 0.01) agg = qr.Aggregate([m1, m2, m3]) agg.set_resonance_coupling(0, 1, qr.convert(150, "1/cm", to="int")) agg.set_resonance_coupling(1, 2, qr.convert(50, "1/cm", to="int")) agg_el.build() agg.build() hame = agg_el.get_Hamiltonian() ham = agg.get_Hamiltonian() # calculate relaxation tensor with qr.eigenbasis_of(hame): # # Operator describing relaxation # K = qr.qm.ProjectionOperator(1, 2, dim=hame.dim) # # System bath interaction with prescribed rate # from quantarhei.qm import SystemBathInteraction sbi = SystemBathInteraction(sys_operators=[K], rates=(1.0 / 100.0, )) sbi.set_system(agg) #agg.set_SystemBathInteraction(sbi) with qr.eigenbasis_of(ham): # # Corresponding Lindblad form # from quantarhei.qm import ElectronicLindbladForm LF = ElectronicLindbladForm(ham, sbi, as_operators=True) # # Evolution of reduced density matrix # prop = qr.ReducedDensityMatrixPropagator(time, ham, LF) # # Evolution by superoperator # eSO = qr.qm.EvolutionSuperOperator(time, ham, LF) eSO.set_dense_dt(5) eSO.calculate() # compare the two propagations pairs = [(5, 4), (5, 5), (6, 5), (7, 5)] for p in pairs: rho_i1 = qr.ReducedDensityMatrix(dim=ham.dim) rho_i1.data[p[0], p[1]] = 1.0 rho_t1 = prop.propagate(rho_i1) exp_rho_t2 = eSO.data[:, :, :, p[0], p[1]] #import matplotlib.pyplot as plt #plt.plot(rho_t1.TimeAxis.data, numpy.real(rho_t1.data[:,p[0],p[1]]), "-r") #plt.plot(rho_t1.TimeAxis.data, numpy.real(exp_rho_t2[:,p[0],p[1]]), "--g") #plt.show() #for kk in range(rho_t1.TimeAxis.length): # print(kk, numpy.real(rho_t1.data[kk,p[0],p[1]]),numpy.real(exp_rho_t2[kk,p[0],p[1]])) #numpy.testing.assert_allclose(RRT.data, rtd) numpy.testing.assert_allclose(numpy.real(rho_t1.data[:, :, :]), numpy.real(exp_rho_t2[:, :, :]), rtol=5.0e-2, atol=1.0e-3)
print("Size of hierarchy of depth", Hy6.depth, "is", Hy6.hsize) Hy7 = qr.KTHierarchy(ham, sbi, 4) print("Size of hierarchy of depth", Hy7.depth, "is", Hy7.hsize) # testing generation of hierarchy indices #print(Hy.generate_indices(4, level=4)) # #raise Exception() ############################################################################### # # Propagation of the HEOM # ############################################################################### # Initial density matrix rhoi = qr.ReducedDensityMatrix(dim=ham.dim) with qr.eigenbasis_of(ham): rhoi.data[2, 2] = 0.8 rhoi.data[1, 1] = 0.1 rhoi.data[3, 3] = 0.1 #print(rhoi) # Definition of the HEOM propagator #kprop3 = qr.KTHierarchyPropagator(timea, Hy3) #kprop4 = qr.KTHierarchyPropagator(timea, Hy4) #kprop5 = qr.KTHierarchyPropagator(timea, Hy5) kprop6 = qr.KTHierarchyPropagator(timea, Hy6) kprop7 = qr.KTHierarchyPropagator(timea, Hy7)
def test_Lindblad_dynamics_comp(self): """Compares Lindblad dynamics calculated from propagator and superoperator """ # Aggregate import quantarhei as qr import quantarhei.models.modelgenerator as mgen time = qr.TimeAxis(0.0, 1000, 1.0) # create a model mg = mgen.ModelGenerator() agg = mg.get_Aggregate(name="trimer-1") agg.build() ham = agg.get_Hamiltonian() # calculate relaxation tensor with qr.eigenbasis_of(ham): # # Operator describing relaxation # from quantarhei.qm import Operator K = Operator(dim=ham.dim, real=True) K.data[1, 2] = 1.0 # # System bath interaction with prescribed rate # from quantarhei.qm import SystemBathInteraction sbi = SystemBathInteraction(sys_operators=[K], rates=(1.0 / 100.0, )) agg.set_SystemBathInteraction(sbi) # # Corresponding Lindblad form # from quantarhei.qm import LindbladForm LF = LindbladForm(ham, sbi, as_operators=False) # # Evolution of reduced density matrix # prop = qr.ReducedDensityMatrixPropagator(time, ham, LF) # # Evolution by superoperator # eSO = qr.qm.EvolutionSuperOperator(time, ham, LF) eSO.set_dense_dt(5) eSO.calculate() # compare the two propagations pairs = [(1, 3), (3, 2), (3, 3)] for p in pairs: rho_i1 = qr.ReducedDensityMatrix(dim=ham.dim) rho_i1.data[p[0], p[1]] = 1.0 rho_t1 = prop.propagate(rho_i1) exp_rho_t2 = eSO.data[:, :, :, p[0], p[1]] #import matplotlib.pyplot as plt #plt.plot(rho_t1.TimeAxis.data, numpy.real(rho_t1.data[:,p[0],p[1]])) #plt.plot(rho_t1.TimeAxis.data, numpy.real(exp_rho_t2[:,p[0],p[1]])) #plt.show() #numpy.testing.assert_allclose(RRT.data, rtd) numpy.testing.assert_allclose(numpy.real(rho_t1.data[:, :, :]), numpy.real(exp_rho_t2[:, :, :]), rtol=1.0e-7, atol=1.0e-6)
def test_redfield_dynamics_comp(self): """Compares Redfield dynamics calculated from propagator and superoperator """ # Aggregate import quantarhei as qr import quantarhei.models.modelgenerator as mgen time = qr.TimeAxis(0.0, 1000, 1.0) # create a model mg = mgen.ModelGenerator() agg = mg.get_Aggregate_with_environment(name="trimer-1_env", timeaxis=time) agg.build() sbi = agg.get_SystemBathInteraction() ham = agg.get_Hamiltonian() # calculate relaxation tensor ham.protect_basis() with qr.eigenbasis_of(ham): RRT = qr.qm.RedfieldRelaxationTensor(ham, sbi) RRT.secularize() ham.unprotect_basis() with qr.eigenbasis_of(ham): # # Evolution of reduced density matrix # prop = qr.ReducedDensityMatrixPropagator(time, ham, RRT) # # Evolution by superoperator # eSO = qr.qm.EvolutionSuperOperator(time, ham, RRT) eSO.set_dense_dt(5) eSO.calculate() # compare the two propagations pairs = [(1, 3), (3, 2), (3, 3)] for p in pairs: rho_i1 = qr.ReducedDensityMatrix(dim=ham.dim) rho_i1.data[p[0], p[1]] = 1.0 rho_t1 = prop.propagate(rho_i1) exp_rho_t2 = eSO.data[:, :, :, p[0], p[1]] #import matplotlib.pyplot as plt #plt.plot(rho_t1.TimeAxis.data, numpy.real(rho_t1.data[:,p[0],p[1]])) #plt.plot(rho_t1.TimeAxis.data, numpy.real(exp_rho_t2[:,p[0],p[1]])) #plt.show() #numpy.testing.assert_allclose(RRT.data, rtd) numpy.testing.assert_allclose(numpy.real(rho_t1.data[:, :, :]), numpy.real(exp_rho_t2[:, :, :]), rtol=1.0e-7, atol=1.0e-6)
print("Setting up Redfield propagator:") t1 = time.time() prop_Redfield = agg.get_ReducedDensityMatrixPropagator( timea, relaxation_theory="standard_Redfield", time_dependent=False, secular_relaxation=True) t2 = time.time() print("...done in", t2 - t1, "sec") # # Initial density matrix # print("Initial condition for the density matrix") shp = H.dim rho_i1 = qr.ReducedDensityMatrix(dim=shp, name="Initial DM") rho_i1.data[shp - 1, shp - 1] = 1.0 print("...done") # # Propagation of the density matrix # print("Propagating density matrix:") t1 = time.time() rho_t1 = prop_Redfield.propagate(rho_i1, name="Redfield evolution from aggregate") t2 = time.time() print("...done in", t2 - t1, "sec") if _show_plots_:
TDRRM = qr.qm.TDRedfieldRateMatrix(ham, sbi) print("\nRelaxation times from the rate matrix") for i in range(1, ham.dim): for j in range(1, ham.dim): print(i, "<-", j, ":", 1.0 / TDRRM.data[time.length - 1, i, j]) ham.unprotect_basis() with qr.eigenbasis_of(ham): # # Evolution of reduced density matrix # prop = qr.ReducedDensityMatrixPropagator(time, ham, RRT) rho_i = qr.ReducedDensityMatrix(dim=ham.dim, name="Initial DM") rho_i.data[3, 3] = 1.0 # FIXME: unprotecting does not work correctly #RRT.unprotect_basis() with qr.eigenbasis_of(sb_reference): print(" Relaxation time site basis: ", 1.0 / RRT.data[1, 1, 2, 2]) RRT.secularize() print(" Relaxation time exciton basis: ", 1.0 / RRT.data[1, 1, 2, 2]) rho_t = prop.propagate(rho_i, name="Redfield evolution") if _show_plots_: rho_t.plot(coherences=False)
# -*- coding: utf-8 -*- """ Demonstration of the secularization of a relaxation tensor """ import numpy import quantarhei as qr import quantarhei.models as models N = 3 # Arbitrary density matrix rho = qr.ReducedDensityMatrix(dim=N) rho.data[0, 0] = 0.1 rho.data[1, 1] = 0.8 rho.data[2, 2] = 0.1 rho.data[1, 2] = 0.3 rho.data[2, 1] = 0.3 print(rho) # Rate matrix KK = qr.qm.RateMatrix(dim=N) KK.set_rate((1, 2), 1.0 / 100.0) KK.set_rate((0, 1), 1.0 / 200.0)