コード例 #1
0
ファイル: test_qmc_hf.py プロジェクト: vkxlzptm/pydmft
def test_solver(chempot, u_int, gend):
    parms = SOLVER_PARAMS
    parms.update(U=u_int, MU=chempot, group='1band{}/'.format(u_int))
    tau, w_n, g0t, Giw, v, intm = hf.setup_PM_sim(parms)
    G0iw = 1 / (1j * w_n + parms['MU'] - .25 * Giw)
    g0t = hf.gw_invfouriertrans(G0iw, tau, w_n, [1., -parms['MU'], 0.])
    gtu, gtd = hf.imp_solver([g0t, g0t], v, intm, parms)
    g = np.squeeze(0.5 * (gtu + gtd))
    assert np.allclose(gend, g, atol=6e-3)
コード例 #2
0
ファイル: test_qmc_hf.py プロジェクト: Titan-C/learn-dmft
def test_solver(chempot, u_int, gend):
    parms = {'BETA': 16., 'N_TAU': 2**11, 'N_MATSUBARA': 64,
             't': 0.5,
             'MU': chempot, 'U': u_int, 'dtau_mc': 0.5, 'n_tau_mc':    32,
             'sweeps': 5000}
    tau, w_n, g0t, Giw, v = hf.setup_PM_sim(parms)
    G0iw = 1/(1j*w_n + parms['MU'] - .25*Giw)
    G0t = hf.gw_invfouriertrans(G0iw, tau, w_n)
    g0t = hf.interpol(G0t, parms['n_tau_mc'])
    gtu, gtd = hf.imp_solver(g0t, g0t, v, parms['sweeps'])
    g = -0.5 * (gtu+gtd)
    assert np.allclose(gend, g, atol=6e-3)
コード例 #3
0
ファイル: test_qmc_hf.py プロジェクト: vkxlzptm/pydmft
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)
コード例 #4
0
ファイル: test_qmc_hf.py プロジェクト: vkxlzptm/pydmft
def test_solver_dimer(chempot, u_int, gend):
    parms = SOLVER_PARAMS
    parms.update(U=u_int,
                 MU=chempot,
                 work_dir='dimer{}/'.format(u_int),
                 SITES=2)
    tau, w_n, g0t, Giw, v, intm = hf.setup_PM_sim(parms)
    G0iw = 1 / (1j * w_n + parms['MU'] - .25 * Giw)
    G0t = hf.gw_invfouriertrans(G0iw, tau, w_n, [1., -parms['MU'], 0.])
    gb0t = np.array([[G0t, np.zeros_like(G0t)], [np.zeros_like(G0t), G0t]])
    gtu, gtd = hf.imp_solver([gb0t] * 2, v, intm, parms)
    g = np.squeeze(0.5 * (gtu + gtd))
    assert np.allclose(gend, g[0, 0], atol=6e-3)
    assert np.allclose(np.zeros_like(g0t), g[0, 1], atol=6e-3)
    assert np.allclose(np.zeros_like(g0t), g[1, 0], atol=6e-3)
    assert np.allclose(gend, g[1, 1], atol=6e-3)
コード例 #5
0
def test_solver(chempot, u_int, gend):
    parms = {
        'BETA': 16.,
        'N_TAU': 2**11,
        'N_MATSUBARA': 64,
        't': 0.5,
        'MU': chempot,
        'U': u_int,
        'dtau_mc': 0.5,
        'n_tau_mc': 32,
        'sweeps': 5000
    }
    tau, w_n, g0t, Giw, v = hf.setup_PM_sim(parms)
    G0iw = 1 / (1j * w_n + parms['MU'] - .25 * Giw)
    G0t = hf.gw_invfouriertrans(G0iw, tau, w_n)
    g0t = hf.interpol(G0t, parms['n_tau_mc'])
    gtu, gtd = hf.imp_solver(g0t, g0t, v, parms['sweeps'])
    g = -0.5 * (gtu + gtd)
    assert np.allclose(gend, g, atol=6e-3)
コード例 #6
0
ファイル: plot_pm.py プロジェクト: Titan-C/learn-dmft
def dmft_loop_pm(gw=None, **kwargs):
    """Implementation of the solver"""
    parameters = {
                   'n_tau_mc':    40,
                   'BETA':        16,
                   'N_TAU':    2**11,
                   'N_MATSUBARA': 64,
                   'U':           2,
                   't':           0.5,
                   'MU':          0,
                   'loops':       8,
                   'sweeps':      20000,
                  }

    tau, w_n, __, Giw, v_aux = hf.setup_PM_sim(parameters)

    simulation = {'parameters': parameters}

    if gw is not None:
        Giw = gw

    for iter_count in range(parameters['loops']):
        G0iw = 1/(1j*w_n + parameters['MU'] - parameters['t']**2 * Giw)
        G0t = gw_invfouriertrans(G0iw, tau, w_n)
        g0t = hf.interpol(G0t, parameters['n_tau_mc'])

        gtu, gtd = hf.imp_solver(g0t, g0t, v_aux, parameters['sweeps'])
        gt = -0.5 * (gtu+gtd)

        Gt = hf.interpol(gt, parameters['N_TAU'])
        Giw = gt_fouriertrans(Gt, tau, w_n)
        simulation['it{:0>2}'.format(iter_count)] = {
                            'G0iw': G0iw,
                            'Giw':  Giw,
                            'gtau': gt,
                            }
    return simulation
コード例 #7
0
ファイル: plot_pm.py プロジェクト: ddcr/learn-dmft
def dmft_loop_pm(gw=None, **kwargs):
    """Implementation of the solver"""
    parameters = {
        'n_tau_mc': 40,
        'BETA': 16,
        'N_TAU': 2**11,
        'N_MATSUBARA': 64,
        'U': 2,
        't': 0.5,
        'MU': 0,
        'loops': 8,
        'sweeps': 20000,
    }

    tau, w_n, __, Giw, v_aux = hf.setup_PM_sim(parameters)

    simulation = {'parameters': parameters}

    if gw is not None:
        Giw = gw

    for iter_count in range(parameters['loops']):
        G0iw = 1 / (1j * w_n + parameters['MU'] - parameters['t']**2 * Giw)
        G0t = gw_invfouriertrans(G0iw, tau, w_n)
        g0t = hf.interpol(G0t, parameters['n_tau_mc'])

        gtu, gtd = hf.imp_solver(g0t, g0t, v_aux, parameters['sweeps'])
        gt = -0.5 * (gtu + gtd)

        Gt = hf.interpol(gt, parameters['N_TAU'])
        Giw = gt_fouriertrans(Gt, tau, w_n)
        simulation['it{:0>2}'.format(iter_count)] = {
            'G0iw': G0iw,
            'Giw': Giw,
            'gtau': gt,
        }
    return simulation
コード例 #8
0
ファイル: dimer_dop.py プロジェクト: vkxlzptm/pydmft
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()
コード例 #9
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()
コード例 #10
0
ファイル: single_site.py プロジェクト: vkxlzptm/pydmft
def dmft_loop_pm(simulation, U, g_iw_start=None):
    """Implementation of the solver"""
    setup = {'t':           .5,
             'SITES':       1,
            }

    current_u = 'U'+str(U)
    setup.update(simulation)
    setup['U'] = U
    setup['simt'] = 'PM' # simulation type ParaMagnetic

    tau, w_n, _, giw, v_aux, intm = hf.setup_PM_sim(setup)
    if setup['AFM']:
        giw = giw + np.array([[-1], [1]])*1e-3*giw.imag
        setup['simt'] = 'AFM' # simulation type Anti-Ferro-Magnetic

    if g_iw_start is not None:
        giw = g_iw_start

    gtau = gf.gw_invfouriertrans(giw, tau, w_n, [1., 0., .25])
    save_dir = os.path.join(setup['ofile'].format(**setup), current_u)
    try:
        with open(save_dir + '/setup', 'r') as conf:
            last_loop = json.load(conf)['last_loop']
        gtau = np.load(os.path.join(save_dir,
                                    'it{:03}'.format(last_loop),
                                    'gtau.npy'))
        last_loop += 1
    except (IOError, OSError):
        last_loop = 0

    for iter_count in range(last_loop, last_loop + setup['Niter']):
        # For saving in the h5 file
        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', setup['U'])

        giw = gf.gt_fouriertrans(gtau, tau, w_n,
                                 pss.gf_tail(gtau, U, setup['MU']))

        if setup['AFM']:
            g0iw = 1/(1j*w_n + setup['MU'] - setup['t']**2 * giw[[1, 0]])
            g0tau = gf.gw_invfouriertrans(g0iw, tau, w_n, [1., 0., .25])
            gtu, gtd = hf.imp_solver([g0tau[0], g0tau[1]], v_aux, intm, setup)
            gtau = np.squeeze([gtu, gtd])

        else:
            # enforce Half-fill, particle-hole symmetry
            giw.real = 0.

            g0iw = 1/(1j*w_n + setup['MU'] - setup['t']**2 * giw)
            g0tau = gf.gw_invfouriertrans(g0iw, tau, w_n, [1., 0., .25])
            gtu, gtd = hf.imp_solver([g0tau]*2, v_aux, intm, setup)
            gtau = np.squeeze(0.5 * (gtu+gtd))


        if COMM.rank == 0:
            np.save(work_dir + '/gtau', gtau)
            with open(save_dir + '/setup', 'w') as conf:
                setup['last_loop'] = iter_count
                json.dump(setup, conf, indent=2)
        sys.stdout.flush()

    return giw