def get_chi0_nk_at_specific_w(g_wk, nw_index=1, nwf=None): r""" Compute the generalized bare lattice susceptibility :math:`\chi^{0}_{\bar{a}b\bar{c}d}(i\omega_{n=\mathrm{nw\_index}}, i\nu_n, \mathbf{k})` from the single-particle Green's function :math:`G_{a\bar{b}}(i\nu_n, \mathbf{k})` for a specific :math:`i\omega_{n=\mathrm{nw\_index}}`. Parameters ---------- g_wk : Gf, Single-particle Green's function :math:`G_{a\bar{b}}(i\nu_n, \mathbf{k})`. nw_index : int, The bosonic Matsubara frequency index :math:`i\omega_{n=\mathrm{nw\_index}}` at which :math:`\chi^0` is calculated. nwf : int, Number of fermionic frequencies in :math:`\chi^0`. Returns ------- chi0_nk : Gf, Generalized bare lattice susceptibility :math:`\chi^{0}_{\bar{a}b\bar{c}d}(i\omega_{n=\mathrm{nw\_index}}, i\nu_n, \mathbf{k})`. """ fmesh = g_wk.mesh.components[0] kmesh = g_wk.mesh.components[1] if nwf is None: nwf = len(fmesh) // 2 mpi.barrier() mpi.report('g_wk ' + str(g_wk[Idx(2), Idx(0, 1, 2)][0, 0])) n = np.sum(g_wk.data) // len(kmesh) mpi.report('n ' + str(n)) mpi.barrier() mpi.report('--> g_wr from g_wk') g_wr = fourier_wk_to_wr(g_wk) mpi.report('--> chi0_wnr from g_wr') chi0_nr = chi0_nr_from_gr_PH_at_specific_w(nw_index=nw_index, nn=nwf, g_nr=g_wr) del g_wr mpi.report('--> chi0_wnk from chi0_wnr') # Create a 'fake' bosonic mesh to be able to use 'chi0q_from_chi0r' chi0_wnr = add_fake_bosonic_mesh(chi0_nr) del chi0_nr chi0_wnk = chi0q_from_chi0r(chi0_wnr) del chi0_wnr chi0_nk = chi0_wnk[Idx(0), :, :] del chi0_wnk return chi0_nk
def test_solve_lattice_bse_at_specific_w_against_full(g0_wk, gamma_wnn, nw_index): chi_kw, chi0_kw = solve_lattice_bse(g0_wk, gamma_wnn) chi_k_at_specific_w, chi0_k_at_specific_w = solve_lattice_bse_at_specific_w( g0_wk, gamma_wnn, nw_index=nw_index ) np.testing.assert_allclose( chi0_kw[:, Idx(nw_index)].data, chi0_k_at_specific_w.data, atol=10e-16 ) np.testing.assert_allclose( chi_kw[:, Idx(nw_index)].data, chi_k_at_specific_w.data, atol=10e-16 )
def test_add_fake_bosonic_mesh_with_gf_nk(bzmesh): nmesh = MeshImFreq(beta=1, S="Fermion", n_max=1) gf_nk = Gf(mesh=MeshProduct(nmesh, bzmesh), target_shape=(2, 2)) gf_wnk = add_fake_bosonic_mesh(gf_nk) np.testing.assert_allclose(gf_nk.data, gf_wnk[Idx(0), :, :].data)
def test_add_fake_bosonic_mesh_with_gf_k_with_beta(bzmesh): gf_k = Gf(mesh=bzmesh, target_shape=(2, 2)) beta = 10 gf_wk = add_fake_bosonic_mesh(gf_k, beta=beta) np.testing.assert_allclose(gf_k.data, gf_wk[Idx(0), :].data) assert gf_wk.mesh[0].beta == beta
def test_chi0_nk_at_specific_w_against_full(g0_wk, p): chi0_wnk = get_chi0_wnk(g0_wk, nw=p.nw_chi, nwf=p.nwf) chi0_nk_at_specific_w = get_chi0_nk_at_specific_w(g0_wk, nw_index=p.nw_index, nwf=p.nwf) np.testing.assert_allclose(chi0_wnk[Idx(p.nw_index), :, :].data, chi0_nk_at_specific_w.data)
def plot_output(g0_wk, gamma): from triqs.plot.mpl_interface import oplot, plt initial_delta = semi_random_initial_delta(g0_wk) next_delta_summation = eliashberg_product(gamma_big, g0_wk, initial_delta) gamma_dyn_tr, gamma_const_r = preprocess_gamma_for_fft(gamma) next_delta_fft = eliashberg_product_fft(gamma_dyn_tr, gamma_const_r, g0_wk, initial_delta) deltas = [initial_delta, next_delta_summation, next_delta_fft] warnings.filterwarnings("ignore") #ignore some matplotlib warnings subp = [4, 3, 1] fig = plt.figure(figsize=(18, 15)) titles = ['Input', 'Summation', 'FFT'] for k_point in [Idx(0, 0, 0), Idx(1, 0, 0)]: ax = plt.subplot(*subp) subp[-1] += 1 oplot(g0_wk[:, k_point]) plt.title('GF') ax = plt.subplot(*subp) subp[-1] += 1 oplot(gamma[:, k_point]) plt.title('Gamma') ax = plt.subplot(*subp) subp[-1] += 1 oplot(gamma_dyn_tr[:, k_point]) plt.title('Gamma dyn tr') for delta, title in zip(deltas, titles): ax = plt.subplot(*subp) subp[-1] += 1 oplot(delta[:, k_point]) plt.title(title) ax.legend_ = None plt.show()
def test_chi0_nr_at_specific_w_against_full(g0_wr, p): chi0_wnr = chi0r_from_gr_PH(nw=p.nw_chi, nn=p.nwf, g_nr=g0_wr) chi0_nr_at_specific_w = chi0_nr_from_gr_PH_at_specific_w( nw_index=p.nw_index, nn=p.nwf, g_nr=g0_wr ) np.testing.assert_allclose( chi0_wnr[Idx(p.nw_index), :, :].data, chi0_nr_at_specific_w.data )
def compare_deltas(deltas_1, deltas_2=None, static=False): """ Build comparison matrix of list of Gf """ if not deltas_2: deltas_2 = deltas_1 if static: deltas_1 = [ele[Idx(0), :] for ele in deltas_1] deltas_2 = [ele[Idx(0), :] for ele in deltas_2] diff = np.zeros(shape=(len(deltas_1), len(deltas_2))) for i, delta_1 in enumerate(deltas_1): for j, delta_2 in enumerate(deltas_2): diff[i, j] = np.max(np.abs(delta_1.data - delta_2.data)) return diff
def put_gf_on_mesh(g_in, wmesh): assert (len(wmesh) <= len(g_in.mesh)) g_out = Gf(mesh=wmesh, target_shape=g_in.target_shape) for w in wmesh: index = w.linear_index + wmesh.first_index() # absolute index g_out[w] = g_in[Idx(index)] return g_out
def plot_delta(delta): import matplotlib.pyplot as plt fig, axes = plt.subplots(3, 3) vmax = np.max(np.abs(delta[Idx(0), :].data)) for orb1, orb2 in itertools.product(list(range(p.norb)), repeat=2): shape = (p.nk, p.nk, p.norb, p.norb) data = delta[Idx(0), :].data.reshape(shape) plt.sca(axes[orb1, orb2]) plt.imshow(data[:, :, orb1, orb2].real, cmap="RdBu_r", vmax=vmax, vmin=-vmax) plt.colorbar() plt.sca(axes[-1, -1]) for orb1, orb2 in itertools.product(list(range(p.norb)), repeat=2): plt.plot(delta.data[:, 1, orb1, orb2].real) plt.plot(delta.data[:, 1, orb1, orb2].imag) plt.show()
def plot_g2(G2, cplx=None, idx_labels=None, w=Idx(0), opt={}, title=None): data = G2[w, :, :].data if cplx == 're': data = data.real elif cplx == 'im': data = data.imag n = data.shape[-1] N = n**2 subp = [N, N, 1] colorbar_flag = True import itertools for idxs in itertools.product(range(n), repeat=4): i1, i2, i3, i4 = idxs d = data[:, :, i1, i2, i3, i4] ax = plt.subplot(*subp) subp[-1] += 1 if idx_labels is not None: labels = [idx_labels[idx] for idx in idxs] sub_title = r'$c^\dagger_{%s} c_{%s} c^\dagger_{%s} c_{%s}$' % tuple( labels) else: sub_title = str(idxs) plt.title(sub_title, fontsize=8) #plt.pcolormesh(d, **opt) if np.max(np.abs(d)) > 1e-10: plt.imshow(d, **opt) if colorbar_flag: if title is not None: plt.title(title) plt.colorbar() colorbar_flag = False ax.set_xticks([]) ax.set_yticks([]) plt.axis('equal') plt.tight_layout()
def get_chi_SzSz(chi): # -- Contract Sz Sz response Sx = 0.5 * np.array([[0., 1.], [1., 0]]) Sy = 0.5 * np.array([[0., -1.j], [1.j, 0]]) Sz = np.diag([+0.5, -0.5]) N = np.eye(2) #Op1, Op2 = Sx, Sx #Op1, Op2 = Sy, Sy Op1, Op2 = Sz, Sz #Op1, Op2 = N, N chi_SzSz = chi[0, 0, 0, 0].copy() chi_SzSz.data[:] = np.einsum('wqabcd,ab,cd->wq', chi.data, Op1, Op2)[:, :] chi_SzSz = chi_SzSz[Idx(0), :] return chi_SzSz
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 triqs.plot.mpl_interface import oplot, plt oplot(p.Sigmalatt_iw) oplot(sigma, 'x') plt.show() exit() return sigma
def plot_chi(chi, title): chi_k = chi[Idx(0), :][0, 0, 0, 0] # zero frequency, and scalar k = np.linspace(-0.75, 0.75, num=100) * 2. * np.pi Kx, Ky = np.meshgrid(k, k) interp = np.vectorize(lambda kx, ky : chi_k([kx, ky, 0]).real) interp = interp(Kx, Ky) plt.imshow( interp, cmap=plt.get_cmap('magma'), extent=(k.min(), k.max(), k.min(), k.max()), origin='lower', vmin=0, vmax=interp.max()) plt.title(title) plt.xlabel(r'$\frac{a}{2\pi} \cdot k_x$') plt.ylabel(r'$\frac{a}{2\pi} \cdot k_y$') plt.colorbar()
n = rho[0, 0] + rho[1, 1] m = 0.5 * (rho[0, 0] - rho[1, 1]) print('n, m =', n, m) E_tot = E_kin - U*(n**2/4 - m**2) print('E_tot =', E_tot) np.testing.assert_almost_equal(E_tot_ref, E_tot, decimal=6) # ------------------------------------------------------------------ # -- Lattice chi0 print('--> chi00_wk') chi00_wk = imtime_bubble_chi0_wk(g0_wk, nw=1) print('chi0_q0 =\n', chi00_wk[Idx(0), Idx(0, 0, 0)].real.reshape((4,4))) print('--> lindhard_chi00_wk') chi00_wk_analytic = lindhard_chi00_wk(e_k=e_k, nw=1, beta=beta, mu=mu) print('chi0_q0_analytic =\n', chi00_wk_analytic[ Idx(0), Idx(0, 0, 0)].real.reshape((4,4))) np.testing.assert_almost_equal( chi00_wk.data, chi00_wk_analytic.data, decimal=5) chi0_q0_ref = chi0_q0_integral(t, beta) print('chi0_q0 =', chi00_wk[Idx(0), Idx(0, 0, 0)][0,0,0,0].real) print('chi0_q0_ref =', chi0_q0_ref) np.testing.assert_almost_equal(
def Idxs(integer_index_list): from triqs.gf import Idx return tuple( Idx(i) for i in integer_index_list )
def get_chi0_wnk(g_wk, nw=1, nwf=None): r""" Compute the generalized bare lattice susceptibility :math:`\chi^{0}_{\bar{a}b\bar{c}d}(i\omega_n, i\nu_n, \mathbf{k})` from the single-particle Green's function :math:`G_{a\bar{b}}(i\nu_n, \mathbf{k})`. Parameters ---------- g_wk : Gf, Single-particle Green's function :math:`G_{a\bar{b}}(i\nu_n, \mathbf{k})`. nw : int, Number of bosonic frequencies in :math:`\chi^0`. nwf : int, Number of fermionic frequencies in :math:`\chi^0`. Returns ------- chi0_wnk : Gf, Generalized bare lattice susceptibility :math:`\chi^{0}_{\bar{a}b\bar{c}d}(i\omega_n, i\nu_n, \mathbf{k})`. """ fmesh = g_wk.mesh.components[0] kmesh = g_wk.mesh.components[1] if nwf is None: nwf = len(fmesh) // 2 mpi.barrier() mpi.report('g_wk ' + str(g_wk[Idx(2), Idx(0, 0, 0)][0, 0])) n = np.sum(g_wk.data) / len(kmesh) mpi.report('n ' + str(n)) mpi.barrier() mpi.report('--> g_wr from g_wk') g_wr = fourier_wk_to_wr(g_wk) mpi.barrier() mpi.report('g_wr ' + str(g_wr[Idx(2), Idx(0, 0, 0)][0, 0])) n_r = np.sum(g_wr.data, axis=0)[0] mpi.report('n_r=0 ' + str(n_r[0, 0])) mpi.barrier() mpi.report('--> chi0_wnr from g_wr') chi0_wnr = chi0r_from_gr_PH(nw=nw, nn=nwf, g_nr=g_wr) #mpi.report('--> chi0_wnr from g_wr (nompi)') #chi0_wnr_nompi = chi0r_from_gr_PH_nompi(nw=nw, nn=nwf, g_wr=g_wr) del g_wr #abs_diff = np.abs(chi0_wnr.data - chi0_wnr_nompi.data) #mpi.report('shape = ' + str(abs_diff.shape)) #idx = np.argmax(abs_diff) #mpi.report('argmax = ' + str(idx)) #diff = np.max(abs_diff) #mpi.report('diff = %6.6f' % diff) #del chi0_wnr #chi0_wnr = chi0_wnr_nompi #exit() mpi.barrier() mpi.report('chi0_wnr ' + str(chi0_wnr[Idx(0), Idx(0), Idx(0, 0, 0)][0, 0, 0, 0])) chi0_r0 = np.sum(chi0_wnr[:, :, Idx(0, 0, 0)].data) mpi.report('chi0_r0 ' + str(chi0_r0)) mpi.barrier() mpi.report('--> chi0_wnk from chi0_wnr') chi0_wnk = chi0q_from_chi0r(chi0_wnr) del chi0_wnr mpi.barrier() mpi.report('chi0_wnk ' + str(chi0_wnk[Idx(0), Idx(0), Idx(0, 0, 0)][0, 0, 0, 0])) chi0 = np.sum(chi0_wnk.data) / len(kmesh) mpi.report('chi0 = ' + str(chi0)) mpi.barrier() #if mpi.is_master_node(): if False: from triqs_tprf.ParameterCollection import ParameterCollection p = ParameterCollection() p.g_wk = g_wk p.g_wr = g_wr p.chi0_wnr = chi0_wnr p.chi0_wnk = chi0_wnk print('--> Writing debug info for BSE') with HDFArchive('data_debug_bse.h5', 'w') as arch: arch['p'] = p mpi.barrier() return chi0_wnk
hfr.chi0_SzSz = hfr.bare_response(Sz, Sz) hfr.chi_SzSz = hfr.response(Sz, Sz) #hfr.chi0_k = hfr.compute_chi0_k() np.testing.assert_almost_equal(hr.chi0_SzSz, hfr.chi0_SzSz) np.testing.assert_almost_equal(hr.chi_SzSz, hfr.chi_SzSz) # ------------------------------------------------------------------ # -- Call TPRF chi0_wk bubble calc wmesh = MeshImFreq(beta=beta, S='Fermion', n_max=n_w) g0_wk = lattice_dyson_g0_wk(mu=mu, e_k=e_k, mesh=wmesh) chi0_wk = imtime_bubble_chi0_wk(g0_wk, nw=1) chi0_abcd = chi0_wk[Idx(0), Idx(0,0,0)].copy() chi0_ab = hr.extract_dens_dens(chi0_abcd) chi0_SzSz = np.einsum('ab,abcd,cd->', Sz, chi0_abcd, Sz) print('chi0_abcd diff =', np.max(np.abs(chi0_abcd - hfr.chi0_abcd))) np.testing.assert_almost_equal(chi0_abcd, hfr.chi0_abcd, decimal=6) print('chi0_ab diff =', np.max(np.abs(chi0_ab - hr.chi0_ab))) np.testing.assert_almost_equal(chi0_ab, hr.chi0_ab) np.testing.assert_almost_equal(chi0_SzSz, hr.chi0_SzSz) if False: chi0_k = chi0_wk[Idx(0), :] np.set_printoptions(
e_k_interp = e_k_interp(kx, ky, kz) plt.figure() plt.plot(k_plot, e_k_interp, '-') plt.axes().set_xticks(K_plot) plt.axes().set_xticklabels([r'$\Gamma$', r'$X$', r'$M$', r'$\Gamma$']) plt.ylabel(r'$\epsilon(\mathbf{k})$') plt.grid() plt.tight_layout() plt.savefig('figure_e_k_bandpath.pdf') # ------------------------------------------------------------------ chi_k = chi00_wk[Idx(0), :][0, 0, 0, 0] # zero frequency, and scalar chi_k_interp = np.vectorize(lambda kx, ky, kz: chi_k([kx, ky, kz]).real) chi_k_interp = chi_k_interp(kx, ky, kz) plt.figure() plt.plot(k_plot, chi_k_interp, '-') plt.axes().set_xticks(K_plot) plt.axes().set_xticklabels([r'$\Gamma$', r'$X$', r'$M$', r'$\Gamma$']) plt.ylabel(r'$\chi_0(\mathbf{k}, i\omega_n = 0)$') plt.grid() plt.tight_layout() plt.savefig('figure_chi00_k_bandpath.pdf')
# ---------------------------------------------------------------------- # -- Bare susceptibility from Green's function bubble nw = 20 beta = 0.544 from triqs.gf import MeshImFreq, Idx wmesh = MeshImFreq(beta=beta, S='Fermion', n_max=nw) from triqs_tprf.lattice import lattice_dyson_g0_wk 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) print() print('chi0_q0 =\n', chi00_wk[Idx(0), Idx(0, 0, 0)].real.reshape((16,16))) #print #import itertools #for idxs in itertools.product(range(2), repeat=4): # print idxs, chi00_wk[Idx(0), Idx(0, 0, 0)].real[idxs] chi0_q0_ref = chi0_q0_integral(t, beta) print() print('chi0_q0 =', chi00_wk[Idx(0), Idx(0, 0, 0)][0,0,0,0].real) print('chi0_q0_ref =', chi0_q0_ref) print() # ---------------------------------------------------------------------- # -- Kanamori interaction
# -- Two site super lattice P = np.array([[2]]) Units_prim = np.array(t_r_prim.Units) print('Units_prim =\n', Units_prim) Units = np.dot(P, Units_prim) print('Units =\n', Units) t_r = TBSuperLattice(t_r_prim, P) kmesh = t_r.get_kmesh(n_k) e_k = t_r.fourier(kmesh) print(e_k.target_shape) print('eps(k=0) =\n', e_k[Idx(0, 0, 0)]) # -- Local double occ and spin operators gf_struct = [[0, 4]] docc = n(0, 0) * n(0, 2) + n(0, 1) * n(0, 3) print('docc =', docc) sigma_x = 0.5 * np.rot90(np.diag([1., 1.])) sigma_y = 0.5 * np.rot90(np.diag([1.j, -1.j])) sigma_z = 0.5 * np.diag([1., -1.]) print('sigma_x =\n', sigma_x) print('sigma_y =\n', sigma_y)
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=int)) kmesh = MeshBrZone(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
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)
def solve_lattice_bse_at_specific_w(g_wk, gamma_wnn, nw_index): r""" Compute the generalized lattice susceptibility :math:`\chi_{\bar{a}b\bar{c}d}(i\omega_{n=\mathrm{nw\_index}}, \mathbf{k})` using the Bethe-Salpeter equation (BSE) for a specific :math:`i\omega_{n=\mathrm{nw\_index}}`. Parameters ---------- g_wk : Gf, Single-particle Green's function :math:`G_{a\bar{b}}(i\nu_n, \mathbf{k})`. gamma_wnn : Gf, Local particle-hole vertex function :math:`\Gamma_{a\bar{b}c\bar{d}}(i\omega_n, i\nu_n, i\nu_n')`. nw_index : int, The bosonic Matsubara frequency index :math:`i\omega_{n=\mathrm{nw\_index}}` at which the BSE is solved. Returns ------- chi_k : Gf, Generalized lattice susceptibility :math:`\chi_{\bar{a}b\bar{c}d}(i\omega_{n=\mathrm{nw\_index}}, \mathbf{k})`. chi0_k : Gf, Generalized bare lattice susceptibility :math:`\chi^0_{\bar{a}b\bar{c}d}(i\omega_{n=\mathrm{nw\_index}}, \mathbf{k})`. """ # Only use \Gamma at the specific \omega gamma_nn = gamma_wnn[Idx(nw_index), :, :] # Keep fake bosonic mesh for usability with other functions gamma_wnn = add_fake_bosonic_mesh(gamma_nn) fmesh_g = g_wk.mesh.components[0] kmesh = g_wk.mesh.components[1] bmesh = gamma_wnn.mesh.components[0] fmesh = gamma_wnn.mesh.components[1] nk = len(kmesh) nwf = len(fmesh) // 2 nwf_g = len(fmesh_g) // 2 if mpi.is_master_node(): print(tprf_banner(), "\n") print( 'Lattcie BSE with local vertex approximation at specific \omega.\n' ) print('nk =', nk) print('nw_index =', nw_index) print('nwf =', nwf) print('nwf_g =', nwf_g) print() mpi.report('--> chi0_wk_tail_corr') # Calculate chi0_wk up to the specific \omega chi0_wk_tail_corr = imtime_bubble_chi0_wk(g_wk, nw=np.abs(nw_index) + 1, save_memory=True) # Only use specific \omega, but put back on fake bosonic mesh chi0_k_tail_corr = chi0_wk_tail_corr[Idx(nw_index), :] chi0_wk_tail_corr = add_fake_bosonic_mesh(chi0_k_tail_corr, beta=bmesh.beta) chi0_nk = get_chi0_nk_at_specific_w(g_wk, nw_index=nw_index, nwf=nwf) # Keep fake bosonic mesh for usability with other functions chi0_wnk = add_fake_bosonic_mesh(chi0_nk) mpi.report('--> trace chi0_wnk') chi0_wk = chi0q_sum_nu(chi0_wnk) dchi_wk = chi0_wk_tail_corr - chi0_wk chi0_kw = Gf(mesh=MeshProduct(kmesh, bmesh), target_shape=chi0_wk_tail_corr.target_shape) chi0_kw.data[:] = chi0_wk_tail_corr.data.swapaxes(0, 1) del chi0_wk del chi0_wk_tail_corr assert (chi0_wnk.mesh.components[0] == bmesh) assert (chi0_wnk.mesh.components[1] == fmesh) assert (chi0_wnk.mesh.components[2] == kmesh) # -- Lattice BSE calc with built in trace mpi.report('--> chi_kw from BSE') #mpi.report('DEBUG BSE INACTIVE'*72) chi_kw = chiq_sum_nu_from_chi0q_and_gamma_PH(chi0_wnk, gamma_wnn) #chi_kw = chi0_kw.copy() mpi.barrier() mpi.report('--> chi_kw from BSE (done)') del chi0_wnk mpi.report('--> chi_kw tail corrected (using chi0_wnk)') for k in kmesh: chi_kw[ k, :] += dchi_wk[:, k] # -- account for high freq of chi_0 (better than nothing) del dchi_wk mpi.report('--> solve_lattice_bse, done.') chi_k = chi_kw[:, Idx(0)] del chi_kw chi0_k = chi0_kw[:, Idx(0)] del chi0_kw return chi_k, chi0_k
def solve_lattice_bse(g_wk, gamma_wnn): r""" Compute the generalized lattice susceptibility :math:`\chi_{\bar{a}b\bar{c}d}(\mathbf{k}, \omega_n)` using the Bethe-Salpeter equation (BSE). Parameters ---------- g_wk : Gf, Single-particle Green's function :math:`G_{a\bar{b}}(i\nu_n, \mathbf{k})`. gamma_wnn : Gf, Local particle-hole vertex function :math:`\Gamma_{a\bar{b}c\bar{d}}(i\omega_n, i\nu_n, i\nu_n')`. Returns ------- chi_kw : Gf, Generalized lattice susceptibility :math:`\chi_{\bar{a}b\bar{c}d}(\mathbf{k}, i\omega_n)`. chi0_kw : Gf, Generalized bare lattice susceptibility :math:`\chi^0_{\bar{a}b\bar{c}d}(\mathbf{k}, i\omega_n)`. """ fmesh_g = g_wk.mesh.components[0] kmesh = g_wk.mesh.components[1] bmesh = gamma_wnn.mesh.components[0] fmesh = gamma_wnn.mesh.components[1] nk = len(kmesh) nw = (len(bmesh) + 1) // 2 nwf = len(fmesh) // 2 nwf_g = len(fmesh_g) // 2 if mpi.is_master_node(): print(tprf_banner(), "\n") print('Lattcie BSE with local vertex approximation.\n') print('nk =', nk) print('nw =', nw) print('nwf =', nwf) print('nwf_g =', nwf_g) print() mpi.report('--> chi0_wk_tail_corr') chi0_wk_tail_corr = imtime_bubble_chi0_wk(g_wk, nw=nw) mpi.barrier() mpi.report('B1 ' + str(chi0_wk_tail_corr[Idx(0), Idx(0, 0, 0)][0, 0, 0, 0])) mpi.barrier() chi0_wnk = get_chi0_wnk(g_wk, nw=nw, nwf=nwf) mpi.barrier() mpi.report('C ' + str(chi0_wnk[Idx(0), Idx(0), Idx(0, 0, 0)][0, 0, 0, 0])) mpi.barrier() mpi.report('--> trace chi0_wnk') chi0_wk = chi0q_sum_nu(chi0_wnk) mpi.barrier() mpi.report('D ' + str(chi0_wk[Idx(0), Idx(0, 0, 0)][0, 0, 0, 0])) mpi.barrier() dchi_wk = chi0_wk_tail_corr - chi0_wk chi0_kw = Gf(mesh=MeshProduct(kmesh, bmesh), target_shape=chi0_wk_tail_corr.target_shape) chi0_kw.data[:] = chi0_wk_tail_corr.data.swapaxes(0, 1) del chi0_wk del chi0_wk_tail_corr assert (chi0_wnk.mesh.components[0] == bmesh) assert (chi0_wnk.mesh.components[1] == fmesh) assert (chi0_wnk.mesh.components[2] == kmesh) # -- Lattice BSE calc with built in trace mpi.report('--> chi_kw from BSE') #mpi.report('DEBUG BSE INACTIVE'*72) chi_kw = chiq_sum_nu_from_chi0q_and_gamma_PH(chi0_wnk, gamma_wnn) #chi_kw = chi0_kw.copy() mpi.barrier() mpi.report('--> chi_kw from BSE (done)') del chi0_wnk mpi.report('--> chi_kw tail corrected (using chi0_wnk)') for k in kmesh: chi_kw[ k, :] += dchi_wk[:, k] # -- account for high freq of chi_0 (better than nothing) del dchi_wk mpi.report('--> solve_lattice_bse, done.') return chi_kw, chi0_kw
n = rho[0, 0] + rho[1, 1] m = 0.5 * (rho[0, 0] - rho[1, 1]) print('n, m =', n, m) E_tot = E_kin - U * (n**2 / 4 - m**2) print('E_tot =', E_tot) np.testing.assert_almost_equal(E_tot_ref, E_tot, decimal=6) # ------------------------------------------------------------------ # -- Lattice chi0 print('--> chi00_wk') chi00_wk = imtime_bubble_chi0_wk(g0_wk, nw=1) print('chi0_q0 =\n', chi00_wk[Idx(0), Idx(0, 0, 0)].real.reshape((4, 4))) print('--> lindhard_chi00_wk') chi00_wk_analytic = lindhard_chi00_wk(e_k=e_k, nw=1, beta=beta, mu=mu) print('chi0_q0_analytic =\n', chi00_wk_analytic[Idx(0), Idx(0, 0, 0)].real.reshape( (4, 4))) np.testing.assert_almost_equal(chi00_wk.data, chi00_wk_analytic.data, decimal=5) chi0_q0_ref = chi0_q0_integral(t, beta) print('chi0_q0 =', chi00_wk[Idx(0), Idx(0, 0, 0)][0, 0, 0, 0].real) print('chi0_q0_ref =', chi0_q0_ref)
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 = MeshBrZone(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