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

1import pytest 

2 

3from gpaw import GPAW 

4from gpaw.xas import XAS 

5import gpaw.mpi as mpi 

6 

7 

8dks = 20 

9 

10 

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 

19 

20 

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): 

25 

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) 

31 

32 x1, y1 = xas_sym_nosp 

33 

34 assert x2 == pytest.approx(x1) 

35 assert y2 == pytest.approx(y1) 

36 

37 

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): 

42 

43 comm = mpi.world.new_communicator([mpi.world.rank]) 

44 

45 parallel = {'kpt': 2} 

46 calc2 = GPAW(gpw_files['si_corehole_nosym_pw'], 

47 parallel=parallel) 

48 

49 xas2 = XAS(calc2) 

50 x2, y2 = xas2.get_oscillator_strength(dks=dks) 

51 

52 calc1 = GPAW(gpw_files['si_corehole_nosym_pw'], 

53 communicator=comm) 

54 xas1 = XAS(calc1) 

55 

56 x1, y1 = xas1.get_oscillator_strength(dks=dks) 

57 

58 assert x2 == pytest.approx(x1) 

59 assert y2 == pytest.approx(y1) 

60 

61 

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): 

66 

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) 

73 

74 x1, y1 = xas_sym_nosp 

75 

76 assert x2 == pytest.approx(x1) 

77 assert y2 == pytest.approx(y1) 

78 

79 

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): 

85 

86 parallel = {'kpt': 2, 

87 'band': 1} 

88 

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) 

93 

94 x2, y2 = xas2.get_oscillator_strength(dks=dks) 

95 

96 comm = mpi.world.new_communicator([mpi.world.rank]) 

97 

98 calc1 = GPAW(gpw_files['si_corehole_sym_pw'], 

99 communicator=comm, spinpol=True) 

100 

101 calc1.get_potential_energy() 

102 

103 xas1 = XAS(calc1, spin=0) 

104 x1, y1 = xas1.get_oscillator_strength(dks=dks) 

105 

106 assert x2 == pytest.approx(x1, 1.1e-1) 

107 assert y2 == pytest.approx(y1, abs=1.3e-5) 

108 

109 

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): 

114 

115 parallel = {'kpt': 2, 

116 'band': 1} 

117 

118 calc2 = GPAW(gpw_files['si_corehole_sym_pw'], 

119 parallel=parallel) 

120 

121 xes2 = XAS(calc2, 'xes') 

122 x2, y2 = xes2.get_oscillator_strength(dks=dks) 

123 

124 comm = mpi.world.new_communicator([mpi.world.rank]) 

125 

126 calc1 = GPAW(gpw_files['si_corehole_sym_pw'], 

127 communicator=comm) 

128 

129 xes1 = XAS(calc1, 'xes') 

130 

131 x1, y1 = xes1.get_oscillator_strength(dks=dks) 

132 

133 assert x2 == pytest.approx(x1) 

134 assert y2 == pytest.approx(y1) 

135 

136 

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): 

141 

142 parallel = {'band': 4, 

143 'kpt': 2} 

144 

145 calc2 = GPAW(gpw_files['si_corehole_sym_pw'], 

146 parallel=parallel) 

147 

148 xas2 = XAS(calc2, 'all') 

149 x2, y2 = xas2.get_oscillator_strength(dks=dks) 

150 

151 comm = mpi.world.new_communicator([mpi.world.rank]) 

152 

153 calc1 = GPAW(gpw_files['si_corehole_sym_pw'], 

154 communicator=comm) 

155 

156 xas1 = XAS(calc1, 'all') 

157 

158 x1, y1 = xas1.get_oscillator_strength(dks=dks) 

159 

160 assert x2 == pytest.approx(x1) 

161 assert y2 == pytest.approx(y1)