def test_tempo_parameters_bad_input():
    with pytest.raises(AssertionError):
        tempo.TempoParameters("x", 42, 1.0e-5, "rough", "bla", {})
    with pytest.raises(AssertionError):
        tempo.TempoParameters(0.1, "x", 1.0e-5, "rough", "bla", {})
    with pytest.raises(AssertionError):
        tempo.TempoParameters(0.1, 42, "x", "rough", "bla", {})
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_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_plot_correlations_with_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)
    param = tempo.TempoParameters(dt=0.1, dkmax=50, epsrel=3.9e-8)
    tempo.helpers.plot_correlations_with_parameters(correlations, param)
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_tensor_network_tempo_backend_C(backend):
    tempo_params_C = tempo.TempoParameters(dt=0.05, dkmax=10, epsrel=10**(-7))
    tempo_C = tempo.Tempo(system_C,
                          bath_C,
                          tempo_params_C,
                          initial_state_C,
                          start_time=0.0,
                          backend=backend)
    tempo_C.compute(end_time=1.0)
    dyn_C = tempo_C.get_dynamics()
    assert dyn_C.times[-1] == 1.0
    np.testing.assert_almost_equal(dyn_C.states[-1], rho_C, decimal=4)
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)
示例#8
0
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,
                          backend_config=backend_config)
    tempo_E.compute(end_time=t_end_E)
    dyn_E = tempo_E.get_dynamics()
    np.testing.assert_almost_equal(dyn_E.states[-1], rho_E, decimal=4)
def test_tempo_parameters():
    tempo_param = tempo.TempoParameters(0.1, None, 1.0e-5, "rough", "bla", {})
    str(tempo_param)
    assert tempo_param.dt == 0.1
    assert tempo_param.dkmax == None
    assert tempo_param.epsrel == 1.0e-5
    tempo_param.dt = 0.05
    tempo_param.dkmax = 42
    tempo_param.epsrel = 1.0e-6
    assert tempo_param.dt == 0.05
    assert tempo_param.dkmax == 42
    assert tempo_param.epsrel == 1.0e-6
    del tempo_param.dkmax
    assert tempo_param.dkmax == None
示例#10
0
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,
                          tempo_params_A,
                          initial_state_A,
                          start_time=0.0,
                          backend=backend,
                          backend_config=backend_config)
    tempo_A.compute(end_time=1.0)
    dyn_A = tempo_A.get_dynamics()
    np.testing.assert_almost_equal(dyn_A.states[-1], rho_A, decimal=4)
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)
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)

# and extract the expectation values $\langle\sigma_{xy}\rangle = \sqrt{\langle\sigma_x\rangle^2 + \langle\sigma_y\rangle^2}$ for plotting:

# In[8]:

t, s_x = dynamics.expectations(tempo.operators.sigma("x"), real=True)
t, s_y = dynamics.expectations(tempo.operators.sigma("y"), real=True)
s_xy = np.sqrt(s_x**2 + s_y**2)
# 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()

# ### A.1: The Model and its Parameters