Example #1
0
def make_calc(beta=2.0, h_field=0.0):
    
    # ------------------------------------------------------------------
    # -- Hubbard atom with two bath sites, Hamiltonian

    p = ParameterCollection(
        beta = beta,
        h_field = h_field,
        U = 5.0,
        ntau = 40,
        niw = 15,
        )

    p.mu = 0.5*p.U
    
    # ------------------------------------------------------------------

    print '--> Solving SIAM with parameters'
    print p
    
    # ------------------------------------------------------------------

    up, do = 'up', 'dn'
    docc = c_dag(up,0) * c(up,0) * c_dag(do,0) * c(do,0)
    mA = c_dag(up,0) * c(up,0) - c_dag(do,0) * c(do,0)
    nA = c_dag(up,0) * c(up,0) + c_dag(do,0) * c(do,0)

    p.H = -p.mu * nA + p.U * docc + p.h_field * mA
    
    # ------------------------------------------------------------------

    fundamental_operators = [c(up,0), c(do,0)]
    
    ed = TriqsExactDiagonalization(p.H, fundamental_operators, p.beta)

    g_tau = GfImTime(beta=beta, statistic='Fermion', n_points=40, indices=[0])
    g_iw = GfImFreq(beta=beta, statistic='Fermion', n_points=10, indices=[0])

    p.G_tau = BlockGf(name_list=[up,do], block_list=[g_tau]*2, make_copies=True)
    p.G_iw = BlockGf(name_list=[up,do], block_list=[g_iw]*2, make_copies=True)
    
    ed.set_g2_tau(p.G_tau[up], c(up,0), c_dag(up,0))
    ed.set_g2_tau(p.G_tau[do], c(do,0), c_dag(do,0))

    ed.set_g2_iwn(p.G_iw[up], c(up,0), c_dag(up,0))
    ed.set_g2_iwn(p.G_iw[do], c(do,0), c_dag(do,0))

    p.magnetization = ed.get_expectation_value(0.5 * mA)
    p.magnetization2 = ed.get_expectation_value(0.25 * mA * mA)
    
    # ------------------------------------------------------------------
    # -- Store to hdf5
    
    filename = 'data_pyed_h_field_%4.4f.h5' % h_field
    with HDFArchive(filename,'w') as res:
        res['p'] = p
Example #2
0
    def create_gf(self, ish=0, gf_function=GfImFreq, **kwargs):
        """ Create a zero BlockGf having the gf_struct_solver structure.

        When using GfImFreq as gf_function, typically you have to
        supply beta as keyword argument.

        Parameters
        ----------
        ish : int
            shell index
        gf_function : constructor
            function used to construct the Gf objects constituting the
            individual blocks; default: GfImFreq
        **kwargs :
            options passed on to the Gf constructor for the individual
            blocks
        """

        names = self.gf_struct_solver[ish].keys()
        blocks = []
        for n in names:
            G = gf_function(indices=self.gf_struct_solver[ish][n], **kwargs)
            blocks.append(G)
        G = BlockGf(name_list=names, block_list=blocks)
        return G
Example #3
0
def readold_sigma_iw_list(oldfile):

    if rank == 0:

        print 'oldfile', oldfile
        results = HDFArchive(oldfile, 'r')

        Sigma_iw_list = []

        n_iw_new = results["Sigma_iw___at_0/bl/mesh/size"]
        iw_mesh_new = MeshImFreq(beta, 'Fermion', n_iw_new / 2)
        ### n_iw for MeshImFreq is positive number of frequencies,
        ### when read out from hdf-file it is total number of freqs.

        for i in range(0, N_atoms):

            dataname = "Sigma_iw___at_" + str(i)
            tmp = results[dataname]

            S = BlockGf(mesh=iw_mesh_new, gf_struct=gf_struct)
            S["bl"].data[...] = tmp["bl"].data[...]

            Sigma_iw_list.append(S)

    else:
        Sigma_iw_list = None

    Sigma_iw_list = world.bcast(Sigma_iw_list, root=0)

    return Sigma_iw_list
Example #4
0
def downfold_G_lattice(G0_iw_full_):

    G_lattice_iw_list = []
    t_ij_list = []

    offset = 0
    for i in range(0, N_atoms):

        G = BlockGf(mesh=iw_mesh, gf_struct=gf_struct)

        #print 'G["bl"].data.shape', G["bl"].data.shape
        #print 'G0_iw_full_["bl"].data[:, 0:offset, 0:offset] ',  G0_iw_full_["bl"].data[:, 0:offset, 0:offset].shape

        size_block = len(spin_names) * len(orb_names)

        G["bl"].data[...] = G0_iw_full_["bl"].data[:,
                                                   offset:offset + size_block,
                                                   offset:offset + size_block]

        G_lattice_iw_list.append(G)

        hk_mean = hk.mean(axis=0)
        t_ij = hk_mean[offset:offset + size_block, offset:offset + size_block]

        t_ij_list.append(t_ij)

        offset = offset + size_block

    return G_lattice_iw_list, t_ij_list
Example #5
0
def get_zero_sigma_iw_list():

    Sigma_iw_list = []

    for i in range(0, N_atoms):

        G = BlockGf(mesh=iw_mesh, gf_struct=gf_struct)
        Sigma_iw_list.append(G)

    return Sigma_iw_list
Example #6
0
def compute_new_weiss_field(G_lattice_iw_list_, Sigma_iw_list_):

    G0_iw_list = []

    for g, s in zip(G_lattice_iw_list_, Sigma_iw_list_):

        G0_iw = BlockGf(mesh=iw_mesh, gf_struct=gf_struct)

        G0_iw << inverse(inverse(g) + s)

        G0_iw_list.append(G0_iw)

    return G0_iw_list
Example #7
0
def get_local_lattice_gf(mu_, hk_, sigma_):

    mu_mat = mu_ * np.eye(N_size_hk)

    G_lattice_iw_full = BlockGf(mesh=iw_mesh, gf_struct=gf_struct_full)

    nk_per_core = int(Nk) / int(size)
    rest = int(Nk) % int(size)

    #print 'rank', rank
    #print 'size', size
    #print 'nk_per_core ', nk_per_core
    #print 'rest', rest

    if rank < rest:
        my_ks = range(rank * nk_per_core + rank,
                      (rank + 1) * nk_per_core + rank + 1)
    else:
        my_ks = range(rank * nk_per_core + rest,
                      (rank + 1) * nk_per_core + rest)

    my_G0 = np.zeros_like(iw_vec_full)

    #print 'rank, my_ks', rank, my_ks

    for k in my_ks:

        tmp = linalg.inv(iw_vec_full + mu_mat - hk_[k, :, :] - sigma_)

        my_G0 += tmp

    ### sum of the quantity
    ### this still crashes with more than one node..
    #qtty_rank = np.asarray(my_G0)
    #G0_iw_full_mat = np.zeros_like(my_G0)
    #MPI.COMM_WORLD.Allreduce(qtty_rank, G0_iw_full_mat)

    #G_lattice_iw_full["bl"].data[...] = G0_iw_full_mat / float(Nk)

    ### alternative version
    qtty_rank = np.asarray(my_G0)
    qtty_mean_root = np.zeros_like(iw_vec_full)
    world.Reduce(qtty_rank, qtty_mean_root, root=0)
    qtty_mean = world.bcast(qtty_mean_root, root=0)

    G_lattice_iw_full["bl"].data[...] = qtty_mean / float(Nk)

    return G_lattice_iw_full
Example #8
0
def upfold_Sigma(Sigma_iw_list_):

    Sigma_iw_full_ = BlockGf(mesh=iw_mesh, gf_struct=gf_struct_full)

    offset = 0
    for Sigma_iw in Sigma_iw_list_:

        size_block = len(spin_names) * len(orb_names)

        Sigma_iw_full_["bl"].data[:, offset:offset + size_block,
                                  offset:offset +
                                  size_block] = Sigma_iw["bl"].data[...]

        offset = offset + size_block

    return Sigma_iw_full_
Example #9
0
def get_test_impurity_model(norb=2, ntau=1000, beta=10.0):
    """ Function that generates a random impurity model for testing """

    from pytriqs.operators import c, c_dag, Operator, dagger

    from pyed.OperatorUtils import fundamental_operators_from_gf_struct
    from pyed.OperatorUtils import symmetrize_quartic_tensor
    from pyed.OperatorUtils import get_quadratic_operator
    from pyed.OperatorUtils import operator_from_quartic_tensor

    orb_idxs = list(np.arange(norb))
    spin_idxs = ['up', 'do']
    gf_struct = [[spin_idx, orb_idxs] for spin_idx in spin_idxs]

    # -- Random Hamiltonian

    fundamental_operators = fundamental_operators_from_gf_struct(gf_struct)

    N = len(fundamental_operators)
    t_OO = np.random.random((N, N)) + 1.j * np.random.random((N, N))
    t_OO = 0.5 * (t_OO + np.conj(t_OO.T))

    #print 't_OO.real =\n', t_OO.real
    #print 't_OO.imag =\n', t_OO.imag

    U_OOOO = np.random.random((N, N, N, N)) + 1.j * np.random.random(
        (N, N, N, N))
    U_OOOO = symmetrize_quartic_tensor(U_OOOO, conjugation=True)

    #print 'gf_struct =', gf_struct
    #print 'fundamental_operators = ', fundamental_operators

    H_loc = get_quadratic_operator(t_OO, fundamental_operators) + \
        operator_from_quartic_tensor(U_OOOO, fundamental_operators)

    #print 'H_loc =', H_loc

    from pytriqs.gf import MeshImTime, BlockGf

    mesh = MeshImTime(beta, 'Fermion', ntau)
    Delta_tau = BlockGf(mesh=mesh, gf_struct=gf_struct)

    for block_name, delta_tau in Delta_tau:
        delta_tau.data[:] = -0.5

    return gf_struct, Delta_tau, H_loc
Example #10
0
def legendre_filter(G_tau, order=100, G_l_cut=1e-19):
    """ Filter binned imaginary time Green's function
    using a Legendre filter of given order and coefficient threshold. 
    
    Parameters
    ----------

    G_tau : TRIQS imaginary time Block Green's function

    order : int
        Legendre expansion order in the filter

    G_l_cut : float
        Legendre coefficient cut-off 

    Returns
    -------

    G_l : TRIQS Legendre Block Green's function
        Fitted Green's function on a Legendre mesh

    """

    import numpy as np
    from pytriqs.gf import BlockGf
    from pytriqs.gf.tools import fit_legendre
    from pytriqs.gf.gf_fnt import enforce_discontinuity

    l_g_l = []

    for b, g in G_tau:

        g_l = fit_legendre(g, order=order)
        g_l.data[:] *= (np.abs(g_l.data) > G_l_cut)
        enforce_discontinuity(g_l, np.array([[1.]]))
        l_g_l.append(g_l)

    G_l = BlockGf(name_list=list(G_tau.indices), block_list=l_g_l)
    return G_l
Example #11
0
w_vec = np.array([ w for w in wmesh])[nw:]
print len(w_vec)

w_min = w_vec[n_min].value
w_max = w_vec[n_max].value

print w_min, w_max
#exit()

# -- triqs/unstable implementation

if False:
    from pytriqs.gf import BlockGf
    from pytriqs.gf.tools import tail_fit
    Delta_iw_fit = Delta_iw.copy()
    Delta_iw_fit_bgf = BlockGf(name_list=[0], block_list=[Delta_iw_fit])
    tail_fit(Delta_iw_fit_bgf, fit_min_n=n_min, fit_max_n=n_max, fit_max_moment=order_max)
    filename = 'data_tail_fit_example_unstable.h5'
    figure_filename = 'figure_tail_fit_example_unstable.pdf'

# -- triqs/new_tail implementation
elif False:
    from pytriqs.gf.gf_fnt import fit_tail_on_window, replace_by_tail

    known_moments = np.zeros((0, 2, 2), dtype=np.complex) # no known moments
    print 'known_moments.shape =', known_moments.shape
    
    tail, err = fit_tail_on_window(
        Delta_iw,
        n_min = n_min,
        n_max = n_max,
Example #12
0
# ----------------------------------------------------------------------
if __name__ == '__main__':

    gf_struct, Delta_tau, H_loc = get_test_impurity_model(norb=3,
                                                          ntau=1000,
                                                          beta=10.0)

    beta = Delta_tau.mesh.beta
    n_iw = 100
    n_tau = 1000

    from pytriqs.gf import MeshImFreq, MeshImTime
    from pytriqs.gf import BlockGf, inverse, iOmega_n, Fourier

    iw_mesh = MeshImFreq(beta, 'Fermion', n_iw)
    G0_iw = BlockGf(mesh=iw_mesh, gf_struct=gf_struct)

    debug_H = []
    for block, g0_iw in G0_iw:
        s = (3, 3)
        H = np.random.random(s) + 1.j * np.random.random(s)
        H = H + np.conjugate(H.T)

        g0_iw << inverse(iOmega_n - H - inverse(iOmega_n - 0.3 * H))

        debug_H.append(H)

    # ------------------------------------------------------------------

    Delta_iw = BlockGf(mesh=iw_mesh, gf_struct=gf_struct)
    H_loc_block = []
Example #13
0
def make_calc(beta=2.0, h_field=0.0):

    # ------------------------------------------------------------------
    # -- Hubbard atom with two bath sites, Hamiltonian

    p = ParameterCollection(
        beta=beta,
        V1=2.0,
        V2=5.0,
        epsilon1=0.10,
        epsilon2=3.00,
        h_field=h_field,
        mu=0.0,
        U=5.0,
        ntau=800,
        niw=15,
    )

    # ------------------------------------------------------------------

    print '--> Solving SIAM with parameters'
    print p

    # ------------------------------------------------------------------

    up, do = 'up', 'dn'
    docc = c_dag(up, 0) * c(up, 0) * c_dag(do, 0) * c(do, 0)
    mA = c_dag(up, 0) * c(up, 0) - c_dag(do, 0) * c(do, 0)

    nA = c_dag(up, 0) * c(up, 0) + c_dag(do, 0) * c(do, 0)
    nB = c_dag(up, 1) * c(up, 1) + c_dag(do, 1) * c(do, 1)
    nC = c_dag(up, 2) * c(up, 2) + c_dag(do, 2) * c(do, 2)

    p.H = -p.mu * nA + p.U * docc + p.h_field * mA + \
        p.epsilon1 * nB + p.epsilon2 * nC + \
        p.V1 * (c_dag(up,0)*c(up,1) + c_dag(up,1)*c(up,0) + \
              c_dag(do,0)*c(do,1) + c_dag(do,1)*c(do,0) ) + \
        p.V2 * (c_dag(up,0)*c(up,2) + c_dag(up,2)*c(up,0) + \
              c_dag(do,0)*c(do,2) + c_dag(do,2)*c(do,0) )

    # ------------------------------------------------------------------

    fundamental_operators = [
        c(up, 0), c(do, 0),
        c(up, 1), c(do, 1),
        c(up, 2), c(do, 2)
    ]

    ed = TriqsExactDiagonalization(p.H, fundamental_operators, p.beta)

    g_tau = GfImTime(beta=beta, statistic='Fermion', n_points=400, indices=[0])
    g_iw = GfImFreq(beta=beta, statistic='Fermion', n_points=10, indices=[0])

    p.G_tau = BlockGf(name_list=[up, do],
                      block_list=[g_tau] * 2,
                      make_copies=True)
    p.G_iw = BlockGf(name_list=[up, do],
                     block_list=[g_iw] * 2,
                     make_copies=True)

    ed.set_g2_tau(p.G_tau[up][0, 0], c(up, 0), c_dag(up, 0))
    ed.set_g2_tau(p.G_tau[do][0, 0], c(do, 0), c_dag(do, 0))

    ed.set_g2_iwn(p.G_iw[up][0, 0], c(up, 0), c_dag(up, 0))
    ed.set_g2_iwn(p.G_iw[do][0, 0], c(do, 0), c_dag(do, 0))

    p.magnetization = ed.get_expectation_value(0.5 * mA)

    p.O_tau = Gf(mesh=MeshImTime(beta, 'Fermion', 400), target_shape=[])
    ed.set_g2_tau(p.O_tau, n(up, 0), n(do, 0))
    p.O_tau.data[:] *= -1.

    p.exp_val = ed.get_expectation_value(n(up, 0) * n(do, 0))

    # ------------------------------------------------------------------
    # -- Store to hdf5

    filename = 'data_pyed_h_field_%4.4f.h5' % h_field
    with HDFArchive(filename, 'w') as res:
        res['p'] = p
Example #14
0
def ctqmc_solver(h_int_, G0_iw_):

    # --------- Construct the CTHYB solver ----------
    if solver == "triqs":
        constr_params = {
            'beta': beta,
            'gf_struct': gf_struct,
            'n_iw': n_iw,
            'n_tau': 10000,  # triqs value
            'n_l': 50,
            #'complex': True   # only necessary for w2dyn
        }
    elif solver == "w2dyn":
        constr_params = {
            'beta': beta,
            'gf_struct': gf_struct,
            'n_iw': n_iw,
            'n_tau': 9999,  # w2dyn value
            'n_l': 50,
            'complex': True  # only necessary for w2dyn
        }
    S = Solver(**constr_params)

    # --------- Initialize G0_iw ----------
    S.G0_iw << G0_iw_

    # --------- Solve! ----------
    solve_params = {
        'h_int': h_int_,
        'n_warmup_cycles': n_warmup_cycles,
        #'n_cycles' : 1000000000,
        'n_cycles': n_cycles,
        'max_time': max_time,
        'length_cycle': length_cycle,
        'move_double': True,
        'measure_pert_order': True,
        'measure_G_l': True
    }

    #start = time.time()
    print 'running solver...'

    process = psutil.Process(os.getpid())
    print "memory info before: ", process.memory_info(
    ).rss / 1024 / 1024, " MB"

    S.solve(**solve_params)

    process = psutil.Process(os.getpid())
    print "memory info after: ", process.memory_info().rss / 1024 / 1024, " MB"

    print 'exited solver rank ', rank
    #end = time.time()

    G_iw_from_legendre = G0_iw_.copy()
    G_iw_from_legendre << LegendreToMatsubara(S.G_l)
    print 'G_iw_from_legendre', G_iw_from_legendre
    ##exit()

    ### giw from legendre, calculated within the interface
    #print 'S.G_iw_from_leg', S.G_iw_from_leg
    #exit()

    n_tau = 200
    tau_mesh2 = MeshImTime(beta, 'Fermion', n_tau)
    my_G_tau = BlockGf(mesh=tau_mesh2, gf_struct=gf_struct)
    print 'S.G_tau["bl"][:,:].data ', S.G_tau["bl"][:, :].data.shape

    my_G_tau["bl"][:, :].data[...] = S.G_tau["bl"][:, :].data.reshape(
        200, 50, N_bands * 2, N_bands * 2).mean(axis=1)

    #return my_G_tau, S.G_iw_from_leg
    #return my_G_tau, S.G_iw
    if solver == 'triqs':
        return my_G_tau, G_iw_from_legendre, S.average_sign
    else:
        return my_G_tau, S.G_iw_from_leg, S.average_sign
Example #15
0
            S["bl"].data[...] = tmp["bl"].data[...]

            Sigma_iw_list.append(S)

    else:
        Sigma_iw_list = None

    Sigma_iw_list = world.bcast(Sigma_iw_list, root=0)

    return Sigma_iw_list


check_output_folder()

### start calculation from scratch
Sigma_iw_full = BlockGf(mesh=iw_mesh, gf_struct=gf_struct_full)
Sigma_iw_list = get_zero_sigma_iw_list()

### start from old calculation
#Sigma_iw_list = readold_sigma_iw_list("data_from_scratch/iteration_027.h5")
#Sigma_iw_full = upfold_Sigma(Sigma_iw_list)

for iter in range(0, N_iter):

    results = initialize_outputfile(iter)

    G_lattice_iw_full = get_local_lattice_gf(mu, hk, Sigma_iw_full["bl"].data)

    G_lattice_iw_list, t_ij_list = downfold_G_lattice(G_lattice_iw_full)

    write_qtty(G_lattice_iw_list, "G_lattice_iw", results)