From 9b8a307f082d44b90b172709fd1772d95a2689cf Mon Sep 17 00:00:00 2001 From: Jelle Teijema Date: Mon, 17 Apr 2023 19:15:29 +0200 Subject: [PATCH] Fix bug with seed values in basic template and some minor other improvements (#17) --- asreviewcontrib/makita/entrypoint.py | 4 +- asreviewcontrib/makita/template_arfi.py | 40 +++++++++++-------- .../templates/template_basic.txt.template | 2 +- 3 files changed, 26 insertions(+), 20 deletions(-) diff --git a/asreviewcontrib/makita/entrypoint.py b/asreviewcontrib/makita/entrypoint.py index 0ce90d3..90fd059 100644 --- a/asreviewcontrib/makita/entrypoint.py +++ b/asreviewcontrib/makita/entrypoint.py @@ -25,8 +25,8 @@ def is_valid_template(fp): def _valid_job_file(param): ext = Path(param).suffix - if ext.lower() not in ('.sh', '.bat'): - raise argparse.ArgumentTypeError('File must have a .sh or .bat extension') + if ext.lower() not in ('.sh', '.bat', '.yaml'): + raise argparse.ArgumentTypeError('File must have a .sh, .bat, .yaml extension') return param diff --git a/asreviewcontrib/makita/template_arfi.py b/asreviewcontrib/makita/template_arfi.py index f7529e6..4053ad3 100644 --- a/asreviewcontrib/makita/template_arfi.py +++ b/asreviewcontrib/makita/template_arfi.py @@ -55,7 +55,10 @@ def render_jobs_arfi( check_filename_dataset(fp_dataset) # render priors - priors = get_priors(fp_dataset, init_seed=init_seed + i, n_priors=n_priors) + priors = get_priors(fp_dataset, + init_seed=init_seed + i, + n_priors=n_priors + ) # params for single dataset params.append( @@ -70,22 +73,25 @@ def render_jobs_arfi( # open template TODO@{Replace by more sustainable module} template = ConfigTemplate(fp_template) - for s in template.scripts: - t_script = get_file(s, "script") - export_fp = Path(scripts_folder, s) - add_file(t_script, export_fp) - - for s in template.docs: - t_docs = get_file(s, - "doc", - datasets=datasets, - template_name=template.name if template.name == "ARFI" else "custom", # NOQA - template_name_long=template.name_long, - template_scripts=template.scripts, - output_folder=output_folder, - job_file=job_file, - ) - add_file(t_docs, s) + # check if template.script is not NoneType + if template.scripts is not None: + for s in template.scripts: + t_script = get_file(s, "script") + export_fp = Path(scripts_folder, s) + add_file(t_script, export_fp) + + if template.docs is not None: + for s in template.docs: + t_docs = get_file(s, + "doc", + datasets=datasets, + template_name=template.name if template.name == "ARFI" else "custom", # NOQA + template_name_long=template.name_long, + template_scripts=template.scripts, + output_folder=output_folder, + job_file=job_file, + ) + add_file(t_docs, s) return template.render( { diff --git a/asreviewcontrib/makita/templates/template_basic.txt.template b/asreviewcontrib/makita/templates/template_basic.txt.template index 2906b18..bf00c98 100644 --- a/asreviewcontrib/makita/templates/template_basic.txt.template +++ b/asreviewcontrib/makita/templates/template_basic.txt.template @@ -42,7 +42,7 @@ asreview wordcloud {{ dataset.input_file }} -o {{ output_folder }}/simulation/{{ # Simulate runs mkdir {{ output_folder }}/simulation/{{ dataset.input_file_stem }}/state_files {% for run in range(dataset.n_runs) %} -asreview simulate {{ dataset.input_file }} -s {{ output_folder }}/simulation/{{ dataset.input_file_stem }}/state_files/sim_{{ dataset.input_file_stem }}_{{ run }}.asreview --init_seed {{ dataset.init_seed }} --seed {{ dataset.model_seed }} +asreview simulate {{ dataset.input_file }} -s {{ output_folder }}/simulation/{{ dataset.input_file_stem }}/state_files/sim_{{ dataset.input_file_stem }}_{{ run }}.asreview --init_seed {{ dataset.init_seed + run}} --seed {{ dataset.model_seed + run}} asreview metrics {{ output_folder }}/simulation/{{ dataset.input_file_stem }}/state_files/sim_{{ dataset.input_file_stem }}_{{ run }}.asreview -o {{ output_folder }}/simulation/{{ dataset.input_file_stem }}/metrics/metrics_sim_{{ dataset.input_file_stem }}_{{ run }}.json {% endfor %}