Skip to content
Open
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions src/pinefarm/cli/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,18 +190,18 @@ def run_dataset(runner):

# collect results in the output pineappl grid
runner.generate_pineappl()

table.print_table(
table.convolute_grid(
runner.grid, runner.pdf, integrated=isinstance(runner, mg5.Mg5)
),
runner.results(),
runner.dest,
)

# TODO: annotate_version should be a post-processing step
# however at the moment only works in 1-grid cases
runner.annotate_versions()
if not hasattr(runner, "ps_link"):
Comment thread
andrpie marked this conversation as resolved.
Outdated
table.print_table(
table.convolute_grid(
runner.grid, runner.pdf, integrated=isinstance(runner, mg5.Mg5)
),
runner.results(),
runner.dest,
)

# TODO: annotate_version should be a post-processing step
# however at the moment only works in 1-grid cases
runner.annotate_versions()

runner.postprocess()

Expand Down
5 changes: 5 additions & 0 deletions src/pinefarm/external/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,9 @@ def decide_external_tool(dsname: str):

return mg5.Mg5, "blue"

if (configs["paths"]["runcards"] / dsname / "ploughshare_link.txt").exists():
from . import plough

return plough.Plough, "purple"

raise ValueError(f"pinefarm could not discover the tool to use for {dsname}")
2 changes: 1 addition & 1 deletion src/pinefarm/external/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ def postprocess(self):
entries = {}
if metadata.exists():
for line in metadata.read_text().splitlines():
k, v = line.split("=")
k, v = line.split("=", 1)
entries[k] = v

for ext in ["*.pineappl.lz4", "*.pineappl"]:
Expand Down
80 changes: 80 additions & 0 deletions src/pinefarm/external/plough.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
"""Download grids + convert them to pineappl format."""

import os
import shutil
import tarfile
import urllib.request

import pineappl
import requests

from .. import table
from . import interface

PLOUGHSHARE_LINK_FILENAME = "ploughshare_link.txt"
Comment thread
felixhekhorn marked this conversation as resolved.
GRIDS_TMP = "grids"


class Plough(interface.External):
"""Interface provider."""
Comment thread
andrpie marked this conversation as resolved.
Outdated

def __init__(self, pinecard, theorycard, *args, **kwargs):
super().__init__(pinecard, theorycard, *args, **kwargs)
self.ps_link = self.source / PLOUGHSHARE_LINK_FILENAME
self.link = self.ps_link.read_text()

self.filename = self.link.rsplit("/")[-1]
self.dir_name = self.filename.rsplit(".", 1)[0]
self.tarball = self.dest / self.filename

def run(self):
"""Download and extract the .tgz file."""
print("Downloading from ploughshare...")
try:
self.download_to_dest()
if self.tarball.exists():
print(f"Grids successfully downloaded to {self.tarball}")
else:
raise FileNotFoundError(
f"{self.tarball} not found but the download didn't seem to fail?"
)
except Exception as e:
raise FileNotFoundError(f"{self.tarball} could not be downloaded!") from e
print(f"Grids successfully downloaded to {self.tarball}")
print("Extracting files...")
self.extract_tarball()
print(f"Grids successfully extracted to {self.dest}")
self.cleanup()

def results(self):
"""Results are collected and compared at the pineappl (script) level."""
Comment thread
andrpie marked this conversation as resolved.
Outdated
pass

def collect_versions(self):
"""No additional programs involved."""
return {}

def generate_pineappl(self):
"""Grids are converted in postrun.sh."""
return

def download_to_dest(self):
"""Download the file to the output folder."""
urllib.request.urlretrieve(self.link, self.dest / self.filename)
Comment thread
andrpie marked this conversation as resolved.
Outdated

def extract_tarball(self):
"""Extract the contents."""
with tarfile.open(self.tarball, "r:*") as tf:
tf.extractall(self.dest)
self.grids_dir = self.dest / self.dir_name / GRIDS_TMP
Comment thread
andrpie marked this conversation as resolved.
Outdated
grids_list = sorted(os.listdir(self.grids_dir))
for i, grid in enumerate(grids_list):
extension = grid.split(".", 2)[2]
print(extension)
os.rename(self.grids_dir / grid, self.dest / f"grid_{i}.{extension}")

def cleanup(self):
"""Delete unnecessary files and create tmp.pineappl.lz4 to allow postprocessing."""
shutil.rmtree(self.dest / self.dir_name)
self.tarball.unlink()
open(self.dest / "tmp.pineappl.lz4", "x")
Comment thread
andrpie marked this conversation as resolved.
Outdated
Loading