def test_next_delta(g0_wk, gamma, expected_next_delta): Gamma_pp_dyn_tr, Gamma_pp_const_r = preprocess_gamma_for_fft(gamma) next_delta = eliashberg_product_fft(Gamma_pp_dyn_tr, Gamma_pp_const_r, g0_wk, g0_wk) np.testing.assert_allclose(next_delta.data, expected_next_delta.data, atol=10e-12)
def save_new_benchmarks(filename, p): eliashberg_ingredients = create_eliashberg_ingredients(p) g0_wk = eliashberg_ingredients.g0_wk gamma = eliashberg_ingredients.gamma Gamma_pp_dyn_tr, Gamma_pp_const_r = preprocess_gamma_for_fft(gamma) next_delta = eliashberg_product_fft(Gamma_pp_dyn_tr, Gamma_pp_const_r, g0_wk, g0_wk) Es, eigen_modes = solve_eliashberg(gamma, g0_wk, product='FFT', solver='IRAM') p.next_delta = next_delta p.E = Es[0] p.eigen_mode = eigen_modes[0] write_TarGZ_HDFArchive(filename, p=p)
def test_eliashberg_product_for_same_initital_delta(g0_wk, gamma, gamma_big): initial_delta = semi_random_initial_delta(g0_wk, seed=1337) 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) diff = compare_deltas([next_delta_summation, next_delta_fft]) print_diff(diff) np.testing.assert_allclose(diff, 0, atol=p.atol) print('The summation and FFT implementation of the eliashberg product' ' both yield the same result.')
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_eliashberg_product_fft_constant(g0_wk, gamma): gamma.data[:] = np.random.rand(*gamma.data.shape[1:]) gamma_dyn_tr, gamma_const_r = preprocess_gamma_for_fft(gamma) initial_delta = semi_random_initial_delta(g0_wk) delta_1 = eliashberg_product_fft_constant(gamma_const_r, g0_wk, initial_delta) delta_2 = eliashberg_product_fft(gamma_dyn_tr, gamma_const_r, g0_wk, initial_delta) np.testing.assert_allclose(delta_1.data, delta_2.data) print( 'The functions eliashberg_product_fft and eliashberg_product_fft_constant' ' yield the same result for a Gamma that is only constant in momentum space.' '\nThe function split_into_dynamic_wk_and_constant_k therefore also worked correcty.' )
def test_eliashberg_product_for_different_initital_delta( g0_wk, gamma, gamma_big): initial_delta = semi_random_initial_delta(g0_wk, seed=1337) next_delta_summation = eliashberg_product(gamma_big, g0_wk, initial_delta) gamma_dyn_tr, gamma_const_r = preprocess_gamma_for_fft(gamma) initial_delta = semi_random_initial_delta(g0_wk, seed=1338) next_delta_fft = eliashberg_product_fft(gamma_dyn_tr, gamma_const_r, g0_wk, initial_delta) diff = compare_deltas([next_delta_summation, next_delta_fft]) print_diff(diff) try: np.testing.assert_allclose(diff, 0, atol=p.atol) raise ValueError except AssertionError: print( 'The summation and FFT implementation of the eliashberg product' ' both yield DIFFERENT results, as expected when using a different inital delta.' )
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 gamma_dyn_wk, gamma_const_k = split_into_dynamic_wk_and_constant_k(gamma_big) gamma_dyn_tr, gamma_const_r = dynamic_and_constant_to_tr(gamma_dyn_wk, gamma_const_k) # -- Test the Eliashberg equation next_delta = eliashberg_product(gamma_big, g0_wk, g0_wk) next_delta_fft = eliashberg_product_fft(gamma_dyn_tr, gamma_const_r, g0_wk, g0_wk) np.testing.assert_allclose(next_delta.data, next_delta_fft.data, atol=1e-7) Es, eigen_modes = solve_eliashberg(gamma_big, g0_wk) Es_fft, eigen_modes_fft = solve_eliashberg_fft(gamma_big, g0_wk) E = Es[0] eigen_mode = eigen_modes[0] E_fft = Es_fft[0] eigen_mode_fft = eigen_modes_fft[0] np.testing.assert_allclose(E, E_fft, atol=1e-7) try: np.testing.assert_allclose(eigen_mode.data, eigen_mode_fft.data, atol=1e-7)