Skip to content
Open
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
1 change: 1 addition & 0 deletions src/pineko/cli/convolve.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ def subcommand(
assumptions=assumptions,
comparison_pdfs=pdfs,
min_as=min_as,
grid_path=pathlib.Path(grid_path),
)

if len(operators) > 1:
Expand Down
34 changes: 27 additions & 7 deletions src/pineko/evolve.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Tools related to evolution/eko."""

import copy
import hashlib
import json
import logging
import os
Expand Down Expand Up @@ -67,7 +68,21 @@ def construct_atlas(tcard):
return atlas


def construct_empty_fktable(grid, theory_meta, fktable_path):
def set_fktable_metadata(fktable, theory_meta, grid_path=None):
"""Store the common FK metadata and, if available, grid provenance."""
fktable.set_metadata("pineko_version", version.__version__)
fktable.set_metadata("theory_card", json.dumps(theory_meta))
if grid_path is None:
return

grid_path_obj = pathlib.Path(grid_path).resolve()
grid_hash = hashlib.md5(grid_path_obj.read_bytes()).hexdigest()
fktable.set_metadata("grid_hash", grid_hash)
fktable.set_metadata("grid_theory", grid_path_obj.parent.name)
fktable.set_metadata("grid_name", grid_path_obj.name)


def construct_empty_fktable(grid, theory_meta, fktable_path, grid_path=None):
"""Construct and write a structurally valid but numerically empty FK table.

"Empty" means the FK table carries a single trivial order ``(0,0,0,0,0)``
Expand Down Expand Up @@ -111,8 +126,7 @@ def construct_empty_fktable(grid, theory_meta, fktable_path):
scale_funcs=grid.scales,
)
fktable = pineappl.fk_table.FkTable(empty_grid)
fktable.set_metadata("pineko_version", version.__version__)
fktable.set_metadata("theory_card", json.dumps(theory_meta))
set_fktable_metadata(fktable, theory_meta, grid_path=grid_path)
fktable.write_lz4(str(fktable_path))
return fktable

Expand Down Expand Up @@ -353,6 +367,7 @@ def evolve_grid(
assumptions="Nf6Ind",
comparison_pdfs: Optional[list[str]] = None,
min_as=None,
grid_path: Optional[os.PathLike] = None,
):
"""Convolute grid with EKO from file paths.

Expand Down Expand Up @@ -382,6 +397,8 @@ def evolve_grid(
if given, a comparison table (with / without evolution) will be printed
min_as: None or int
minimum power of strong coupling
grid_path : str or os.PathLike or None
path to the grid file, used to store grid hash metadata

Returns
-------
Expand All @@ -399,7 +416,9 @@ def evolve_grid(
# A grid with no orders is a valid input for some workflows. In that case we
# cannot build evolution kinematics, so we directly emit an empty FK table.
if len(grid.orders()) == 0:
fktable = construct_empty_fktable(grid, theory_meta, fktable_path)
fktable = construct_empty_fktable(
grid, theory_meta, fktable_path, grid_path=grid_path
)
return grid, fktable, None

order_mask = pineappl.boc.Order.create_mask(grid.orders(), max_as, max_al, True)
Expand All @@ -423,7 +442,9 @@ def evolve_grid(
# `XGrid` requires at least 2 points, otherwise it panics. In this case, we
# simply return an empty FK table instead.
if (len(x_grid) < 2) or (len(muf2_grid) == 0) or (len(mur2_grid) == 0):
fktable = construct_empty_fktable(grid, theory_meta, fktable_path)
fktable = construct_empty_fktable(
grid, theory_meta, fktable_path, grid_path=grid_path
)
return grid, fktable, None

xif = 1.0 if operators[0].operator_card.configs.scvar_method is not None else xif
Expand Down Expand Up @@ -507,8 +528,7 @@ def prepare(operator, convolution_types):
f"eko_operator_card{suffix}", json.dumps(operator.operator_card.raw)
)

fktable.set_metadata("pineko_version", version.__version__)
fktable.set_metadata("theory_card", json.dumps(theory_meta))
set_fktable_metadata(fktable, theory_meta, grid_path=grid_path)

# compare before/after
comparison = None
Expand Down
5 changes: 5 additions & 0 deletions src/pineko/fonll.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,11 @@ def produce_combined_fk(
Path(configs.configs["paths"]["theory_cards"]) / f"{theoryid}.yaml"
)
update_fk_theorycard(combined_fk, input_theorycard_path)
grid_hash = " ".join(
f"{idx:02d}-{fk.metadata['grid_hash']}" for idx, fk in enumerate(fk_dict.values())
)
combined_fk.set_metadata("grid_hash", grid_hash)
combined_fk.set_metadata("grid_theory", str(theoryid))
# save final FONLL fktable
fk_folder = Path(configs.configs["paths"]["fktables"]) / str(theoryid)
fk_folder.mkdir(exist_ok=True)
Expand Down
1 change: 1 addition & 0 deletions src/pineko/theory.py
Original file line number Diff line number Diff line change
Expand Up @@ -562,6 +562,7 @@ def fk(self, name, grid_path, tcard, pdfs):
theory_meta=tcard,
assumptions=assumptions,
comparison_pdfs=pdfs,
grid_path=grid_path,
)

if n_ekos > 1:
Expand Down
Loading