-
-
Notifications
You must be signed in to change notification settings - Fork 375
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
Standalone GQ: Output NaNs when exception is caught #3173
Conversation
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.
Looks good other than scope of a logger in one file.
@@ -81,7 +81,6 @@ class gq_writer { | |||
if (ss.str().length() > 0) | |||
logger_.info(ss); | |||
logger_.info(e.what()); | |||
return; |
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.
If this isn't going to return, then the following logger_
call outside the catch duplicates the ss
message. The full context is this:
try {
model.write_array(rng, const_cast<std::vector<double>&>(draw), params_i,
values, false, true, &ss);
} catch (const std::exception& e) {
if (ss.str().length() > 0)
logger_.info(ss);
logger_.info(e.what());
}
if (ss.str().length() > 0)
logger_.info(ss);
The conditional logging after the catch should be moved into the try block to avoid duplicating logger_.info(ss)
.
This is also making me think the logger itself should be ignoring empty string messages rather than duplicating this everywhere.
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.
Good catch.
Ignoring empty strings has a (nearly 5 year old!) issue open: #2577
// model test_gq.stan generates 4 values, 3 commas | ||
EXPECT_EQ(count_matches(",", sample_ss.str()), 3); | ||
|
||
EXPECT_EQ(count_matches("nan", sample_ss.str()), 4); |
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 for adding the test.
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 for the update.
Thanks, and feel free to merge when tests finish. |
Submission Checklist
./runTests.py src/test/unit
make cpplint
Summary
Closes stan-dev/cmdstan#1007. Since stan-dev/stanc3#1165 we have made sure that
write_array
always populates the array with NaNs, so writing it out is safe even after an exception.Intended Effect
Standalone generate quantities behavior now matches that of sampling (nans output if write_array fails) and the number of rows in the output of standalone generated quantities is now always the number of rows in the input
fitted_params
.How to Verify
The example from stan-dev/cmdstan#1007 works well
Side Effects
Documentation
Copyright and Licensing
Please list the copyright holder for the work you are submitting (this will be you or your assignee, such as a university or company):
Simons Foundation
By submitting this pull request, the copyright holder is agreeing to license the submitted work under the following licenses: