def test_transformation_in_different_basis(self): """(LINDBLAD) Testing transformations into different bases """ #Manager().warn_about_basis_change = True #Manager().warn_about_basis_changing_objects = True LT1 = LindbladForm(self.H1, self.sbi1, as_operators=True, name="LT1") LT2 = LindbladForm(self.H1, self.sbi1, as_operators=False, name="LT2") rho0 = ReducedDensityMatrix(dim=self.H1.dim, name="ahoj") with eigenbasis_of(self.H1): rho0.data[1, 1] = 0.7 rho0.data[0, 0] = 0.3 with eigenbasis_of(self.H1): rhot1_e = LT1.apply(rho0, copy=True) with eigenbasis_of(self.H1): rhot2_e = LT2.apply(rho0, copy=True) rhot1_l = LT1.apply(rho0, copy=True) rhot2_l = LT2.apply(rho0, copy=True) numpy.testing.assert_allclose(rhot1_l.data, rhot1_e.data) numpy.testing.assert_allclose(rhot2_l.data, rhot2_e.data) numpy.testing.assert_allclose(rhot1_e.data, rhot2_e.data) #, rtol=1.0e-2)
def test_propagation_in_different_basis(self): """(LINDBLAD) Testing comparison of propagations in different bases """ LT1 = LindbladForm(self.H1, self.sbi1, as_operators=True) LT2 = LindbladForm(self.H1, self.sbi1, as_operators=False) time = TimeAxis(0.0, 1000, 1.0) prop1 = ReducedDensityMatrixPropagator(time, self.H1, LT1) prop2 = ReducedDensityMatrixPropagator(time, self.H1, LT2) rho0 = ReducedDensityMatrix(dim=self.H1.dim) rho0.data[1, 1] = 1.0 with eigenbasis_of(self.H1): rhot1_e = prop1.propagate(rho0) with eigenbasis_of(self.H1): rhot2_e = prop2.propagate(rho0) rhot1_l = prop1.propagate(rho0) rhot2_l = prop2.propagate(rho0) numpy.testing.assert_allclose(rhot1_l.data, rhot1_e.data) numpy.testing.assert_allclose(rhot2_l.data, rhot2_e.data) numpy.testing.assert_allclose(rhot1_e.data, rhot2_e.data) #, rtol=1.0e-2)
def test_transformation_in_different_basis(self): """(LINDBLAD) Testing transformations into different bases """ #Manager().warn_about_basis_change = True #Manager().warn_about_basis_changing_objects = True LT1 = LindbladForm(self.H1, self.sbi1, as_operators=True, name="LT1") LT2 = LindbladForm(self.H1, self.sbi1, as_operators=False, name="LT2") rho0 = ReducedDensityMatrix(dim=self.H1.dim, name="ahoj") with eigenbasis_of(self.H1): rho0.data[1,1] = 0.7 rho0.data[0,0] = 0.3 with eigenbasis_of(self.H1): rhot1_e = LT1.apply(rho0, copy=True) with eigenbasis_of(self.H1): rhot2_e = LT2.apply(rho0, copy=True) rhot1_l = LT1.apply(rho0, copy=True) rhot2_l = LT2.apply(rho0, copy=True) numpy.testing.assert_allclose(rhot1_l.data, rhot1_e.data) numpy.testing.assert_allclose(rhot2_l.data, rhot2_e.data) numpy.testing.assert_allclose(rhot1_e.data, rhot2_e.data) #, rtol=1.0e-2)
def test_propagation_in_different_basis(self): """(LINDBLAD) Testing comparison of propagations in different bases """ LT1 = LindbladForm(self.H1, self.sbi1, as_operators=True) LT2 = LindbladForm(self.H1, self.sbi1, as_operators=False) time = TimeAxis(0.0, 1000, 1.0) prop1 = ReducedDensityMatrixPropagator(time, self.H1, LT1) prop2 = ReducedDensityMatrixPropagator(time, self.H1, LT2) rho0 = ReducedDensityMatrix(dim=self.H1.dim) rho0.data[1,1] = 1.0 with eigenbasis_of(self.H1): rhot1_e = prop1.propagate(rho0) with eigenbasis_of(self.H1): rhot2_e = prop2.propagate(rho0) rhot1_l = prop1.propagate(rho0) rhot2_l = prop2.propagate(rho0) numpy.testing.assert_allclose(rhot1_l.data, rhot1_e.data) numpy.testing.assert_allclose(rhot2_l.data, rhot2_e.data) numpy.testing.assert_allclose(rhot1_e.data, rhot2_e.data) #, rtol=1.0e-2)
def test_trace_over_vibrations(self): """Testing trace over vibrational DOF """ agg = self.vagg ham = agg.get_Hamiltonian() rho = ReducedDensityMatrix(dim=ham.dim) rho._data[5, 5] = 1.0 redr = agg.trace_over_vibrations(rho) numpy.testing.assert_almost_equal(numpy.trace(redr._data), 1.0, decimal=7) N = agg.Nb[0] rho = ReducedDensityMatrix(dim=ham.dim) rho._data[N+5, N+5] = 1.0 redr = agg.trace_over_vibrations(rho) numpy.testing.assert_almost_equal(numpy.trace(redr._data), 1.0, decimal=3) N = agg.Nb[1] rho = ReducedDensityMatrix(dim=ham.dim) rho._data[N+5, N+5] = 1.0 redr = agg.trace_over_vibrations(rho) numpy.testing.assert_almost_equal(numpy.trace(redr._data), 1.0, decimal=2)
def test_conversion_2_populations(self): """Testing conversion of reduced density matrix to population vector """ rdm = ReducedDensityMatrix( data=[[0.5, 0.0, 0.1], [0.0, 0.3, 0.0], [0.1, 0.0, 0.2]]) pop = rdm.get_populations() self.assertTrue(numpy.allclose(pop, [0.5, 0.3, 0.2]))
def test_conversion_2_populations(self): """Testing conversion of reduced density matrix to population vector """ rdm = ReducedDensityMatrix(data=[[0.5, 0.0, 0.1], [0.0, 0.3, 0.0], [0.1, 0.0, 0.2]]) pop = rdm.get_populations() self.assertTrue(numpy.allclose(pop,[0.5,0.3,0.2]))
def test_comparison_with_and_without_vib(self): """Testing ElectronicLindbladForm in propagation """ # Lindblad forms LT = ElectronicLindbladForm(self.ham, self.sbi, as_operators=False) vLT = ElectronicLindbladForm(self.vham, self.vsbi, as_operators=False) # Propagators time = TimeAxis(0.0, 1000, 1.0) el_prop = ReducedDensityMatrixPropagator(time, self.ham, LT) vib_prop = ReducedDensityMatrixPropagator(time, self.vham, vLT) # electronic initial condition rho0 = ReducedDensityMatrix(dim=self.ham.dim) rho0.data[2,2] = 1.0 # vibronic intial condition vrho0 = ReducedDensityMatrix(dim=self.vham.dim) agg = self.vsbi.system Nin = agg.vibindices[2][0] vrho0.data[Nin, Nin] = 1.0 # propagations rhot = el_prop.propagate(rho0) vrhot = vib_prop.propagate(vrho0) # averaging over vibrational level at t=0 Nel = agg.Nel aver_vrhot0 = agg.trace_over_vibrations(vrho0) # Test numpy.testing.assert_allclose(rhot._data[0,:,:], rho0._data) numpy.testing.assert_allclose(rhot._data[0,:,:], aver_vrhot0._data) aver_vrhot10 = agg.trace_over_vibrations(vrhot, 10) numpy.testing.assert_allclose(rhot._data[10,:,:], aver_vrhot10._data) aver_vrhot800 = agg.trace_over_vibrations(vrhot, 800) numpy.testing.assert_allclose(rhot._data[800,:,:], aver_vrhot800._data)
def test_saveable(self): """Testing reduced density matrix as Saveable """ rdm = ReducedDensityMatrix(data=[[0.5, 0.0, 0.1], [0.0, 0.3, 0.0], [0.1, 0.0, 0.2]]) #import h5py #with h5py.File("test_file_operators",driver="core", # backing_store=False) as fid: import tempfile with tempfile.TemporaryFile() as fid: rdm.save(fid) #, test=True) fid.seek(0) rdm2 = ReducedDensityMatrix() rdm2 = rdm2.load(fid) #, test=True) self.assertTrue(numpy.allclose(rdm2.data,rdm.data))
def test_comparison_of_dynamics(self): """Testing site basis dynamics by Lindblad """ LT1 = LindbladForm(self.H1, self.sbi1, as_operators=True) LT2 = LindbladForm(self.H1, self.sbi1, as_operators=False) time = TimeAxis(0.0, 1000, 1.0) prop1 = ReducedDensityMatrixPropagator(time, self.H1, LT1) prop2 = ReducedDensityMatrixPropagator(time, self.H1, LT2) rho0 = ReducedDensityMatrix(dim=self.H1.dim) rho0.data[1,1] = 1.0 rhot1 = prop1.propagate(rho0) rhot2 = prop2.propagate(rho0) numpy.testing.assert_allclose(rhot1.data,rhot2.data) #, rtol=1.0e-2)
def test_comparison_of_dynamics(self): """Testing site basis dynamics by Lindblad """ LT1 = LindbladForm(self.H1, self.sbi1, as_operators=True) LT2 = LindbladForm(self.H1, self.sbi1, as_operators=False) time = TimeAxis(0.0, 1000, 1.0) prop1 = ReducedDensityMatrixPropagator(time, self.H1, LT1) prop2 = ReducedDensityMatrixPropagator(time, self.H1, LT2) rho0 = ReducedDensityMatrix(dim=self.H1.dim) rho0.data[1, 1] = 1.0 rhot1 = prop1.propagate(rho0) rhot2 = prop2.propagate(rho0) numpy.testing.assert_allclose(rhot1.data, rhot2.data) #, rtol=1.0e-2)
def test_trace_over_vibrations(self): """(Aggregate) Testing trace over vibrational DOF """ agg = self.vagg ham = agg.get_Hamiltonian() rho = ReducedDensityMatrix(dim=ham.dim) rho._data[5, 5] = 1.0 redr = agg.trace_over_vibrations(rho) numpy.testing.assert_almost_equal(numpy.trace(redr._data), 1.0, decimal=7) N = agg.Nb[0] rho = ReducedDensityMatrix(dim=ham.dim) rho._data[N+5, N+5] = 1.0 redr = agg.trace_over_vibrations(rho) numpy.testing.assert_almost_equal(numpy.trace(redr._data), 1.0, decimal=3) N = agg.Nb[1] rho = ReducedDensityMatrix(dim=ham.dim) rho._data[N+5, N+5] = 1.0 redr = agg.trace_over_vibrations(rho) numpy.testing.assert_almost_equal(numpy.trace(redr._data), 1.0, decimal=2)
def test_comparison_with_and_without_vib(self): """Testing ElectronicLindbladForm in propagation """ # Lindblad forms LT = ElectronicLindbladForm(self.ham, self.sbi, as_operators=False) vLT = ElectronicLindbladForm(self.vham, self.vsbi, as_operators=False) # Propagators time = TimeAxis(0.0, 1000, 1.0) el_prop = ReducedDensityMatrixPropagator(time, self.ham, LT) vib_prop = ReducedDensityMatrixPropagator(time, self.vham, vLT) # electronic initial condition rho0 = ReducedDensityMatrix(dim=self.ham.dim) rho0.data[2, 2] = 1.0 # vibronic intial condition vrho0 = ReducedDensityMatrix(dim=self.vham.dim) agg = self.vsbi.system Nin = agg.vibindices[2][0] vrho0.data[Nin, Nin] = 1.0 # propagations rhot = el_prop.propagate(rho0) vrhot = vib_prop.propagate(vrho0) # averaging over vibrational level at t=0 Nel = agg.Nel aver_vrhot0 = agg.trace_over_vibrations(vrho0) # Test numpy.testing.assert_array_equal(rhot._data[0, :, :], rho0._data) numpy.testing.assert_array_equal(rhot._data[0, :, :], aver_vrhot0._data) aver_vrhot10 = agg.trace_over_vibrations(vrhot, 10) numpy.testing.assert_array_equal(rhot._data[10, :, :], aver_vrhot10._data) aver_vrhot800 = agg.trace_over_vibrations(vrhot, 800) numpy.testing.assert_array_equal(rhot._data[800, :, :], aver_vrhot800._data)
ham = vagg.get_Hamiltonian() print("Hamiltonian dimension: ", ham.dim) print("Constructing electronic Lindblad form") eLF = ElectronicLindbladForm(ham, vsbi, as_operators=True) print("...done") time = TimeAxis(0.0, 1000, 1.0) from quantarhei.qm import ReducedDensityMatrixPropagator vibprop = ReducedDensityMatrixPropagator(time, ham, eLF) from quantarhei.qm import ReducedDensityMatrix rho0 = ReducedDensityMatrix(dim=ham.dim) Ni = vagg.vibindices[3][0] rho0.data[Ni, Ni] = 1.0 print("Density matrix propagation: ") rhot = vibprop.propagate(rho0) print("...done") print("\nThe same but NO vibrational modes") m1v = Molecule([0.0, 1.0]) m2v = Molecule([0.0, 1.1]) m3v = Molecule([0.0, 1.2]) vagg2 = Aggregate(molecules=[m1v, m2v, m3v]) vagg2.build()
def test_comparison_of_exciton_dynamics(self): """Testing exciton basis dynamics by Lindblad """ # site basis form to be compared with LT1 = LindbladForm(self.H1, self.sbi1, as_operators=True) # exciton basis forms LT13 = LindbladForm(self.H3, self.sbi3, as_operators=True) LT23 = LindbladForm(self.H3, self.sbi3, as_operators=False) LT4e = LindbladForm(self.H4, self.sbi4e, as_operators=True) LT4s = LindbladForm(self.H4s, self.sbi4s, as_operators=True) time = TimeAxis(0.0, 1000, 1.0) # # Propagators # prop0 = ReducedDensityMatrixPropagator(time, self.H1, LT1) prop1 = ReducedDensityMatrixPropagator(time, self.H3, LT13) prop2 = ReducedDensityMatrixPropagator(time, self.H3, LT23) prop4e = ReducedDensityMatrixPropagator(time, self.H4, LT4e) prop4s = ReducedDensityMatrixPropagator(time, self.H4s, LT4s) # # Initial conditions # rho0 = ReducedDensityMatrix(dim=self.H3.dim) rho0c = ReducedDensityMatrix(dim=self.H1.dim) # excitonic with eigenbasis_of(self.H3): rho0c.data[1,1] = 1.0 rho0.data[1,1] = 1.0 rho04e = ReducedDensityMatrix(dim=self.H4.dim) rho04s = ReducedDensityMatrix(dim=self.H4.dim) with eigenbasis_of(self.H4): rho04e.data[2,2] = 1.0 rho04s.data[2,2] = 1.0 # # Propagations # rhotc = prop0.propagate(rho0c) rhot1 = prop1.propagate(rho0) rhot2 = prop2.propagate(rho0) rhot4e = prop4e.propagate(rho04e) rhot4s = prop4s.propagate(rho04s) # propagation with operator- and tensor forms should be the same numpy.testing.assert_allclose(rhot1.data,rhot2.data) #, rtol=1.0e-2) # # Population time evolution by Lindblad is independent # of the level structure and basis, as long as I compare # populations in basis in which the Lindblad form was defined # P = numpy.zeros((2, time.length)) Pc = numpy.zeros((2, time.length)) P4e = numpy.zeros((3, time.length)) P4s = numpy.zeros((3, time.length)) with eigenbasis_of(self.H3): for i in range(time.length): P[0,i] = numpy.real(rhot1.data[i,0,0]) # population of exciton 0 P[1,i] = numpy.real(rhot1.data[i,1,1]) # population of exciton 1 for i in range(time.length): Pc[0,i] = numpy.real(rhotc.data[i,0,0]) # population of exciton 0 Pc[1,i] = numpy.real(rhotc.data[i,1,1]) # population of exciton 1 # we compare populations numpy.testing.assert_allclose(Pc,P) #, rtol=1.0e-2) with eigenbasis_of(self.H4): for i in range(time.length): P4e[0,i] = numpy.real(rhot4e.data[i,0,0]) # population of exciton 0 P4e[1,i] = numpy.real(rhot4e.data[i,1,1]) # population of exciton 1 P4e[2,i] = numpy.real(rhot4e.data[i,2,2]) # population of exciton 1 for i in range(time.length): P4s[0,i] = numpy.real(rhot4s.data[i,0,0]) # population of exciton 0 P4s[1,i] = numpy.real(rhot4s.data[i,1,1]) # population of exciton 1 P4s[2,i] = numpy.real(rhot4s.data[i,2,2]) # population of exciton 1 # import matplotlib.pyplot as plt # # plt.plot(time.data,P4s[0,:], "-r") # plt.plot(time.data,P4s[1,:], "-r") # plt.plot(time.data,P4s[2,:], "-r") # plt.plot(time.data,P4e[0,:], "-g") # plt.plot(time.data,P4e[1,:], "-g") # plt.plot(time.data,P4e[2,:], "-g") # plt.show() numpy.testing.assert_allclose(P4e, P4s, atol=1.0e-8)
from quantarhei.qm import ElectronicLindbladForm ham = vagg.get_Hamiltonian() print("Hamiltonian dimension: ", ham.dim) print("Constructing electronic Lindblad form") eLF = ElectronicLindbladForm(ham, vsbi, as_operators=True) print("...done") time = TimeAxis(0.0, 1000, 1.0) from quantarhei.qm import ReducedDensityMatrixPropagator vibprop = ReducedDensityMatrixPropagator(time, ham, eLF) from quantarhei.qm import ReducedDensityMatrix rho0 = ReducedDensityMatrix(dim=ham.dim) Ni = vagg.vibindices[3][0] rho0.data[Ni, Ni] = 1.0 print("Density matrix propagation: ") rhot = vibprop.propagate(rho0) print("...done") print("\nThe same but NO vibrational modes") m1v = Molecule([0.0, 1.0]) m2v = Molecule([0.0, 1.1]) m3v = Molecule([0.0, 1.2]) vagg2 = Aggregate(molecules=[m1v, m2v, m3v]) vagg2.build()
def test_comparison_of_exciton_dynamics(self): """Testing exciton basis dynamics by Lindblad """ # site basis form to be compared with LT1 = LindbladForm(self.H1, self.sbi1, as_operators=True) # exciton basis forms LT13 = LindbladForm(self.H3, self.sbi3, as_operators=True) LT23 = LindbladForm(self.H3, self.sbi3, as_operators=False) LT4e = LindbladForm(self.H4, self.sbi4e, as_operators=True) LT4s = LindbladForm(self.H4s, self.sbi4s, as_operators=True) time = TimeAxis(0.0, 1000, 1.0) # # Propagators # prop0 = ReducedDensityMatrixPropagator(time, self.H1, LT1) prop1 = ReducedDensityMatrixPropagator(time, self.H3, LT13) prop2 = ReducedDensityMatrixPropagator(time, self.H3, LT23) prop4e = ReducedDensityMatrixPropagator(time, self.H4, LT4e) prop4s = ReducedDensityMatrixPropagator(time, self.H4s, LT4s) # # Initial conditions # rho0 = ReducedDensityMatrix(dim=self.H3.dim) rho0c = ReducedDensityMatrix(dim=self.H1.dim) # excitonic with eigenbasis_of(self.H3): rho0c.data[1, 1] = 1.0 rho0.data[1, 1] = 1.0 rho04e = ReducedDensityMatrix(dim=self.H4.dim) rho04s = ReducedDensityMatrix(dim=self.H4.dim) with eigenbasis_of(self.H4): rho04e.data[2, 2] = 1.0 rho04s.data[2, 2] = 1.0 # # Propagations # rhotc = prop0.propagate(rho0c) rhot1 = prop1.propagate(rho0) rhot2 = prop2.propagate(rho0) rhot4e = prop4e.propagate(rho04e) rhot4s = prop4s.propagate(rho04s) # propagation with operator- and tensor forms should be the same numpy.testing.assert_allclose(rhot1.data, rhot2.data) #, rtol=1.0e-2) # # Population time evolution by Lindblad is independent # of the level structure and basis, as long as I compare # populations in basis in which the Lindblad form was defined # P = numpy.zeros((2, time.length)) Pc = numpy.zeros((2, time.length)) P4e = numpy.zeros((3, time.length)) P4s = numpy.zeros((3, time.length)) with eigenbasis_of(self.H3): for i in range(time.length): P[0, i] = numpy.real(rhot1.data[i, 0, 0]) # population of exciton 0 P[1, i] = numpy.real(rhot1.data[i, 1, 1]) # population of exciton 1 for i in range(time.length): Pc[0, i] = numpy.real(rhotc.data[i, 0, 0]) # population of exciton 0 Pc[1, i] = numpy.real(rhotc.data[i, 1, 1]) # population of exciton 1 # we compare populations numpy.testing.assert_allclose(Pc, P) #, rtol=1.0e-2) with eigenbasis_of(self.H4): for i in range(time.length): P4e[0, i] = numpy.real(rhot4e.data[i, 0, 0]) # population of exciton 0 P4e[1, i] = numpy.real(rhot4e.data[i, 1, 1]) # population of exciton 1 P4e[2, i] = numpy.real(rhot4e.data[i, 2, 2]) # population of exciton 1 for i in range(time.length): P4s[0, i] = numpy.real(rhot4s.data[i, 0, 0]) # population of exciton 0 P4s[1, i] = numpy.real(rhot4s.data[i, 1, 1]) # population of exciton 1 P4s[2, i] = numpy.real(rhot4s.data[i, 2, 2]) # population of exciton 1 # import matplotlib.pyplot as plt # # plt.plot(time.data,P4s[0,:], "-r") # plt.plot(time.data,P4s[1,:], "-r") # plt.plot(time.data,P4s[2,:], "-r") # plt.plot(time.data,P4e[0,:], "-g") # plt.plot(time.data,P4e[1,:], "-g") # plt.plot(time.data,P4e[2,:], "-g") # plt.show() numpy.testing.assert_allclose(P4e, P4s, atol=1.0e-8)
#for n in range(4): # print(numpy.real(RT.data[n,n,5,5])) # #RR = RedfieldRateMatrix(HH,sbi) #for n in range(4): # print(numpy.real(RR.data[n,5])) """ IMPLEMENT AG.get_initial_RDM() """ # Sets an initial population of sites according to the transition dipole #AG.set_impulsive_population() rho = ReducedDensityMatrix(dim=HH.dim) #rho.data = AG.rho0 #rho.data[0,0] = 1.0 rho.data[HH.dim-1,HH.dim-1] = 1.0 #rho.data[1,0] = 0.5 #rho.data[0,1] = 0.5 rho.normalize2() print("Propagating density matrix ...") start = tm.time() # Convert to exciton basis in which RT was calculated ss = HH.diagonalize() # Relaxation tensors are defined in the eigenstate basis prop = RDMPropagator(time,HH,RTensor=RT) #prop.setDtRefinement(10)
def test_trace_over_vibrations(self): """(Aggregate) Testing trace over vibrational DOF """ agg = self.vagg ham = agg.get_Hamiltonian() rho = ReducedDensityMatrix(dim=ham.dim) rho._data[5, 5] = 1.0 redr = agg.trace_over_vibrations(rho) numpy.testing.assert_almost_equal(numpy.trace(redr._data), 1.0, decimal=7) N = agg.Nb[0] rho = ReducedDensityMatrix(dim=ham.dim) rho._data[N + 5, N + 5] = 1.0 redr = agg.trace_over_vibrations(rho) numpy.testing.assert_almost_equal(numpy.trace(redr._data), 1.0, decimal=3) N = agg.Nb[1] rho = ReducedDensityMatrix(dim=ham.dim) rho._data[N + 5, N + 5] = 1.0 redr = agg.trace_over_vibrations(rho) numpy.testing.assert_almost_equal(numpy.trace(redr._data), 1.0, decimal=2) rho = ReducedDensityMatrix(dim=ham.dim) n_part = 1. / (agg.Nb[0]) for state_ind in range(agg.Nb[0]): rho._data[state_ind, state_ind] = n_part redr = agg.trace_over_vibrations(rho) numpy.testing.assert_almost_equal(numpy.trace(redr._data), 1.0, decimal=7)