Skip to content

Commit

Permalink
Merge pull request #2140 from NNPDF/return_existing_paths
Browse files Browse the repository at this point in the history
Only return lhapdf data paths that do exist
  • Loading branch information
scarlehoff committed Aug 12, 2024
2 parents 604b2b9 + b4d7475 commit cb68fe4
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
11 changes: 11 additions & 0 deletions validphys2/src/validphys/lhaindex.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import glob
import os
import os.path as osp
from pathlib import Path
import re

from reportengine.compat import yaml
Expand Down Expand Up @@ -130,6 +131,16 @@ 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():
return lhapath
return lhapdf.paths()[-1]


Expand Down
3 changes: 2 additions & 1 deletion validphys2/src/validphys/lhapdf_compatibility.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"""
Expand Down

0 comments on commit cb68fe4

Please sign in to comment.