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

Use the NNPDF data instead of yamldb #159

Merged
merged 14 commits into from
Mar 26, 2024
6 changes: 4 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,16 @@ repository = "https://github.com/N3PDF/pineko"
packages = [{ include = "pineko", from = "src" }]

[tool.poetry.dependencies]
python = ">=3.8,<3.12"
python = ">=3.9,<3.13"
eko = "^0.14.0"
pineappl = "^0.6.2"
pineappl = "^0.7.3"
PyYAML = "^6.0"
numpy = "^1.21.0"
pandas = "^1.4.1"
rich = "^12.5.1"
click = "^8.0.4"
tomli = "^2.0.1"
nnpdf = { git = "https://github.com/NNPDF/nnpdf", optional = true}

[tool.poetry.group.docs]
optional = true
Expand All @@ -57,6 +58,7 @@ ipython = "^8.0"

[tool.poetry.extras]
docs = ["sphinx", "sphinx-rtd-theme", "sphinxcontrib-bibtex"]
nnpdf = ["nnpdf"]

[tool.poetry.scripts]
pineko = "pineko:command"
Expand Down
18 changes: 16 additions & 2 deletions src/pineko/configs.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
"Holds loaded configurations"

NEEDED_KEYS = [
"ymldb",
"operator_cards",
"grids",
"operator_card_template_name",
Expand All @@ -23,6 +22,7 @@
]

NEEDED_FILES = ["operator_card_template_name"]
GENERIC_OPTIONS = "general"


def defaults(base_configs):
Expand Down Expand Up @@ -59,8 +59,22 @@ def enhance_paths(configs_):
configs_ : dict
configuration
"""
required_keys = list(NEEDED_KEYS)
giacomomagni marked this conversation as resolved.
Show resolved Hide resolved
# Check that one of nnpdf / ymldb is given
generic_options = configs_.get(GENERIC_OPTIONS, {})
if generic_options.get("nnpdf", False):
# Fail as soon as possible
try:
import validphys
except ModuleNotFoundError:
raise ModuleNotFoundError(
"Cannot use `nnpdf=True` without a valid installation of NNPDF"
)
else:
required_keys.append("ymldb")

# required keys without default
for key in NEEDED_KEYS:
for key in required_keys:
if key not in configs_["paths"]:
raise ValueError(f"Configuration is missing a 'paths.{key}' key")
if key in NEEDED_FILES:
Expand Down
39 changes: 33 additions & 6 deletions src/pineko/theory.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,21 @@
logger = logging.getLogger(__name__)


def _load_grids_from_nnpdf(dataset_name):
"""Load the list of fktables/grids necessary from a NNPDF dataset."""
# Hide the validphys import to avoid unnecessary failures
from validphys.commondataparser import EXT
from validphys.datafiles import legacy_to_new_map
from validphys.loader import Loader
scarlehoff marked this conversation as resolved.
Show resolved Hide resolved

# We only need the metadata, so this should be enough
dataset_name, variant = legacy_to_new_map(dataset_name)
cd = Loader().check_commondata(dataset_name, variant=variant)
fks = cd.metadata.theory.FK_tables
# Return it flat
return [f"{i}.{EXT}" for operand in fks for i in operand]


def check_scvar_evolve(grid, max_as, max_al, kind: check.Scale):
"""Check scale variations and central orders consistency."""
available, max_as_effective = check.contains_sv(grid, max_as, max_al, kind)
Expand Down Expand Up @@ -64,6 +79,12 @@ def operator_cards_path(self):
"""Suffix paths.operator_cards with theory id."""
return configs.configs["paths"]["operator_cards"] / str(self.theory_id)

@property
def use_nnpdf(self):
"""Whether to use NNPDF for the loading of data information."""
generic_info = configs.configs.get(configs.GENERIC_OPTIONS, {})
return generic_info.get("nnpdf", False)

def ekos_path(self, tid=None):
"""Suffix paths.ekos with theory id.

Expand Down Expand Up @@ -116,12 +137,18 @@ def load_grids(self, ds):
grids : dict
mapping basename to path
"""
paths = configs.configs["paths"]
_info, grids = parser.get_yaml_information(
paths["ymldb"] / f"{ds}.yaml", self.grids_path()
)
# the list is still nested, so flatten
grids = [grid for opgrids in grids for grid in opgrids]
if self.use_nnpdf:
# Take fktable information from NNPDF
raw_grids = _load_grids_from_nnpdf(ds)
grids = [self.grids_path() / i for i in raw_grids]
else:
paths = configs.configs["paths"]
_info, grids = parser.get_yaml_information(
paths["ymldb"] / f"{ds}.yaml", self.grids_path()
)
# the list is still nested, so flatten
grids = [grid for opgrids in raw_grids for grid in opgrids]

# then turn into a map name -> path
grids = {grid.stem.rsplit(".", 1)[0]: grid for grid in grids}
return grids
Expand Down
Loading