def test_tempo_bad_input(): start_time = -0.3 end_time = 0.84 correlation_function = lambda t: (np.cos(6.0*t)+1j*np.sin(6.0*t)) \ * np.exp(-12.0*t) correlations = tempo.CustomCorrelations(correlation_function, max_correlation_time=0.5) bath = tempo.Bath(0.5 * tempo.operators.sigma("z"), correlations) tempo_param = tempo.PtTempoParameters(0.1, 5, 1.0e-5, name="rough-A") tempo.PtTempo(bath=bath, parameters=tempo_param, start_time=start_time, end_time=end_time) with pytest.raises(AssertionError): tempo.PtTempo(bath=bath, parameters=tempo_param, start_time="bla", end_time=end_time) with pytest.raises(AssertionError): tempo.PtTempo(bath=bath, parameters=tempo_param, start_time=start_time, end_time="bla") with pytest.raises(AssertionError): tempo.PtTempo(bath=bath, parameters=tempo_param, start_time=0.0, end_time=0.0001)
def generate_pt(temp): start_time = 0.0 end_time = 10.0 correlations = tempo.PowerLawSD(alpha=alpha, zeta=3, cutoff=omega_cutoff, cutoff_type='gaussian', temperature=temp) bath = tempo.Bath(0.5 * tempo.operators.sigma("z"), correlations) dt = 0.1 # 0.01 dkmax = 20 # 200 epsrel = 1.0e-6 # 1.0e-7 tempo_parameters = tempo.TempoParameters(dt=dt, dkmax=dkmax, epsrel=epsrel) pt_tempo_parameters = tempo.PtTempoParameters(dt=dt, dkmax=dkmax, epsrel=epsrel) pt = tempo.pt_tempo_compute(bath=bath, start_time=start_time, end_time=end_time, parameters=pt_tempo_parameters, progress_type='bar') pt.export("details_pt_tempo_{}K.processTensor".format(temp), overwrite=True)
def test_pt_tempo(): start_time = -0.3 end_time = 0.84 system = tempo.System(0.5 * tempo.operators.sigma("x")) correlation_function = lambda t: (np.cos(6.0*t)+1j*np.sin(6.0*t)) \ * np.exp(-12.0*t) correlations = tempo.CustomCorrelations(correlation_function, max_correlation_time=0.5) bath = tempo.Bath(0.5 * tempo.operators.sigma("z"), correlations) initial_state = tempo.operators.spin_dm("z+") tempo_param_A = tempo.PtTempoParameters(0.1, 5, 1.0e-5, name="rough-A") pt_tempo_sys_A = tempo.PtTempo(bath=bath, parameters=tempo_param_A, start_time=start_time, end_time=end_time) assert pt_tempo_sys_A.dimension == 2 pt_tempo_sys_A.compute() pt_A = pt_tempo_sys_A.get_process_tensor() assert len(pt_A.times) == 12 tempo_param_B = tempo.PtTempoParameters(0.1, None, 1.0e-5, name="rough-B") pt_tempo_sys_B = tempo.PtTempo(bath=bath, parameters=tempo_param_B, start_time=start_time, end_time=end_time) pt_B = pt_tempo_sys_B.get_process_tensor()
def test_tempo(): start_time = -0.3 end_time1 = 0.4 end_time2 = 0.6 end_time3 = 0.84 system = tempo.System(0.5 * tempo.operators.sigma("x")) correlation_function = lambda t: (np.cos(6.0*t)+1j*np.sin(6.0*t)) \ * np.exp(-12.0*t) correlations = tempo.CustomCorrelations(correlation_function, max_correlation_time=0.5) bath = tempo.Bath(0.5 * tempo.operators.sigma("z"), correlations) initial_state = tempo.operators.spin_dm("z+") tempo_param_A = tempo.TempoParameters(0.1, 5, 1.0e-5, name="rough-A") tempo_sys_A = tempo.Tempo(system=system, bath=bath, parameters=tempo_param_A, initial_state=initial_state, start_time=start_time) assert tempo_sys_A.dimension == 2 tempo_sys_A.compute(end_time=end_time1, progress_type="bar") tempo_sys_A.compute(end_time=end_time2, progress_type="silent") tempo_sys_A.compute(end_time=end_time3, progress_type="simple") dyn_A = tempo_sys_A.get_dynamics() assert len(dyn_A.times) == 13
def test_tempo_bad_input(): start_time = -0.3 end_time = 0.84 system = tempo.System(0.5 * tempo.operators.sigma("x")) correlation_function = lambda t: (np.cos(6.0*t)+1j*np.sin(6.0*t)) \ * np.exp(-12.0*t) correlations = tempo.CustomCorrelations(correlation_function, max_correlation_time=0.5) bath = tempo.Bath(0.5 * tempo.operators.sigma("z"), correlations) initial_state = tempo.operators.spin_dm("z+") tempo_param_A = tempo.TempoParameters(0.1, 5, 1.0e-5, name="rough-A") with pytest.raises(AssertionError): tempo_sys_A = tempo.Tempo(system=system, bath=bath, parameters=tempo_param_A, initial_state="bla", start_time=start_time) with pytest.raises(AssertionError): tempo_sys_A = tempo.Tempo(system=system, bath=bath, parameters=tempo_param_A, initial_state=initial_state, start_time="bla") tempo_sys_A = tempo.Tempo(system=system, bath=bath, parameters=tempo_param_A, initial_state=initial_state, start_time=start_time) with pytest.raises(AssertionError): tempo_sys_A.compute(end_time="bla", progress_type="bar")
def test_guess_pt_tempo_parameters(): correlation_function = lambda t: (np.cos(t) + 1j * np.sin(6.0 * t) ) * np.exp(-2.0 * t) correlations = tempo.CustomCorrelations(correlation_function, max_correlation_time=10.0) bath = tempo.Bath(0.5 * tempo.operators.sigma("z"), correlations) with pytest.warns(UserWarning): param = tempo.guess_pt_tempo_parameters(bath=bath, start_time=0.0, end_time=15.0)
def test_tensor_network_tempo_backend_non_diag(backend): Omega = 1.0 omega_cutoff = 5.0 alpha = 0.3 sx = tempo.operators.sigma("x") sy = tempo.operators.sigma("y") sz = tempo.operators.sigma("z") bases = [{"sys_op":sx, "coupling_op":sz, \ "init_state":tempo.operators.spin_dm("y+")}, {"sys_op":sy, "coupling_op":sx, \ "init_state":tempo.operators.spin_dm("z+")}, {"sys_op":sz, "coupling_op":sy, \ "init_state":tempo.operators.spin_dm("x+")}] results = [] for i, base in enumerate(bases): system = tempo.System(0.5 * base["sys_op"]) correlations = tempo.PowerLawSD(alpha=alpha, zeta=1, cutoff=omega_cutoff, cutoff_type='exponential', max_correlation_time=8.0) bath = tempo.Bath(0.5 * base["coupling_op"], correlations) tempo_parameters = tempo.TempoParameters(dt=0.1, dkmax=30, epsrel=10**(-5)) dynamics = tempo.tempo_compute(system=system, bath=bath, initial_state=base["init_state"], start_time=0.0, end_time=1.0, parameters=tempo_parameters, backend=backend) _, s_x = dynamics.expectations(0.5 * tempo.operators.sigma("x"), real=True) _, s_y = dynamics.expectations(0.5 * tempo.operators.sigma("y"), real=True) _, s_z = dynamics.expectations(0.5 * tempo.operators.sigma("z"), real=True) if i == 0: results.append(np.array([s_x, s_y, s_z])) elif i == 1: results.append(np.array([s_y, s_z, s_x])) elif i == 2: results.append(np.array([s_z, s_x, s_y])) assert np.allclose(results[0], results[1], atol=tempo_parameters.epsrel) assert np.allclose(results[0], results[2], atol=tempo_parameters.epsrel)
def test_tempo_compute(): start_time = -0.3 end_time = 0.84 correlation_function = lambda t: (np.cos(6.0*t)+1j*np.sin(6.0*t)) \ * np.exp(-12.0*t) correlations = tempo.CustomCorrelations(correlation_function, max_correlation_time=0.5) bath = tempo.Bath(0.5 * tempo.operators.sigma("z"), correlations) initial_state = tempo.operators.spin_dm("z+") with pytest.warns(UserWarning): pt_A = tempo.pt_tempo_compute(bath=bath, start_time=start_time, end_time=end_time)
def test_tempo_dynamics_reference(): system = tempo.System(0.5 * tempo.operators.sigma("x")) correlations = tempo.PowerLawSD(alpha=0.1, zeta=1, cutoff=1.0, cutoff_type='exponential', max_correlation_time=0.5) bath = tempo.Bath(0.5 * tempo.operators.sigma("z"), correlations) tempo_parameters = tempo.TempoParameters(dt=0.1, dkmax=10, epsrel=10**(-4)) tempo_A = tempo.Tempo(system=system, bath=bath, parameters=tempo_parameters, initial_state=tempo.operators.spin_dm("up"), start_time=0.0) dynamics_1 = tempo_A.compute(end_time=0.2) t_1, sz_1 = dynamics_1.expectations(tempo.operators.sigma("z")) tempo_A.compute(end_time=0.4) dynamics_2 = tempo_A.get_dynamics() t_2, sz_2 = dynamics_2.expectations(tempo.operators.sigma("z")) assert dynamics_1 == dynamics_2 assert len(t_2) > len(t_1)
def test_guess_tempo_parameters(): system = tempo.System(0.5 * tempo.operators.sigma("x")) correlation_function = lambda t: (np.cos(t) + 1j * np.sin(6.0 * t) ) * np.exp(-2.0 * t) correlations = tempo.CustomCorrelations(correlation_function, max_correlation_time=10.0) bath = tempo.Bath(0.5 * tempo.operators.sigma("z"), correlations) with pytest.warns(UserWarning): param = tempo.guess_tempo_parameters(bath=bath, start_time=0.0, end_time=15.0) with pytest.raises(AssertionError): # bad start time input param = tempo.guess_tempo_parameters(bath=bath, start_time="bla", end_time=15.0) with pytest.raises(AssertionError): # bad end time input param = tempo.guess_tempo_parameters(bath=bath, start_time=0.0, end_time="bla") with pytest.raises(ValueError): # bad start/end time (swapped) param = tempo.guess_tempo_parameters(bath=bath, start_time=10.0, end_time=0.0) with pytest.raises(AssertionError): # bad tollerance param = tempo.guess_tempo_parameters(bath=bath, start_time=0.0, end_time=15.0, tollerance="bla") with pytest.raises(AssertionError): # bad tollerance (negative) param = tempo.guess_tempo_parameters(bath=bath, start_time=0.0, end_time=15.0, tollerance=-0.2) with pytest.warns(UserWarning): # reach MAX_DKMAX param = tempo.guess_tempo_parameters(bath=bath, start_time=0.0, end_time=15.0, tollerance=1.0e-12)
# In[6]: def hamiltonian_t(t): return detuning(t) / 2.0 * tempo.operators.sigma("z") + gaussian_shape( t, area=np.pi / 2.0, tau=0.245) / 2.0 * tempo.operators.sigma("x") system = tempo.TimeDependentSystem(hamiltonian_t) correlations = tempo.PowerLawSD(alpha=alpha, zeta=3, cutoff=omega_cutoff, cutoff_type='gaussian', max_correlation_time=5.0, temperature=temperature) bath = tempo.Bath(tempo.operators.sigma("z") / 2.0, correlations) # ### B.4: TEMPO computation # With all physical objects defined, we are now ready to compute the dynamics of the quantum dot using TEMPO (using quite rough convergence parameters): # In[7]: tempo_parameters = tempo.TempoParameters(dt=0.05, dkmax=40, epsrel=10**(-5)) tempo_sys = tempo.Tempo(system=system, bath=bath, initial_state=initial_state, start_time=-2.0, parameters=tempo_parameters) dynamics = tempo_sys.compute(end_time=3.0)
y_plus = np.exp(-phi) dm = (1 - y_plus) * tempo.operators.spin_dm("mixed") \ + y_plus * tempo.operators.spin_dm("y+") return dm rho_E = exact_result(t_end_E) correlations_E = tempo.PowerLawSD(alpha=alpha_E, zeta=3.0, cutoff=cutoff_E, cutoff_type="exponential", temperature=temperature_E, name="superohmic", ) bath_E = tempo.Bath(coupling_operator_E, correlations_E, name="superohmic phonon bath") system_E = tempo.System(h_sys_E) # ----------------------------------------------------------------------------- @pytest.mark.parametrize('backend,backend_config', [("tensor-network", {"backend":"numpy"}),]) def test_tensor_network_tempo_backend_E(backend, backend_config): tempo_params_E = tempo.TempoParameters(dt=0.4, dkmax=5, epsrel=1.0e-6) tempo_E = tempo.Tempo(system_E, bath_E, tempo_params_E, initial_state_E,
temperature_A = 0.2 # end time t_end_A = 1.0 # result obtained with release code (made hermitian): rho_A = np.array([[0.7809559 + 0.j, -0.09456333 + 0.16671419j], [-0.09456333 - 0.16671419j, 0.2190441 + 0.j]]) correlations_A = tempo.PowerLawSD(alpha=alpha_A, zeta=1.0, cutoff=cutoff_A, cutoff_type="exponential", temperature=temperature_A, name="ohmic") bath_A = tempo.Bath(coupling_operator_A, correlations_A, name="phonon bath") system_A = tempo.System(h_sys_A, gammas=[gamma_A_1, gamma_A_2], lindblad_operators=[ tempo.operators.sigma("-"), tempo.operators.sigma("z") ]) # ----------------------------------------------------------------------------- @pytest.mark.parametrize('backend,backend_config', [("tensor-network", { "backend": "numpy" }), ("tensor-network", None)]) def test_tensor_network_tempo_backend_A(backend, backend_config): tempo_params_A = tempo.TempoParameters(dt=0.05,
TEMP_FILE = "tests/data/temp.processTensor" # -- prepare a process tensor ------------------------------------------------- system = tempo.System(tempo.operators.sigma("x")) initial_state = tempo.operators.spin_dm("z+") correlations = tempo.PowerLawSD(alpha=0.3, zeta=1.0, cutoff=5.0, cutoff_type="exponential", temperature=0.2, name="ohmic") bath = tempo.Bath(0.5*tempo.operators.sigma("z"), correlations, name="phonon bath") tempo_params = tempo.PtTempoParameters(dt=0.1, dkmax=5, epsrel=10**(-5)) pt = tempo.pt_tempo_compute(bath, start_time=0.0, end_time=1.0, parameters=tempo_params) pt.export(TEMP_FILE, overwrite=True) del pt def test_process_tensor(): pt = tempo.import_process_tensor(TEMP_FILE) str(pt)
# # As a first example let's try to reconstruct one of the lines in figure 2a of [Strathearn2018] ([Nat. Comm. 9, 3322 (2018)](https://doi.org/10.1038/s41467-018-05617-3) / [arXiv:1711.09641v3](https://arxiv.org/abs/1711.09641)). In this example we compute the time evolution of a spin which is strongly coupled to an ohmic bath (spin-boson model). Before we go through this step by step below, let's have a brief look at the script that will do the job - just to have an idea where we are going: # In[3]: Omega = 1.0 omega_cutoff = 5.0 alpha = 0.3 system = tempo.System(0.5 * Omega * tempo.operators.sigma("x")) correlations = tempo.PowerLawSD(alpha=alpha, zeta=1, cutoff=omega_cutoff, cutoff_type='exponential', max_correlation_time=8.0) bath = tempo.Bath(0.5 * tempo.operators.sigma("z"), correlations) tempo_parameters = tempo.TempoParameters(dt=0.1, dkmax=30, epsrel=10**(-4)) dynamics = tempo.tempo_compute(system=system, bath=bath, initial_state=tempo.operators.spin_dm("up"), start_time=0.0, end_time=15.0, parameters=tempo_parameters) t, s_z = dynamics.expectations(0.5 * tempo.operators.sigma("z"), real=True) plt.plot(t, s_z, label=r'$\alpha=0.3$') plt.xlabel(r'$t\,\Omega$') plt.ylabel(r'$<S_z>$') plt.legend()
t_end_C = 1.0 # result obtained with release code (made hermitian, dkmax=10): rho_C = np.array( [[ 0.12576653+0.j ,-0.11739956-0.14312036j, 0.12211454-0.05963583j], [-0.11739956+0.14312036j, 0.61315893+0.j ,-0.06636825+0.26917271j], [ 0.12211454+0.05963583j,-0.06636825-0.26917271j, 0.26107455+0.j ]]) correlations_C = tempo.PowerLawSD(alpha=alpha_C, zeta=1.0, cutoff=cutoff_C, cutoff_type="exponential", temperature=temperature_C, name="ohmic") bath_C = tempo.Bath(coupling_operator_C, correlations_C, name="phonon bath") system_C = tempo.System(h_sys_C, gammas=[gamma_C_1, gamma_C_2], lindblad_operators=[lindblad_operators_C_1, lindblad_operators_C_2]) # ----------------------------------------------------------------------------- @pytest.mark.parametrize('backend',["tensor-network"]) def test_tensor_network_tempo_backend_C(backend): tempo_params_C = tempo.TempoParameters(dt=0.05, dkmax=11, epsrel=10**(-7)) tempo_C = tempo.Tempo(system_C,
temperature_D = 0.2 # end time t_end_D = 1.0 # result obtained with release code (made hermitian): rho_D = np.array([[0.91244238 + 0.0j, -0.0586503 + 1.33156274e-01j], [-0.0586503 - 1.33156274e-01j, 0.08755133 + 0.0j]]) correlations_D = tempo.PowerLawSD(alpha=alpha_D, zeta=1.0, cutoff=cutoff_D, cutoff_type="exponential", temperature=temperature_D, name="ohmic") bath_D = tempo.Bath(coupling_operator_D, correlations_D, name="phonon bath") system_D = tempo.TimeDependentSystem(h_sys_D, gammas=[gamma_D_1, gamma_D_2], lindblad_operators=[ lambda t: tempo.operators.sigma("-"), lambda t: tempo.operators.sigma("z") ]) # ----------------------------------------------------------------------------- @pytest.mark.parametrize('backend,backend_config', [("tensor-network", { "backend": "numpy" }), ("tensor-network", None)]) def test_tensor_network_tempo_backend_D(backend, backend_config): tempo_params_D = tempo.TempoParameters(dt=0.05,