Skip to content

Commit e366eb9

Browse files
authored
feat: Promote validate kwarg to top-level functions in pyhf.simplemodels (#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.
1 parent c68e43b commit e366eb9

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

docs/contributors.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,4 @@ Contributors include:
2828
- Lars Henkelmann
2929
- Aryan Roy
3030
- Jerry Ling
31+
- Nathan Simpson

src/pyhf/simplemodels.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ def __dir__():
99
return __all__
1010

1111

12-
def correlated_background(signal, bkg, bkg_up, bkg_down, batch_size=None):
12+
def correlated_background(
13+
signal, bkg, bkg_up, bkg_down, batch_size=None, validate=True
14+
):
1315
r"""
1416
Construct a simple single channel :class:`~pyhf.pdf.Model` with a
1517
:class:`~pyhf.modifiers.histosys` modifier representing a background
@@ -23,6 +25,8 @@ def correlated_background(signal, bkg, bkg_up, bkg_down, batch_size=None):
2325
bkg_down (:obj:`list`): The background sample under a downward variation
2426
corresponding to :math:`\alpha=-1`.
2527
batch_size (:obj:`None` or :obj:`int`): Number of simultaneous (batched) Models to compute.
28+
validate (:obj:`bool`): If :obj:`True`, validate the model before returning.
29+
Only set this to :obj:`False` if you have an experimental use case and know what you're doing.
2630
2731
Returns:
2832
~pyhf.pdf.Model: The statistical model adhering to the :obj:`model.json` schema.
@@ -75,10 +79,12 @@ def correlated_background(signal, bkg, bkg_up, bkg_down, batch_size=None):
7579
}
7680
]
7781
}
78-
return Model(spec, batch_size=batch_size)
82+
return Model(spec, batch_size=batch_size, validate=validate)
7983

8084

81-
def uncorrelated_background(signal, bkg, bkg_uncertainty, batch_size=None):
85+
def uncorrelated_background(
86+
signal, bkg, bkg_uncertainty, batch_size=None, validate=True
87+
):
8288
"""
8389
Construct a simple single channel :class:`~pyhf.pdf.Model` with a
8490
:class:`~pyhf.modifiers.shapesys` modifier representing an uncorrelated
@@ -106,6 +112,8 @@ def uncorrelated_background(signal, bkg, bkg_uncertainty, batch_size=None):
106112
bkg (:obj:`list`): The data in the background sample
107113
bkg_uncertainty (:obj:`list`): The statistical uncertainty on the background sample counts
108114
batch_size (:obj:`None` or :obj:`int`): Number of simultaneous (batched) Models to compute
115+
validate (:obj:`bool`): If :obj:`True`, validate the model before returning.
116+
Only set this to :obj:`False` if you have an experimental use case and know what you're doing.
109117
110118
Returns:
111119
~pyhf.pdf.Model: The statistical model adhering to the :obj:`model.json` schema
@@ -138,7 +146,7 @@ def uncorrelated_background(signal, bkg, bkg_uncertainty, batch_size=None):
138146
}
139147
]
140148
}
141-
return Model(spec, batch_size=batch_size)
149+
return Model(spec, batch_size=batch_size, validate=validate)
142150

143151

144152
# Deprecated APIs

0 commit comments

Comments
 (0)