Skip to content
Snippets Groups Projects

Feat/dss cimprove master rebasing

Closed Andrey Samartsev requested to merge feat/DSSCimproveMasterRebasing into feat/DSSCdarksImprove
1 file
+ 1
1
Compare changes
  • Side-by-side
  • Inline
+ 57
11
from datetime import datetime
from glob import glob
from importlib.machinery import SourceFileLoader
from os import chdir, listdir, makedirs, path, remove, stat
@@ -122,21 +123,23 @@ def prepare_plots(run_path, threshold=1000000):
shell=False)
def make_timing_summary(run_path, joblist):
def make_timing_summary(run_path, joblist, request_time, submission_time):
"""
Create an rst file with timing summary of executed slurm jobs
Create an rst file with timing summary of executed notebooks
:param run_path: Run path of the slurm job
:param joblist: List of slurm jobs
:param request_time: Timestamp of notebook request
:param submission_time: Timestamp for slurm jobs being submitted
"""
print('Prepare timing summary')
run_path = path.abspath(run_path)
pars_vals = []
pars = 'JobID,Elapsed,Suspended'
pars = 'JobID,Start,End,Elapsed,Suspended,State'
pars_name = pars.split(',')
for job in joblist:
out = check_output(['sacct', '-j', job,
out = check_output(['sacct', '-T', '-j', job,
'--format={}'.format(pars)],
shell=False)
lines = str(out).split('\\n')
@@ -153,17 +156,34 @@ def make_timing_summary(run_path, joblist):
==============
.. math::
{% for line in table %}
{% for line in time_table %}
{{ line }}
{%- endfor %}
.. math::
{% for line in job_table %}
{{ line }}
{%- endfor %}
''')
time_vals = [['Time of Request', request_time],
['Job submission', submission_time],
['Report compilation',
datetime.now().strftime('%Y-%m-%dT%H:%M:%S')]]
with open("{}/timing_summary.rst".format(run_path), "w+") as gfile:
if len(pars_vals) > 0:
table = tabulate.tabulate(pars_vals, tablefmt='latex',
job_table = tabulate.tabulate(pars_vals, tablefmt='latex',
headers=pars_name)
gfile.write(dedent(tmpl.render(table=table.split('\n'))))
time_table = tabulate.tabulate(time_vals, tablefmt='latex',
headers=['Processing step',
'Timestamp'])
gfile.write(dedent(tmpl.render(job_table=job_table.split('\n'),
time_table=time_table.split('\n'))))
def make_report(run_path, tmp_path, out_path, project, author, version,
@@ -240,6 +260,18 @@ def make_report(run_path, tmp_path, out_path, project, author, version,
move("{}/conf.py.tmp".format(run_path), "{}/conf.py".format(run_path))
direntries = listdir(run_path)
lead_rstfiles = ['InputParameters.rst', 'timing_summary.rst']
# Order rst files based on the known order(lead_rstfiles).
for f in direntries:
if f in lead_rstfiles:
direntries.insert(lead_rstfiles.index(f),
direntries.pop(direntries.index(f)))
# Move summary to the top, if it is exists,
# after the known leading rst files.
if "summary" in f.lower() and f not in lead_rstfiles:
direntries.insert(len(lead_rstfiles),
direntries.pop(direntries.index(f)))
files_to_handle = []
for entry in direntries:
if isfile("{}/{}".format(run_path, entry)):
@@ -272,9 +304,21 @@ def make_report(run_path, tmp_path, out_path, project, author, version,
"can be inspected at: {}".format(run_path))
return
print("Moving report to final location: {}".format(out_path))
makedirs(out_path, exist_ok=True)
copy('{}/_build/latex/{}.pdf'.format(run_path, report_name), out_path)
print("Removing temporary files at: {}".format(tmp_path))
rmtree(tmp_path)
temp_dirs = glob(f'{tmp_path}/*/')
# Remove folders with figures and sphinx files.
print(f"Removing directories [{temp_dirs}] in temp folder: {tmp_path}")
for dtmp in temp_dirs:
rmtree(f'{dtmp}/')
# Moving temporary files to out-folder after successful execution
# This helps in keeping elements needed for re-producibility.
print(f"Moving temporary files to final location"
f": {out_path}/{os.path.basename(tmp_path)} with name: "
f"slurm_out_{report_name}")
move(tmp_path, f"{out_path}/slurm_out_{report_name}")
def make_titlepage(sphinx_path, project, data_path, version):
@@ -324,7 +368,8 @@ def tex_escape(text):
def finalize(joblist, finaljob, run_path, out_path, project, calibration,
author, version, report_to, data_path='Unknown'):
author, version, report_to, data_path='Unknown',
request_time='', submission_time=''):
print("Waiting on jobs to finish: {}".format(joblist))
while True:
found_jobs = set()
@@ -338,7 +383,8 @@ def finalize(joblist, finaljob, run_path, out_path, project, calibration,
sleep(10)
prepare_plots(run_path)
make_timing_summary(run_path, joblist + [str(finaljob)])
make_timing_summary(run_path, joblist + [str(finaljob)], request_time,
submission_time)
sphinx_path = combine_report(run_path, calibration)
make_titlepage(sphinx_path, project, data_path, version)
make_report(sphinx_path, run_path, out_path, project, author, version,
Loading