Crash when combining point prescriptions with a user covmat - #2504
Crash when combining point prescriptions with a user covmat#2504achiefa wants to merge 4 commits into
Conversation
There was a problem hiding this comment.
Pull request overview
Fixes a vp-setupfit crash during reportengine graph resolution when both point-prescription theory covmats and a user-provided covmat are enabled, by removing an argcheck dependency that required an unresolved production rule (group_dataset_inputs_by_metadata) at argcheck time.
Changes:
- Remove
check_fit_dataset_order_matches_groupedargcheck from theory covariance utilities. - Stop applying that argcheck to
total_theory_covmat, eliminating theKeyErrorduring dependency resolution. - Remove the now-unused
procs_index_matchedhelper.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
validphys2/src/validphys/theorycovariance/theorycovarianceutils.py |
Removes the argcheck function that depended on group_dataset_inputs_by_metadata. |
validphys2/src/validphys/theorycovariance/construction.py |
Removes the argcheck decorator from total_theory_covmat and deletes unused index-matching helper code. |
Comments suppressed due to low confidence (1)
validphys2/src/validphys/theorycovariance/construction.py:549
- This change removes the only runtime guard that caught (and now triggered) the dataset-ordering mismatch scenario when combining point prescriptions + user covmat. Since this PR is specifically fixing a real crash in vp-setupfit/reportengine graph resolution, it would be good to add a regression test that exercises
nnfit_theory_covmatwith bothpoint_prescriptionsanduser_covmat_pathand asserts it resolves without error (and returns a correctly indexed/typed covmat). That will prevent reintroducing the KeyError and ensure the intended dependency graph remains resolvable.
@table
def total_theory_covmat(theory_covmat_custom, user_covmat):
"""
Sum of scale variation and user covmat, where both are used.
"""
return theory_covmat_custom + user_covmat
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
|
||
| # The user covmat is looked up with ``Loader.check_vp_output_file``, which | ||
| # rejects absolute paths, so it has to be found relative to the cwd. The name is | ||
| # made distinctive so that it cannot collide with anything in the vp cache. |
There was a problem hiding this comment.
How would you then restructure the parametrization. Note that tmp_path_factory is already a tmp directory, and the test already goes into it. Would you build the config dict inside the test?
There was a problem hiding this comment.
I would not restructure anything. The comment says the name is to avoid clashes. An unique temporary name (with uuid for instance) would for sure avoid clashes.
| "errors when running fits with theory covmat. Datasets should " | ||
| f"be ordered by {processed_metadata_group} in the runcard.", | ||
| ) | ||
|
|
There was a problem hiding this comment.
I see this check is from the time the fitting code was c++ so I'm ready to believe it is obsolete.
However, I also know that two different PhD students three year apart spent many hours on a misordered sum of covmats.
Now it would be about 3 years later from last time... are you absolutely sure this is safe to remove?
Btw, a way to check whether the hypothesis is correct from what you say would be to simply add groups_index to data_input_matched_procs_index as a dummy argument. That should be enough to trigger the production.
There was a problem hiding this comment.
Btw, a way to check whether the hypothesis is correct from what you say would be to simply add groups_index to data_input_matched_procs_index as a dummy argument. That should be enough to trigger the production.
Yes, I tried to add groups_index as a dummy argument and it worked. However, I'm not in favour of this solution for two reasons. First, it's very hard to understand the reason why the dummy variable has been included. However, a comment may help in this case. Second, as you said we'd have an important part of the code (checking ordering of covmats) that rely on obselete code. Moreover, if we were to keep this obselete code, we'd have two functions checking the same thing in two not-so-different branches of the code.
There was a problem hiding this comment.
No, I don't think it should be added as an argument of course.
But it is a way to check whether it was a possible issue or the actual issue.
There was a problem hiding this comment.
Good. I reach these conclusions:
check_fit_dataset_order_matches_groupedchecks ifgroup_dataset_inputs_by_metadatafollows or not runcard order.- However,
group_dataset_inputs_by_metadatais never used to construct an index in the theory covmat pipeline. - The method itself is called in
nnpdf/validphys2/src/validphys/config.py
Lines 1928 to 1929 in abee4f0
but it's a different thing. - Anyway, this checked was a guard and didn't fix the order of the code: it just refused to run. Now the code fixes the ordering by reindexing. On the writing side,
theory_covmat_custom_fitting/total_theory_covmat_fitting/user_covmat_fittingpush the covmat through_reindex_covmat_to_fitting_orderwithdata_input_matched_procs_index. This latter matches with the order of the runcard, which is the same as the exp. covmat. On the reading side,produce_loaded_theory_covmatalways reindexes. - The critical part is
nnpdf/validphys2/src/validphys/theorycovariance/construction.py
Lines 544 to 549 in abee4f0
where both matrices are added. However,fromfile_covmatuses the same index as intheory_covmat_custom_per_prescription, namelyprocs_index. If their index mismatches, then the sum would complain rasing an error.
Given these points, I think it's safe to remove this function.
I was tryin to add the user covmat generated for the PC uncertainties on top of the point prescription.
vp-setupfitcrashed during reportengine graph resolution:This goes away if I remove the user covmat from the runcard.
Possible explanation
When both covmats are provided,
total_theory_covmatis the provider which carries a check:@check_fit_dataset_order_matches_groupedand the related@make_argcheck. Now, my understanding is thatgroup_dataset_inputs_by_metadatais a production rule that is not resolved in the namespec at the time of the argcheck, which datacuts::theory::theorycovmatconfig (argcheck does not trigger produce_rules). I think this chain used to be correct by accident before @jacoterh and I modified this part of the code for the bug with the diagonal basis. Before the *_fitting providers (includingtotal_theory_covmat_fitting) usedtaking
groups_indexand forcing the production ofgroup_dataset_inputs_by_metadata. Nowprocs_index_matchedis replaced bydata_input_matched_procs_index(data_input, procs_index), which doesn't callgroups_index.At the same time, this was obselete and wasn't captured by the tests. In
total_theory_covmat_fitting, the covmat is already reindexed usingdata_input_matched_procs_index. Therefore, it can be removed.