Example #1
0
def test_hf_fast_updatecond_complex(chempot, u_int, updater):
    """Test over the fast update after a spin flip"""
    w_n = cgf.matsubara_freq(20, 20)
    SO_N1 = np.array([[0, 1j, -1], [-1j, 0, 1j], [-1, -1j, 0]]) / 2

    # Semi circle GF by iteration
    H_loc = SO_N1 + chempot * np.eye(3)
    g_0_1 = [1j * wn * np.eye(3) - H_loc for wn in w_n]
    g_0 = [la.inv(g) for g in g_0_1]
    for i in range(40):
        g_0_1 = [
            1j * wn * np.eye(3) - H_loc - 0.25 * g for wn, g in zip(w_n, g_0)
        ]
        g_0 = [la.inv(g) for g in g_0_1]

    G_tail = [np.eye(3).reshape(3, 3, 1), H_loc.reshape(3, 3, 1), 0]
    tau = np.arange(0, 20, 20 / len(w_n))

    g_0 = np.array(g_0)
    g0t = cgf.gw_invfouriertrans(np.rollaxis(g_0, 0, 3), tau, w_n, G_tail)
    v = hf.ising_v(tau[1], u_int, len(tau) * 3)
    v = np.squeeze(v)
    g0ttp = hf.retarded_weiss(g0t)
    kroneker = np.eye(v.size)

    groot = hf.gnewclean(g0ttp, v, kroneker)
    g_fast_flip = np.copy(groot)

    flip = randrange(v.size)
    v[flip] *= -1

    g_flip = hf.gnewclean(g0ttp, v, kroneker)
    updater(g_fast_flip, 2 * v[flip], flip)

    assert np.allclose(g_flip, g_fast_flip)
Example #2
0
def test_solver_atom(u_int):
    parms = SOLVER_PARAMS
    parms.update(U=u_int, group='atom{}/'.format(u_int))
    v = hf.ising_v(parms['dtau_mc'], parms['U'], L=2 * parms['N_MATSUBARA'])
    tau = np.linspace(0, parms['BETA'], 2 * parms['N_MATSUBARA'])
    intm = hf.interaction_matrix(1)  # one orbital
    g0t = -.5 * np.ones(len(tau))
    parms['work_dir'] = os.path.join(parms['ofile'], 'saves')
    gtu, gtd = hf.imp_solver([g0t, g0t], v, intm, parms)
    g = np.squeeze(-0.5 * (gtu + gtd))  # make positive for next log
    result = np.polyfit(tau[:10], np.log(g[:10]), 1)
    assert np.allclose(result, [-u_int / 2., np.log(.5)], atol=0.02)
Example #3
0
def dmft_loop_pm(simulation, U, g_iw_start=None):
    """Implementation of the solver"""
    setup = {
        't': 0.5,
        'BANDS': 1,
        'SITES': 2,
    }

    setup.update(simulation)
    setup['dtau_mc'] = setup['BETA'] / 2. / setup['N_MATSUBARA']
    current_u = 'U' + str(U)
    setup['U'] = U
    setup['simt'] = 'PM'  # simulation type ParaMagnetic
    if setup['AFM']:
        setup['simt'] = 'AFM'  # simulation type AntiFerroMagnetic

    tau, w_n = gf.tau_wn_setup(setup)
    intm = hf.interaction_matrix(setup['BANDS'])
    setup['n_tau_mc'] = len(tau)
    mu, tp = setup['MU'], setup['tp']
    giw_d, giw_o = dimer.gf_met(w_n, mu, tp, 0.5, 0.)

    gmix = np.array([[1j * w_n + mu, -tp * np.ones_like(w_n)],
                     [-tp * np.ones_like(w_n), 1j * w_n + mu]])

    giw = np.array([[giw_d, giw_o], [giw_o, giw_d]])
    g0tau0 = -0.5 * np.eye(2).reshape(2, 2, 1)
    gtu = gf.gw_invfouriertrans(giw, tau, w_n, pd.gf_tail(g0tau0, 0., mu, tp))
    gtd = np.copy(gtu)

    if g_iw_start is not None:
        giw_up = g_iw_start[0]
        giw_dw = g_iw_start[1]

    save_dir = os.path.join(setup['ofile'].format(**setup), current_u)
    try:  # try reloading data from disk
        with open(save_dir + '/setup', 'r') as conf:
            last_loop = json.load(conf)['last_loop']
        gtu = np.load(
            os.path.join(save_dir, 'it{:03}'.format(last_loop),
                         'gtau_up.npy')).reshape(2, 2, -1)
        gtd = np.load(
            os.path.join(save_dir, 'it{:03}'.format(last_loop),
                         'gtau_dw.npy')).reshape(2, 2, -1)

        last_loop += 1
    except (IOError, KeyError, ValueError):  # if no data clean start
        last_loop = 0

    V_field = hf.ising_v(setup['dtau_mc'],
                         U,
                         L=setup['SITES'] * setup['n_tau_mc'],
                         polar=setup['spin_polarization'])

    for iter_count in range(last_loop, last_loop + setup['Niter']):
        work_dir = os.path.join(save_dir, 'it{:03}'.format(iter_count))
        setup['work_dir'] = work_dir

        if comm.rank == 0:
            print('On loop', iter_count, 'beta', setup['BETA'], 'U', U, 'tp',
                  tp)
        # paramagnetic cleaning
        gtu = 0.5 * (gtu + gtd)
        gtd = gtu

        giw_up = gf.gt_fouriertrans(gtu, tau, w_n, pd.gf_tail(gtu, U, mu, tp))
        giw_dw = gf.gt_fouriertrans(gtd, tau, w_n, pd.gf_tail(gtd, U, mu, tp))

        # Bethe lattice bath
        g0iw_up = dimer.mat_2_inv(gmix - 0.25 * giw_up)
        g0iw_dw = dimer.mat_2_inv(gmix - 0.25 * giw_dw)

        g0tau_up = gf.gw_invfouriertrans(g0iw_up, tau, w_n,
                                         pd.gf_tail(g0tau0, 0., mu, tp))
        g0tau_dw = gf.gw_invfouriertrans(g0iw_dw, tau, w_n,
                                         pd.gf_tail(g0tau0, 0., mu, tp))

        # Impurity solver

        gtu, gtd = hf.imp_solver([g0tau_dw, g0tau_up], V_field, intm, setup)

        # Save output
        if comm.rank == 0:
            np.save(work_dir + '/gtau_up', gtu.reshape(4, -1))
            np.save(work_dir + '/gtau_dw', gtd.reshape(4, -1))
            with open(save_dir + '/setup', 'w') as conf:
                setup['last_loop'] = iter_count
                json.dump(setup, conf, indent=2)
        sys.stdout.flush()
Example #4
0
def dmft_loop_pm(simulation):
    """Implementation of the solver"""
    setup = {
        't': 0.5,
        'BANDS': 1,
        'SITES': 2,
    }

    if simulation['new_seed']:
        if comm.rank == 0:
            hf.set_new_seed(simulation, ['gtau_d', 'gtau_o'])
        simulation['U'] = simulation['new_seed'][1]
        return

    setup.update(simulation)
    setup['dtau_mc'] = setup['BETA'] / 2. / setup['N_MATSUBARA']
    current_u = 'U' + str(setup['U'])

    tau, w_n = gf.tau_wn_setup(setup)
    intm = hf.interaction_matrix(setup['BANDS'])
    setup['n_tau_mc'] = len(tau)
    mu, tp, U = setup['MU'], setup['tp'], setup['U']

    giw_d_up, giw_o_up = dimer.gf_met(w_n, 1e-3, tp, 0.5, 0.)
    giw_d_dw, giw_o_dw = dimer.gf_met(w_n, -1e-3, tp, 0.5, 0.)
    gmix = np.array([[1j * w_n, -tp * np.ones_like(w_n)],
                     [-tp * np.ones_like(w_n), 1j * w_n]])
    g0tail = [
        np.eye(2).reshape(2, 2, 1),
        tp * np.array([[0, 1], [1, 0]]).reshape(2, 2, 1),
        np.array([[tp**2, 0], [0, tp**2]]).reshape(2, 2, 1)
    ]
    gtail = [
        np.eye(2).reshape(2, 2, 1),
        tp * np.array([[0, 1], [1, 0]]).reshape(2, 2, 1),
        np.array([[tp**2 + U**2 / 4, 0], [0,
                                          tp**2 + U**2 / 4]]).reshape(2, 2, 1)
    ]

    giw_up = np.array([[giw_d_up, giw_o_up], [giw_o_dw, giw_d_dw]])
    giw_dw = np.array([[giw_d_dw, giw_o_dw], [giw_o_up, giw_d_up]])

    try:  # try reloading data from disk
        with h5.File(setup['ofile'].format(**setup), 'r') as last_run:
            last_loop = len(last_run[current_u].keys())
            last_it = 'it{:03}'.format(last_loop - 1)
            giw_d, giw_o = pd.get_giw(last_run[current_u], last_it, tau, w_n)
    except (IOError, KeyError):  # if no data clean start
        last_loop = 0

    V_field = hf.ising_v(setup['dtau_mc'],
                         setup['U'],
                         L=setup['SITES'] * setup['n_tau_mc'],
                         polar=setup['spin_polarization'])

    for loop_count in range(last_loop, last_loop + setup['Niter']):
        # For saving in the h5 file
        dest_group = current_u + '/it{:03}/'.format(loop_count)
        setup['group'] = dest_group

        if comm.rank == 0:
            print('On loop', loop_count, 'beta', setup['BETA'], 'U', U, 'tp',
                  tp)

        # Bethe lattice bath
        g0iw_up = mat_2_inv(gmix - 0.25 * giw_up)
        g0iw_dw = mat_2_inv(gmix - 0.25 * giw_dw)

        g0tau_up = gf.gw_invfouriertrans(g0iw_up, tau, w_n, g0tail)
        g0tau_dw = gf.gw_invfouriertrans(g0iw_dw, tau, w_n, g0tail)

        # Impurity solver

        gtu, gtd = hf.imp_solver([g0tau_up, g0tau_dw], V_field, intm, setup)

        giw_up = gf.gt_fouriertrans(-gtu, tau, w_n, gtail)
        giw_dw = gf.gt_fouriertrans(-gtd, tau, w_n, gtail)

        # Save output
        if comm.rank == 0:
            with h5.File(setup['ofile'].format(**setup), 'a') as store:
                store[dest_group + 'gtau_u'] = gtu
                store[dest_group + 'gtau_d'] = gtd
                h5.add_attributes(store[dest_group], setup)
        sys.stdout.flush()