Skip to content
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
32 changes: 32 additions & 0 deletions n3fit/src/n3fit/n3fit_checks_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,15 @@
This module contains a checks provider to be used by n3fit apps
"""

import hashlib
import logging
from pathlib import Path

import n3fit.checks

log = logging.getLogger(__name__)
MD5FK_FILENAME = "md5fk"


@n3fit.checks.check_consistent_basis
@n3fit.checks.wrapper_check_NN
Expand Down Expand Up @@ -40,3 +47,28 @@ def n3fit_checks_action(
@n3fit.checks.check_eko_exists
def evolven3fit_checks_action(theoryid):
return


def fktable_hasher(data, output_path):
"""Writes a hash of the FK-tables to a log file.
This hash can be used to ensure whether two
(supposedly identical) FK-tables of the same
theory and dataset are numerically identical.
"""
md5fk_path = output_path / MD5FK_FILENAME

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess it makes sense to define this constant as a module level variable instead of here.

# Open a file to write in
with open(md5fk_path, "w") as f:
# Loop through the dataspecs object
for dataset in data.datasets:
fkspecs = dataset.fkspecs
for fk in fkspecs:
# Get the FK-table path
fkpaths = fk.fkpath
# For older theories, ensure we always pass a tuple
if not isinstance(fkpaths, tuple):
fkpaths = (fk.fkpath,)
# And then write the hash of the raw bytes
for fkpath in fkpaths:
fkhash = hashlib.md5(fkpath.read_bytes()).hexdigest()
f.write(f"{Path(fkpath.stem).stem} {fkhash}\n")
log.info(f"FK-table md5 hashes stored in {output_path}/md5fk")
4 changes: 3 additions & 1 deletion n3fit/src/n3fit/scripts/vp_setupfit.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,11 @@
from validphys.loader import FallbackLoader, PhotonQEDNotFound, TheoryNotFound
from validphys.utils import yaml_safe


loader = FallbackLoader()

SETUPFIT_FIXED_CONFIG = dict(
actions_=['datacuts check_t0pdfset', 'theory evolven3fit_checks_action']
actions_=['datacuts check_t0pdfset', 'theory evolven3fit_checks_action', 'theory fktable_hasher']
)

SETUPFIT_PROVIDERS = [
Expand Down Expand Up @@ -286,6 +287,7 @@ def run(self):

# if succeeded print md5
self.environment.save_md5()

except SetupFitError as e:
log.error(f"Error in setup-fit:\n{e}")
sys.exit(1)
Expand Down
Loading