Skip to content

GW hardening [do not merge] #40

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 44 commits into
base: unstable
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
a123432
[gw] hf sigma tests wip
HugoStrand Apr 18, 2023
fc542c3
[gw] hartree + fock sigma reprod hf_solver
HugoStrand Apr 19, 2023
f2d8710
[gw] python doc for hartree_sigma fock_sigma
HugoStrand Apr 19, 2023
40d3c87
[gw] analytic cf wip
HugoStrand Apr 19, 2023
8081287
[gw] hubbard dimer analytic ref test working
HugoStrand Apr 21, 2023
0764a16
[gw] GWSolver with tests
HugoStrand Apr 21, 2023
888cf85
[bubble] verbose flag
HugoStrand Apr 23, 2023
c5177cc
[gw] test cf ed, G0W0 and scGW
HugoStrand Apr 23, 2023
75572b6
[gw] sc vs sic testing
HugoStrand Apr 24, 2023
c34699e
[gw] spinless hubbard dimer test
HugoStrand Apr 25, 2023
16eeae0
[gw] move gw hubbard dimer to test
HugoStrand Apr 25, 2023
bd52103
[gw] cleanup hubbard dimer tests
HugoStrand Apr 25, 2023
4de4057
[gw] hubbard dimer ed reference result
HugoStrand Apr 25, 2023
5fa7908
[gw] hf real space calc and GWSolv h5 storage
HugoStrand Apr 28, 2023
4ce7638
[gw] ret rf result
HugoStrand Apr 28, 2023
33f6c2f
[gw] gw_dynamic_sigma renaming
HugoStrand Apr 28, 2023
aa5bb6b
[gw] add ase timer for benchmarking
HugoStrand Apr 28, 2023
6ccf23f
[gw] mpi print fixes
HugoStrand Apr 28, 2023
c92fcb7
[gw] parallelization optimization
HugoStrand Apr 28, 2023
e4661d7
[gw] fix ed ref for hubbard dimer test
HugoStrand Apr 29, 2023
ed4abdd
[gw] dynamical interaction fix index bug
HugoStrand Apr 29, 2023
93f3422
[gw] timers on post proc methods
HugoStrand Apr 29, 2023
3021e99
[sanitizer] error fixes
HugoStrand Apr 29, 2023
9927db4
[gw] fix density calculations
HugoStrand Apr 30, 2023
8b2f4a6
[gw] Hartree sigma V(q=0)rho(r=0)
HugoStrand May 2, 2023
a6cdb0f
[gw] subtract V_k to get W_dyn_wk in gw_solver
YannIntVeld May 2, 2023
b8bd11c
[gw] Added a single-kpoint gw test
YannIntVeld May 3, 2023
a413365
[gw] fixed subtract V_k to get W_dyn_wk
YannIntVeld May 3, 2023
bb5cca5
[gw] extended single k-point gw test to real-freq
YannIntVeld May 3, 2023
7a5eff4
[bse] remove broken kmesh cmp
HugoStrand May 5, 2023
1b859e4
[gw] save non int mu0
HugoStrand May 5, 2023
4c367e8
[dbse] c++ calculator
HugoStrand May 8, 2023
a9e4123
[gw] Updated index order in real-freq GW
YannIntVeld May 10, 2023
465cca1
[gw] Added a test which compares full GW and GW via spectral represen…
YannIntVeld May 10, 2023
de918ab
[gw] updated the documentation for index order fix
YannIntVeld May 10, 2023
0da67c8
[gw] Added imaginary part in interaction of GW method comparison
YannIntVeld May 10, 2023
1e5ec2d
[gw] small changes to GW compare methods test
YannIntVeld May 11, 2023
f50fcc3
[gw] Renamed GW method comparison test
YannIntVeld May 11, 2023
b78f355
[gw] Split the dynamic and static parts of the g0w_sigma function
YannIntVeld May 11, 2023
6e12c4e
[g0w] Single k-point calculations
YannIntVeld May 15, 2023
b5a415d
Moved fermi and bose functions to lattice_utility.cpp
YannIntVeld May 16, 2023
50175b1
[g0w] Implemented single kpoint calculation for g0w_dyn_sigma
YannIntVeld May 16, 2023
6bc42ff
[g0w] Single kpoint for combined stat and dyn
YannIntVeld May 16, 2023
f01e30b
[g0w] Renamed g0w_dyn_sigma
YannIntVeld May 16, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
143 changes: 143 additions & 0 deletions c++/triqs_tprf/lattice/chi_imfreq.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -676,6 +676,149 @@ chi_kwnn_t chiq_from_chi0q_and_gamma_PH(chi_wnk_cvt chi0_wnk, chi_wnn_cvt gamma_

// ----------------------------------------------------

chi_kw_t chiq_sum_nu_from_chi0q_and_gamma_and_L_wn_PH(chi_wnk_cvt chi0_wnk, chi_wnn_cvt gamma_ph_wnn, chi_nn_cvt L_wn) {

auto _ = all_t{};

mpi::communicator comm;

auto target_shape = chi0_wnk.target_shape();
// auto &[bmesh, fmesh, kmesh] = chi0_wnk.mesh();
auto &bmesh = std::get<0>(chi0_wnk.mesh());
auto &fmesh = std::get<1>(chi0_wnk.mesh());
auto &kmesh = std::get<2>(chi0_wnk.mesh());

double beta = fmesh.domain().beta;

chi_kw_t chi_kw({kmesh, bmesh}, target_shape);

auto arr = mpi_view(chi_kw.mesh()); // FIXME Use library implementation
std::cout << "BSE rank " << comm.rank() << " of " << comm.size() << " has "
<< arr.size() << " jobs." << std::endl;

triqs::utility::timer t;
t.start();

#pragma omp parallel for
for (unsigned int idx = 0; idx < arr.size(); idx++) {
auto &[k, w] = arr(idx);

//triqs::utility::timer t_copy_1, t_chi0_nn, t_bse, t_chi_tr, t_copy_2;

// ----------------------------------------------------
//t_copy_1.start();

chi_w_t chi0_n(fmesh, target_shape);

#pragma omp critical
chi0_n = chi0_wnk[w, _, k];

//t_copy_1.stop();
//std::cout << "BSE: copy_1 " << double(t_copy_1) << " s" << std::endl;
// ----------------------------------------------------
//t_chi0_nn.start();

chi_nn_t chi0_nn({fmesh, fmesh}, target_shape);
chi0_nn *= 0.;

for (auto const &n : fmesh) chi0_nn[n, n] = chi0_n[n];

//t_chi0_nn.stop();
//std::cout << "BSE: chi0_nn " << double(t_chi0_nn) << " s" << std::endl;
// ----------------------------------------------------
//t_bse.start();

auto I = identity<Channel_t::PH>(chi0_nn);

chi_nn_t gamma_nn({fmesh, fmesh}, target_shape);

#pragma omp critical
gamma_nn = gamma_ph_wnn[w, _, _];

// this step could be optimized, using the diagonality of chi0 and I
auto denom = chi_nn_t{I - product<Channel_t::PH>(chi0_nn, gamma_nn)};

// also the last product here
auto chi = chi_nn_t{product<Channel_t::PH>(inverse<Channel_t::PH>(denom), chi0_nn)};

//t_bse.stop();
//std::cout << "BSE: bse inv " << double(t_bse) << " s" << std::endl;
// ----------------------------------------------------
//t_chi_tr.start();

// trace out fermionic frequencies
array<std::complex<double>, 4> tr_chi(target_shape);
tr_chi = scalar_product_PH(L_wn[w, _], chi, L_wn[w, _]);

/*
tr_chi() = 0;

for (auto const &n1 : fmesh) {
auto Ll = L_wn[w, n1];
for (auto const &n2 : fmesh) {
auto Lr = L_wn[w, n2];
auto C = chi[n1, n2];
for (auto const &[a, b, c, d] : chi.target_indices()) {
for (auto const &[e, f, g, h] : chi.target_indices()) {
tr_chi(a,b,c,d) += Ll(e,f,b,a) * C(e,f,g,h) * Lr(h,g,c,d);
}
}
}
}

array<std::complex<double>, 4> tr_chi_ref(target_shape);
tr_chi_ref = scalar_product_PH(L_wn[w, _], chi, L_wn[w, _]);

for (auto const &[a, b, c, d] : chi.target_indices()) {
auto diff = std::abs( tr_chi(a,b,c,d) - tr_chi_ref(a,b,c,d) );
std::cout << a << ", " << b << ", " << c << ", " << d << " - " << diff << "\n";
if(diff > 1e-6) {
exit(0);
}
}
*/

//t_chi_tr.stop();
//std::cout << "BSE: chi tr " << double(t_chi_tr) << " s" << std::endl;
// ----------------------------------------------------
//t_copy_2.start();

#pragma omp critical
chi_kw[k, w] = tr_chi;

//t_copy_2.stop();
//std::cout << "BSE: copy_2 " << double(t_copy_2) << " s" << std::endl;
// ----------------------------------------------------

if(comm.rank() == 0 && omp_get_thread_num() == 0) {

int Nomp = omp_get_num_threads();
int N = int(floor(arr.size() / double(Nomp)));

//double t_left = double(t) * ( N / (idx + 1) - 1. );
int done_percent = (N == 0) ? 100 : int(floor(100 * double(idx + 1) / N));

std::cout << "BSE " << triqs::utility::timestamp() << " "
<< std::setfill(' ') << std::setw(3) << done_percent << "% "
<< "ETA " << triqs::utility::estimate_time_left(N, idx, t)
<< " job no "
<< std::setfill(' ') << std::setw(5) << int(idx)
<< " of approx " << N << " jobs/thread/rank." << std::endl;
}

}

chi_kw = mpi::all_reduce(chi_kw);

t.stop();
if(comm.rank() == 0 )
std::cout << "BSE TIME: " << double(t) << " s" << std::endl;

return chi_kw;
}

// ----------------------------------------------------

chi_kw_t chiq_sum_nu_from_chi0q_and_gamma_PH(chi_wnk_cvt chi0_wnk, chi_wnn_cvt gamma_ph_wnn) {

auto _ = all_t{};
Expand Down
9 changes: 9 additions & 0 deletions c++/triqs_tprf/lattice/chi_imfreq.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,15 @@ chi_kwnn_t chiq_from_chi0q_and_gamma_PH(chi_wnk_cvt chi0_wnk, chi_wnn_cvt gamma_
*/
chi_kw_t chiq_sum_nu_from_chi0q_and_gamma_PH(chi_wnk_cvt chi0_wnk, chi_wnn_cvt gamma_ph_wnn);

/** Dual lattice Bethe-Salpeter equation solver for the generalized susceptibility :math:`\chi^{(0)}_{\bar{a}b\bar{c}d}(\omega, \mathbf{k})`.

@param chi0_wnk Generalized lattice bubble susceptibility :math:`\chi^{(0)}_{\bar{a}b\bar{c}d}(\omega, \mathbf{k})`.
@param gamma_ph_wnn Local particle-hole vertex function :math:`\Gamma^{(PH)}_{\bar{a}b\bar{c}d}(\omega, \nu, \nu')`.
@param L_wn Local triangular particle-hole vertex function :math:`L^{(PH)}_{\bar{a}b\bar{c}d}(\omega, \nu)`.
@return Generalized lattice susceptibility :math:`\chi_{\bar{a}b\bar{c}d}(\omega, \mathbf{k})`.
*/
chi_kw_t chiq_sum_nu_from_chi0q_and_gamma_and_L_wn_PH(chi_wnk_cvt chi0_wnk, chi_wnn_cvt gamma_ph_wnn, chi_nn_cvt L_wn);

gf<prod<brzone, imfreq>, tensor_valued<4>>
chiq_sum_nu_from_g_wk_and_gamma_PH(gk_iw_t g_wk, g2_iw_vt gamma_ph_wnn, int tail_corr_nwf=-1);

Expand Down
4 changes: 0 additions & 4 deletions c++/triqs_tprf/lattice/chi_retime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ std::tuple<g_Tk_t, g_Tk_t> g0_Tk_les_gtr_from_e_k(e_k_cvt e_k, mesh::retime Tmes

chi_Tr_t chi0_Tr_from_g_Tr_PH(g_Tr_cvt g_Tr_les, g_Tr_cvt g_Tr_gtr) {

auto _ = all_t{};
auto I = std::complex(0.,1.);

auto Tmesh = std::get<0>(g_Tr_les.mesh());
Expand All @@ -104,9 +103,6 @@ chi_Tr_t chi0_Tr_from_g_Tr_PH(g_Tr_cvt g_Tr_les, g_Tr_cvt g_Tr_gtr) {

chi_Tr_t chi0_Tr{{Tmesh, rmesh}, {nb, nb, nb, nb}};

auto g_target = g_Tr_les.target();
auto chi_target = chi0_Tr.target();

//for (auto const &r : rmesh) {

auto arr = mpi_view(Tmesh);
Expand Down
52 changes: 50 additions & 2 deletions c++/triqs_tprf/lattice/dynamical_screened_interaction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
namespace triqs_tprf {

enum SusceptibilityType { bubble, generalized };

template <SusceptibilityType susType, typename chi_t, typename v_t> auto screened_interaction_from_generic_susceptibility(chi_t &chi, v_t &V) {

auto const &[freqmesh, kmesh] = chi.mesh();
Expand Down Expand Up @@ -82,10 +82,58 @@ namespace triqs_tprf {
return W;
}

chi_wk_t dynamical_screened_interaction_W(chi_wk_cvt chi_wk, chi_k_cvt V_k) {

auto const &[wmesh, kmesh] = chi_wk.mesh();
auto const &v_kmesh = V_k.mesh();

if (kmesh != v_kmesh) TRIQS_RUNTIME_ERROR << "dynamical_screened_interaction_W: k-space meshes are not the same\n";

auto W_wk = make_gf(chi_wk);
W_wk() = 0.;
size_t nb = chi_wk.target_shape()[0];

using scalar_t = typename chi_wk_cvt::scalar_t;
auto I = nda::eye<scalar_t>(nb * nb);

// MPI and openMP parallell loop
auto arr = mpi_view(W_wk.mesh());

#pragma omp parallel for
for (unsigned int idx = 0; idx < arr.size(); idx++) {
auto &[w, k] = arr(idx);

array<scalar_t, 4> denom{nb, nb, nb, nb};
array<scalar_t, 4> inv_denom{nb, nb, nb, nb};

auto denom_mat = make_matrix_view(group_indices_view(denom, idx_group<0, 1>, idx_group<3, 2>));
auto inv_denom_mat = make_matrix_view(group_indices_view(inv_denom, idx_group<0, 1>, idx_group<3, 2>));

denom_mat = I;

for (auto const &[a, b, c, d] : V_k.target_indices())
for( auto e : range(nb) )
for( auto f : range(nb) )
denom(a,b,c,d) -= chi_wk[w,k](a,b,e,f)*V_k[k](e,f,c,d);

inv_denom_mat = inverse(denom_mat);

for (auto const &[a, b, c, d] : V_k.target_indices())
for( auto e : range(nb) )
for( auto f : range(nb) )
W_wk[w, k](a,b,c,d) += V_k[k](a,b,e,f) * inv_denom(e,f,c,d);
}

W_wk = mpi::all_reduce(W_wk);
return W_wk;
}

/*
chi_wk_t dynamical_screened_interaction_W(chi_wk_cvt PI_wk, chi_k_cvt V_k) {
return screened_interaction_from_generic_susceptibility<bubble>(PI_wk, V_k);
}

*/

chi_fk_t dynamical_screened_interaction_W(chi_fk_cvt PI_fk, chi_k_cvt V_k) {
return screened_interaction_from_generic_susceptibility<bubble>(PI_fk, V_k);
}
Expand Down
Loading