From a95f1b4b12e402b1b99a2d3d9dad51647516180b Mon Sep 17 00:00:00 2001 From: Giordon Stark Date: Tue, 10 Dec 2024 20:45:53 -0500 Subject: [PATCH 1/3] add test to ensure the level is being set correctly --- tests/test_infer.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/tests/test_infer.py b/tests/test_infer.py index 0ccd072b94..0726d0565a 100644 --- a/tests/test_infer.py +++ b/tests/test_infer.py @@ -642,3 +642,28 @@ def test_deprecated_upperlimit(hypotest_args): "pyhf.infer.intervals.upperlimit is deprecated in favor of pyhf.infer.intervals.upper_limits.upper_limit" in str(_warning[-1].message) ) + + +def test_issue2563_toms748_scan_setLevel(tmp_path, hypotest_args): + """ + Test that setting the level actually gives us what we expect. + """ + _, data, model = hypotest_args + + obs_limit_95, exp_limits_95 = pyhf.infer.intervals.upper_limits.upper_limit( + data, model, rtol=1e-8, level=0.05, scan=None + ) + + obs_limit_90, exp_limits_90 = pyhf.infer.intervals.upper_limits.upper_limit( + data, model, rtol=1e-8, level=0.10, scan=None + ) + + assert obs_limit_95 != pytest.approx( + obs_limit_90 + ), "Observed limit at 95% is the same as the observed limit at 90%" + for index, (exp_limit_95, exp_limit_90) in enumerate( + zip(exp_limits_95, exp_limits_90), 1 + ): + assert exp_limit_95 != pytest.approx( + exp_limit_90 + ), f"Expected limit for 95% is the same as the expected limit at 90% for position {index}" From 5ed93b18be6c4d80202a72d7018f9105c61cbc11 Mon Sep 17 00:00:00 2001 From: Giordon Stark Date: Tue, 10 Dec 2024 20:46:26 -0500 Subject: [PATCH 2/3] clarify docstring more --- tests/test_infer.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_infer.py b/tests/test_infer.py index 0726d0565a..44442f9af0 100644 --- a/tests/test_infer.py +++ b/tests/test_infer.py @@ -646,7 +646,7 @@ def test_deprecated_upperlimit(hypotest_args): def test_issue2563_toms748_scan_setLevel(tmp_path, hypotest_args): """ - Test that setting the level actually gives us what we expect. + Test that setting the level actually gives us what we expect for scan=None (using the toms748 algorithm) """ _, data, model = hypotest_args From 5fce17652842402b0042e95768d6549d94622a6d Mon Sep 17 00:00:00 2001 From: Giordon Stark Date: Tue, 10 Dec 2024 20:47:17 -0500 Subject: [PATCH 3/3] fix --- src/pyhf/infer/intervals/upper_limits.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/pyhf/infer/intervals/upper_limits.py b/src/pyhf/infer/intervals/upper_limits.py index 6b86d586fe..1e3b488bc9 100644 --- a/src/pyhf/infer/intervals/upper_limits.py +++ b/src/pyhf/infer/intervals/upper_limits.py @@ -262,6 +262,7 @@ def upper_limit( model, bounds[0], bounds[1], + level=level, from_upper_limit_fn=True, **hypotest_kwargs, )