-
Notifications
You must be signed in to change notification settings - Fork 84
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: Check parameter shapes for pdf API calls #1461
base: main
Are you sure you want to change the base?
Conversation
Codecov Report
@@ Coverage Diff @@
## master #1461 +/- ##
=======================================
Coverage 98.12% 98.12%
=======================================
Files 64 64
Lines 4270 4278 +8
Branches 683 687 +4
=======================================
+ Hits 4190 4198 +8
Misses 46 46
Partials 34 34
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
I wonder whether for these types of API we shsould have a pattern
such that for performance critical or internal paths (i.e. where pyhf itself calls |
I had this idea where I wanted to use decorators. It can introspect the arguments and do the checks based on something consistent, rather than copy/paste code around a lot. In this case, something like |
raise exceptions.InvalidPdfParameters( | ||
f'eval failed as pars has len {pars.shape[-1]} but {self.config.npars} was expected' | ||
) | ||
|
||
return self.make_pdf(pars)[1].expected_data() | ||
|
||
def _modifications(self, pars): |
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.
given that we do input validation here it suggests that this has become a publicly consumable API. maybe we should add a model.modifications
and do the input checks there and call _modifications
if inputs are ok
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.
_modifications
isn't currently a public API. This certainly could become one, although I might argue that we remove it from Model
and keep it on MainModel
unless there's a reason to pass-through it. e.g. pdf.main_model.modifications
is just as clear to me. Unless the suggestion here is to remove the checks from main_model
and constraint_model
and keep all checks on model
which is also possible, but feels like a mess.
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.
main_model
is needed for return_by_sample
, so it feels similarly "public" as Model
.
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.
Sure, but main_model.expected_actualdata(..., return_by_sample)
is fine -- since that's public. However main_model._modifications
isn't necessarily public. Although at the moment only used by main_model.expected_data
-- so I'm fine either way.
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.
Unless the suggestion here is to remove the checks from
main_model
andconstraint_model
My comment was meant as an example for why that may not be desirable, sorry I should have made that clear. Promoting _modifications
to public in the longer term is a nice idea, it looks very useful for model debugging.
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.
I created an issue regarding the proposal of making _modifications
public: #1652.
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.
as it is now this will be called on each logpdf call.. so it's perf. critical.. should we have some kind of split of "pdf.method" and "pdf._method_unsafe"? or do we think it doesn't make a difference?
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.
@lukasheinrich @kratsg If we can revisit the performance impact here soon it would be nice to have this get into v0.7.0
.
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 all LGTM @kratsg — thanks. I'll let you and @lukasheinrich resolve the current discussion and implement any changes that you want, but I'm happy to have this merged whenever you both are.
62a7a0c
to
9ea3230
Compare
e36109f
to
390b100
Compare
Pull Request Description
Resolves #1459. Check that
expected_data
,expected_auxdata
, andexpected_actualdata
are being called with the right shape forpars
(the parameters) before evaluating. This is usually caught by lower-level code, however the error is not as user-friendly.A quick note: it is ok to add
if/raise
in these API calls as they're not meant to be "fast" in our code -- but this could potentially be a problem if we need to allow for autodiff capabilities. For now, we're only enforcing thatlogpdf()
calls are the performant ones.Checklist Before Requesting Reviewer
Before Merging
For the PR Assignees: