From dfc7110eeb4d0393476a8caf9cdf698310ffd208 Mon Sep 17 00:00:00 2001 From: Andrew Pietraszkiewicz Date: Tue, 28 Jul 2026 00:39:09 +0200 Subject: [PATCH 1/2] initial commit Won't work for legacy dataset inputs! --- .../validphys/comparefittemplates/report.md | 1 + .../comparefittemplates/report_lite.md | 1 + validphys2/src/validphys/fitdata.py | 31 +++++++++++++++++++ 3 files changed, 33 insertions(+) diff --git a/validphys2/src/validphys/comparefittemplates/report.md b/validphys2/src/validphys/comparefittemplates/report.md index 3f19d074a5..4ccdd42a69 100644 --- a/validphys2/src/validphys/comparefittemplates/report.md +++ b/validphys2/src/validphys/comparefittemplates/report.md @@ -120,6 +120,7 @@ Dataset differences and cuts ---------------------------- {@print_dataset_differences@} {@print_different_cuts@} +{@print_different_variants@} Code versions ------------- diff --git a/validphys2/src/validphys/comparefittemplates/report_lite.md b/validphys2/src/validphys/comparefittemplates/report_lite.md index a00a2d886f..7e9ea779a0 100644 --- a/validphys2/src/validphys/comparefittemplates/report_lite.md +++ b/validphys2/src/validphys/comparefittemplates/report_lite.md @@ -72,6 +72,7 @@ Dataset differences and cuts ---------------------------- {@print_dataset_differences@} {@print_different_cuts@} +{@print_different_variants@} Code versions ------------- diff --git a/validphys2/src/validphys/fitdata.py b/validphys2/src/validphys/fitdata.py index de89b37672..e83ff108e9 100644 --- a/validphys2/src/validphys/fitdata.py +++ b/validphys2/src/validphys/fitdata.py @@ -423,6 +423,37 @@ def print_different_cuts(fits, test_for_same_cuts): return res.getvalue() +@_assert_two_fits +def test_for_same_variants(fits, match_datasets_by_name): + """Given two fits, return a dictionary of where keys are names of datatets with + different variants and keys are tuples (var_1, var_2) where var_i is the variant + of the dataset used in fit i. + """ + first, second = fits + c = match_datasets_by_name.common + first_variants = {d['dataset']: d.get('variant') for d in first.as_input()['dataset_inputs']} + second_variants = {d['dataset']: d.get('variant') for d in second.as_input()['dataset_inputs']} + different_variants = {} + for ds in c: + if first_variants[ds] != second_variants[ds]: + different_variants[ds] = (first_variants[ds], second_variants[ds]) + return different_variants + +def print_different_variants(fits, test_for_same_variants): + """Print a summary of the datasets that are included in both fits but have + different variants.""" + res = StringIO() + first_fit, second_fit = fits + if test_for_same_variants: + res.write( + "The following datasets are both included but use different variants:\n\n" + ) + for ds, (first, second) in test_for_same_variants.items(): + res.write(f"{ds}: {first_fit} uses variant {first}, while {second_fit} uses variant {second}.") + res.write('\n') + + return res.getvalue() + def fit_theory_covmat_summary(fit, fitthcovmat): """returns a table with a single column for the `fit`, with three rows From 47bbc9a12f0def64066c38f3b7fb0d10969b8ad0 Mon Sep 17 00:00:00 2001 From: Andrew Pietraszkiewicz Date: Tue, 28 Jul 2026 14:12:37 +0200 Subject: [PATCH 2/2] ensure legacy compatibility --- validphys2/src/validphys/fitdata.py | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/validphys2/src/validphys/fitdata.py b/validphys2/src/validphys/fitdata.py index e83ff108e9..55eb23c5ae 100644 --- a/validphys2/src/validphys/fitdata.py +++ b/validphys2/src/validphys/fitdata.py @@ -12,6 +12,7 @@ import numpy as np import pandas as pd +from nnpdf_data import legacy_to_new_map from reportengine import collect from reportengine.checks import CheckError, make_argcheck from reportengine.floatformatting import ValueErrorTuple @@ -423,20 +424,33 @@ def print_different_cuts(fits, test_for_same_cuts): return res.getvalue() +def find_the_variant(dataset, sys=None, variant=None): + """Given the (legacy) dataset input, find the new name and the right variant. + """ + new_name, new_variant = legacy_to_new_map(dataset_name=dataset, sys=sys) + if variant is None: + return new_name, new_variant + else: + return new_name, variant + @_assert_two_fits def test_for_same_variants(fits, match_datasets_by_name): """Given two fits, return a dictionary of where keys are names of datatets with different variants and keys are tuples (var_1, var_2) where var_i is the variant of the dataset used in fit i. """ - first, second = fits c = match_datasets_by_name.common - first_variants = {d['dataset']: d.get('variant') for d in first.as_input()['dataset_inputs']} - second_variants = {d['dataset']: d.get('variant') for d in second.as_input()['dataset_inputs']} + first, second = fits + variants = dict() different_variants = {} + for f in fits: + variants[f.name] = dict() + for ds in f.as_input()["dataset_inputs"]: + name, variant = find_the_variant(ds['dataset'], sys=ds.get("sys"), variant=ds.get("variant")) + variants[f.name][name] = variant for ds in c: - if first_variants[ds] != second_variants[ds]: - different_variants[ds] = (first_variants[ds], second_variants[ds]) + if variants[first.name][ds] != variants[second.name][ds]: + different_variants[ds] = (variants[first.name][ds], variants[second.name][ds]) return different_variants def print_different_variants(fits, test_for_same_variants): @@ -454,7 +468,6 @@ def print_different_variants(fits, test_for_same_variants): return res.getvalue() - def fit_theory_covmat_summary(fit, fitthcovmat): """returns a table with a single column for the `fit`, with three rows indicating if the theory covariance matrix was used in the 'sampling' of the pseudodata,