コード例 #1
0
def get_giw(sim_dir, iteration_slice, tau=None, w_n=None, setup=None):
    r"""Recovers with Fourier Transform G_iw from H5 file

    Parameters
    ----------
    h5parent : hdf5 group to go
    iteration_slice : list of iteration names to average over
    tau : 1D real array time slices of HF data
    w_n : 1D real array matsubara frequencies

    Returns
    -------
    tuple : :math:`G(\tau)`, :math:`G(i\omega_n)`
    """

    recovered_sim_info = False
    if None in (tau, w_n, setup):
        with open(sim_dir + '/setup', 'r') as read:
            setup = json.load(read)
        tau, w_n = gf.tau_wn_setup(setup)
        recovered_sim_info = True

    gtau = averager(sim_dir, 'gtau.npy', iteration_slice)
    giw = gf.gt_fouriertrans(gtau, tau, w_n,
                             gf_tail(gtau, setup['U'], setup['MU']))

    if recovered_sim_info:
        return giw, gtau, tau, w_n, setup
    else:
        return giw, gtau
コード例 #2
0
ファイル: ipt_imag.py プロジェクト: vkxlzptm/pydmft
def single_band_ipt_solver(u_int, g_0_iwn, w_n, tau):
    r"""Given a Green function it returns a dressed one and the self-energy

    .. math:: \Sigma(\tau) \approx U^2 \mathcal{G}^0(\tau)^3

    .. math:: G = \mathcal{G}^0(i\omega_n)/(1 - \Sigma(i\omega_n)\mathcal{G}^0(i\omega_n))

    The Fourier transforms use as tail expansion of the atomic limit self-enegy

    .. math:: \Sigma(i\omega_n\rightarrow \infty) = \frac{U^2}{4(i\omega_n)}

    Parameters
    ----------
    u_int: float, local contact interaction
    g_0_iwn: complex 1D ndarray
        *bare* Green function, the Weiss field
    w_n: real 1D ndarray
        Matsubara frequencies
    tau: real 1D array
        Imaginary time points, not included edge point of :math:`\beta^-`
    """

    g_0_tau = gw_invfouriertrans(g_0_iwn, tau, w_n, [1., 0., 0.25])
    sigma_tau = u_int**2 * g_0_tau**3
    sigma_iwn = gt_fouriertrans(sigma_tau, tau, w_n, [u_int**2 / 4., 0., 0.])
    g_iwn = g_0_iwn / (1 - sigma_iwn * g_0_iwn)

    return g_iwn, sigma_iwn
コード例 #3
0
ファイル: ipt_imag.py プロジェクト: Titan-C/learn-dmft
def solver(u_int, g_0_iwn, w_n, tau):

    g_0_tau = gw_invfouriertrans(g_0_iwn, tau, w_n)
    sigma_tau = u_int**2 * g_0_tau**3
    sigma_iwn = gt_fouriertrans(sigma_tau, tau, w_n)
    g_iwn = g_0_iwn / (1 - sigma_iwn * g_0_iwn)

    return g_iwn, sigma_iwn
コード例 #4
0
ファイル: ipt_imag.py プロジェクト: vkxlzptm/pydmft
def dimer_sigma(u_int, tp, g0iw_d, g0iw_o, tau, w_n):
    r"""Given a Green function it returns the self-energy

    .. math:: \Sigma(\tau) \approx - U^2 \mathcal{G}^0(\tau)\mathcal{G}^0(-\tau)\mathcal{G}^0(\tau)

    Which is done element wise given the form of the local interaction
    in the dimer. For symmetry reasons only the 2 arrays are returned,
    corresponding to the diagonal and off-diagonal terms of the matrix
    self-energy

    The Fourier transforms uses an empirically established tail expansion

    .. math:: \Sigma(i\omega_n\rightarrow \infty)_{AA} =
        \frac{U^2}{4i\omega_n} + \frac{M_3}{(i\omega_n)^3}
    .. math:: \Sigma(i\omega_n\rightarrow \infty)_{AB} = \frac{M_2}{2(i\omega_n)^2}

    where :math:`M_3,M_2` are calculated from the derivatives of the :math:`\Sigma(\tau)`

    Parameters
    ----------
    u_int : float, local contact interaction
    tp : float, dimer hybridization strength
    g0iw_d : complex 1D ndarray
        *bare* local Green function, the Weiss field
    g0iw_o : complex 1D ndarray
        *bare* hybridizing Green function, the Weiss field
    tau: real 1D array
        Imaginary time points, not included edge point of :math:`\beta^-`
    w_n: real 1D ndarray
        Matsubara frequencies
    """

    g0t_d = gw_invfouriertrans(g0iw_d, tau, w_n, [1., 0., tp**2 + 0.25])
    g0t_o = gw_invfouriertrans(g0iw_o, tau, w_n, [0., tp, 0.])

    st_d, st_o = _dimer_sigma(g0t_d, g0t_o, u_int)

    dj2d = -2 * ((st_d[2] - 2 * st_d[1] + st_d[0]) / tau[1]**2)
    sw_d = gt_fouriertrans(
        st_d, tau, w_n, [u_int**2 / 4, 0., dj2d])
    dj1o = 2 * (st_o[1] - st_o[0]) / tau[1]
    sw_o = gt_fouriertrans(st_o, tau, w_n, [0., dj1o, 0.])

    return sw_d, sw_o
コード例 #5
0
ファイル: test_common.py プロジェクト: vkxlzptm/pydmft
def test_fourier_trasforms(chempot, beta=50., n_matsubara=128):
    """Test the tail improved fourier transforms"""
    parms = {'BETA': beta, 'N_MATSUBARA': n_matsubara}
    tau, w_n = gf.tau_wn_setup(parms)
    giw = gf.greenF(w_n, mu=chempot)

    for gwr in [giw, np.array([giw, giw])]:
        g_tau = gf.gw_invfouriertrans(gwr, tau, w_n, [1., -chempot, 0.25])
        g_iomega = gf.gt_fouriertrans(g_tau, tau, w_n, [1., -chempot, 0.25])
        assert np.allclose(gwr, g_iomega)
コード例 #6
0
def test_fourier_trasforms(chempot, beta=50., n_tau=2**11, n_matsubara=64):
    """Test the tail improved fourier transforms"""
    parms = {'BETA': beta, 'N_TAU': n_tau, 'N_MATSUBARA': n_matsubara}
    tau, w_n = tau_wn_setup(parms)
    gw = greenF(w_n, mu=chempot)

    for gwr in [gw, np.array([gw, gw])]:
        g_tau = gw_invfouriertrans(gwr, tau, w_n)
        g_iomega = gt_fouriertrans(g_tau, tau, w_n)
        assert np.allclose(gwr, g_iomega)
コード例 #7
0
ファイル: test_common.py プロジェクト: Titan-C/learn-dmft
def test_fourier_trasforms(chempot, beta=50., n_tau=2**11, n_matsubara=64):
    """Test the tail improved fourier transforms"""
    parms = {'BETA': beta, 'N_TAU': n_tau, 'N_MATSUBARA': n_matsubara}
    tau, w_n = tau_wn_setup(parms)
    gw = greenF(w_n, mu=chempot)

    for gwr in [gw, np.array([gw, gw])]:
        g_tau = gw_invfouriertrans(gwr, tau, w_n)
        g_iomega = gt_fouriertrans(g_tau, tau, w_n)
        assert np.allclose(gwr, g_iomega)
コード例 #8
0
def collect_bined_saves():
    binede_dat = glob('gtau_bin_*')
    G = np.array([np.load(dfile) for dfile in binede_dat])
    gtau = G.mean(1)
    tau, w_n = gf.tau_wn_setup(dict(BETA=32., N_MATSUBARA=32))
    fw = gf.matsubara_freq(32., 64, -63)

    giw = gf.gt_fouriertrans(gtau, tau, w_n, [1., 0., .25 + 2.5**2 / 4])

    sgiw = np.concatenate((giw.conj().T[::-1], giw.T))
    np.savez('bined', w_n=fw, giw=sgiw)
コード例 #9
0
ファイル: hf_dimer.py プロジェクト: vkxlzptm/pydmft
def get_giw(filestr, tau=None, w_n=None, setup=None):
    """Recovers with Fourier Transform G_iw and G_tau from npy file

    Parameters
    ----------
    filestr : string
            file with array data G(tau)
    setup : dictionary about simulation parameters
    tau : real float array
            Imaginary time points
    w_n : real float array
            fermionic matsubara frequencies. Only use the positive ones

    Returns
    -------
    tuple complex ndarray (giw, gtau)
            Interacting Greens function in matsubara frequencies
            and original Imaginary time. Entries are list ordered and
            not in matrix shape

    See also
    --------
    get_sigmaiw
    """

    recovered_sim_info = False
    if None in (tau, w_n, setup):
        sim_dir = os.path.dirname(os.path.dirname(os.path.abspath(filestr)))
        with open(sim_dir + '/setup', 'r') as read:
            setup = json.load(read)
        tau, w_n = gf.tau_wn_setup(setup)
        recovered_sim_info = True

    gtau = np.load(filestr)
    mu, tp, u_int = setup['MU'], setup['tp'], setup['U']
    giw = gf.gt_fouriertrans(gtau.reshape(2, 2, -1), tau, w_n,
                             gf_tail(gtau.reshape(2, 2, -1), u_int, mu, tp))

    if recovered_sim_info:
        return giw.reshape(4, -1), gtau, tau, w_n, setup
    else:
        return giw.reshape(4, -1), gtau
コード例 #10
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
コード例 #11
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
コード例 #12
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()
コード例 #13
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()
コード例 #14
0
# Redo from the QMC tau, tail following G(tau) discontinuity
gt = gtau.sum(0) * .5
gt = np.concatenate((gt, [-1 - gt[0]]))
taub = np.concatenate((tau, [64.]))

gtautck = splrep(taub, gt, s=0)
dev0 = [splev(0, gtautck, der=i) for i in range(4)]
devb = [splev(64, gtautck, der=i) for i in range(4)]

ders = np.abs(-gf.np.array(dev0) - gf.np.array(devb))

taud = np.arange(0, 64, 64 / 1024.)
plt.plot(taub, gt, taud, splev(taud, gtautck, der=0), '+-')

wnl = gf.matsubara_freq(64., 1024)
gif = gf.gt_fouriertrans(splev(taud, gtautck, der=0), taud, wnl, ders)
# plt.plot(wnl, gif.real * wnl**2, wnl, (gif.imag + 1 / wnl) * wnl**3)
# plt.ylim([-3, 3])

# tail replacement
tail = -1j / wnl - ders[1] / wnl**2 + \
    ders[2] * 1j / wnl**3 + ders[3] / wnl**4
x = 64
gif[x:] = tail[x:]
# plt.plot(wnl, gif.real * wnl**2, wnl, (gif.imag + 1 / wnl) * wnl**3)
plt.figure('G(iwn)')
plt.plot(wnl, gif.real, 'o:', label='metal Re')
plt.plot(wnl, gif.imag, 's:', label='metal Im')


###############################################################################
コード例 #15
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