Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(backport): Catch use of multi-component parameters as POI #2212

Merged
merged 1 commit into from
May 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()