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_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_process_tensor_backends(backend, backend_config): initial_state = tempo.operators.spin_dm("y+") initial_tensor = initial_state.flatten().reshape((1, -1)) system = tempo.System(tempo.operators.sigma("z")) pt = tempo.ProcessTensor(times=None, tensors=[], initial_tensor=None, backend=backend, backend_config=backend_config) pt.export(TEMP_FILE, overwrite=True) pt.get_bond_dimensions() pt = tempo.ProcessTensor(times=None, tensors=[], initial_tensor=initial_tensor, backend=backend, backend_config=backend_config) pt.export(TEMP_FILE, overwrite=True) pt.get_bond_dimensions() pt.compute_final_state_from_system(system=system) pt.compute_dynamics_from_system(system=system) tensor = tempo.operators.identity(4).reshape((1, 1, 4, 4)) pt = tempo.ProcessTensor(times=None, tensors=[tensor], initial_tensor=initial_tensor, backend=backend, backend_config=backend_config) pt.export(TEMP_FILE, overwrite=True) pt.get_bond_dimensions() pt.compute_final_state_from_system(system=system) pt.compute_dynamics_from_system(system=system)
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_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 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+") with pytest.warns(UserWarning): dyn_A = tempo.tempo_compute(system=system, bath=bath, initial_state=initial_state, 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)
+ 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, start_time=t_start_E, backend=backend,
# See the License for the specific language governing permissions and # limitations under the License. """ Tests for the time_evovling_mpo.process_tensor module. """ import pytest import time_evolving_mpo as tempo 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,
# * A.1: The Model and its Parameters # * A.2: Create System, Spectral Density and Bath Objects # * A.3: The TEMPO Computation # ------------------------------------------------- # ## Example A - The Spin Boson Model # # 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)
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, bath_C, tempo_params_C, initial_state_C, start_time=0.0,
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, dkmax=None, epsrel=10**(-7)) tempo_A = tempo.Tempo(system_A, bath_A,
os.environ['NUMEXPR_NUM_THREADS'] = '1' import time_evolving_mpo as tempo import numpy as np import matplotlib.pyplot as plt from scipy import constants Omega = 0.0 # 1.0 # omega_cutoff = 3.0 # alpha = 0.1 omega_cutoff = 2.0e-3 * constants.electron_volt * 1e-12 / constants.hbar alpha = constants.hbar * 11.2e-3 * omega_cutoff**2 * 1e12/ \ (2 * constants.pi * constants.Boltzmann) system = tempo.System(0.0 * Omega * tempo.operators.sigma("x")) initial_state = tempo.operators.spin_dm("y+") 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)