Skip to content

Commit

Permalink
fix: Catch use of multi-component parameters as POI with error message (
Browse files Browse the repository at this point in the history
#2197)

* Raise exceptions.InvalidModel for multiple component parameter of interest.
  This guards against modifiers like 'shapefactor', 'shapesys', and 'staterror'
  from being used as POIs.
   - Remove use of 'assert' to check the same information.
* Add test to test_pdf.py to validate.
  • Loading branch information
alexander-held authored May 17, 2023
1 parent 22c1699 commit 30dc756
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/pyhf/pdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -464,10 +464,13 @@ def set_poi(self, name):
raise exceptions.InvalidModel(
f"The parameter of interest '{name:s}' cannot be fit as it is not declared in the model specification."
)
s = self.par_slice(name)
assert s.stop - s.start == 1
if self.param_set(name).n_parameters > 1:
# multi-parameter modifiers are not supported as POIs
raise exceptions.InvalidModel(
f"The parameter '{name:s}' contains multiple components and is not currently supported as parameter of interest."
)
self._poi_name = name
self._poi_index = s.start
self._poi_index = self.par_slice(name).start

def _create_and_register_paramsets(self, required_paramsets):
next_index = 0
Expand Down
30 changes: 30 additions & 0 deletions tests/test_pdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -1329,3 +1329,33 @@ def test_is_shared_paramset_shapesys_same_sample_same_channel():

with pytest.raises(pyhf.exceptions.InvalidModel):
pyhf.Workspace(spec).model()


def test_multi_component_poi():
spec = {
"channels": [
{
"name": "SR",
"samples": [
{
"data": [5.0, 10.0],
"modifiers": [
{"data": None, "name": "mu", "type": "shapefactor"}
],
"name": "Signal",
}
],
}
],
"measurements": [
{"config": {"parameters": [], "poi": "mu"}, "name": "example"}
],
"observations": [{"data": [5.0, 10.0], "name": "SR"}],
"version": "1.0.0",
}

with pytest.raises(
pyhf.exceptions.InvalidModel,
match="The parameter 'mu' contains multiple components and is not currently supported as parameter of interest.",
):
pyhf.Workspace(spec).model()

0 comments on commit 30dc756

Please sign in to comment.