Skip to content

Commit d9ccf67

Browse files
docs: Add docstring for public method
1 parent 0bf30b8 commit d9ccf67

File tree

2 files changed

+77
-0
lines changed

2 files changed

+77
-0
lines changed

docs/api.rst

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,17 @@ Utilities
226226
digest
227227
citation
228228

229+
Experimental
230+
------------
231+
232+
.. currentmodule:: pyhf.experimental
233+
234+
.. autosummary::
235+
:toctree: _generated/
236+
:nosignatures:
237+
238+
modifiers
239+
229240
Contrib
230241
-------
231242

src/pyhf/experimental/modifiers.py

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,72 @@ def apply(self, pars):
173173
def add_custom_modifier(
174174
func_name: str, deps: list[str], new_params: dict[str, dict[str, Sequence[float]]]
175175
) -> dict[str, tuple[BaseBuilder, BaseApplier]]:
176+
r"""
177+
Add a custom modifier type with the modifier data defined through a custom
178+
numexpr string expression.
179+
180+
Example:
181+
182+
>>> import pyhf
183+
>>> import pyhf.experimental.modifiers
184+
>>> pyhf.set_backend("numpy")
185+
>>> new_params = {
186+
... "m1": {"inits": (1.0,), "bounds": ((-5.0, 5.0),)},
187+
... "m2": {"inits": (1.0,), "bounds": ((-5.0, 5.0),)},
188+
... }
189+
>>> expanded_pyhf = pyhf.experimental.modifiers.add_custom_modifier(
190+
... "custom", ["m1", "m2"], new_params
191+
... )
192+
>>> model = pyhf.Model(
193+
... {
194+
... "channels": [
195+
... {
196+
... "name": "singlechannel",
197+
... "samples": [
198+
... {
199+
... "name": "signal",
200+
... "data": [10, 20],
201+
... "modifiers": [
202+
... {
203+
... "name": "f2",
204+
... "type": "custom",
205+
... "data": {"expr": "m1"},
206+
... },
207+
... ],
208+
... },
209+
... {
210+
... "name": "background",
211+
... "data": [100, 150],
212+
... "modifiers": [
213+
... {
214+
... "name": "f1",
215+
... "type": "custom",
216+
... "data": {"expr": "m1+(m2**2)"},
217+
... },
218+
... ],
219+
... },
220+
... ],
221+
... }
222+
... ]
223+
... },
224+
... modifier_set=expanded_pyhf,
225+
... poi_name="m1",
226+
... validate=False,
227+
... batch_size=1,
228+
... )
229+
>>> model.config.modifiers
230+
[('f1', 'custom'), ('f2', 'custom')]
231+
232+
Args:
233+
func_name (:obj:`str`): The name of the custom modifier type.
234+
deps (:obj:`list`): The names of the new parameters of the modifier
235+
function.
236+
new_params (:obj:`dict`): The new parameters.
237+
238+
Returns:
239+
:obj:`dict`: The updated ``pyhf.modifiers.histfactory_set`` with the added
240+
custom modifier type.
241+
"""
176242
_builder = make_builder(func_name, deps, new_params)
177243
_applier = make_applier(func_name, deps, new_params)
178244

0 commit comments

Comments
 (0)