Coverage for gpaw/test/corehole/test_xas_parallel.py: 25%
81 statements
« prev ^ index » next coverage.py v7.7.1, created at 2025-07-19 00:19 +0000
« prev ^ index » next coverage.py v7.7.1, created at 2025-07-19 00:19 +0000
1import pytest
3from gpaw import GPAW
4from gpaw.xas import XAS
5import gpaw.mpi as mpi
8dks = 20
11@pytest.fixture
12def xas_sym_nosp(
13 in_tmp_dir, add_cwd_to_setup_paths, gpw_files):
14 comm = mpi.world.new_communicator([mpi.world.rank])
15 calc1 = GPAW(gpw_files['si_corehole_sym_pw'], communicator=comm)
16 xas1 = XAS(calc1)
17 x1, y1 = xas1.get_oscillator_strength(dks=dks)
18 return x1, y1
21@pytest.mark.skipif(mpi.size % 4 != 0,
22 reason='works only for multiples of 4 cores')
23def test_xas_paralell_kpts_and_domian(
24 in_tmp_dir, add_cwd_to_setup_paths, gpw_files, xas_sym_nosp):
26 parallel = {'kpt': 2,
27 'band': 1}
28 calc2 = GPAW(gpw_files['si_corehole_sym_pw'], parallel=parallel)
29 xas2 = XAS(calc2)
30 x2, y2 = xas2.get_oscillator_strength(dks=dks)
32 x1, y1 = xas_sym_nosp
34 assert x2 == pytest.approx(x1)
35 assert y2 == pytest.approx(y1)
38@pytest.mark.skipif(mpi.size % 2 != 0,
39 reason='works only for multiples of 2 cores')
40def test_xas_paralell_multiple_kpt_pr_rank(
41 in_tmp_dir, add_cwd_to_setup_paths, gpw_files):
43 comm = mpi.world.new_communicator([mpi.world.rank])
45 parallel = {'kpt': 2}
46 calc2 = GPAW(gpw_files['si_corehole_nosym_pw'],
47 parallel=parallel)
49 xas2 = XAS(calc2)
50 x2, y2 = xas2.get_oscillator_strength(dks=dks)
52 calc1 = GPAW(gpw_files['si_corehole_nosym_pw'],
53 communicator=comm)
54 xas1 = XAS(calc1)
56 x1, y1 = xas1.get_oscillator_strength(dks=dks)
58 assert x2 == pytest.approx(x1)
59 assert y2 == pytest.approx(y1)
62@pytest.mark.skipif(mpi.size % 4 != 0,
63 reason='works only for multiples of 4 cores')
64def test_xas_band_and_kpts_parallel(
65 in_tmp_dir, add_cwd_to_setup_paths, gpw_files, xas_sym_nosp):
67 parallel = {'band': 2,
68 'kpt': 2}
69 calc2 = GPAW(gpw_files['si_corehole_sym_pw'],
70 parallel=parallel)
71 xas2 = XAS(calc2)
72 x2, y2 = xas2.get_oscillator_strength(dks=dks)
74 x1, y1 = xas_sym_nosp
76 assert x2 == pytest.approx(x1)
77 assert y2 == pytest.approx(y1)
80@pytest.mark.skipif(mpi.size % 4 != 0,
81 reason='works only for multiples of 4 cores')
82@pytest.mark.old_gpaw_only
83def test_xas_kpts_domian_parallel_spinpol(
84 in_tmp_dir, add_cwd_to_setup_paths, gpw_files):
86 parallel = {'kpt': 2,
87 'band': 1}
89 calc2 = GPAW(gpw_files['si_corehole_sym_pw'],
90 spinpol=True, parallel=parallel)
91 calc2.get_potential_energy()
92 xas2 = XAS(calc2, spin=0)
94 x2, y2 = xas2.get_oscillator_strength(dks=dks)
96 comm = mpi.world.new_communicator([mpi.world.rank])
98 calc1 = GPAW(gpw_files['si_corehole_sym_pw'],
99 communicator=comm, spinpol=True)
101 calc1.get_potential_energy()
103 xas1 = XAS(calc1, spin=0)
104 x1, y1 = xas1.get_oscillator_strength(dks=dks)
106 assert x2 == pytest.approx(x1, 1.1e-1)
107 assert y2 == pytest.approx(y1, abs=1.3e-5)
110@pytest.mark.skipif(mpi.size % 4 != 0,
111 reason='works only for multiples of 4 cores')
112def test_xes_kpts_and_domain_parallel(
113 in_tmp_dir, add_cwd_to_setup_paths, gpw_files):
115 parallel = {'kpt': 2,
116 'band': 1}
118 calc2 = GPAW(gpw_files['si_corehole_sym_pw'],
119 parallel=parallel)
121 xes2 = XAS(calc2, 'xes')
122 x2, y2 = xes2.get_oscillator_strength(dks=dks)
124 comm = mpi.world.new_communicator([mpi.world.rank])
126 calc1 = GPAW(gpw_files['si_corehole_sym_pw'],
127 communicator=comm)
129 xes1 = XAS(calc1, 'xes')
131 x1, y1 = xes1.get_oscillator_strength(dks=dks)
133 assert x2 == pytest.approx(x1)
134 assert y2 == pytest.approx(y1)
137@pytest.mark.skipif(mpi.size % 8 != 0,
138 reason='works only for multiples of 8 cores')
139def test_all_band_and_kpts_parallel(
140 in_tmp_dir, add_cwd_to_setup_paths, gpw_files):
142 parallel = {'band': 4,
143 'kpt': 2}
145 calc2 = GPAW(gpw_files['si_corehole_sym_pw'],
146 parallel=parallel)
148 xas2 = XAS(calc2, 'all')
149 x2, y2 = xas2.get_oscillator_strength(dks=dks)
151 comm = mpi.world.new_communicator([mpi.world.rank])
153 calc1 = GPAW(gpw_files['si_corehole_sym_pw'],
154 communicator=comm)
156 xas1 = XAS(calc1, 'all')
158 x1, y1 = xas1.get_oscillator_strength(dks=dks)
160 assert x2 == pytest.approx(x1)
161 assert y2 == pytest.approx(y1)