示例#1
0
def test_simple(fname=None):
    # Type settings
    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

    # 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,
    )):
        try:
            if n % callback_interval == 0:
                rho = np.reshape(r.array, (-1, 4))[0]
                logger.info("{} {} {} {} {}".format(time, rho[0], rho[1], rho[2], rho[3]))
        except:
            break

    return
示例#2
0
def test_delta(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()}
    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.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,
                #split=False,
            )):
        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]))

    return
示例#3
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)
示例#4
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)
示例#5
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)
示例#6
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
示例#7
0
def test_train(fname=None):
    # HEOM metas
    corr.print()

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

    # 2-site TT
    tensor_train = tensor_train_template(rho_0, n_dims, rank=1)
    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.svd_err = 1.e-8
    solver.svd_rank = max_tier
    solver.ps_method = 'unite'

    projector = np.zeros((max_tier, 1))
    projector[0] = 1.0
    logger = Logger(filename=fname, level='info').logger
    logger2 = Logger(filename=fname + '_norm', level='info').logger
    for n, (time, _) in enumerate(solver.propagator(steps=count, ode_inter=dt_unit, split=True)):
        #print('n = {}: '.format(n))
        #for t in tensor_train:
        #    print('{}: {}'.format(t, t.shape))
        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]
            logger2.warning("{} {}".format(time, rho[0] + rho[3]))
            logger.info("{} {} {} {} {}".format(time, rho[0], rho[1], rho[2], rho[3]))
    return
示例#8
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)
示例#9
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)