Skip to content

Commit 9823530

Browse files
committed
feature: Add functions to extract timing
feature: Add functions to extract timing from OUTCARS. This includes _find_outcars, a helper function that finds all OUTCARS present in the calculation/job's folder; compTime, which sums up the time over all the OUTCARS; fftTime, which sums FFT process times (VASP must be compiled with -DPROFILING); and fftFrac, which divides the time spent on FFT by the total time.
1 parent f8d311a commit 9823530

File tree

1 file changed

+112
-0
lines changed

1 file changed

+112
-0
lines changed

src/pylada/vasp/extract/base.py

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1842,6 +1842,118 @@ def pbsscript(self):
18421842
slurm_dict[setting[0]] = setting[1]
18431843

18441844
return slurm_dict
1845+
1846+
1847+
def _find_outcars(self):
1848+
""" Builds list of OUTCARS from relaxation. """
1849+
import os
1850+
1851+
relax_dir = self.directory
1852+
outcars=[]
1853+
for root, dirs, files in os.walk(relax_dir):
1854+
for name in files:
1855+
filepath=os.path.join(root, name)
1856+
if filepath.split('/')[-1]=='OUTCAR':
1857+
outcars.append(filepath)
1858+
return outcars
1859+
1860+
@property
1861+
@make_cached
1862+
def compTime(self):
1863+
""" Sum of times listed at end of OUTCARs for all restarts,
1864+
converted to hours. USE CAUTION, as OUTCARS that have
1865+
been overwritten due to restarts are not counted as of
1866+
Jul 22 2024.
1867+
"""
1868+
from quantities import hour
1869+
from numpy import array
1870+
1871+
outcars = self._find_outcars()
1872+
#Summing over all OUTCARs
1873+
dir_hrs=0
1874+
for path in outcars:
1875+
a_file = open(path,'r')
1876+
hrs=0
1877+
# found_time = False
1878+
if 'profiling' in self.functional.program:
1879+
# 68 is minimum, extra added in case of \
1880+
# accidental newlines at end
1881+
lines=a_file.readlines()[-73:]
1882+
for line in lines:
1883+
if 'total_time' in line:
1884+
split_line=line.split()
1885+
if len(split_line) == 3:
1886+
hrs=float(split_line[-2])/3600
1887+
elif len(split_line) == 5:
1888+
hrs=float(split_line[-3])/3600
1889+
# found_time = True
1890+
break
1891+
else:
1892+
# 8 is minimum, extra added in case of \
1893+
# accidental newlines at end
1894+
lines=a_file.readlines()[-13:]
1895+
for line in lines:
1896+
if 'Elapsed time' in line:
1897+
hrs=float(line.split()[-1])/3600
1898+
# found_time = True
1899+
break
1900+
a_file.close()
1901+
# if not found_time:
1902+
# err_path = path[:-6] + 'stderr'
1903+
# err_file = open(err_path,'r')
1904+
# err_lines = err_file.readlines()
1905+
# for line in err_lines:
1906+
# if 'DUE TO TIME LIMIT' in line:
1907+
# wall_time = self.pbsscript['--time']
1908+
# wall_time = wall_time.split(':')
1909+
# i = 0
1910+
# wall_time.reverse()
1911+
# for time in wall_time:
1912+
# time = float(time)
1913+
# hrs+= time * (60**i) / 3600
1914+
# i+=1
1915+
# err_file.close()
1916+
dir_hrs+=hrs
1917+
return array(round(dir_hrs, 4)) * hour
1918+
1919+
@property
1920+
@make_cached
1921+
def fftTime(self):
1922+
""" Sum of fft process times listed at end of OUTCARs
1923+
for all restarts, converted to hours.
1924+
WARNING: VASP must be compiled with -DPROFILING
1925+
for this to work, and 'profiling' must be in the
1926+
absolute path of the executable.
1927+
"""
1928+
from quantities import hour
1929+
from numpy import array
1930+
1931+
outcars = self._find_outcars()
1932+
#Summing over all OUTCARs
1933+
dir_hrs=0
1934+
for path in outcars:
1935+
a_file = open(path,'r')
1936+
hrs=0
1937+
if 'profiling' in self.functional.program:
1938+
# 66 is minimum, extra added in case of \
1939+
# accidental newlines at end
1940+
lines=a_file.readlines()[-71:]
1941+
for line in lines:
1942+
if 'fft' in line:
1943+
split_line=line.split()
1944+
hrs+=float(split_line[-2])/3600
1945+
a_file.close()
1946+
dir_hrs+=hrs
1947+
return array(round(dir_hrs, 4)) * hour
1948+
1949+
@property
1950+
@make_cached
1951+
def fftFrac(self):
1952+
""" WARNING: VASP must be compiled with -DPROFILING
1953+
for this to work, and 'profiling' must be in the
1954+
absolute path of the executable.
1955+
"""
1956+
return round(self.fftTime / self.compTime, 4)
18451957
def __dir__(self):
18461958
""" Attributes and members of this class.
18471959

0 commit comments

Comments
 (0)