Coverage for gpaw/test/response/test_gw_restart_file.py: 100%

24 statements  

« prev     ^ index     » next       coverage.py v7.7.1, created at 2025-07-08 00:17 +0000

1import pytest 

2import numpy as np 

3from gpaw.response.g0w0 import G0W0 

4from gpaw.mpi import world 

5 

6 

7class FragileG0W0(G0W0): 

8 def calculate_q(self, *args, **kwargs): 

9 if not hasattr(self, 'doom'): 

10 self.doom = 0 

11 self.doom += 1 # Advance doom 

12 if self.doom == 12: 

13 raise ValueError('Cthulhu awakens') 

14 G0W0.calculate_q(self, *args, **kwargs) 

15 

16 

17@pytest.mark.response 

18def test_restart_file(in_tmp_dir, gpw_files): 

19 kwargs = dict(bands=(3, 5), 

20 nbands=9, 

21 nblocks=world.size, 

22 ecut=40, 

23 kpts=[0, 1]) 

24 gw = FragileG0W0(gpw_files['bn_pw'], **kwargs) 

25 with pytest.raises(ValueError, match='Cthulhu*'): 

26 gw.calculate() 

27 

28 assert gw.doom == 12 

29 

30 # Use FragileG0W0 also in the restart. 

31 # The FragileG0W0 cannot by itself calculate the full thing because 

32 # calculate_q is called 16 times in total. Thus, it must be that 

33 # it was helped by the previous calculation. 

34 gw = FragileG0W0(gpw_files['bn_pw'], **kwargs) 

35 results = gw.calculate() 

36 

37 gw = G0W0(gpw_files['bn_pw'], filename='referencecalc', **kwargs) 

38 results2 = gw.calculate() 

39 

40 assert np.allclose(results['qp'], results2['qp'])