diff --git a/validphys2/src/validphys/tests/regressions/test_sum_rules_MC.csv b/validphys2/src/validphys/tests/regressions/test_sum_rules_MC.csv new file mode 100644 index 0000000000..1493b61173 --- /dev/null +++ b/validphys2/src/validphys/tests/regressions/test_sum_rules_MC.csv @@ -0,0 +1,15 @@ + mean std min max Central value +momentum 1.0000359397024803 5.384464994542894e-07 1.000034619691424 1.0000372097117414 1.0000359463817983 +uvalence 1.9997929722405798 0.00028226750040615813 1.9987658750095758 2.000123119074607 1.9997934800108916 +dvalence 0.9997171906346781 0.00028320184172691307 0.9986900055519239 1.0000492249686646 0.9997173761604233 +svalence 0.00024972763167990374 0.0003322524099365173 -0.00042330789669951796 0.00144823410093127 0.0002510958414509573 +u momentum fraction 0.2555 0.0021 -1.0 -1.0 -1.0 +ubar momentum fraction 3.387E-2 7.5E-4 -1.0 -1.0 -1.0 +d momentum fraction 0.1278 0.0021 -1.0 -1.0 -1.0 +dbar momentum fraction 0.0422 0.0012 -1.0 -1.0 -1.0 +s momentum fraction 0.0316 0.0020 -1.0 -1.0 -1.0 +sbar momentum fraction 0.0253 0.0012 -1.0 -1.0 -1.0 +cp momentum fraction 0.0286 0.0017 -1.0 -1.0 -1.0 +g momentum fraction 0.4466 0.0017 -1.0 -1.0 -1.0 +T3 0.79 0.23 -1.0 -1.0 -1.0 +T8 4.73 0.70 -1.0 -1.0 -1.0 diff --git a/validphys2/src/validphys/tests/regressions/test_sum_rules_hessian.csv b/validphys2/src/validphys/tests/regressions/test_sum_rules_hessian.csv new file mode 100644 index 0000000000..2cbd36e8e6 --- /dev/null +++ b/validphys2/src/validphys/tests/regressions/test_sum_rules_hessian.csv @@ -0,0 +1,15 @@ + mean std min max Central value +momentum 1.0000359343288223 3.262768320141462e-08 1.0000357928883208 1.0000360043344905 1.0000359428250625 +uvalence 1.999794587352472 3.771059740749569e-05 1.9996273397296627 1.9998792759145556 1.999804641339146 +dvalence 0.999719265014927 3.893093441227586e-05 0.9995458470781201 0.9998028245378152 0.9997279363904001 +svalence 0.00021669265424246442 4.864440927527348e-05 3.0026081505308416e-05 0.000370776050729299 0.0002126701429466457 +u momentum fraction 0.2554 0.00025 -1.0 -1.0 -1.0 +ubar momentum fraction 0.03386 0.0001 -1.0 -1.0 -1.0 +d momentum fraction 0.1277 0.00029 -1.0 -1.0 -1.0 +dbar momentum fraction 0.04224 0.00016 -1.0 -1.0 -1.0 +s momentum fraction 0.03172 0.00027 -1.0 -1.0 -1.0 +sbar momentum fraction 0.0253 0.00016 -1.0 -1.0 -1.0 +cp momentum fraction 0.02882 0.00023 -1.0 -1.0 -1.0 +g momentum fraction 0.44649 0.00025 -1.0 -1.0 -1.0 +T3 0.807 0.033 -1.0 -1.0 -1.0 +T8 4.65 0.1 -1.0 -1.0 -1.0 diff --git a/validphys2/src/validphys/tests/test_sumrules.py b/validphys2/src/validphys/tests/test_sumrules.py new file mode 100644 index 0000000000..7b7dd0f78f --- /dev/null +++ b/validphys2/src/validphys/tests/test_sumrules.py @@ -0,0 +1,53 @@ +""" + Test for the sum rules +""" +import pytest +import pandas as pd +from validphys.api import API +from validphys.tableloader import sane_load + +from .conftest import PDF, HESSIAN_PDF +from .test_regressions import make_table_comp + +Q = 10 # GeV + + +def parse_sumrules(filename): + """Parse the regression""" + return sane_load(filename, header=0) + + +@pytest.mark.parametrize("pdf_name", [PDF, HESSIAN_PDF]) +def test_central_value(pdf_name): + """Check that the central value is the same as the mean""" + all_sr = API.sum_rules_table(pdf=pdf_name, Q=Q) + cv_sr = API.central_sum_rules_table(pdf=pdf_name, Q=Q) + pd.testing.assert_series_equal(cv_sr.squeeze(), all_sr["mean"], atol=1e-5, check_names=False) + + +def _regression_sum_rules(pdf_name): + known_sumrules = API.sum_rules_table(pdf=pdf_name, Q=Q) + central_val = API.central_sum_rules_table(pdf=pdf_name, Q=Q) + # First concatenate the central value to the sum rules + ret = pd.concat([known_sumrules, central_val], axis=1) + # The unknown sum rules need to be treated a bit because + # 1) They don't contain min or max + # 2) They are of type object? + unk_sumrules = API.unknown_sum_rules_table(pdf=pdf_name, Q=Q) + for col in ret.columns: + if col in unk_sumrules.columns: + unk_sumrules[col] = unk_sumrules[col].astype(float) + if col not in unk_sumrules.columns: + unk_sumrules[col] = -1.0 + # all together now: + return pd.concat([ret, unk_sumrules]) + + +@make_table_comp(parse_sumrules) +def test_sum_rules_MC(): + return _regression_sum_rules(PDF) + + +@make_table_comp(parse_sumrules) +def test_sum_rules_hessian(): + return _regression_sum_rules(HESSIAN_PDF)