Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only return lhapdf data paths that do exist #2140

Merged
merged 2 commits into from
Aug 12, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
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():
scarlehoff marked this conversation as resolved.
Show resolved Hide resolved
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