Skip to content

Commit

Permalink
feat: Promote validate kwarg to top-level functions in `pyhf.simple…
Browse files Browse the repository at this point in the history
…models` (#1858)

* Add `validate` kwarg to pyhf.simplemodels.uncorrelated_background and
pyhf.simplemodels.correlated_background API. This allows expert users to avoid
validating their models in specific circumstances.
* Add Nathan Simpson to contributors list.
  • Loading branch information
phinate authored Sep 2, 2022
1 parent c68e43b commit e366eb9
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
1 change: 1 addition & 0 deletions docs/contributors.rst
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,4 @@ Contributors include:
- Lars Henkelmann
- Aryan Roy
- Jerry Ling
- Nathan Simpson
16 changes: 12 additions & 4 deletions src/pyhf/simplemodels.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ def __dir__():
return __all__


def correlated_background(signal, bkg, bkg_up, bkg_down, batch_size=None):
def correlated_background(
signal, bkg, bkg_up, bkg_down, batch_size=None, validate=True
):
r"""
Construct a simple single channel :class:`~pyhf.pdf.Model` with a
:class:`~pyhf.modifiers.histosys` modifier representing a background
Expand All @@ -23,6 +25,8 @@ def correlated_background(signal, bkg, bkg_up, bkg_down, batch_size=None):
bkg_down (:obj:`list`): The background sample under a downward variation
corresponding to :math:`\alpha=-1`.
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.
Returns:
~pyhf.pdf.Model: The statistical model adhering to the :obj:`model.json` schema.
Expand Down Expand Up @@ -75,10 +79,12 @@ def correlated_background(signal, bkg, bkg_up, bkg_down, batch_size=None):
}
]
}
return Model(spec, batch_size=batch_size)
return Model(spec, batch_size=batch_size, validate=validate)


def uncorrelated_background(signal, bkg, bkg_uncertainty, batch_size=None):
def uncorrelated_background(
signal, bkg, bkg_uncertainty, batch_size=None, validate=True
):
"""
Construct a simple single channel :class:`~pyhf.pdf.Model` with a
:class:`~pyhf.modifiers.shapesys` modifier representing an uncorrelated
Expand Down Expand Up @@ -106,6 +112,8 @@ def uncorrelated_background(signal, bkg, bkg_uncertainty, batch_size=None):
bkg (:obj:`list`): The data in the background sample
bkg_uncertainty (:obj:`list`): The statistical uncertainty on the background sample counts
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.
Returns:
~pyhf.pdf.Model: The statistical model adhering to the :obj:`model.json` schema
Expand Down Expand Up @@ -138,7 +146,7 @@ def uncorrelated_background(signal, bkg, bkg_uncertainty, batch_size=None):
}
]
}
return Model(spec, batch_size=batch_size)
return Model(spec, batch_size=batch_size, validate=validate)


# Deprecated APIs
Expand Down

0 comments on commit e366eb9

Please sign in to comment.