From 8c394ad833f5ad012ff52d67f21517a6e7d39a5a Mon Sep 17 00:00:00 2001 From: juacrumar Date: Thu, 14 Mar 2024 16:48:21 +0100 Subject: [PATCH] add the possibility to transparently pass through command line options to the runner --- src/pinefarm/cli/run.py | 17 +++++++++++------ src/pinefarm/external/interface.py | 2 +- .../external/nnlojet/nnpdf_interface.py | 6 +++--- src/pinefarm/external/nnlojet/runcardgen.py | 9 +++++++-- src/pinefarm/external/nnlojet/runner.py | 6 +++--- 5 files changed, 25 insertions(+), 15 deletions(-) diff --git a/src/pinefarm/cli/run.py b/src/pinefarm/cli/run.py index 0c640db..339e2b2 100644 --- a/src/pinefarm/cli/run.py +++ b/src/pinefarm/cli/run.py @@ -16,7 +16,10 @@ @click.argument("dataset") @click.argument("theory-path", type=click.Path(exists=True)) @click.option("--pdf", default="NNPDF31_nlo_as_0118_luxqed") -def subcommand(dataset, theory_path, pdf): +@click.option( + "--warmup", "-w", is_flag=True, help="Run the underlying code in warmup mode" +) +def subcommand(dataset, theory_path, pdf, warmup): """Compute a dataset and compare using a given PDF. Given a DATASET name and a THEORY-PATH, a runcard is executed with the @@ -29,11 +32,14 @@ def subcommand(dataset, theory_path, pdf): # read theory card from file with open(theory_path) as f: theory_card = yaml.safe_load(f) - main(dataset, theory_card, pdf) + main(dataset, theory_card, pdf, warmup=warmup) -def main(dataset, theory, pdf): - """Compute a dataset and compare using a given PDF. + +def main(dataset, theory, pdf, **kwargs): + """Compute a dataset and compare using a given PDF and the given runner + + Keyword arguments are passed transparently to the underlying runner Parameters ---------- @@ -64,9 +70,8 @@ def main(dataset, theory, pdf): except UnboundLocalError as e: raise UnboundLocalError(f"Runcard {dataset} could not be found") from e - rich.print(f"Computing [{datainfo.color}]{dataset}[/]...") - runner = datainfo.external(dataset, theory, pdf, timestamp=timestamp) + runner = datainfo.external(dataset, theory, pdf, timestamp=timestamp, **kwargs) install_reqs(runner, pdf) run_dataset(runner) diff --git a/src/pinefarm/external/interface.py b/src/pinefarm/external/interface.py index 68c8c12..1821962 100644 --- a/src/pinefarm/external/interface.py +++ b/src/pinefarm/external/interface.py @@ -29,7 +29,7 @@ class External(abc.ABC): """ - def __init__(self, name, theory, pdf, timestamp=None): + def __init__(self, name, theory, pdf, timestamp=None, **kwargs): self.name = name self.theory = theory self.pdf = pdf diff --git a/src/pinefarm/external/nnlojet/nnpdf_interface.py b/src/pinefarm/external/nnlojet/nnpdf_interface.py index e616390..f83599b 100755 --- a/src/pinefarm/external/nnlojet/nnpdf_interface.py +++ b/src/pinefarm/external/nnlojet/nnpdf_interface.py @@ -17,8 +17,6 @@ import numpy as np from ruamel.yaml import YAML, CommentedMap from validphys.api import API -from validphys.datafiles import path_vpdata -from validphys.theorydbutils import fetch_theory # set-up the yaml reader yaml = YAML(pure=True) @@ -38,7 +36,7 @@ def _df_to_bins(dataframe): def _nnlojet_observable(observable, process): """Try to automatically understand the NNLOJET observables given the NNPDF process and obs""" - if observable == "y": + if observable == "y" or observable == "eta": if process.upper().startswith("Z"): return "yz" if process.upper().startswith("WP") and not process.upper().endswith("J"): @@ -50,6 +48,8 @@ def _nnlojet_observable(observable, process): return "ptz" if process.upper().startswith("W"): return "ptw" + + # The old observables from NNPDF had the dreaded k1/k2/k3 raise ValueError(f"Observable {observable} not recognized for process {process}") diff --git a/src/pinefarm/external/nnlojet/runcardgen.py b/src/pinefarm/external/nnlojet/runcardgen.py index 0c94063..c710cd4 100755 --- a/src/pinefarm/external/nnlojet/runcardgen.py +++ b/src/pinefarm/external/nnlojet/runcardgen.py @@ -304,7 +304,9 @@ def generate_runcard( return runcard_path -def generate_nnlojet_runcard(yamlinfo, channels=("LO",), output=Path(".")): +def generate_nnlojet_runcard( + yamlinfo, channels=("LO",), output=Path("."), is_warmup=False +): """Generate a nnlojet runcard from a yaml pinecard""" yaml_metadata = YamlLOJET(**yamlinfo) @@ -312,5 +314,8 @@ def generate_nnlojet_runcard(yamlinfo, channels=("LO",), output=Path(".")): runcards = [] for channel in channels: - runcards.append(generate_runcard(yaml_metadata, channel, output=output)) + rpath = generate_runcard( + yaml_metadata, channel, output=output, is_warmup=is_warmup + ) + runcards.append(rpath) return runcards diff --git a/src/pinefarm/external/nnlojet/runner.py b/src/pinefarm/external/nnlojet/runner.py index 5b343a1..3304494 100644 --- a/src/pinefarm/external/nnlojet/runner.py +++ b/src/pinefarm/external/nnlojet/runner.py @@ -12,8 +12,8 @@ class NNLOJET(interface.External): """Interface provider for NNLOJET.""" - def __init__(self, pinecard, theorycard, *args, **kwargs): - super().__init__(pinecard, theorycard, *args, **kwargs) + def __init__(self, pinecard, theorycard, *args, warmup=False, **kwargs): + super().__init__(pinecard, theorycard, *args, warmup=warmup, **kwargs) pinecard = pinecard.replace("NNLOJET_", "") yaml_card = (self.source / pinecard).with_suffix(".yaml") @@ -49,7 +49,7 @@ def __init__(self, pinecard, theorycard, *args, **kwargs): raise NotImplementedError("N3LO still not working") self._nnlojet_runcards = generate_nnlojet_runcard( - yaml_dict, channels, output=self.dest + yaml_dict, channels, output=self.dest, is_warmup=warmup ) def run(self):