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 test_preprocess_gamma_for_fft_types(gamma): gamma_dyn_tr, gamma_const_r = preprocess_gamma_for_fft(gamma) assert type(gamma_dyn_tr.mesh) == MeshProduct assert type(gamma_dyn_tr.mesh[0]) == MeshImTime assert type(gamma_dyn_tr.mesh[1]) == MeshCycLat assert type(gamma_const_r.mesh) == MeshCycLat
def save_new_preprocess_gamma_for_fft_benchmark(filename, p): eliashberg_ingredients = create_eliashberg_ingredients(p) gamma = eliashberg_ingredients.gamma gamma_dyn_tr, gamma_const_r = preprocess_gamma_for_fft(gamma) p.gamma = gamma p.gamma_dyn_tr = gamma_dyn_tr p.gamma_const_r = gamma_const_r write_TarGZ_HDFArchive(filename, p=p)
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_preprocess_gamma_for_fft_benchmark(gamma, p): p_benchmark = read_TarGZ_HDFArchive(p.benchmark_filename)['p'] model_parameters_to_test = ['dim', 'norb', 't', 'mu', 'beta', 'U'] assert_parameter_collection_not_equal_model_parameters( p, p_benchmark, model_parameters_to_test) np.testing.assert_allclose(gamma.data, p_benchmark.gamma.data, atol=1e-10) gamma_dyn_tr, gamma_const_r = preprocess_gamma_for_fft(gamma) np.testing.assert_allclose(gamma_dyn_tr.data, p_benchmark.gamma_dyn_tr.data, atol=1e-10) np.testing.assert_allclose(gamma_const_r.data, p_benchmark.gamma_const_r.data, atol=1e-10)
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.' )