Ejemplo n.º 1
0
def test_brownian():
    lambda_0 = 0.05 # reorganization energy (dimensionless)
    omega_0   = 1.0 # vibrational frequency (dimensionless) 
    zeta      = 0.5 # damping constant      (dimensionless)
    max_tier  = 5
    omega_1 = np.sqrt(omega_0**2 - zeta**2*0.25)

    J = pyheom.Brownian(lambda_0, zeta, omega_0)

    corr_dict = pyheom.noise_decomposition(
        J,
        T = 1,                      # temperature (dimensionless)
        type_LTC = 'PSD',
        n_PSD = 1,
        type_PSD = 'N-1/N'
    )
    s = corr_dict['s'].toarray()
    a = corr_dict['a'].toarray()
    gamma = corr_dict['gamma'].toarray()
    delta = 0

    h = np.array([[omega_1, 0],
                [0, 0]])

    op = np.array([[0, 1],
                [1, 0]])

    max_terms = 3
    corr = Correlation(k_max=max_terms, beta=1)
    corr.symm_coeff = np.diag(s)
    corr.asymm_coeff = np.diag(a)
    corr.exp_coeff = np.diag(gamma)
    corr.delta_coeff = delta
    corr.print()
    heom = Hierachy([max_tier] * max_terms, h, op, corr)
    rho_0 = np.zeros((2, 2))
    rho_0[0, 0] = 1

    init_wfn = heom.gen_extended_rho(rho_0)


    solver = MultiLayer(init_wfn, heom.diff())


    # Define the obersevable of interest
    dat = []
    for n, (time, r) in enumerate(solver.propagator(
        steps=5000,
        ode_inter=0.01,
    )):
        if n % 100 == 0:
            rho = np.reshape(r, (-1, 4))
            for n, _rn in enumerate(rho):
                if n == 0:
                    flat_data = [time] + list(rho[0])
                    dat.append(flat_data)
                if n <= 0:
                    print("Time: {}    ; {}:    {}".format(time, n, _rn[0] + _rn[-1]))
    return np.array(dat)
Ejemplo n.º 2
0
def test_drude():
    from minitn.heom.noise import Drude
    from minitn.lib.units import Quantity

    # System
    e = Quantity(100, 'cm-1').value_in_au
    v = Quantity(50, 'cm-1').value_in_au

    # Bath
    corr2 = Correlation(k_max=1)
    corr2.symm_coeff  = [0.0]  # [4.66691921e+01 * 9.24899189e+01]
    corr2.asymm_coeff = [0.0]  # [4.66691921e+01 * -2.35486582e+01]
    corr2.exp_coeff = [1.0]
    corr2.delta_coeff = 0.0 # delta_coeff()
    corr2.print()

    h = np.array([[e, v],
                  [v, 0]])

    op = np.array([[1, 0],
                   [0, -1]])


    # Superparameters
    max_tier  = 5 # (number of possble values for each n_k in the extended rho)

    heom = Hierachy([max_tier], h, op, corr2)

    phi = np.array([1, 0]) 
    rho_0 = np.tensordot(phi, phi, axes=0)
    init_rho = heom.gen_extended_rho(rho_0)

    solver = MultiLayer(init_rho, heom.diff())

    # Define the obersevable of interest
    dat = []
    for n, (time, r) in enumerate(solver.propagator(
        steps=20000,
        ode_inter=0.1,
    )):
        if n % 100 == 0:
            rho = np.reshape(r, (-1, 4))
            for n, _ in enumerate(rho):
                if n == 0:
                    flat_data = [time] + list(rho[0])
                    dat.append(flat_data)
                    print('Time: {}; rho: {}  {}  {}  {}'.format(*flat_data))
    np.savetxt('test.dat', np.array(dat, dtype=np.complex128))
    return np.array(dat)
Ejemplo n.º 3
0
def test_drude():
    # Type settings
    corr = Correlation(k_max=max_terms)
    corr.symm_coeff = np.diag(corr_dict['s'].toarray())
    corr.asymm_coeff = np.diag(corr_dict['a'].toarray())
    corr.exp_coeff = np.diag(corr_dict['gamma'].toarray())
    corr.delta_coeff = 0.0  # delta_coeff
    corr.print()

    n_dims = [max_tier] * max_terms
    hseom = Hierachy(n_dims, H, V, corr)

    # Adopt MCTDH
    root = simple_hseom(init_wfns, n_dims)
    leaves_dict = {leaf.name: leaf for leaf in root.leaves()}
    all_terms = []
    for term in hseom.diff():
        all_terms.append([(leaves_dict[str(fst)], snd) for fst, snd in term])

    solver = MultiLayer(root, all_terms)
    solver.ode_method = 'RK45'
    solver.snd_order = False
    solver.atol = 1.e-7
    solver.rtol = 1.e-7

    # Define the obersevable of interest
    dat = []
    for n, (time,
            r) in enumerate(solver.propagator(
                steps=count,
                ode_inter=dt_unit,
            )):
        try:
            if n % callback_interval == 0:
                wfns = np.reshape(r.array, (-1, n_state**2))[0]
                print("Time: {};    |c|: {}".format(time,
                                                    np.linalg.norm(wfns)))

                f = np.reshape(wfns, (n_state, n_state))
                rho = sum(np.outer(i, i) for i in f)
                flat_data = [time] + list(np.reshape(rho, -1))
                dat.append(flat_data)
        except:
            break

    return np.array(dat)
Ejemplo n.º 4
0
def test_simple():
    # Type settings
    corr = Correlation(k_max=max_terms)
    corr.symm_coeff = np.diag(corr_dict['s'].toarray())
    corr.asymm_coeff = np.diag(corr_dict['a'].toarray())
    corr.exp_coeff = np.diag(corr_dict['gamma'].toarray())
    corr.delta_coeff = 0.0  # delta_coeff
    corr.print()

    n_dims = [max_tier] * max_terms
    heom = Hierachy(n_dims, H, V, corr)

    # Adopt MCTDH
    root = simple_heom(rho_0, n_dims)
    leaves_dict = {leaf.name: leaf for leaf in root.leaves()}
    all_terms = []
    for term in heom.diff():
        all_terms.append([(leaves_dict[str(fst)], snd) for fst, snd in term])

    #solver = ProjectorSplitting(root, all_terms)
    solver = MultiLayer(root, all_terms)
    solver.ode_method = 'RK45'
    solver.snd_order = False
    solver.atol = 1.e-7
    solver.rtol = 1.e-7

    # Define the obersevable of interest
    dat = []
    for n, (time,
            r) in enumerate(solver.propagator(
                steps=count,
                ode_inter=dt_unit,
            )):
        try:
            if n % callback_interval == 0:
                rho = np.reshape(r.array, (-1, 4))
                flat_data = [time] + list(rho[0])
                dat.append(flat_data)
                print("Time: {};    Tr rho_0: {}".format(
                    time, rho[0, 0] + rho[0, -1]))
        except:
            break

    return np.array(dat)
Ejemplo n.º 5
0
def test_train(fname=None):
    # Type settings
    corr = Correlation(k_max=max_terms)
    corr.symm_coeff = np.diag(corr_dict['s'].toarray())
    corr.asymm_coeff = np.diag(corr_dict['a'].toarray())
    corr.exp_coeff = np.diag(corr_dict['gamma'].toarray())
    corr.delta_coeff = 0.0  # delta_coeff
    corr.print()

    n_dims = [max_tier] * max_terms
    heom = Hierachy(n_dims, H, V, corr)

    # Adopt TT
    tensor_train = tensor_train_template(rho_0, n_dims)
    root = tensor_train[0]
    leaves_dict = {leaf.name: leaf for leaf in root.leaves()}
    all_terms = []
    for term in heom.diff():
        all_terms.append([(leaves_dict[str(fst)], snd) for fst, snd in term])

    solver = MultiLayer(root, all_terms)
    #solver = ProjectorSplitting(root, all_terms)
    solver.ode_method = 'RK45'
    solver.snd_order = False
    solver.atol = 1.e-7
    solver.rtol = 1.e-7
    solver.ps_method = 'split-unite'

    projector = np.zeros((max_tier, 1))
    projector[0] = 1.0
    logger = Logger(filename=fname, level='info').logger
    for n, (time, _) in enumerate(
            solver.propagator(steps=count, ode_inter=dt_unit, split=False)):
        if n % callback_interval == 0:
            head = root.array
            for t in tensor_train[1:]:
                spf = Tensor.partial_product(t.array, 1, projector, 0)
                head = Tensor.partial_product(head, head.ndim - 1, spf, 0)

            rho = np.reshape(head, (4, -1))[:, 0]
            logger.info("{} {} {} {} {}".format(time, rho[0], rho[1], rho[2],
                                                rho[3]))
    return
Ejemplo n.º 6
0
def test_drude(fname=None):
    # Type settings
    corr = Correlation(k_max=max_terms)
    corr.symm_coeff = np.diag(corr_dict['s'].toarray())
    corr.asymm_coeff = np.diag(corr_dict['a'].toarray())
    corr.exp_coeff = np.diag(corr_dict['gamma'].toarray())
    corr.delta_coeff = 0.0  # delta_coeff
    corr.print()

    n_dims = [max_tier] * max_terms
    heom = Hierachy(n_dims, H, V, corr)

    # Adopt MCTDH
    root = simple_heom(rho_0, n_dims)
    leaves_dict = {leaf.name: leaf for leaf in root.leaves()}
    all_terms = []
    for term in heom.diff():
        all_terms.append([(leaves_dict[str(fst)], snd) for fst, snd in term])

    solver = ProjectorSplitting(root, all_terms)
    solver.ode_method = 'DOP853'
    solver.snd_order = False
    solver.atol = 1.e-7
    solver.rtol = 1.e-7

    # Define the obersevable of interest
    logger = Logger(filename=fname, level='info').logger
    for n, (time, r) in enumerate(solver.propagator(
            steps=count,
            ode_inter=dt_unit,
    )):
        if n % callback_interval == 0:
            rho = np.reshape(r.array, (-1, 4))
            logger.info("{} {} {} {} {}".format(time, rho[0, 0], rho[0, 1], rho[0, 2], rho[0, 3]))
            print("Time: {};    Tr rho_0: {}".format(time, rho[0, 0] + rho[0, -1]))

    return
Ejemplo n.º 7
0
def test_drude_train():
    eta = 0.05  # reorganization energy (dimensionless)
    gamma_c = 0.05  # vibrational frequency (dimensionless)
    max_tier = 10

    max_terms = 3
    J = pyheom.Drudian(eta, gamma_c)
    corr_dict = pyheom.noise_decomposition(
        J,
        T=1,  # temperature (dimensionless)
        type_LTC='PSD',
        n_PSD=max_terms - 1,
        type_PSD='N-1/N')

    s = corr_dict['s'].toarray()
    a = corr_dict['a'].toarray()
    gamma = corr_dict['gamma'].toarray()
    delta = 0

    omega_1 = 0.05
    omega_2 = 0.02
    H = np.array([[omega_1, omega_2], [omega_2, 0]])

    V = np.array([[0, 0], [0, 1]])

    corr = Correlation(k_max=max_terms, beta=1)
    corr.symm_coeff = np.diag(s)
    corr.asymm_coeff = np.diag(a)
    corr.exp_coeff = np.diag(gamma)
    corr.delta_coeff = delta
    corr.print()
    heom = Hierachy([max_tier] * max_terms, H, V, corr)

    rho_0 = np.zeros((2, 2))
    rho_0[0, 0] = 1

    # TT HEOM
    tensor_train = tensor_train_template(rho_0, [max_tier] * max_terms,
                                         rank=max_tier)
    root = tensor_train[0]

    leaves_dict = {leaf.name: leaf for leaf in root.leaves()}
    all_terms = []
    for term in heom.diff():
        all_terms.append([(leaves_dict[str(fst)], snd) for fst, snd in term])

    solver = MultiLayer(root, all_terms)
    solver.ode_method = 'RK45'
    solver.snd_order = False
    solver.max_ode_steps = 100000

    # Define the obersevable of interest
    projector = np.zeros((max_tier, 1))
    projector[0] = 1.0

    dat = []
    for n, (time,
            r) in enumerate(solver.propagator(
                steps=20000,
                ode_inter=0.01,
            )):
        head = root.array
        for t in tensor_train[1:]:
            spf = Tensor.partial_product(t.array, 1, projector, 0)
            head = Tensor.partial_product(head, head.ndim - 1, spf, 0)

        rho = np.reshape(head, (4, -1))[:, 0]
        flat_data = [time] + list(rho)
        dat.append(flat_data)
        print("Time {} | Pop_1 {} | Total {}".format(time, rho[0],
                                                     rho[0] + rho[-1]))

    return np.array(dat)
Ejemplo n.º 8
0
# System
n_state = 2
H = np.array([[1.0, 1.0], [1.0, -1.0]])
#H = np.array([[0.0, 0.5], [0.5, 0.0]])
V = np.array([[1.0, 0.0], [0.0, -1.0]])

# Init state
p0 = 1.0
rho_0 = np.array([[p0, 0.0], [0.0, 1.0 - p0]])

# Bath
eta = 2.5  # reorganization energy (dimensionless)
gamma_c = 2.5  # vibrational frequency (dimensionless)
max_tier = 10
max_terms = 3
corr = Correlation(k_max=max_terms)
corr.symm_coeff = np.array([2.0767159490388725, 4.858236601790542, 7.778227240752226])
corr.asymm_coeff = np.array([-0.0625, 0.0, 0.0])
corr.exp_coeff = np.array([2.5, 6.305939144224808, 19.499618752922675])
corr.delta_coeff = 0.0  # delta_coeff

dt_unit = 0.01
callback_interval = 100
count = 500000


def test_train(fname=None):
    # HEOM metas
    corr.print()

    n_dims = [max_tier] * max_terms
Ejemplo n.º 9
0
rho_0 = np.array([[0.5, 0.5], [0.5, 0.5]])

dt_unit = 0.001
callback_interval = 100
count = 50000

# Bath
# C = g**2 (coth (beta omega / 2)) cos wt - ig**2 sin wt
max_terms = 2
max_tier = 20

omega = 0.05
g = 0.1
beta = 0.1

corr = Correlation(k_max=max_terms)
temp_factor = 1.0 / np.tanh(beta * omega / 2)
corr.symm_coeff = np.array(
    [g**2 * (temp_factor + 1) / 2.0, g**2 * (temp_factor - 1) / 2.0])
corr.asymm_coeff = np.array([0.0, 0.0])
corr.exp_coeff = np.array([1.0j * omega, -1.0j * omega])
corr.delta_coeff = 0.0  # delta_coeff
corr.print()


def test_delta(fname=None):

    n_dims = [max_tier] * max_terms
    heom = Hierachy(n_dims, H, V, corr)

    # Adopt MCTDH
Ejemplo n.º 10
0
# System
n_state = 2
H = np.array([[1.0, 1.0], [1.0, -1.0]])
#H = np.array([[0.0, 0.5], [0.5, 0.0]])
V = np.array([[1.0, 0.0], [0.0, -1.0]])

# Init state
p0 = 1.0
rho_0 = np.array([[p0, 0.0], [0.0, 1.0 - p0]])

# Bath
eta = 0.25  # reorganization energy (dimensionless)
gamma_c = 0.25  # vibrational frequency (dimensionless)
max_tier = 10
max_terms = 3
corr = Correlation(k_max=max_terms)
corr.symm_coeff = np.array(
    [0.4973931166166882, 0.041010943929914466, 0.0765163269642356])
corr.asymm_coeff = np.array([-0.0625, 0.0, 0.0])
corr.exp_coeff = np.array([0.25, 6.305939144224808, 19.499618752922675])
corr.delta_coeff = 0.0  # delta_coeff

dt_unit = 0.01
callback_interval = 100
count = 500000


def test_train(fname=None):
    # HEOM metas
    corr.print()
Ejemplo n.º 11
0
def test_drude_tree():
    eta = 0.05  # reorganization energy (dimensionless)
    gamma_c = 0.05  # vibrational frequency (dimensionless)
    max_tier = 10

    max_terms = 3
    J = pyheom.Drudian(eta, gamma_c)
    corr_dict = pyheom.noise_decomposition(
        J,
        T=1,  # temperature (dimensionless)
        type_LTC='PSD',
        n_PSD=max_terms - 1,
        type_PSD='N-1/N')

    s = corr_dict['s'].toarray()
    a = corr_dict['a'].toarray()
    gamma = corr_dict['gamma'].toarray()
    delta = 0

    omega_1 = 0.05
    omega_2 = 0.02
    H = np.array([[omega_1, omega_2], [omega_2, 0]])

    V = np.array([[0, 0], [0, 1]])

    corr = Correlation(k_max=max_terms, beta=1)
    corr.symm_coeff = np.diag(s)
    corr.asymm_coeff = np.diag(a)
    corr.exp_coeff = np.diag(gamma)
    corr.delta_coeff = delta
    corr.print()
    heom = Hierachy([max_tier] * max_terms, H, V, corr)

    rho_0 = np.zeros((2, 2))
    rho_0[0, 0] = 1

    root = tensor_tree_template(rho_0, [max_tier] * max_terms,
                                rank=max_tier // 2)

    solver = MultiLayer(root, heom.diff(), use_str_name=True)
    solver.ode_method = 'RK45'
    solver.snd_order = False
    solver.max_ode_steps = 100000

    dat = []
    for n, (time,
            r) in enumerate(solver.propagator(
                steps=20000,
                ode_inter=0.01,
            )):
        if n % 100 == 0:

            head = root.array

            print(head.shape)

            rho = Tensor.partial_product(r.array, 0, r[0][0].array, 0)
            rho = np.reshape(rho, (-1, 4))

            flat_data = [time] + list(rho[0])
            dat.append(flat_data)
            print("Time: {} | Pop 0: {} | Total: {}".format(
                flat_data[0], flat_data[1], flat_data[1] + flat_data[-1]))

    return np.array(dat)
Ejemplo n.º 12
0
n_state = 2
omega_1 = np.sqrt(omega_0**2 - zeta**2 * 0.25)
H = np.array([[omega_1, 0.0], [0.0, 0.0]])
V = np.array([[0.0, 1.0], [1.0, 0.0]])

# init state
rho_0 = np.zeros((n_state, n_state))
rho_0[0, 0] = 1

dt_unit = 0.001
callback_interval = 100
count = 50000

# Type settings
max_terms = 3
corr = Correlation(k_max=max_terms)
corr.symm_coeff = np.diag(corr_dict['s'].toarray())
corr.asymm_coeff = np.diag(corr_dict['a'].toarray())
corr.exp_coeff = np.diag(corr_dict['gamma'].toarray())
corr.delta_coeff = 0.0  # delta_coeff
corr.print()


def test_brownian(fname=None):

    n_dims = [max_tier] * max_terms
    heom = Hierachy(n_dims, H, V, corr)

    # Adopt MCTDH
    root = simple_heom(rho_0, n_dims)
    leaves_dict = {leaf.name: leaf for leaf in root.leaves()}