From f312e1f59064b375d884d2968c200c17bbe8794b Mon Sep 17 00:00:00 2001 From: Philipp Schmidt <philipp.schmidt@xfel.eu> Date: Mon, 18 Oct 2021 16:21:19 +0200 Subject: [PATCH] Add xfel-calibrate option to skip report generation --- bin/slurm_finalize.sh | 11 +++++++---- src/xfel_calibrate/calibrate.py | 11 +++++++++-- src/xfel_calibrate/finalize.py | 30 ++++++++++++++++++------------ 3 files changed, 34 insertions(+), 18 deletions(-) diff --git a/bin/slurm_finalize.sh b/bin/slurm_finalize.sh index 9eaf9a735..461d7cdd1 100755 --- a/bin/slurm_finalize.sh +++ b/bin/slurm_finalize.sh @@ -6,6 +6,7 @@ set -euo pipefail python_path=$1 temp_dir=$2 finalize_script=$3 +report_to=$4 echo "Running with the following parameters:" echo "Python path: $python_path" @@ -23,9 +24,11 @@ export MPLBACKEND=AGG # Ensure Python uses UTF-8 for files by default export LANG=en_US.UTF-8 -shopt -s failglob # Fail fast if there are no notebooks found -echo "Converting notebooks" -${python_path} -m nbconvert --to rst --TemplateExporter.exclude_input=True "$temp_dir"/*.ipynb -shopt -u failglob # Restore default glob behaviour +if [ -n "$report_to" ]; then + shopt -s failglob # Fail fast if there are no notebooks found + echo "Converting notebooks" + ${python_path} -m nbconvert --to rst --TemplateExporter.exclude_input=True "$temp_dir"/*.ipynb + shopt -u failglob # Restore default glob behaviour +fi ${python_path} "$finalize_script" diff --git a/src/xfel_calibrate/calibrate.py b/src/xfel_calibrate/calibrate.py index e83c60a41..e0ec92e71 100755 --- a/src/xfel_calibrate/calibrate.py +++ b/src/xfel_calibrate/calibrate.py @@ -83,6 +83,9 @@ def make_initial_parser(**kwargs): help='Filename (and optionally path) for output' ' report') + parser.add_argument('--skip-report', action='store_true', + help='Skip report generation in finalize step.') + parser.add_argument('--concurrency-par', type=str, help='Name of concurrency parameter.' 'If not given, it is taken from configuration.') @@ -642,6 +645,7 @@ def run_finalize(fmt_args, temp_path, job_list, sequential=False): sys.executable, # Python with calibration machinery installed temp_path, finalize_script, + fmt_args['report_to'] ] output = check_output(cmd, input=b'').decode('utf8') @@ -1057,7 +1061,9 @@ def run(): out_path.mkdir(parents=True, exist_ok=True) # Use given report name, falling back to notebook title - if args["report_to"] is None: + if args['skip_report']: + report_to = '' + elif args["report_to"] is None: report_to = out_path / title.replace(" ", "") print(f"report_to not specified, will use {report_to}") else: @@ -1086,7 +1092,8 @@ def run(): parm_subdict[name] = p.value metadata["pycalibration-version"] = version - metadata["report-path"] = f"{report_to}.pdf" + metadata["report-path"] = f"{report_to}.pdf" if report_to \ + else '# REPORT SKIPPED #' metadata["concurrency"] = { 'parameter': concurrency_par, 'default': concurrency_defval, diff --git a/src/xfel_calibrate/finalize.py b/src/xfel_calibrate/finalize.py index 368306301..0c3ef4cdc 100644 --- a/src/xfel_calibrate/finalize.py +++ b/src/xfel_calibrate/finalize.py @@ -397,8 +397,6 @@ def finalize(joblist, finaljob, run_path, out_path, version, report_to, data_pat request_time='', submission_time=''): run_path = Path(run_path) - prepare_plots(run_path) - # Archiving files in slurm_tmp if finaljob: joblist.append(str(finaljob)) @@ -427,13 +425,21 @@ def finalize(joblist, finaljob, run_path, out_path, version, report_to, data_pat metadata.save() metadata.save_copy(run_path) - sphinx_path = combine_report(run_path, title) - make_titlepage(sphinx_path, title, data_path, version) - make_report( - Path(sphinx_path), - run_path, - title, - author, - version, - Path(report_to), - ) + if report_to: + prepare_plots(run_path) + + sphinx_path = combine_report(run_path, title) + make_titlepage(sphinx_path, title, data_path, version) + make_report( + Path(sphinx_path), + run_path, + title, + author, + version, + Path(report_to), + ) + else: + # If there is no report location, simply copy the slurm_out_ + # directory to the output. + slurm_archive_dir = Path(out_path) / f"slurm_out_{run_path.name}" + move(str(run_path), str(slurm_archive_dir)) -- GitLab