Skip to content

Commit 2acc738

Browse files
committed
moved fktable_hasher to n3fit_checks_provider
1 parent 5485eb3 commit 2acc738

2 files changed

Lines changed: 21 additions & 25 deletions

File tree

n3fit/src/n3fit/checks.py

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
This module contains checks to be perform by n3fit on the input
33
"""
44

5-
import hashlib
65
import logging
76
import numbers
87
import os
@@ -28,7 +27,6 @@
2827
"layer_type",
2928
"dropout",
3029
]
31-
MD5FK_FILENAME = "md5fk"
3230

3331

3432
def _is_floatable(num):
@@ -566,25 +564,3 @@ def check_eko_exists(theoryid):
566564
_ = FallbackLoader().check_eko(theoryid.id)
567565
except FileNotFoundError:
568566
log.error(f"No eko found for {theoryid}")
569-
570-
571-
def fktable_hasher(data, output_path):
572-
"""Writes a hash of the fk-tables to a log file.
573-
This hash can be used to ensure whether two
574-
(supposedly identical) fk-tables of the same
575-
theory and dataset are numerically identical.
576-
"""
577-
md5fk_path = output_path / MD5FK_FILENAME
578-
# Open a file to write in
579-
with open(md5fk_path, "w") as f:
580-
# Loop through the dataspecs object
581-
for dataset in data.datasets:
582-
fkspecs = dataset.fkspecs
583-
for fk in fkspecs:
584-
# Make a list of the FK tables
585-
table_names = [name for group in fk.metadata.FK_tables for name in group]
586-
for fkpath, table_name in zip(fk.fkpath, table_names):
587-
for fkpath, table_name in zip(fk.fkpath, table_names):
588-
fkhash = hashlib.md5(fkpath.read_bytes()).hexdigest()
589-
f.write(f"{table_name} {fkhash}\n")
590-
log.info(f"FK-table hash written to {md5fk_path}")

n3fit/src/n3fit/n3fit_checks_provider.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"""
66

77
import n3fit.checks
8+
import hashlib
89

910

1011
@n3fit.checks.check_consistent_basis
@@ -41,5 +42,24 @@ def n3fit_checks_action(
4142
def evolven3fit_checks_action(theoryid):
4243
return
4344

45+
4446
def fktable_hasher(data, output_path):
45-
return
47+
"""Writes a hash of the fk-tables to a log file.
48+
This hash can be used to ensure whether two
49+
(supposedly identical) fk-tables of the same
50+
theory and dataset are numerically identical.
51+
"""
52+
MD5FK_FILENAME = "md5fk"
53+
md5fk_path = output_path / MD5FK_FILENAME
54+
# Open a file to write in
55+
with open(md5fk_path, "w") as f:
56+
# Loop through the dataspecs object
57+
for dataset in data.datasets:
58+
fkspecs = dataset.fkspecs
59+
for fk in fkspecs:
60+
# Make a list of the FK tables
61+
table_names = [name for group in fk.metadata.FK_tables for name in group]
62+
for fkpath, table_name in zip(fk.fkpath, table_names):
63+
for fkpath, table_name in zip(fk.fkpath, table_names):
64+
fkhash = hashlib.md5(fkpath.read_bytes()).hexdigest()
65+
f.write(f"{table_name} {fkhash}\n")

0 commit comments

Comments
 (0)