How to use the pyhf.events function in pyhf

To help you get started, we’ve selected a few pyhf examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github scikit-hep / pyhf / tests / test_events.py View on Github external
def test_subscribe_event():
    ename = 'test'

    m = mock.Mock()
    events.subscribe(ename)(m)

    assert ename in events.__events
    assert m in events.__events.get(ename)
    del events.__events[ename]
github scikit-hep / pyhf / tests / test_interpolate.py View on Github external
ename = 'tensorlib_changed'

    # inject into our interpolator class
    interpolator_cls = pyhf.interpolators.get(interpcode)
    with mock.patch('{0:s}._precompute'.format(interpolator_cls.__module__)) as m:
        interpolator = interpolator_cls(histogramssets.tolist(), subscribe=False)
        assert m.call_count == 1
        assert m not in pyhf.events.__events.get(ename, [])
        pyhf.events.trigger(ename)()
        assert m.call_count == 1

    with mock.patch('{0:s}._precompute'.format(interpolator_cls.__module__)) as m:
        interpolator = interpolator_cls(histogramssets.tolist(), subscribe=True)
        assert m.call_count == 1
        assert m in pyhf.events.__events.get(ename, [])
        pyhf.events.trigger(ename)()
        assert m.call_count == 2
github scikit-hep / pyhf / tests / test_events.py View on Github external
def test_disable_event():
    ename = 'test'

    m = mock.Mock()
    noop, noop_m = events.noop, mock.Mock()
    events.noop = noop_m
    events.subscribe(ename)(m)

    events.disable(ename)
    assert m.called is False
    assert ename in events.__disabled_events
    assert events.trigger(ename) == events.noop
    assert events.trigger(ename)() == events.noop()
    assert m.called is False
    assert noop_m.is_called_once()
    events.enable(ename)
    assert ename not in events.__disabled_events
    del events.__events[ename]
    events.noop = noop
github scikit-hep / pyhf / tests / test_interpolate.py View on Github external
def test_interpolator_subscription(interpcode, random_histosets_alphasets_pair):
    histogramssets, alphasets = random_histosets_alphasets_pair
    ename = 'tensorlib_changed'

    # inject into our interpolator class
    interpolator_cls = pyhf.interpolators.get(interpcode)
    with mock.patch('{0:s}._precompute'.format(interpolator_cls.__module__)) as m:
        interpolator = interpolator_cls(histogramssets.tolist(), subscribe=False)
        assert m.call_count == 1
        assert m not in pyhf.events.__events.get(ename, [])
        pyhf.events.trigger(ename)()
        assert m.call_count == 1

    with mock.patch('{0:s}._precompute'.format(interpolator_cls.__module__)) as m:
        interpolator = interpolator_cls(histogramssets.tolist(), subscribe=True)
        assert m.call_count == 1
        assert m in pyhf.events.__events.get(ename, [])
        pyhf.events.trigger(ename)()
        assert m.call_count == 2
github scikit-hep / pyhf / pyhf / modifiers / normsys.py View on Github external
]
                for s in pdfconfig.samples
            ]
            for m in keys
        ]
        self._normsys_mask = [
            [[mega_mods[s][m]['data']['mask']] for s in pdfconfig.samples] for m in keys
        ]

        if len(normsys_mods):
            self.interpolator = getattr(interpolators, self.interpcode)(
                self._normsys_histoset
            )

        self._precompute()
        events.subscribe('tensorlib_changed')(self._precompute)
github scikit-hep / pyhf / pyhf / interpolate.py View on Github external
def __init__(self, histogramssets):
        # nb: this should never be a tensor, store in default backend (e.g. numpy)
        self._histogramssets = default_backend.astensor(histogramssets)
        # initial shape will be (nsysts, 1)
        self.alphasets_shape = (self._histogramssets.shape[0], 1)
        self._precompute()
        events.subscribe('tensorlib_changed')(self._precompute)