-
Notifications
You must be signed in to change notification settings - Fork 85
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: Catch use of multi-component parameters as POI with error message #2197
Conversation
Switched approach to be more generic. |
Codecov ReportPatch coverage:
Additional details and impacted files@@ Coverage Diff @@
## main #2197 +/- ##
=======================================
Coverage 98.30% 98.30%
=======================================
Files 69 69
Lines 4533 4533
Branches 801 802 +1
=======================================
Hits 4456 4456
Misses 45 45
Partials 32 32
Flags with carried forward coverage won't be shown. Click here to find out more.
☔ View full report in Codecov by Sentry. |
922438e
to
a34efec
Compare
@@ -464,6 +464,11 @@ 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." | |||
) | |||
if self.param_set(name).n_parameters > 1: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This now handles shapefactor
/ shapesys
/ staterror
if they act on channels with multiple bins. All of these cases would fail the assert
below. Setups like a histosys
as POI seem to technically work, so even if they might not be useful in practice I guess there is no need to catch those here.
c82deac
to
2ed7648
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @alexander-held and LGTM. 👍 I just have one question on if we couldn't go further.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After the assert
removal this all LGTM @alexander-held. 👍 If @kratsg also approves then once this is merged and I finish the other backports I'll release pyhf
v0.7.2
with this in it today.
* Backport PR #2197 Co-authored-by: Alexander Held <45009355+alexander-held@users.noreply.github.com>
Description
Resolves #2200.
This addresses #2194. When a parameter with multiple components (
shapefactor
/shapesys
/staterror
) is used as POI, the model construction currently fails at anassert
(assuming Python is not run with-O
). This PR turns the failure into an exception with an error message to provide more context.For simple MLEs, bypassing the
assert
actually makes things work (so one could argue to not catch this early and force the exception). However, this would cause even more confusing issues down the line once the POI starts mattering. As an example, ahypotest
could result inRuntimeWarning: invalid value encountered in subtract
withinscipy
. I do not see any benefit in allowing to bypass the exception to allow running things that do not depend on the POI definition though.Checklist Before Requesting Reviewer
Before Merging
For the PR Assignees:
(summary provided by @matthewfeickert)