From 76f3c4e8dab9f8050e472aa8fa05b305582c3964 Mon Sep 17 00:00:00 2001 From: Matthew Feickert Date: Wed, 13 Sep 2023 12:14:22 -0500 Subject: [PATCH 1/5] feat: Remove default POI name --- src/pyhf/pdf.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/pyhf/pdf.py b/src/pyhf/pdf.py index 3b55f2369a..2fd8b3c250 100644 --- a/src/pyhf/pdf.py +++ b/src/pyhf/pdf.py @@ -768,7 +768,9 @@ def __init__( log.info(f"Validating spec against schema: {self.schema:s}") schema.validate(self.spec, self.schema, version=self.version) # build up our representation of the specification - poi_name = config_kwargs.pop('poi_name', 'mu') + # Default to no POI name + # https://github.com/scikit-hep/pyhf/issues/2327 + poi_name = config_kwargs.pop("poi_name", "") self._config = _ModelConfig(self.spec, **config_kwargs) modifiers, _nominal_rates = _nominal_and_modifiers_from_spec( From 49067542e5018c02e24bacf87beeb373642359b5 Mon Sep 17 00:00:00 2001 From: Matthew Feickert Date: Wed, 13 Sep 2023 16:22:49 -0500 Subject: [PATCH 2/5] refactor: Set poi_name='mu' explicitly for simplemodels --- src/pyhf/simplemodels.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/pyhf/simplemodels.py b/src/pyhf/simplemodels.py index 299d3176c1..479fcca79c 100644 --- a/src/pyhf/simplemodels.py +++ b/src/pyhf/simplemodels.py @@ -79,7 +79,7 @@ def correlated_background( } ] } - return Model(spec, batch_size=batch_size, validate=validate) + return Model(spec, batch_size=batch_size, validate=validate, poi_name="mu") def uncorrelated_background( @@ -146,7 +146,7 @@ def uncorrelated_background( } ] } - return Model(spec, batch_size=batch_size, validate=validate) + return Model(spec, batch_size=batch_size, validate=validate, poi_name="mu") # Deprecated APIs From dc454fd48a5edfd1a80d2e886635fd30555071d5 Mon Sep 17 00:00:00 2001 From: Matthew Feickert Date: Wed, 13 Sep 2023 16:32:46 -0500 Subject: [PATCH 3/5] test: Add poi_name='mu' to pyhf.Model creation --- tests/test_backend_consistency.py | 2 +- tests/test_optim.py | 8 ++++---- tests/test_validation.py | 4 +++- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/tests/test_backend_consistency.py b/tests/test_backend_consistency.py index 3a2bca22f3..512b06b707 100644 --- a/tests/test_backend_consistency.py +++ b/tests/test_backend_consistency.py @@ -99,7 +99,7 @@ def test_hypotest_qmu_tilde( else [signal_sample, background_sample] ) spec = {'channels': [{'name': 'singlechannel', 'samples': samples}]} - pdf = pyhf.Model(spec) + pdf = pyhf.Model(spec, poi_name="mu") data = source['bindata']['data'] + pdf.config.auxdata diff --git a/tests/test_optim.py b/tests/test_optim.py index e4c5409076..b94b722cf8 100644 --- a/tests/test_optim.py +++ b/tests/test_optim.py @@ -312,7 +312,7 @@ def spec(source): @pytest.mark.parametrize('mu', [1.0], ids=['mu=1']) def test_optim(backend, source, spec, mu): - pdf = pyhf.Model(spec) + pdf = pyhf.Model(spec, poi_name="mu") data = source['bindata']['data'] + pdf.config.auxdata init_pars = pdf.config.suggested_init() @@ -336,7 +336,7 @@ def test_optim(backend, source, spec, mu): @pytest.mark.parametrize('mu', [1.0], ids=['mu=1']) def test_optim_with_value(backend, source, spec, mu): - pdf = pyhf.Model(spec) + pdf = pyhf.Model(spec, poi_name="mu") data = source['bindata']['data'] + pdf.config.auxdata init_pars = pdf.config.suggested_init() @@ -364,7 +364,7 @@ def test_optim_with_value(backend, source, spec, mu): @pytest.mark.parametrize('mu', [1.0], ids=['mu=1']) @pytest.mark.only_numpy_minuit def test_optim_uncerts(backend, source, spec, mu): - pdf = pyhf.Model(spec) + pdf = pyhf.Model(spec, poi_name="mu") data = source['bindata']['data'] + pdf.config.auxdata init_pars = pdf.config.suggested_init() @@ -391,7 +391,7 @@ def test_optim_uncerts(backend, source, spec, mu): @pytest.mark.parametrize('mu', [1.0], ids=['mu=1']) @pytest.mark.only_numpy_minuit def test_optim_correlations(backend, source, spec, mu): - pdf = pyhf.Model(spec) + pdf = pyhf.Model(spec, poi_name="mu") data = source['bindata']['data'] + pdf.config.auxdata init_pars = pdf.config.suggested_init() diff --git a/tests/test_validation.py b/tests/test_validation.py index 37d7500de1..1e3b54392b 100644 --- a/tests/test_validation.py +++ b/tests/test_validation.py @@ -788,7 +788,9 @@ def test_validation(setup): source = setup['source'] pdf = pyhf.Model( - setup['spec'], modifier_settings={'normsys': {'interpcode': 'code1'}} + setup["spec"], + modifier_settings={"normsys": {"interpcode": "code1"}}, + poi_name="mu", ) if 'channels' in source: From 234da85aa6286ec53249834d73ba53e0e679cb24 Mon Sep 17 00:00:00 2001 From: Matthew Feickert Date: Wed, 13 Sep 2023 16:55:06 -0500 Subject: [PATCH 4/5] Use None as poi_name default --- src/pyhf/pdf.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pyhf/pdf.py b/src/pyhf/pdf.py index 2fd8b3c250..2b03da9020 100644 --- a/src/pyhf/pdf.py +++ b/src/pyhf/pdf.py @@ -770,7 +770,7 @@ def __init__( # build up our representation of the specification # Default to no POI name # https://github.com/scikit-hep/pyhf/issues/2327 - poi_name = config_kwargs.pop("poi_name", "") + poi_name = config_kwargs.pop("poi_name", None) self._config = _ModelConfig(self.spec, **config_kwargs) modifiers, _nominal_rates = _nominal_and_modifiers_from_spec( From 951ad7ae36abb72a07a127a6e96ea7664f509644 Mon Sep 17 00:00:00 2001 From: Matthew Feickert Date: Sat, 16 Sep 2023 01:40:10 -0500 Subject: [PATCH 5/5] Add poi_name argument to simplemodels API --- src/pyhf/simplemodels.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/pyhf/simplemodels.py b/src/pyhf/simplemodels.py index 479fcca79c..805bb0ffd9 100644 --- a/src/pyhf/simplemodels.py +++ b/src/pyhf/simplemodels.py @@ -10,7 +10,7 @@ def __dir__(): def correlated_background( - signal, bkg, bkg_up, bkg_down, batch_size=None, validate=True + signal, bkg, bkg_up, bkg_down, batch_size=None, validate=True, poi_name="mu" ): r""" Construct a simple single channel :class:`~pyhf.pdf.Model` with a @@ -27,10 +27,14 @@ def correlated_background( batch_size (:obj:`None` or :obj:`int`): Number of simultaneous (batched) Models to compute. validate (:obj:`bool`): If :obj:`True`, validate the model before returning. Only set this to :obj:`False` if you have an experimental use case and know what you're doing. + poi_name (:obj:`str`): The :class:`~pyhf.pdf.Model` parameter of interest name. + Defaults to ``"mu"``. Returns: ~pyhf.pdf.Model: The statistical model adhering to the :obj:`model.json` schema. + .. versionchanged:: 0.8.0 Added ``poi_name`` argument. + Example: >>> import pyhf >>> pyhf.set_backend("numpy") @@ -79,11 +83,11 @@ def correlated_background( } ] } - return Model(spec, batch_size=batch_size, validate=validate, poi_name="mu") + return Model(spec, batch_size=batch_size, validate=validate, poi_name=poi_name) def uncorrelated_background( - signal, bkg, bkg_uncertainty, batch_size=None, validate=True + signal, bkg, bkg_uncertainty, batch_size=None, validate=True, poi_name="mu" ): """ Construct a simple single channel :class:`~pyhf.pdf.Model` with a @@ -114,10 +118,13 @@ def uncorrelated_background( batch_size (:obj:`None` or :obj:`int`): Number of simultaneous (batched) Models to compute validate (:obj:`bool`): If :obj:`True`, validate the model before returning. Only set this to :obj:`False` if you have an experimental use case and know what you're doing. + poi_name (:obj:`str`): The :class:`~pyhf.pdf.Model` parameter of interest name. + Defaults to ``"mu"``. Returns: ~pyhf.pdf.Model: The statistical model adhering to the :obj:`model.json` schema + .. versionchanged:: 0.8.0 Added ``poi_name`` argument. """ spec = { 'channels': [ @@ -146,7 +153,7 @@ def uncorrelated_background( } ] } - return Model(spec, batch_size=batch_size, validate=validate, poi_name="mu") + return Model(spec, batch_size=batch_size, validate=validate, poi_name=poi_name) # Deprecated APIs