-
Notifications
You must be signed in to change notification settings - Fork 5
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
Adding check_parameter_positivity()
function to seir.py
#428
base: dev
Are you sure you want to change the base?
Conversation
Still need to add the test function (not ready yet for review) |
@jcblemai I have initial concerns that I did not properly instantiate |
I'm very, very bad at naming things (Carl, Tim are definitely very good at this) but neg_param() is not informative enough as a function name, something like |
parsed_parameter has shape (n_parsed_parameters(unique_strings) X n_times X n_subpop), is that what's causing the CI error ? EDIT: no, see below: |
neg_params()
function to seir.py
check_parameter_positivity()
function to seir.py
It turns out there's only 30 days in April...
Small documentation changes and removing an unrelated but unnecessary loc from `test_seir.py`
Incorporating the information within a `print()` statement into the `ValueError` output in `seir.py::check_parameter_positivity()`
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.
The documentation is great, thanks for doing that! The testing looks good too, I just have some brief comments on that front, should be quick to fix.
My biggest concern is that the error message will be too verbose, I think we want to convey to users quickly the most important thing. Multi-line error messages confuse users and can make it more difficult to diagnose.
error_message = ( | ||
"The earliest date negative for each subpop and unique parameter are:\n" | ||
) | ||
for param_idx, day_idx, sp_idx in non_redundant_negative_parameters: | ||
error_message += f"subpop: {subpop_names[sp_idx]}, parameter {parameter_names[param_idx]}: {dates[day_idx].date()}\n" | ||
raise ValueError( | ||
f"There are negative parsed-parameters, which is likely to result in incorrect integration.\n{error_message}" | ||
) |
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'm concerned that this error message will be quite lengthy and I'm not a fan of multi-line error messages. Is there a way that we could condense this down to one line? Maybe just error on the first negative parameter?
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.
Hm, I agree the message is lengthy, and it is sub-optimal for it to be multiple lines. But, I'm curious what your thoughts are on the usefulness of having an error message that only returns the first negative parameter, even if the function output knows where all of negative parameters are. Is there not a lot of added value in telling the user all of the columns that have negative values, so they can more quickly address the issue? I'm happy to change it to only show the first negative parameter value, but since the function inherently finds the others, I thought it would be useful to include.
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 agree that spewing out all the errors is too much noise - multiple errors often arise from single mistakes that need correcting.
I recommend that we limit the detailed part of the error message to the earliest time, for any parameter or subpop that there is a problem. However, I also think its worthwhile to indicate the totality of the problem. Something like
There are negative parameter error(s) for config FFFF: the first at date DD-MM-YY, subpopulation XX, parameter YY.
Affected subpopulations include: {...}. Affected parameters include {...}. There are NNN total negative entries.
(possibly some of those elements can be curtailed if there are not multple subpops, etc)
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.
Just chiming in that I asked @emprzy for this verbose error message (first date negative for all parameter and subpop negative) as it helps to debug configs without retrying (which, e.g for a RSV config takes 6/7 minutes), sorry Emily. Totally understand that we want to keep it light but I think a good diagnosis (e.g. a graph or something) is useful here, though perhaps not inside the simulate command.
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 think the more clear the error message is the most useful it would be practically, though understand it's long to print out everything for each subpop for example. In particular I think it would be useful as much information about the specific parameters? Maybe a simplification/modification of this:
There are negative parameter errors in subpops {...}, starting from date XXXX:
parameters: eta_X0toX3_highIE*1*1*nuage18to64HR, eta_X1toX4_highIE*1*1*nuage0to17, eta_X1toX4_highIE*1*1*nuage18to64LR....
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.
@saraloo's suggestion seems like a reasonable compromise to me.
Minor: but maybe starting from date YYYY-MM-DD, in parameters: ...
instead, notably no newline. Newlines can be annoying to format in unit tests matching on exception, see this prior version of Parameters
unit tests as an example:
flepiMoP/flepimop/gempyor_pkg/tests/parameters/test_parameters_class.py
Lines 283 to 297 in 2ec9695
with pytest.raises( | |
ValueError, | |
match=( | |
rf"^ERROR loading file {tmp_file} for parameter sigma\:\s+the \'date\' " | |
rf"entries of the provided file do not include all the days specified " | |
rf"to be modeled by\s+the config\. the provided file includes " | |
rf"{(timeseries_end_date - timeseries_start_date).days + 1} days " | |
rf"between {timeseries_start_date}( 00\:00\:00)? to " | |
rf"{timeseries_end_date}( 00\:00\:00)?,\s+while there are " | |
rf"{mock_inputs.number_of_days()} days in the config time span of " | |
rf"{mock_inputs.ti}->{mock_inputs.tf}\. The file must contain entries " | |
rf"for the\s+the exact start and end dates from the config\. $" | |
), | |
): | |
mock_inputs.create_parameters_instance() |
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.
re unit test matching, I'd reiterate that its overkill to match exact messages - for example here, should only be matching first bad date string (irrespective of what's around it), subpop id (ibid), and offending parameters (ibid).
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.
starting from date YYYY-MM-DD, in parameters: ...
@TimothyWillard , does this mean you propose leaving out the subpop information and just including the parameter names that are negative?
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.
@TimothyWillard , does this mean you propose leaving out the subpop information and just including the parameter names that are negative?
My bad, no, I just was conveying an edit to a portion of @saraloo's suggestion. The full change with my edit would be:
There are negative parameter errors in subpops {...}, starting from date YYYY-MM-DD in parameters: eta_X0toX3_highIE*1*1*nuage18to64HR, eta_X1toX4_highIE*1*1*nuage0to17, eta_X1toX4_highIE*1*1*nuage18to64LR....
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.
@TimothyWillard @saraloo @jcblemai
The error message now reads as follows:
ValueError: There are negative parameter errors in subpops ['56000', '44000', '30000'], starting from date 2023-03-19 in parameters ['alpha*1*1*1', 'sigma_OMICRON*1*1*1', '3*gamma*1*1*1'].
Is this what you had in mind? Happy to change it, just wanted to confirm before pushing.
oops forgot to do this before previous push
Describe your changes.
This pull request introduces a function called
check_parameter_positivity()
toseir.py
.check_parameter_positivity()
takes in an array of parsed parameters, as well as parameter names, subpopulation names, and dates, checks for the existence of negative parameter values, and throws aValueError
error if they are found. When throwing the error,check_parameter_positivity()
will only print the earliest (w.r.t date) negative parameter to avoid redundant feedback. Example output will resemble:A test function,
test_check_parameter_positivity()
has also been added totest_seir.py
to testcheck_parameter_positivity()
.Does this pull request make any user interface changes? If so please describe.
No changes to the user interface.
What does your pull request address? Tag relevant issues.
This pull request addresses GH #215.
Tag relevant team members.
@jcblemai