Skip to content

Commit 893f4dd

Browse files
committed
implemented fk hash
1 parent 75e8ce3 commit 893f4dd

1 file changed

Lines changed: 48 additions & 4 deletions

File tree

n3fit/src/n3fit/scripts/vp_setupfit.py

Lines changed: 48 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@
4040
from validphys.loader import FallbackLoader, Loader, PhotonQEDNotFound, TheoryNotFound
4141
from validphys.utils import yaml_safe
4242

43+
#from pineappl import fk_table
44+
45+
4346
loader = FallbackLoader()
4447

4548
SETUPFIT_FIXED_CONFIG = dict(
@@ -65,6 +68,7 @@
6568
FILTER_OUTPUT_FOLDER = "filter"
6669
TABLE_OUTPUT_FOLDER = "tables"
6770
MD5_FILENAME = "md5"
71+
MD5FK_FILENAME = "md5fk"
6872
INPUT_FOLDER = "input"
6973

7074

@@ -131,6 +135,16 @@ def save_md5(self):
131135
g.write(digest)
132136
log.info(f"md5 {digest} stored in {output_filename}")
133137

138+
def save_fk_md5(self, keys):
139+
"""Save FK-table metadata hashes."""
140+
output_filename = self.output_path / MD5FK_FILENAME
141+
142+
with open(output_filename, "w") as f:
143+
for _, value in sorted(keys.items()):
144+
f.write(f"{value}\n")
145+
146+
log.info(f"FK hashes stored in {output_filename}")
147+
134148
@classmethod
135149
def ns_dump_description(cls):
136150
return {'filter_path': "The filter output folder", **super().ns_dump_description()}
@@ -189,10 +203,35 @@ def from_yaml(cls, o, *args, **kwargs):
189203
'datacuts::theory::theorycovmatconfig nnfit_theory_covmat'
190204
)
191205

192-
# Save a hash of the FK-Tables
193-
loader = Loader()
194-
theories_path = loader.theories_path
195-
206+
# Save a hash of the FK-Table metadata
207+
l = Loader()
208+
theories_path = l.theories_path
209+
keys = {}
210+
211+
for ds in file_content["dataset_inputs"]:
212+
setname = ds["dataset"]
213+
cdspec = loader.check_commondata(setname)
214+
215+
fk_tablename = str(cdspec.metadata.theory.FK_tables[0][0])
216+
217+
# There is probably a more elegant way to get the FK-table path
218+
fk_tablepath = (
219+
pathlib.Path(theories_path)
220+
/ f"theory_{theoryid}"
221+
/ "fastkernel"
222+
/ f"{fk_tablename}.pineappl.lz4"
223+
)
224+
225+
# fk = fk_table.FkTable.read(str(fk_tablepath))
226+
# Should we dump the fk.metadata as opposed to fk_tablepath.read_bytes()?
227+
fkhash = hashlib.md5(fk_tablepath.read_bytes()).hexdigest()
228+
229+
230+
keys[fk_tablename] = (
231+
f"{theoryid}_{fk_tablename}_{fkhash}"
232+
)
233+
234+
file_content["_fk_hashes"] = keys
196235

197236

198237
# Check fiatlux configuration
@@ -278,6 +317,11 @@ def run(self):
278317

279318
# if succeeded print md5
280319
self.environment.save_md5()
320+
321+
# and save the fk hashes
322+
import pdb; pdb.set_trace()
323+
fk_hashes = self.config_class["_fk_hashes"]
324+
self.environment.save_fk_md5(fk_hashes)
281325
except SetupFitError as e:
282326
log.error(f"Error in setup-fit:\n{e}")
283327
sys.exit(1)

0 commit comments

Comments
 (0)