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
4 changes: 2 additions & 2 deletions .github/workflows/bench.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ jobs:
virtualenvs-create: false
installer-parallel: true
- name: Install dependencies
run: poetry install --no-interaction --no-root --with test ${{ inputs.poetry-extras }}
run: poetry install --no-interaction --no-root --with test -E nnpdf
- name: Install project
# it is required to repeat extras, otherwise they will be removed from
# the environment
run: poetry install --no-interaction ${{ inputs.poetry-extras }}
run: poetry install --no-interaction -E nnpdf
- name: Install task runner
run: pip install poethepoet
- name: Lint with pylint
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/unittests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ jobs:
test:
strategy:
matrix:
python-version: ["3.8", "3.9", "3.10"]
python-version: ["3.9", "3.10", "3.11"]

uses: NNPDF/workflows/.github/workflows/python-poetry-tests.yml@v2
with:
python-version: ${{ matrix.python-version }}
poetry-extras: "-E nnpdf"
3,189 changes: 2,303 additions & 886 deletions poetry.lock

Large diffs are not rendered by default.

13 changes: 8 additions & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ authors = [
"Alessandro Candido <[email protected]>",
"Andrea Barontini <[email protected]>",
"Felix Hekhorn <[email protected]>",
"Juan Cruz-Martinez <[email protected]>",
]
classifiers = [
"Programming Language :: Python",
Expand All @@ -23,15 +24,16 @@ repository = "https://github.com/N3PDF/pineko"
packages = [{ include = "pineko", from = "src" }]

[tool.poetry.dependencies]
python = ">=3.8,<3.12"
eko = "^0.14.0"
pineappl = "^0.6.2"
python = ">=3.9,<3.13"
eko = "^0.14.2"
pineappl = ">0.7.0"
PyYAML = "^6.0"
numpy = "^1.21.0"
pandas = "^1.4.1"
pandas = "^2.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 @@ -49,14 +51,15 @@ pytest = "^7.1.3"
pytest-cov = "^4.0.0"
pytest-env = "^0.6.2"
pylint = "^2.11.1"
banana-hep = "^0.6.11"
banana-hep = "^0.6.13"

[tool.poetry.group.dev.dependencies]
pdbpp = "^0.10.3"
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
7 changes: 6 additions & 1 deletion src/pineko/fonll.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import yaml

from . import configs, parser, theory_card
from .theory import read_grids_from_nnpdf

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -228,8 +229,12 @@ def assembly_combined_fk(
else:
tcard["DAMPPOWERb"] = 0
tcard["DAMPPOWERc"] = 0

# Getting the paths to the grids
grids_name = grids_names(configs.configs["paths"]["ymldb"] / f"{dataset}.yaml")
grids_name = read_grids_from_nnpdf(dataset)
if grids_name is None:
grids_name = grids_names(configs.configs["paths"]["ymldb"] / f"{dataset}.yaml")

for grid in grids_name:
# Checking if it already exists
new_fk_path = configs.configs["paths"]["fktables"] / str(theoryid) / grid
Expand Down
44 changes: 38 additions & 6 deletions src/pineko/theory.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,32 @@
logger = logging.getLogger(__name__)


def read_grids_from_nnpdf(dataset_name):
scarlehoff marked this conversation as resolved.
Show resolved Hide resolved
"""Read the list of fktables given a dataset name.

If NNPDF is not available, returns None.

Parameters
----------
dataset_name: str
"""
generic_info = configs.configs.get(configs.GENERIC_OPTIONS, {})
if not generic_info.get("nnpdf", False):
return None

# Import NNPDF only if we really want it!
from nnpdf_data import legacy_to_new_map
from validphys.commondataparser import EXT
from validphys.loader import Loader

# 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 @@ -116,12 +142,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]
# Take fktable information from NNPDF
raw_grids = read_grids_from_nnpdf(ds)
if raw_grids is not None:
grids = [self.grids_path() / i for i in raw_grids]
else:
paths = configs.configs["paths"]
_info, raw_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