Skip to content

Commit

Permalink
add the possibility to transparently pass through command line option…
Browse files Browse the repository at this point in the history
…s to the runner
  • Loading branch information
scarlehoff committed Mar 14, 2024
1 parent a5c4770 commit 8c394ad
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 15 deletions.
17 changes: 11 additions & 6 deletions src/pinefarm/cli/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
----------
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/pinefarm/external/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions src/pinefarm/external/nnlojet/nnpdf_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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"):
Expand All @@ -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}")


Expand Down
9 changes: 7 additions & 2 deletions src/pinefarm/external/nnlojet/runcardgen.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,13 +304,18 @@ 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)

output.mkdir(exist_ok=True, parents=True)

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
6 changes: 3 additions & 3 deletions src/pinefarm/external/nnlojet/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit 8c394ad

Please sign in to comment.