Skip to content

Commit

Permalink
tests should pass
Browse files Browse the repository at this point in the history
  • Loading branch information
lukasheinrich committed Oct 12, 2021
1 parent 1ae91c3 commit d7d9ce0
Show file tree
Hide file tree
Showing 12 changed files with 69 additions and 24 deletions.
1 change: 1 addition & 0 deletions src/pyhf/cli/spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from pyhf.workspace import Workspace
from pyhf import modifiers
from pyhf import utils
from pyhf import parameters

log = logging.getLogger(__name__)

Expand Down
34 changes: 32 additions & 2 deletions src/pyhf/modifiers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,35 @@
from .shapefactor import shapefactor_builder, shapefactor_combined
from .normsys import normsys_builder, normsys_combined
from .shapesys import shapesys_builder, shapesys_combined
from .staterror import staterr_builder, staterror_combined
from .staterror import staterror_builder, staterror_combined

__all__ = [
'histosys',
'histosys_builder',
'histosys_combined',
'lumi',
'lumi_builder',
'lumi_combined',
'normfactor',
'normfactor_builder',
'normfactor_combined',
'normsys',
'normsys_builder',
'normsys_combined',
'pyhfset',
'shapefactor',
'shapefactor_builder',
'shapefactor_combined',
'shapesys',
'shapesys_builder',
'shapesys_combined',
'staterror',
'staterror_builder',
'staterror_combined',
]

def __dir__():
return __all__

pyhfset = {
'histosys': (histosys_builder, histosys_combined),
Expand All @@ -13,5 +41,7 @@
'normsys': (normsys_builder, normsys_combined),
'shapefactor': (shapefactor_builder, shapefactor_combined),
'shapesys': (shapesys_builder, shapesys_combined),
'staterror': (staterr_builder, staterror_combined),
'staterror': (staterror_builder, staterror_combined),
}


1 change: 1 addition & 0 deletions src/pyhf/modifiers/histosys.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ def required_parset(sample_data, modifier_data):
'paramset_type': constrained_by_normal,
'n_parameters': 1,
'is_shared': True,
'is_scalar': True,
'inits': (0.0,),
'bounds': ((-5.0, 5.0),),
'fixed': False,
Expand Down
1 change: 1 addition & 0 deletions src/pyhf/modifiers/lumi.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ def required_parset(sample_data, modifier_data):
'paramset_type': constrained_by_normal,
'n_parameters': 1,
'is_shared': True,
'is_scalar': True,
'inits': None, # lumi
'bounds': None, # (0, 10*lumi)
'fixed': False,
Expand Down
1 change: 1 addition & 0 deletions src/pyhf/modifiers/normfactor.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ def required_parset(sample_data, modifier_data):
'paramset_type': unconstrained,
'n_parameters': 1,
'is_shared': True,
'is_scalar': True,
'inits': (1.0,),
'bounds': ((0, 10),),
'fixed': False,
Expand Down
1 change: 1 addition & 0 deletions src/pyhf/modifiers/normsys.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ def required_parset(sample_data, modifier_data):
'paramset_type': constrained_by_normal,
'n_parameters': 1,
'is_shared': True,
'is_scalar': True,
'inits': (0.0,),
'bounds': ((-5.0, 5.0),),
'fixed': False,
Expand Down
1 change: 1 addition & 0 deletions src/pyhf/modifiers/shapefactor.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ def required_parset(sample_data, modifier_data):
'paramset_type': unconstrained,
'n_parameters': len(sample_data),
'is_shared': True,
'is_scalar': False,
'inits': (1.0,) * len(sample_data),
'bounds': ((0.0, 10.0),) * len(sample_data),
'fixed': False,
Expand Down
1 change: 1 addition & 0 deletions src/pyhf/modifiers/shapesys.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ def required_parset(sample_data, modifier_data):
'paramset_type': constrained_by_poisson,
'n_parameters': n_parameters,
'is_shared': False,
'is_scalar': False,
'inits': (1.0,) * n_parameters,
'bounds': ((1e-10, 10.0),) * n_parameters,
'fixed': False,
Expand Down
3 changes: 2 additions & 1 deletion src/pyhf/modifiers/staterror.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@ def required_parset(sample_data, modifier_data):
'paramset_type': constrained_by_normal,
'n_parameters': len(sample_data),
'is_shared': True,
'is_scalar': False,
'inits': (1.0,) * len(sample_data),
'bounds': ((1e-10, 10.0),) * len(sample_data),
'fixed': False,
'auxdata': (1.0,) * len(sample_data),
}


class staterr_builder:
class staterror_builder:
def __init__(self, config):
self._mega_mods = {}
self.config = config
Expand Down
4 changes: 2 additions & 2 deletions tests/test_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ def test_export_sample_zerodata(mocker, spec):

mocker.patch('pyhf.writexml._ROOT_DATA_FILE')
# make sure no RuntimeWarning, https://stackoverflow.com/a/45671804
with pytest.warns(DeprecationWarning) as record:
with pytest.warns(None) as record:
for modifierspec in samplespec['modifiers']:
pyhf.writexml.build_modifier(
{'measurements': [{'config': {'parameters': []}}]},
Expand All @@ -362,7 +362,7 @@ def test_export_sample_zerodata(mocker, spec):
samplename,
sampledata,
)
assert record
assert not record.list


@pytest.mark.parametrize(
Expand Down
39 changes: 23 additions & 16 deletions tests/test_public_api_repr.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,22 +149,29 @@ def test_interpolators_public_api():


def test_modifiers_public_api():
assert dir(pyhf.modifiers) == [
"combined",
"histosys",
"histosys_combined",
"lumi",
"lumi_combined",
"normfactor",
"normfactor_combined",
"normsys",
"normsys_combined",
"shapefactor",
"shapefactor_combined",
"shapesys",
"shapesys_combined",
"staterror",
"staterror_combined",
assert dir(pyhf.modifiers) == [
'histosys',
'histosys_builder',
'histosys_combined',
'lumi',
'lumi_builder',
'lumi_combined',
'normfactor',
'normfactor_builder',
'normfactor_combined',
'normsys',
'normsys_builder',
'normsys_combined',
'pyhfset',
'shapefactor',
'shapefactor_builder',
'shapefactor_combined',
'shapesys',
'shapesys_builder',
'shapesys_combined',
'staterror',
'staterror_builder',
'staterror_combined',
]


Expand Down
6 changes: 3 additions & 3 deletions tests/test_simplemodels.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ def test_correlated_background():
)
assert model.config.channels == ["single_channel"]
assert model.config.samples == ["background", "signal"]
assert model.config.par_order == ["mu", "correlated_bkg_uncertainty"]
assert model.config.par_names() == ['mu', 'correlated_bkg_uncertainty']
assert model.config.suggested_init() == [1.0, 0.0]
assert model.config.par_order == ["correlated_bkg_uncertainty", "mu"]
assert model.config.par_names() == ['correlated_bkg_uncertainty', "mu"]
assert model.config.suggested_init() == [0.0, 1.0]


def test_uncorrelated_background():
Expand Down

0 comments on commit d7d9ce0

Please sign in to comment.