From 8e9eff78f3566b03c69629d2b7da0ba8f57ed99c Mon Sep 17 00:00:00 2001 From: juacrumar Date: Mon, 5 Aug 2024 12:19:47 +0200 Subject: [PATCH 1/2] only return paths that do exist --- validphys2/src/validphys/lhaindex.py | 7 +++++++ validphys2/src/validphys/lhapdf_compatibility.py | 3 ++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/validphys2/src/validphys/lhaindex.py b/validphys2/src/validphys/lhaindex.py index e783366d98..fa765d92d4 100644 --- a/validphys2/src/validphys/lhaindex.py +++ b/validphys2/src/validphys/lhaindex.py @@ -10,6 +10,7 @@ import glob import os import os.path as osp +from pathlib import Path import re from reportengine.compat import yaml @@ -130,6 +131,12 @@ def parse_info(name): def get_lha_datapath(): + """Return an existing datapath from LHAPDF, starting from the end. + If no path is found to exist, recover the old behaviour and returns the last path. + """ + for lhapath in lhapdf.paths()[::-1]: + if Path(lhapath).exists(): + return lhapath return lhapdf.paths()[-1] diff --git a/validphys2/src/validphys/lhapdf_compatibility.py b/validphys2/src/validphys/lhapdf_compatibility.py index 5a04b3902d..83cc6fbd88 100644 --- a/validphys2/src/validphys/lhapdf_compatibility.py +++ b/validphys2/src/validphys/lhapdf_compatibility.py @@ -6,6 +6,7 @@ `lhapdf-management` and `pdfflow` which cover all the features of LHAPDF used during the fit (and likely most of validphys) """ + from functools import cached_property import numpy as np @@ -86,7 +87,7 @@ def xfxQ(self, a, b, c=None): if isinstance(a, int): return ret_dict.get(a, zeros) - return [ret_dict.get(i, zeros) for i in a] + return np.array([ret_dict.get(i, zeros) for i in a]).T def xfxQ2(self, a, b, c=None): """Wrapper for LHAPDF xfxQ2 function, like xfxQ for Q2""" From b4d747546d464eedf45e4c2b55bf9193bde6468d Mon Sep 17 00:00:00 2001 From: "Juan M. Cruz-Martinez" Date: Mon, 5 Aug 2024 14:56:55 +0200 Subject: [PATCH 2/2] Update lhaindex.py --- validphys2/src/validphys/lhaindex.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/validphys2/src/validphys/lhaindex.py b/validphys2/src/validphys/lhaindex.py index fa765d92d4..9a10d66ff1 100644 --- a/validphys2/src/validphys/lhaindex.py +++ b/validphys2/src/validphys/lhaindex.py @@ -133,6 +133,10 @@ def parse_info(name): def get_lha_datapath(): """Return an existing datapath from LHAPDF, starting from the end. If no path is found to exist, recover the old behaviour and returns the last path. + + The check for existence intends to solve problems where a previously filled `LHAPATH` + or `LHAPDF_DATA_PATH` environment variable is pointing to a non-existent path or shared + systems where LHAPDF might be compiled with hard-coded paths not available to all users. """ for lhapath in lhapdf.paths()[::-1]: if Path(lhapath).exists():