Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Don't specify a default POI name #2328

Merged
merged 5 commits into from
Sep 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/pyhf/pdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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", None)
self._config = _ModelConfig(self.spec, **config_kwargs)

modifiers, _nominal_rates = _nominal_and_modifiers_from_spec(
Expand Down
15 changes: 11 additions & 4 deletions src/pyhf/simplemodels.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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")
Expand Down Expand Up @@ -79,11 +83,11 @@ def correlated_background(
}
]
}
return Model(spec, batch_size=batch_size, validate=validate)
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
Expand Down Expand Up @@ -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': [
Expand Down Expand Up @@ -146,7 +153,7 @@ def uncorrelated_background(
}
]
}
return Model(spec, batch_size=batch_size, validate=validate)
return Model(spec, batch_size=batch_size, validate=validate, poi_name=poi_name)


# Deprecated APIs
Expand Down
2 changes: 1 addition & 1 deletion tests/test_backend_consistency.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
8 changes: 4 additions & 4 deletions tests/test_optim.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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()
Expand Down Expand Up @@ -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()
Expand All @@ -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()
Expand Down
4 changes: 3 additions & 1 deletion tests/test_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -788,7 +788,9 @@
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:
Expand Down Expand Up @@ -1033,7 +1035,7 @@
result_nograd = pyhf.infer.mle.fit(data, pdf, do_grad=False)
result_grad = pyhf.infer.mle.fit(data, pdf, do_grad=True)

# TODO: let's make this agreement better

Check notice on line 1038 in tests/test_validation.py

View check run for this annotation

codefactor.io / CodeFactor

tests/test_validation.py#L1038

unresolved comment '# TODO: let's make this agreement better' (C100)
assert np.allclose(
pyhf.tensorlib.tolist(result_nograd),
pyhf.tensorlib.tolist(result_grad),
Expand Down