-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2046 from NNPDF/fix_closure_commondata_loader
Correct bug in commondata loading for closure tests
- Loading branch information
Showing
4 changed files
with
81 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
""" | ||
Tests for multiclosure utilities | ||
""" | ||
|
||
import numpy as np | ||
import pytest | ||
|
||
from reportengine.resourcebuilder import ResourceError | ||
from validphys.api import API | ||
|
||
# These fits contain _only_ data | ||
MULTICLOSURE_FITS = ["240412-test-multiclosure-001", "240412-test-multiclosure-002"] | ||
|
||
|
||
def test_multiclosure_data_fits_cv(fromfit_closure_config, data_fromfit_cuts_config): | ||
"""Test that we can generate level 1 data and then read it using the | ||
utilities of ``multiclosure_pseudodata``. | ||
This works as both a test of the ``data_fits_cv`` pipeline | ||
and as canary for possible regression regarding already generated data""" | ||
base_fit = MULTICLOSURE_FITS[0] | ||
|
||
# Get the data generated by the fit | ||
full_config = {"fits": MULTICLOSURE_FITS, "fit": base_fit, **fromfit_closure_config} | ||
get_fit_cv = API.data_fits_cv(**full_config) | ||
|
||
# Now get the "real" data | ||
fit = API.fit(fit=base_fit) | ||
dataset_inputs = fit.as_input()["dataset_inputs"] | ||
|
||
# Now assert that the data is different for each of the closure tests | ||
# and all of them are different from the central data! | ||
|
||
for dinput, fit_data in zip(dataset_inputs, get_fit_cv): | ||
ds = API.dataset(dataset_input=dinput, **data_fromfit_cuts_config, fit=base_fit) | ||
# Load with cuts and get the central value | ||
cv = ds.load_commondata().central_values | ||
fit_data.append(cv.values.reshape(-1, 1)) | ||
|
||
_, unique = np.unique(fit_data, axis=0, return_counts=True) | ||
|
||
if not np.allclose(unique, 1.0): | ||
raise ValueError(f"Multiclosure reading failed, data is the same when it shouldn't!") | ||
|
||
# Ensure that the use_fit_commondata key is still controlling the load | ||
with pytest.raises(ResourceError): | ||
full_config["use_fitcommondata"] = False | ||
_ = API.data_fits_cv(**full_config) |