Repository navigation
fix(evolve): verify grid hash against stored hash txt if present (#267) - #269
ashishsoni-ai wants to merge 3 commits into
Conversation
scarlehoff
left a comment
There was a problem hiding this comment.
The test itself is exactly what I had in mind, but it looks unnecessarily complicated?
| txt_candidates = [ | ||
| grid_path_obj.parent / f"{grid_path_obj.name}.txt", | ||
| grid_path_obj.with_suffix(".txt"), | ||
| ] |
There was a problem hiding this comment.
What is the difference between these two possible candidates? Are they not the same?
| if stem_name.endswith(ext): | ||
| stem_name = stem_name[: -len(ext)] | ||
| txt_candidates.append(grid_path_obj.parent / f"{stem_name}.txt") | ||
| break |
There was a problem hiding this comment.
Why this loop. All pineappl grids have the same extension, which should be defined in parser.py.
|
Thanks @scarlehoff! Simplified both the implementation and the test:
|
scarlehoff
left a comment
There was a problem hiding this comment.
The check as it is and where it is, is correct.
however thinking about the happiness of the users, the most expensive part is computing the evolution kernel, and the current check happens at the level of the FkTable creation (correct! don't get me wrong)
But we should have a second check that happens at the very beginning, the first time we read the grid (to create the operator card and kernel) pineko should immediately check whether the grid's hash matches the stored hash and fail there otherwise. Fail fast, fail soon and all that.
| grid_path_obj = pathlib.Path(grid_path).resolve() | ||
| grid_hash = hashlib.md5(grid_path_obj.read_bytes()).hexdigest() | ||
|
|
||
| # Check that the grid's hash agrees with the stored hash (if present) (#267) |
There was a problem hiding this comment.
| # Check that the grid's hash agrees with the stored hash (if present) (#267) | |
| # Check that the grid's hash agrees with the stored hash (if present) |
| raise ValueError( | ||
| f"Grid hash mismatch for '{grid_path_obj.name}': " | ||
| f"computed {grid_hash}, but stored hash in '{txt_path.name}' is {stored_hash}" | ||
| ) |
There was a problem hiding this comment.
There are valid reasons to run pineko with a modified grid that has not been upload to the server yet, so the error message should tell the user the solution, which is to upload the grid to the theory server using the available script in the theories_slim repository.
Otherwise, the user must remove the .txt file if they want to run.
Looking at the grid hashes stored in some of the jet fktables I realized something relatively bad (cc @felixhekhorn) which is that some of the fktables came from grids that I was not able to match with any of the grids that we have online.
I think this should be flagged smh, i.e., we should have a metadata key in the fktable comes_from_online_grid which defaults to False and that is flipped to True only once this check passes.
e.g., if the user decides they want to run pineko and not upload the grid to the server, the fktable will forever be shamed with comes_from_online_grid=False
|
Btw, for my own education. You are running this with Antigravity and with a free account, is that correct? Do you mind sharing the kind of prompts you are using? I'm curious about how much direction you need to give antigravity. The results themselves are not bad, although there is a lot of redundancy (like the check for different extensions) which is completely unfounded (I don't think we do that anywhere). |
|
Thanks @scarlehoff! I've updated the PR with all of your suggestions:
Regarding your question about Antigravity: I'm using the paid Pro version of Antigravity IDE. My workflow is to first read the issue and understand the context with AI, then give a clear, structured prompt targeting the exact modules and conventions so it implements the fix cleanly, and finally review and test the diff locally. Your feedback on avoiding unnecessary abstractions (like the extension loop) is super helpful for keeping my prompts tighter. |
Closes #267
Summary
In
set_fktable_metadata(), verifies that the computed MD5 hash of an input grid matches the hash stored in an accompanying.txtfile (if present in the grid directory) before writing the provenance metadata into the FK table. If a mismatch is detected, raises an informativeValueErrorto prevent propagating corrupted or incorrectly matched grids, as requested in #267.Changes
src/pineko/evolve.py:grid_pathis provided, check for candidate hash.txtfiles ingrid_path_obj.parent(<name>.txt,<name>.with_suffix('.txt'), or<stem>.txt)..txthash file is found, verifystored_hash == grid_hash, raisingValueErroron mismatch..txtfile exists, proceeds normally without error.tests/test_evolve.py:.txthash file..txtfile (both raw hash andmd5sum<hash> <filename>format)..txtfile.Verification
pytest -k "not test_nnpdf_grids" tests/: 26 passed.black --check src/pineko/evolve.py tests/test_evolve.py: clean.git diff --check: 0 issues.AI usage
Harness: Antigravity IDE
Model: Gemini 3.8 Flash