|
40 | 40 | from validphys.loader import FallbackLoader, Loader, PhotonQEDNotFound, TheoryNotFound |
41 | 41 | from validphys.utils import yaml_safe |
42 | 42 |
|
| 43 | +#from pineappl import fk_table |
| 44 | + |
| 45 | + |
43 | 46 | loader = FallbackLoader() |
44 | 47 |
|
45 | 48 | SETUPFIT_FIXED_CONFIG = dict( |
|
65 | 68 | FILTER_OUTPUT_FOLDER = "filter" |
66 | 69 | TABLE_OUTPUT_FOLDER = "tables" |
67 | 70 | MD5_FILENAME = "md5" |
| 71 | +MD5FK_FILENAME = "md5fk" |
68 | 72 | INPUT_FOLDER = "input" |
69 | 73 |
|
70 | 74 |
|
@@ -131,6 +135,16 @@ def save_md5(self): |
131 | 135 | g.write(digest) |
132 | 136 | log.info(f"md5 {digest} stored in {output_filename}") |
133 | 137 |
|
| 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 | + |
134 | 148 | @classmethod |
135 | 149 | def ns_dump_description(cls): |
136 | 150 | return {'filter_path': "The filter output folder", **super().ns_dump_description()} |
@@ -189,10 +203,35 @@ def from_yaml(cls, o, *args, **kwargs): |
189 | 203 | 'datacuts::theory::theorycovmatconfig nnfit_theory_covmat' |
190 | 204 | ) |
191 | 205 |
|
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 |
196 | 235 |
|
197 | 236 |
|
198 | 237 | # Check fiatlux configuration |
@@ -278,6 +317,11 @@ def run(self): |
278 | 317 |
|
279 | 318 | # if succeeded print md5 |
280 | 319 | 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) |
281 | 325 | except SetupFitError as e: |
282 | 326 | log.error(f"Error in setup-fit:\n{e}") |
283 | 327 | sys.exit(1) |
|
0 commit comments