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
def fixed_fermionic_window_python_wnk(chi_wnk, nwf): r""" Helper routine to reduce the number of fermionic Matsubara frequencies :math:`\nu` in a two frequency and one momenta dependent generalized susceptibility :math:`\chi_{abcd}(\omega, \nu, \mathbf{k})`. Parameters ---------- chi_wnk : two frequency and one momenta dependent generalized susceptibility :math:`\chi_{abcd}(\omega, \nu, \mathbf{k})`. nwf : number of fermionic frequencies to keep. Returns ------- chi_wnk_out : Susceptibility with reduced number of fermionic Matsubara frequencies. """ g2 = chi_wnk wmesh, nmesh, kmesh = g2.mesh.components beta = g2.mesh.components[0].beta nmesh_small = MeshImFreq(beta=beta, S='Fermion', n_max=nwf) chi_wnk_out = Gf(mesh=MeshProduct(wmesh, nmesh_small, kmesh), target_shape=g2.target_shape) n = g2.data.shape[1] s = n / 2 - nwf e = n / 2 + nwf chi_wnk_out.data[:] = g2.data[:, s:e, :] return chi_wnk_out
def setup_dmft_calculation(p): p = copy.deepcopy(p) p.iter = 0 # -- Local Hubbard interaction from pytriqs.operators import n p.solve.h_int = p.U*n('up', 0)*n('do', 0) - 0.5*p.U*(n('up', 0) + n('do', 0)) # -- 2D square lattice w. nearest neighbour hopping t from triqs_tprf.tight_binding import TBLattice T = -p.t * np.eye(2) H = TBLattice( units = [(1, 0, 0), (0, 1, 0)], orbital_positions = [(0,0,0)]*2, orbital_names = ['up', 'do'], hopping = {(0, +1) : T, (0, -1) : T, (+1, 0) : T, (-1, 0) : T}) p.e_k = H.on_mesh_brillouin_zone(n_k = (p.n_k, p.n_k, 1)) # -- Initial zero guess for the self-energy p.sigma_w = Gf(mesh=MeshImFreq(p.init.beta, 'Fermion', p.init.n_iw), target_shape=[2, 2]) p.sigma_w.zero() return p
def __init__(self, g1_inu, n_iw, n_inu, blocks_to_calculate=[], blockstructure_to_compare_with="AABB"): """ g1_inu has to be a BlockGf of GfImFreq """ mb = MeshImFreq(g1_inu.mesh.beta, "Boson", n_iw) mf = MeshImFreq(g1_inu.mesh.beta, "Fermion", n_inu) blockmesh = MeshProduct(mb, mf, mf) blocks = [] self.gf2_struct = dict() for i in g1_inu.indices: blocksR = [] for j in g1_inu.indices: blockindex = (i, j) m, n = g1_inu[i].data.shape[1], g1_inu[j].data.shape[1] blockshape = [m, m, n, n] blocksR.append(Gf(mesh=blockmesh, target_shape=blockshape)) self.gf2_struct[blockindex] = (m, n) blocks.append(blocksR) g1_indices = [i for i in g1_inu.indices] Block2Gf.__init__(self, g1_indices, g1_indices, blocks) self.beta = g1_inu.mesh.beta # mesh adjustments for negative frequencies and g1/g2 mesh-offsets self.n_iw = len(mb) self.n_inu = len(mf) self.bosonic_mesh = np.array( [w for w in self[blockindex].mesh.components[0]]) self.fermionic_mesh = np.array( [w for w in self[blockindex].mesh.components[1]]) g1_mesh = np.array([w for w in g1_inu.mesh]) fermionic_mesh_offset = np.argwhere( g1_mesh.imag == self.fermionic_mesh.imag[0])[0, 0] bosonic_mesh_offset = np.argwhere(0 == self.bosonic_mesh.imag)[0, 0] self.f_mesh_inds = np.arange(fermionic_mesh_offset, self.n_inu + fermionic_mesh_offset) self.b_mesh_inds = np.arange(-bosonic_mesh_offset, self.n_iw - bosonic_mesh_offset) if len(blocks_to_calculate) == 0: blocks_to_calculate = self.indices self.blockstruct = blockstructure_to_compare_with contractions = {"direct": [1, 0, 3, 2], "exchange": [1, 2, 3, 0]} for blockindex in blocks_to_calculate: self.set_block(g1_inu, blockindex, contractions)
def solve_lattice_bse(parm, momsus=False): print '--> solve_lattice_bse' print 'nw =', parm.nw print 'nwf =', parm.nwf # ------------------------------------------------------------------ # -- Setup lattice bl = BravaisLattice([(1, 0, 0), (0, 1, 0)]) bz = BrillouinZone(bl) bzmesh = MeshBrillouinZone(bz, n_k=1) # only one k-point e_k = Gf(mesh=bzmesh, target_shape=[1, 1]) e_k *= 0. # ------------------------------------------------------------------ # -- Lattice single-particle Green's function mesh = MeshImFreq(beta=parm.beta, S='Fermion', n_max=parm.nwf_gf) parm.Sigma_iw = parm.G_iw.copy() G0_iw = parm.G_iw.copy() G0_iw << inverse(iOmega_n + 0.5 * parm.U) parm.Sigma_iw << inverse(G0_iw) - inverse(parm.G_iw) parm.mu = 0.5 * parm.U g_wk = lattice_dyson_g_wk(mu=parm.mu, e_k=e_k, sigma_w=parm.Sigma_iw) g_wr = fourier_wk_to_wr(g_wk) # ------------------------------------------------------------------ # -- Non-interacting generalized lattice susceptibility chi0_wr = chi0r_from_gr_PH(nw=parm.nw, nnu=parm.nwf, gr=g_wr) chi0_wk = chi0q_from_chi0r(chi0_wr) # ------------------------------------------------------------------ # -- Solve lattice BSE parm.chi_wk = chiq_from_chi0q_and_gamma_PH(chi0_wk, parm.gamma_m) # ------------------------------------------------------------------ # -- Store results and static results num = np.squeeze(parm.chi_wk.data.real) ref = np.squeeze(parm.chi_m.data.real) diff = np.max(np.abs(num - ref)) print 'diff =', diff parm.chi_w = chiq_sum_nu_q(parm.chi_wk) # static suscept return parm
def strip_sigma(nw, beta, sigma_in, debug=False): np.testing.assert_almost_equal(beta, sigma_in.mesh.beta) wmesh = MeshImFreq(beta, 'Fermion', n_max=nw) sigma = Gf(mesh=wmesh, target_shape=sigma_in.target_shape) for w in wmesh: index = w.linear_index + wmesh.first_index() # absolute index sigma[w] = sigma_in[Idx(index)] if debug: from pytriqs.plot.mpl_interface import oplot, plt oplot(p.Sigmalatt_iw) oplot(sigma, 'x') plt.show() exit() return sigma
def bubble_setup(beta, mu, tb_lattice, nk, nw, sigma_w=None): print tprf_banner(), "\n" print 'beta =', beta print 'mu =', mu print 'sigma =', (not (sigma == None)) norb = tb_lattice.NOrbitalsInUnitCell print 'nk =', nk print 'nw =', nw print 'norb =', norb print ntau = 4 * nw ntot = np.prod(nk) * norb**4 + np.prod(nk) * (nw + ntau) * norb**2 nbytes = ntot * np.complex128().nbytes ngb = nbytes / 1024.**3 print 'Approx. Memory Utilization: %2.2f GB\n' % ngb periodization_matrix = np.diag(np.array(list(nk), dtype=np.int32)) #print 'periodization_matrix =\n', periodization_matrix bz = BrillouinZone(tb_lattice.bl) bzmesh = MeshBrillouinZone(bz, periodization_matrix) print '--> ek' e_k = ek_tb_dispersion_on_bzmesh(tb_lattice, bzmesh, bz) if sigma is None: print '--> g0k' wmesh = MeshImFreq(beta=beta, S='Fermion', n_max=nw) g_wk = lattice_dyson_g0_wk(mu=mu, e_k=e_k, mesh=wmesh) else: print '--> gk' sigma_w = strip_sigma(nw, beta, sigma) g_wk = lattice_dyson_g_wk(mu=mu, e_k=e_k, sigma_w=sigma_w) print '--> gr_from_gk (k->r)' g_wr = fourier_wk_to_wr(g_wk) del g_wk print '--> grt_from_grw (w->tau)' g_tr = fourier_wr_to_tr(g_wr) del g_wr if sigma is None: return g_tr else: return g_tr, sigma_w
def delta_inv(beta, nw, nk=100): mesh = MeshImFreq(beta, 'Fermion', n_max=nw) Sigma0, Sigma1 = 1.337, 3.5235 ek = 2. * np.random.random(nk) - 1. G = Gf(mesh=mesh, target_shape=[1, 1]) Sig = G.copy() for w in Sig.mesh: Sig[w][:] = Sigma0 + Sigma1 / w for e in ek: G << G + inverse(iOmega_n - e - Sig) G /= nk Delta = G.copy() Delta << inverse(G) - iOmega_n + Sig sum_ek = -np.sum(ek) / nk Roo = np.abs(Sigma0) + 1. w = [w for w in mesh] wmax = np.abs(w[-1].value) tail, err = Delta.fit_tail() order = len(tail) trunc_err_anal = (Roo / (0.8 * wmax))**order ratio = tail[0] / sum_ek diff = np.abs(1 - ratio) print '-' * 72 print 'beta =', beta print 'nw =', nw print 'wmax =', wmax print 'tail_fit order =', len(tail) print 'tail_fit err =', err print tail[:3] #print sum_ek print 'trunc_err_anal =', trunc_err_anal print 'ratio =', ratio print 'diff =', diff return diff[0, 0]
def G2_loc_fixed_fermionic_window_python(g2, nwf): """ Limit the last two fermionic freqiencies of a three frequency Green's function object :math:`G(\omega, \nu, \nu')` to ``nwf``. """ nw = (g2.data.shape[0] + 1) / 2 n = g2.data.shape[1] beta = g2.mesh.components[0].beta assert (n / 2 >= nwf) from pytriqs.gf import Gf, MeshImFreq, MeshProduct mesh_iw = MeshImFreq(beta=beta, S='Boson', n_max=nw) mesh_inu = MeshImFreq(beta=beta, S='Fermion', n_max=nwf) mesh_prod = MeshProduct(mesh_iw, mesh_inu, mesh_inu) g2_out = Gf(mesh=mesh_prod, target_shape=g2.target_shape) s = n / 2 - nwf e = n / 2 + nwf g2_out.data[:] = g2.data[:, s:e, s:e] return g2_out
def fixed_fermionic_window_python_wnk(g2, nwf): #nw = (g2.data.shape[0] + 1) / 2 wmesh, nmesh, kmesh = g2.mesh.components beta = g2.mesh.components[0].beta nmesh_small = MeshImFreq(beta=beta, S='Fermion', n_max=nwf) g2_out = Gf(mesh=MeshProduct(wmesh, nmesh_small, kmesh), target_shape=g2.target_shape) n = g2.data.shape[1] s = n / 2 - nwf e = n / 2 + nwf g2_out.data[:] = g2.data[:, s:e, :] return g2_out
def make_calc(): # ------------------------------------------------------------------ # -- Read precomputed ED data filename = "data_pomerol.tar.gz" p = read_TarGZ_HDFArchive(filename) # ------------------------------------------------------------------ # -- RPA tensor from triqs_tprf.rpa_tensor import get_rpa_tensor from triqs_tprf.rpa_tensor import fundamental_operators_from_gf_struct fundamental_operators = fundamental_operators_from_gf_struct(p.gf_struct) p.U_abcd = get_rpa_tensor(p.H_int, fundamental_operators) # ------------------------------------------------------------------ # -- Generalized PH susceptibility loc_bse = ParameterCollection() loc_bse.chi_wnn = chi_from_gg2_PH(p.G_iw, p.G2_iw_ph) loc_bse.chi0_wnn = chi0_from_gg2_PH(p.G_iw, p.G2_iw_ph) loc_bse.gamma_wnn = inverse_PH(loc_bse.chi0_wnn) - inverse_PH( loc_bse.chi_wnn) loc_bse.chi_wnn_ref = inverse_PH( inverse_PH(loc_bse.chi0_wnn) - loc_bse.gamma_wnn) np.testing.assert_array_almost_equal(loc_bse.chi_wnn.data, loc_bse.chi_wnn_ref.data) loc_bse.chi0_w = trace_nn(loc_bse.chi0_wnn) loc_bse.chi_w = trace_nn(loc_bse.chi_wnn) # ------------------------------------------------------------------ # -- RPA, using BSE inverses and constant Gamma loc_rpa = ParameterCollection() loc_rpa.U_abcd = p.U_abcd # -- Build constant gamma loc_rpa.gamma_wnn = loc_bse.gamma_wnn.copy() loc_rpa.gamma_wnn.data[:] = loc_rpa.U_abcd[None, None, None, ...] # Nb! In the three frequency form $\Gamma \propto U/\beta^2$ loc_rpa.gamma_wnn.data[:] /= p.beta**2 loc_rpa.chi0_wnn = loc_bse.chi0_wnn loc_rpa.chi0_w = loc_bse.chi0_w # -- Solve RPA loc_rpa.chi_wnn = inverse_PH( inverse_PH(loc_rpa.chi0_wnn) - loc_rpa.gamma_wnn) loc_rpa.chi_w = trace_nn(loc_rpa.chi_wnn) # ------------------------------------------------------------------ # -- Bubble RPA on lattice lat_rpa = ParameterCollection() # -- Setup dummy lattice Green's function equal to local Green's function bz = BrillouinZone( BravaisLattice(units=np.eye(3), orbital_positions=[(0, 0, 0)])) periodization_matrix = np.diag(np.array(list([1] * 3), dtype=np.int32)) kmesh = MeshBrillouinZone(bz, periodization_matrix) wmesh = MeshImFreq(beta=p.beta, S='Fermion', n_max=p.nwf_gf) lat_rpa.g_wk = Gf(mesh=MeshProduct(wmesh, kmesh), target_shape=p.G_iw.target_shape) lat_rpa.g_wk[:, Idx(0, 0, 0)] = p.G_iw # -- chi0_wk bubble and chi_wk_rpa bubble RPA from triqs_tprf.lattice_utils import imtime_bubble_chi0_wk lat_rpa.chi0_wk = imtime_bubble_chi0_wk(lat_rpa.g_wk, nw=1) from triqs_tprf.lattice import solve_rpa_PH lat_rpa.chi_wk = solve_rpa_PH(lat_rpa.chi0_wk, p.U_abcd) lat_rpa.chi0_w = lat_rpa.chi0_wk[:, Idx(0, 0, 0)] lat_rpa.chi_w = lat_rpa.chi_wk[:, Idx(0, 0, 0)] print '--> cf Tr[chi0] and chi0_wk' print loc_rpa.chi0_w.data.reshape((4, 4)).real print lat_rpa.chi0_w.data.reshape((4, 4)).real np.testing.assert_array_almost_equal(loc_rpa.chi0_w.data, lat_rpa.chi0_w.data, decimal=2) print 'ok!' print '--> cf Tr[chi_rpa] and chi_wk_rpa' print loc_rpa.chi_w.data.reshape((4, 4)).real print lat_rpa.chi_w.data.reshape((4, 4)).real np.testing.assert_array_almost_equal(loc_rpa.chi_w.data, lat_rpa.chi_w.data, decimal=2) print 'ok!' # ------------------------------------------------------------------ # -- Lattice BSE lat_bse = ParameterCollection() lat_bse.g_wk = lat_rpa.g_wk from triqs_tprf.lattice import fourier_wk_to_wr lat_bse.g_wr = fourier_wk_to_wr(lat_bse.g_wk) from triqs_tprf.lattice import chi0r_from_gr_PH lat_bse.chi0_wnr = chi0r_from_gr_PH(nw=1, nnu=p.nwf, gr=lat_bse.g_wr) from triqs_tprf.lattice import chi0q_from_chi0r lat_bse.chi0_wnk = chi0q_from_chi0r(lat_bse.chi0_wnr) # -- Lattice BSE calc from triqs_tprf.lattice import chiq_from_chi0q_and_gamma_PH lat_bse.chi_kwnn = chiq_from_chi0q_and_gamma_PH(lat_bse.chi0_wnk, loc_bse.gamma_wnn) # -- Trace results from triqs_tprf.lattice import chi0q_sum_nu_tail_corr_PH from triqs_tprf.lattice import chi0q_sum_nu lat_bse.chi0_wk_tail_corr = chi0q_sum_nu_tail_corr_PH(lat_bse.chi0_wnk) lat_bse.chi0_wk = chi0q_sum_nu(lat_bse.chi0_wnk) from triqs_tprf.lattice import chiq_sum_nu, chiq_sum_nu_q lat_bse.chi_kw = chiq_sum_nu(lat_bse.chi_kwnn) lat_bse.chi0_w_tail_corr = lat_bse.chi0_wk_tail_corr[:, Idx(0, 0, 0)] lat_bse.chi0_w = lat_bse.chi0_wk[:, Idx(0, 0, 0)] lat_bse.chi_w = lat_bse.chi_kw[Idx(0, 0, 0), :] print '--> cf Tr[chi0_wnk] and chi0_wk' print lat_bse.chi0_w_tail_corr.data.reshape((4, 4)).real print lat_bse.chi0_w.data.reshape((4, 4)).real print lat_rpa.chi0_w.data.reshape((4, 4)).real np.testing.assert_array_almost_equal(lat_bse.chi0_w_tail_corr.data, lat_rpa.chi0_w.data) np.testing.assert_array_almost_equal(lat_bse.chi0_w.data, lat_rpa.chi0_w.data, decimal=2) print 'ok!' print '--> cf Tr[chi_kwnn] and chi_wk' print lat_bse.chi_w.data.reshape((4, 4)).real print loc_bse.chi_w.data.reshape((4, 4)).real np.testing.assert_array_almost_equal(lat_bse.chi_w.data, loc_bse.chi_w.data) print 'ok!' # ------------------------------------------------------------------ # -- Store to hdf5 filename = 'data_bse_rpa.h5' with HDFArchive(filename, 'w') as res: res['p'] = p
import pytriqs.utility.mpi as mpi from pytriqs.gf import Gf, MeshImFreq, MeshImTime, iOmega_n, inverse, Fourier, InverseFourier beta = 10.0 gf_struct = [['0', [0, 1]]] target_shape = [2, 2] nw = 48 nt = 3 * nw S = SolverCore(beta=beta, gf_struct=gf_struct, n_iw=nw, n_tau=nt) h_int = n('0', 0) * n('0', 1) wmesh = MeshImFreq(beta=beta, S='Fermion', n_max=nw) tmesh = MeshImTime(beta=beta, S='Fermion', n_max=nt) Delta_iw = Gf(mesh=wmesh, target_shape=target_shape) Ek = np.array([ [1.00, 0.75], [0.75, -1.20], ]) E_loc = np.array([ [0.2, 0.3], [0.3, 0.4], ]) V = np.array([
p.diag = 0.5 + p.delta p.odiag = 0.5 - p.delta p.solve.alpha = [[[p.diag, p.odiag] for i in indices] for bl, indices in p.gf_struct] # -- Total impurity hamiltonian and interaction part p.H_0 = -p.mu * (n('up', 0) + n('dn', 0)) - p.h * (n('up', 0) - n('dn', 0)) p.H_int = p.U * n('up', 0) * n('dn', 0) p.H = p.H_0 + p.H_int p.solve.h_int = p.H_int # -- Non-Interacting Impurity Green function iw_mesh = MeshImFreq(p.beta, 'Fermion', p.n_iw) p.G0_iw = Gf_from_struct(mesh=iw_mesh, struct=p.gf_struct) h_field_dict = dict(up=p.h, dn=-p.h) for name, g0_iw in p.G0_iw: h_field = h_field_dict[name] g0_iw << inverse(iOmega_n + p.mu + h_field) # -- CTINT S = SolverCore(**p.solver_core.dict()) S.G0_iw << p.G0_iw S.solve(**p.solve.dict()) # -- Store to hdf5 archive
(-1, 0): -t_intra * np.eye(n_orb_spin) - t_inter * inter_orbital_hopping, }, orbital_positions=[(0, 0, 0)] * n_orb_spin, ) e_k = H.on_mesh_brillouin_zone(n_k=(16, 16, 1)) print(e_k) # ---------------------------------------------------------------------- # -- Bare susceptibility from Green's function bubble from pytriqs.gf import MeshImFreq from triqs_tprf.lattice import lattice_dyson_g0_wk wmesh = MeshImFreq(beta=5.0, S='Fermion', n_max=30) g0_wk = lattice_dyson_g0_wk(mu=0., e_k=e_k, mesh=wmesh) from triqs_tprf.lattice_utils import imtime_bubble_chi0_wk chi00_wk = imtime_bubble_chi0_wk(g0_wk, nw=1) # ---------------------------------------------------------------------- # -- Kanamori interaction from pytriqs.operators.util import U_matrix_kanamori, h_int_kanamori from triqs_tprf.OperatorUtils import fundamental_operators_from_gf_struct from triqs_tprf.rpa_tensor import get_rpa_tensor U = 1.0 J = 0.1
def anderson(use_qn=True, use_blocks=True): spin_names = ("up","dn") mkind = lambda spin: (spin,0) if use_blocks else ("tot",spin) # Input parameters beta = 10.0 U = 2.0 mu = 1.0 h = 0.1 #V = 0.5 V = 1.0 epsilon = 2.3 n_iw = 1025 n_tau = 10001 p = {} p["max_time"] = -1 p["random_name"] = "" p["random_seed"] = 123 * mpi.rank + 567 p["length_cycle"] = 50 p["n_warmup_cycles"] = 50000 p["n_cycles"] = 5000000 p["measure_density_matrix"] = True p["use_norm_as_weight"] = True results_file_name = "anderson" if use_blocks: results_file_name += ".block" if use_qn: results_file_name += ".qn" results_file_name += ".h5" mpi.report("Welcome to Anderson (1 correlated site + symmetric bath) test.") H = U*n(*mkind("up"))*n(*mkind("dn")) QN = [] if use_qn: for spin in spin_names: QN.append(n(*mkind(spin))) p["quantum_numbers"] = QN p["partition_method"] = "quantum_numbers" gf_struct = {} for spin in spin_names: bn, i = mkind(spin) gf_struct.setdefault(bn,[]).append(i) gf_struct = [ [key, value] for key, value in gf_struct.items() ] # convert from dict to list of lists mpi.report("Constructing the solver...") # Construct the solver S = SolverCore(beta=beta, gf_struct=gf_struct, n_tau=n_tau, n_iw=n_iw) mpi.report("Preparing the hybridization function...") # Set hybridization function delta_w = Gf(mesh=MeshImFreq(beta, 'Fermion', n_iw), target_shape=[]) delta_w << (V**2) * inverse(iOmega_n - epsilon) + (V**2) * inverse(iOmega_n + epsilon) for spin in spin_names: bn, i = mkind(spin) S.G0_iw[bn][i,i] << inverse(iOmega_n + mu - {'up':h,'dn':-h}[spin] - delta_w) mpi.report("Running the simulation...") # Solve the problem S.solve(h_int=H, **p) # Save the results if mpi.is_master_node(): static_observables = {'Nup' : n(*mkind("up")), 'Ndn' : n(*mkind("dn")), 'unity' : Operator(1.0)} dm = S.density_matrix for oname in static_observables.keys(): print oname, trace_rho_op(dm,static_observables[oname],S.h_loc_diagonalization) with HDFArchive(results_file_name,'w') as Results: Results['G_tau'] = S.G_tau
def five_plus_five(use_interaction=True): results_file_name = "5_plus_5." + ("int." if use_interaction else "") + "h5" # Block structure of GF L = 2 # d-orbital spin_names = ("up", "dn") orb_names = cubic_names(L) # Input parameters beta = 40. mu = 26 U = 4.0 J = 0.7 F0 = U F2 = J * (14.0 / (1.0 + 0.63)) F4 = F2 * 0.63 # Dump the local Hamiltonian to a text file (set to None to disable dumping) H_dump = "H.txt" # Dump Delta parameters to a text file (set to None to disable dumping) Delta_dump = "Delta_params.txt" # Hybridization function parameters # Delta(\tau) is diagonal in the basis of cubic harmonics # Each component of Delta(\tau) is represented as a list of single-particle # terms parametrized by pairs (V_k,\epsilon_k). delta_params = { "xy": { 'V': 0.2, 'e': -0.2 }, "yz": { 'V': 0.2, 'e': -0.15 }, "z^2": { 'V': 0.2, 'e': -0.1 }, "xz": { 'V': 0.2, 'e': 0.05 }, "x^2-y^2": { 'V': 0.2, 'e': 0.4 } } atomic_levels = { ('up_xy', 0): -0.2, ('dn_xy', 0): -0.2, ('up_yz', 0): -0.15, ('dn_yz', 0): -0.15, ('up_z^2', 0): -0.1, ('dn_z^2', 0): -0.1, ('up_xz', 0): 0.05, ('dn_xz', 0): 0.05, ('up_x^2-y^2', 0): 0.4, ('dn_x^2-y^2', 0): 0.4 } n_iw = 1025 n_tau = 10001 p = {} p["max_time"] = -1 p["random_name"] = "" p["random_seed"] = 123 * mpi.rank + 567 p["length_cycle"] = 50 #p["n_warmup_cycles"] = 5000 p["n_warmup_cycles"] = 500 p["n_cycles"] = int(1.e1 / mpi.size) #p["n_cycles"] = int(5.e5 / mpi.size) #p["n_cycles"] = int(5.e6 / mpi.size) p["partition_method"] = "autopartition" p["measure_G_tau"] = True p["move_shift"] = True p["move_double"] = True p["measure_pert_order"] = False p["performance_analysis"] = False p["use_trace_estimator"] = False mpi.report("Welcome to 5+5 (5 orbitals + 5 bath sites) test.") gf_struct = set_operator_structure(spin_names, orb_names, False) mkind = get_mkind(False, None) H = Operator() if use_interaction: # Local Hamiltonian U_mat = U_matrix(L, [F0, F2, F4], basis='cubic') H += h_int_slater(spin_names, orb_names, U_mat, False, H_dump=H_dump) else: mu = 0. p["h_int"] = H # Quantum numbers (N_up and N_down) QN = [Operator(), Operator()] for cn in orb_names: for i, sn in enumerate(spin_names): QN[i] += n(*mkind(sn, cn)) if p["partition_method"] == "quantum_numbers": p["quantum_numbers"] = QN mpi.report("Constructing the solver...") # Construct the solver S = SolverCore(beta=beta, gf_struct=gf_struct, n_tau=n_tau, n_iw=n_iw) mpi.report("Preparing the hybridization function...") H_hyb = Operator() # Set hybridization function if Delta_dump: Delta_dump_file = open(Delta_dump, 'w') for sn, cn in product(spin_names, orb_names): bn, i = mkind(sn, cn) V = delta_params[cn]['V'] e = delta_params[cn]['e'] delta_w = Gf(mesh=MeshImFreq(beta, 'Fermion', n_iw), target_shape=[]) delta_w << (V**2) * inverse(iOmega_n - e) S.G0_iw[bn][i, i] << inverse(iOmega_n + mu - atomic_levels[(bn, i)] - delta_w) cnb = cn + '_b' # bath level a = sn + '_' + cn b = sn + '_' + cn + '_b' H_hyb += ( atomic_levels[(bn,i)] - mu ) * n(a, 0) + \ n(b,0) * e + V * ( c(a,0) * c_dag(b,0) + c(b,0) * c_dag(a,0) ) # Dump Delta parameters if Delta_dump: Delta_dump_file.write(bn + '\t') Delta_dump_file.write(str(V) + '\t') Delta_dump_file.write(str(e) + '\n') if mpi.is_master_node(): filename_ham = 'data_Ham%s.h5' % ('_int' if use_interaction else '') with HDFArchive(filename_ham, 'w') as arch: arch['H'] = H_hyb + H arch['gf_struct'] = gf_struct arch['beta'] = beta mpi.report("Running the simulation...") # Solve the problem S.solve(**p) # Save the results if mpi.is_master_node(): Results = HDFArchive(results_file_name, 'w') Results['G_tau'] = S.G_tau Results['G0_iw'] = S.G0_iw Results['use_interaction'] = use_interaction Results['delta_params'] = delta_params Results['spin_names'] = spin_names Results['orb_names'] = orb_names import __main__ Results.create_group("log") log = Results["log"] log["version"] = version.version log["triqs_hash"] = version.triqs_hash log["cthyb_hash"] = version.cthyb_hash log["script"] = inspect.getsource(__main__)
# Calculate theoretical curves if not use_interaction: #g_theor = GfImTime(indices = range(len(orb_names)), beta=beta, n_points=n_tau) g_theor = GfImTime(indices=range(len(orb_names)), beta=beta, n_points=1000) for nc, cn in enumerate(orb_names): V = delta_params[cn]['V'] e = delta_params[cn]['e'] e1 = e - V e2 = e + V #g_theor_w = GfImFreq(indices = [0], beta=beta, n_points=1000) g_theor_w = Gf(mesh=MeshImFreq(beta, 'Fermion', 100), target_shape=[]) g_theor_w << 0.5 * inverse(iOmega_n - e1) + 0.5 * inverse(iOmega_n - e2) g_theor[nc, nc] << Fourier(g_theor_w) pp = PdfPages('G%s.pdf' % ('int' if use_interaction else '')) for sn in spin_names: for nc, cn in enumerate(orb_names): plt.clf() gf = rebinning_tau(arch['G_tau'][mkind(sn, cn)[0]], 200) # Plot the results oplot(gf, name="cthyb")
def mesh_product_iterator_numpy(mesh): return [ map(np.array, zip(*list(x))) for x in mesh_product_iterator(chi4_tau.mesh) ] # ---------------------------------------------------------------------- if __name__ == '__main__': nw = 20 nt = 45 beta = 2.0 imtime = MeshImTime(beta, 'Fermion', nt) imfreq = MeshImFreq(beta, 'Fermion', nw) imtime3 = MeshProduct(imtime, imtime, imtime) imfreq3 = MeshProduct(imfreq, imfreq, imfreq) chi4_tau = Gf(name=r'$g(\tau)$', mesh=imtime3, target_shape=[1, 1, 1, 1]) print dir(chi4_tau.indices) for i in chi4_tau.indices: print i exit() # -- Smooth anti-periodic function w = 0.5 e1, e2, e3 = w, w, w E = np.array([e1, e2, e3])
t_r = TBLattice( units=[(1, 0, 0)], hopping={ (+1, ): t, (-1, ): t, }, orbital_positions=[(0, 0, 0)] * norb, ) e_k = t_r.on_mesh_brillouin_zone(n_k=(8, 1, 1)) print e_k.data kmesh = e_k.mesh wmesh = MeshImFreq(beta, 'Fermion', nw) g_wk = lattice_dyson_g0_wk(mu=mu, e_k=e_k, mesh=wmesh) V_k = Gf(mesh=kmesh, target_shape=[norb] * 4) V_k.data[:] = V print('--> pi_bubble') PI_wk = bubble_PI_wk(g_wk) print('--> screened_interaction_W') Wr_wk = retarded_screened_interaction_Wr_wk(PI_wk, V_k) print('--> gw_self_energy') sigma_wk = gw_sigma_wk(Wr_wk, g_wk, fft_flag=True) sigma_wk_ref = gw_sigma_wk(Wr_wk, g_wk, fft_flag=False) np.testing.assert_array_almost_equal(sigma_wk.data, sigma_wk_ref.data)
# ---------------------------------------------------------------------- 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)
non_diagonal_hoppings = [ele for ele in all_nn_hoppings if sum(np.abs(ele)) == 1] t = -p.t * np.eye(p.norbs) H = TBLattice( units = full_units[:p.dim], hopping = {hop : t for hop in non_diagonal_hoppings}, orbital_positions = [(0,0,0)]*p.norbs, ) e_k = H.on_mesh_brillouin_zone(n_k=[p.nk]*p.dim + [1]*(3-p.dim)) # A bigger w-mesh is needed to construct a Gamma with a twice as big w-mesh than GF big_factor = 2.0 wmesh = MeshImFreq(beta=p.beta, S='Fermion', n_max=p.nw) wmesh_big = MeshImFreq(beta=p.beta, S='Fermion', n_max=int(big_factor*p.nw)) g0_wk = lattice_dyson_g0_wk(mu=p.mu, e_k=e_k, mesh=wmesh) g0_wk_big = lattice_dyson_g0_wk(mu=p.mu, e_k=e_k, mesh=wmesh_big) chi0_wk_big = imtime_bubble_chi0_wk(g0_wk_big, nw=int(big_factor*p.nw)+1) U_c, U_s = kanamori_charge_and_spin_quartic_interaction_tensors(p.norbs, p.U, 0, 0, 0) chi_s_big = solve_rpa_PH(chi0_wk_big, U_s) chi_c_big = solve_rpa_PH(chi0_wk_big, -U_c) # Minus for correct charge rpa equation gamma_big = gamma_PP_singlet(chi_c_big, chi_s_big, U_c, U_s) # -- Preprocess gamma for the FFT implementation
def test_square_lattice_chi00(): # ------------------------------------------------------------------ # -- Discretizations n_k = (2, 2, 1) nw_g = 500 nnu = 400 nw = 1 # ------------------------------------------------------------------ # -- tight binding parameters beta = 20.0 mu = 0.0 t = 1.0 h_loc = np.array([ [-0.3, -0.5], [-0.5, .4], ]) T = -t * np.array([ [1., 0.23], [0.23, 0.5], ]) # ------------------------------------------------------------------ # -- tight binding print '--> tight binding model' t_r = TBLattice( units=[(1, 0, 0), (0, 1, 0)], hopping={ # nearest neighbour hopping -t (0, 0): h_loc, (0, +1): T, (0, -1): T, (+1, 0): T, (-1, 0): T, }, orbital_positions=[(0, 0, 0)] * 2, orbital_names=['up_0', 'do_0'], ) e_k = t_r.on_mesh_brillouin_zone(n_k) kmesh = e_k.mesh wmesh = MeshImFreq(beta=beta, S='Fermion', n_max=nw_g) print '--> g0_wk' g0_wk = lattice_dyson_g0_wk(mu=mu, e_k=e_k, mesh=wmesh) print '--> g0_wr' g0_wr = fourier_wk_to_wr(g0_wk) print '--> g0_tr' g0_tr = fourier_wr_to_tr(g0_wr) # ------------------------------------------------------------------ # -- anaytic chi00 print '--> chi00_wk analytic' chi00_wk_analytic = lindhard_chi00_wk(e_k=e_k, nw=nw, beta=beta, mu=mu) print '--> chi00_wr analytic' chi00_wr_analytic = chi_wr_from_chi_wk(chi00_wk_analytic) # ------------------------------------------------------------------ # -- imtime chi00 print '--> chi0_tr_from_grt_PH' chi00_tr = chi0_tr_from_grt_PH(g0_tr) print '--> chi_wr_from_chi_tr' chi00_wr = chi_wr_from_chi_tr(chi00_tr, nw=1) print '--> chi_w0r_from_chi_tr' chi00_wr_ref = chi_w0r_from_chi_tr(chi00_tr) print '--> chi0_w0r_from_grt_PH' chi00_wr_opt = chi0_w0r_from_grt_PH(g0_tr) print 'dchi00_wr =', np.max( np.abs(chi00_wr_analytic.data - chi00_wr.data)) print 'dchi00_wr_ref =', np.max( np.abs(chi00_wr_analytic.data - chi00_wr_ref.data)) print 'dchi00_wr_opt =', np.max( np.abs(chi00_wr_analytic.data - chi00_wr_opt.data)) np.testing.assert_array_almost_equal(chi00_wr_analytic.data, chi00_wr.data, decimal=8) np.testing.assert_array_almost_equal(chi00_wr_analytic.data, chi00_wr_ref.data, decimal=4) np.testing.assert_array_almost_equal(chi00_wr_analytic.data, chi00_wr_opt.data, decimal=4) print '--> chi_wk_from_chi_wr' chi00_wk_imtime = chi_wk_from_chi_wr(chi00_wr) # ------------------------------------------------------------------ # -- imtime chi00 helper function chi00_wk_imtime_2 = imtime_bubble_chi0_wk(g0_wk, nw=1) # ------------------------------------------------------------------ # -- imfreq chi00 print '--> chi00_wnr' chi00_wnr = chi0r_from_gr_PH(nw=1, nnu=nnu, gr=g0_wr) print '--> chi00_wnk' chi00_wnk = chi0q_from_chi0r(chi00_wnr) # -- Test per k and w calculator for chi0_wnk print '--> chi00_wnk_ref' from triqs_tprf.lattice import chi0q_from_g_wk_PH chi00_wnk_ref = chi0q_from_g_wk_PH(nw=1, nnu=nnu, g_wk=g0_wk) diff = np.max(np.abs(chi00_wnk.data - chi00_wnk_ref.data)) print 'chi00_wnk diff =', diff np.testing.assert_array_almost_equal(chi00_wnk.data, chi00_wnk_ref.data) print '--> chi00_wk_imfreq' chi00_wk_imfreq = chi0q_sum_nu(chi00_wnk) print '--> chi00_wk_imfreq_tail_corr' chi00_wk_imfreq_tail_corr = chi0q_sum_nu_tail_corr_PH(chi00_wnk) # ------------------------------------------------------------------ # -- Compare results def cf_chi_w0(chi1, chi2, decimal=9): chi1, chi2 = chi1[Idx(0), :].data, chi2[Idx(0), :].data diff = np.linalg.norm(chi1 - chi2) print '|dchi| =', diff np.testing.assert_array_almost_equal(chi1, chi2, decimal=decimal) print '--> Cf analytic with imtime' cf_chi_w0(chi00_wk_analytic, chi00_wk_imtime, decimal=7) print '--> Cf analytic with imtime 2' cf_chi_w0(chi00_wk_analytic, chi00_wk_imtime_2, decimal=4) print '--> Cf analytic with imfreq' cf_chi_w0(chi00_wk_analytic, chi00_wk_imfreq, decimal=2) print '--> Cf analytic with imfreq (tail corr)' cf_chi_w0(chi00_wk_analytic, chi00_wk_imfreq_tail_corr, decimal=5)
# -- BZ-sampling bz = BrillouinZone(BravaisLattice([[1,0],[0,1]])) bzmesh = MeshBrillouinZone(bz, n_k=n_k) q_list = [q for q in bzmesh] # -- Dispersion ek = Gf(mesh=bzmesh, target_shape=[1, 1]) for idx, k in enumerate(bzmesh): #ek[k] = -2*t*(np.cos(k[0]) + np.cos(k[1])) # does not work... ek.data[idx] = -2*(np.cos(k[0]) + np.cos(k[1])) mesh = MeshImFreq(beta=beta, S='Fermion', n_max=nw_g) bmesh = MeshImFreq(beta=beta, S='Boson', n_max=nw) iw_list = np.array([ iw for iw in bmesh ]) iw_zero_idx = np.where(iw_list == 0)[0][0] # -- Lattice single-particle Green's function g0k = g0k_from_ek(mu=mu, ek=ek, mesh=mesh) g0r = gr_from_gk(g0k) # -- Non-interacting generalized lattice susceptibility chi0r = chi0r_from_gr_PH(nw=nw, nnu=nnu, gr=g0r) chi0q = chi0q_from_chi0r(chi0r, bz)
def make_calc(): # ------------------------------------------------------------------ # -- Read precomputed ED data filename = "bse_and_rpa_loc_vs_latt.tar.gz" p = read_TarGZ_HDFArchive(filename)['p'] # ------------------------------------------------------------------ # -- RPA tensor from triqs_tprf.rpa_tensor import get_rpa_tensor from triqs_tprf.rpa_tensor import fundamental_operators_from_gf_struct fundamental_operators = fundamental_operators_from_gf_struct(p.gf_struct) p.U_abcd = get_rpa_tensor(p.H_int, fundamental_operators) # ------------------------------------------------------------------ # -- Generalized PH susceptibility loc_bse = ParameterCollection() loc_bse.chi_wnn = chi_from_gg2_PH(p.G_iw, p.G2_iw_ph) loc_bse.chi0_wnn = chi0_from_gg2_PH(p.G_iw, p.G2_iw_ph) loc_bse.gamma_wnn = inverse_PH(loc_bse.chi0_wnn) - inverse_PH( loc_bse.chi_wnn) loc_bse.chi_wnn_ref = inverse_PH( inverse_PH(loc_bse.chi0_wnn) - loc_bse.gamma_wnn) np.testing.assert_array_almost_equal(loc_bse.chi_wnn.data, loc_bse.chi_wnn_ref.data) from triqs_tprf.bse import solve_local_bse loc_bse.gamma_wnn_ref = solve_local_bse(loc_bse.chi0_wnn, loc_bse.chi_wnn) np.testing.assert_array_almost_equal(loc_bse.gamma_wnn.data, loc_bse.gamma_wnn_ref.data) loc_bse.chi0_w = trace_nn(loc_bse.chi0_wnn) loc_bse.chi_w = trace_nn(loc_bse.chi_wnn) # ------------------------------------------------------------------ # -- RPA, using BSE inverses and constant Gamma loc_rpa = ParameterCollection() loc_rpa.chi0_wnn = loc_bse.chi0_wnn loc_rpa.chi0_w = loc_bse.chi0_w loc_rpa.U_abcd = p.U_abcd # -- Build constant gamma from triqs_tprf.rpa_tensor import get_gamma_rpa loc_rpa.gamma_wnn = get_gamma_rpa(loc_rpa.chi0_wnn, loc_rpa.U_abcd) # -- Solve RPA loc_rpa.chi_wnn = inverse_PH( inverse_PH(loc_rpa.chi0_wnn) - loc_rpa.gamma_wnn) loc_rpa.chi_w = trace_nn(loc_rpa.chi_wnn) # ------------------------------------------------------------------ # -- Bubble RPA on lattice lat_rpa = ParameterCollection() # -- Setup dummy lattice Green's function equal to local Green's function bz = BrillouinZone( BravaisLattice(units=np.eye(3), orbital_positions=[(0, 0, 0)])) periodization_matrix = np.diag(np.array(list([1] * 3), dtype=np.int32)) kmesh = MeshBrillouinZone(bz, periodization_matrix) wmesh = MeshImFreq(beta=p.beta, S='Fermion', n_max=p.nwf_gf) lat_rpa.g_wk = Gf(mesh=MeshProduct(wmesh, kmesh), target_shape=p.G_iw.target_shape) lat_rpa.g_wk[:, Idx(0, 0, 0)] = p.G_iw # -- chi0_wk bubble and chi_wk_rpa bubble RPA from triqs_tprf.lattice_utils import imtime_bubble_chi0_wk lat_rpa.chi0_wk = imtime_bubble_chi0_wk(lat_rpa.g_wk, nw=1) from triqs_tprf.lattice import solve_rpa_PH lat_rpa.chi_wk = solve_rpa_PH(lat_rpa.chi0_wk, p.U_abcd) lat_rpa.chi0_w = lat_rpa.chi0_wk[:, Idx(0, 0, 0)] lat_rpa.chi_w = lat_rpa.chi_wk[:, Idx(0, 0, 0)] print '--> cf Tr[chi0] and chi0_wk' print loc_rpa.chi0_w.data.reshape((4, 4)).real print lat_rpa.chi0_w.data.reshape((4, 4)).real np.testing.assert_array_almost_equal(loc_rpa.chi0_w.data, lat_rpa.chi0_w.data, decimal=2) print 'ok!' print '--> cf Tr[chi_rpa] and chi_wk_rpa' print loc_rpa.chi_w.data.reshape((4, 4)).real print lat_rpa.chi_w.data.reshape((4, 4)).real np.testing.assert_array_almost_equal(loc_rpa.chi_w.data, lat_rpa.chi_w.data, decimal=2) print 'ok!' # ------------------------------------------------------------------ # -- Lattice BSE lat_bse = ParameterCollection() lat_bse.g_wk = lat_rpa.g_wk lat_bse.mu = p.mu lat_bse.e_k = Gf(mesh=kmesh, target_shape=p.G_iw.target_shape) lat_bse.e_k[Idx(0, 0, 0)] = np.eye(2) lat_bse.sigma_w = p.G_iw.copy() lat_bse.sigma_w << iOmega_n + lat_bse.mu * np.eye(2) - lat_bse.e_k[Idx( 0, 0, 0)] - inverse(p.G_iw) lat_bse.g_wk_ref = lat_bse.g_wk.copy() lat_bse.g_wk_ref[:, Idx(0, 0, 0)] << inverse(iOmega_n + lat_bse.mu * np.eye(2) - lat_bse.e_k[Idx(0, 0, 0)] - lat_bse.sigma_w) np.testing.assert_array_almost_equal(lat_bse.g_wk.data, lat_bse.g_wk_ref.data) #for w in lat_bse.g_wk.mesh.components[0]: # print w, lat_bse.g_wk[w, Idx(0,0,0)][0, 0] from triqs_tprf.lattice import fourier_wk_to_wr lat_bse.g_wr = fourier_wk_to_wr(lat_bse.g_wk) from triqs_tprf.lattice import chi0r_from_gr_PH lat_bse.chi0_wnr = chi0r_from_gr_PH(nw=1, nn=p.nwf, g_nr=lat_bse.g_wr) from triqs_tprf.lattice import chi0q_from_chi0r lat_bse.chi0_wnk = chi0q_from_chi0r(lat_bse.chi0_wnr) #for n in lat_bse.chi0_wnk.mesh.components[1]: # print n.value, lat_bse.chi0_wnk[Idx(0), n, Idx(0,0,0)][0,0,0,0] # -- Lattice BSE calc from triqs_tprf.lattice import chiq_from_chi0q_and_gamma_PH lat_bse.chi_kwnn = chiq_from_chi0q_and_gamma_PH(lat_bse.chi0_wnk, loc_bse.gamma_wnn) # -- Lattice BSE calc with built in trace from triqs_tprf.lattice import chiq_sum_nu_from_chi0q_and_gamma_PH lat_bse.chi_kw_ref = chiq_sum_nu_from_chi0q_and_gamma_PH( lat_bse.chi0_wnk, loc_bse.gamma_wnn) # -- Lattice BSE calc with built in trace using g_wk from triqs_tprf.lattice import chiq_sum_nu_from_g_wk_and_gamma_PH lat_bse.chi_kw_tail_corr_ref = chiq_sum_nu_from_g_wk_and_gamma_PH( lat_bse.g_wk, loc_bse.gamma_wnn) # -- Trace results from triqs_tprf.lattice import chi0q_sum_nu_tail_corr_PH from triqs_tprf.lattice import chi0q_sum_nu lat_bse.chi0_wk_tail_corr = chi0q_sum_nu_tail_corr_PH(lat_bse.chi0_wnk) lat_bse.chi0_wk = chi0q_sum_nu(lat_bse.chi0_wnk) from triqs_tprf.lattice import chiq_sum_nu, chiq_sum_nu_q lat_bse.chi_kw = chiq_sum_nu(lat_bse.chi_kwnn) np.testing.assert_array_almost_equal(lat_bse.chi_kw.data, lat_bse.chi_kw_ref.data) from triqs_tprf.bse import solve_lattice_bse lat_bse.chi_kw_tail_corr, tmp = solve_lattice_bse(lat_bse.g_wk, loc_bse.gamma_wnn) from triqs_tprf.bse import solve_lattice_bse_e_k_sigma_w lat_bse.chi_kw_tail_corr_new = solve_lattice_bse_e_k_sigma_w( lat_bse.mu, lat_bse.e_k, lat_bse.sigma_w, loc_bse.gamma_wnn) np.testing.assert_array_almost_equal(lat_bse.chi_kw_tail_corr.data, lat_bse.chi_kw_tail_corr_ref.data) np.testing.assert_array_almost_equal(lat_bse.chi_kw_tail_corr.data, lat_bse.chi_kw_tail_corr_new.data) np.testing.assert_array_almost_equal(lat_bse.chi_kw_tail_corr_ref.data, lat_bse.chi_kw_tail_corr_new.data) lat_bse.chi0_w_tail_corr = lat_bse.chi0_wk_tail_corr[:, Idx(0, 0, 0)] lat_bse.chi0_w = lat_bse.chi0_wk[:, Idx(0, 0, 0)] lat_bse.chi_w_tail_corr = lat_bse.chi_kw_tail_corr[Idx(0, 0, 0), :] lat_bse.chi_w = lat_bse.chi_kw[Idx(0, 0, 0), :] print '--> cf Tr[chi0_wnk] and chi0_wk' print lat_bse.chi0_w_tail_corr.data.reshape((4, 4)).real print lat_bse.chi0_w.data.reshape((4, 4)).real print lat_rpa.chi0_w.data.reshape((4, 4)).real np.testing.assert_array_almost_equal(lat_bse.chi0_w_tail_corr.data, lat_rpa.chi0_w.data) np.testing.assert_array_almost_equal(lat_bse.chi0_w.data, lat_rpa.chi0_w.data, decimal=2) print 'ok!' print '--> cf Tr[chi_kwnn] and chi_wk (without chi0 tail corr)' print lat_bse.chi_w.data.reshape((4, 4)).real print loc_bse.chi_w.data.reshape((4, 4)).real np.testing.assert_array_almost_equal(lat_bse.chi_w.data, loc_bse.chi_w.data) print 'ok!' # ------------------------------------------------------------------ # -- Use chi0 tail corrected trace to correct chi_rpa cf bubble dchi_wk = lat_bse.chi0_wk_tail_corr - lat_bse.chi0_wk dchi_w = dchi_wk[:, Idx(0, 0, 0)] loc_rpa.chi_w_tail_corr = loc_rpa.chi_w + dchi_w # -- this will be the same, but it will be close to the real physical value lat_bse.chi_w_tail_corr_ref = lat_bse.chi_w + dchi_w loc_bse.chi_w_tail_corr_ref = loc_bse.chi_w + dchi_w print '--> cf Tr[chi_rpa] and chi_wk_rpa' print loc_rpa.chi_w.data.reshape((4, 4)).real print loc_rpa.chi_w_tail_corr.data.reshape((4, 4)).real print lat_rpa.chi_w.data.reshape((4, 4)).real np.testing.assert_array_almost_equal(loc_rpa.chi_w_tail_corr.data, lat_rpa.chi_w.data, decimal=3) print '--> cf Tr[chi_kwnn] with tail corr (from chi0_wnk)' print lat_bse.chi_w_tail_corr.data.reshape((4, 4)).real print lat_bse.chi_w_tail_corr_ref.data.reshape((4, 4)).real np.testing.assert_array_almost_equal(lat_bse.chi_w_tail_corr.data, lat_bse.chi_w_tail_corr_ref.data) print 'ok!' # ------------------------------------------------------------------ # -- Store to hdf5 filename = 'data_bse_rpa.h5' with HDFArchive(filename, 'w') as res: res['p'] = p
import pytriqs.utility.mpi as mpi from pytriqs.gf import Gf, MeshImFreq, MeshProduct from pytriqs.gf import MeshBrillouinZone, MeshCyclicLattice from pytriqs.lattice import BrillouinZone, BravaisLattice from triqs_tprf.lattice import lattice_dyson_g0_wk from triqs_tprf.lattice import fourier_wk_to_wr from triqs_tprf.lattice import fourier_wr_to_wk bz = BrillouinZone(BravaisLattice([[1, 0], [0, 1]])) periodization_matrix = np.diag(np.array([10, 10, 1], dtype=np.int32)) bzmesh = MeshBrillouinZone(bz, periodization_matrix) lmesh = MeshCyclicLattice(bz.lattice, periodization_matrix) e_k = Gf(mesh=bzmesh, target_shape=[1, 1]) for k in bzmesh: e_k[k] = -2 * (np.cos(k[0]) + np.cos(k[1])) # does not work... mesh = MeshImFreq(beta=1.0, S='Fermion', n_max=1024) g0_wk = lattice_dyson_g0_wk(mu=1.0, e_k=e_k, mesh=mesh) g0_wr = fourier_wk_to_wr(g0_wk) g0_wk_ref = fourier_wr_to_wk(g0_wr) np.testing.assert_array_almost_equal(g0_wk.data, g0_wk_ref.data)