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

PSR: Return early if no draws #3246

Merged
merged 1 commit into from
Jan 3, 2024
Merged

PSR: Return early if no draws #3246

merged 1 commit into from
Jan 3, 2024

Conversation

andrjohns
Copy link
Contributor

Submission Checklist

  • Run unit tests: ./runTests.py src/test/unit
  • Run cpplint: make cpplint
  • Declare copyright holder and open-source license: see below

Summary

stan::analyze::compute_potential_scale_reduction still attempts to calculate the PSR if there are 0 draws passed, which is currently causing a segfault when calling stansummary on the output from optimize:

andrew@Andrews-MacBook-Air bernoulli % ./bernoulli optimize data file=bernoulli.data.json
...

andrew@Andrews-MacBook-Air bernoulli % ../../bin/stansummary output.csv
Warning: non-fatal error reading adaptation data
Assertion failed: (index >= 0 && index < size()), function operator(), file DenseCoeffsBase.h, line 181.
zsh: abort      ../../bin/stansummary output.csv

Intended Effect

No segfault

How to Verify

Call stansummary with this applied.

Side Effects

N/A

Documentation

N/A

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): Andrew Johnson

By submitting this pull request, the copyright holder is agreeing to license the submitted work under the following licenses:

@@ -35,6 +35,9 @@ inline double compute_potential_scale_reduction(
std::vector<const double*> draws, std::vector<size_t> sizes) {
int num_chains = sizes.size();
size_t num_draws = sizes[0];
if (num_draws == 0) {
return std::numeric_limits<double>::quiet_NaN();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@andrjohns, the change looks great.

Before it gets merge, just a question: is quiet_NaN the right behavior here? I don't know how this gets used next, so just wanting to sure this isn't going to trigger other problems. (I'm guessing that NaN is the right choice; just wanting to double check.)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only place this is used is for user-facing output (from stansummary) so I believe NaN is a reasonable choice. We also return NaN if all chains are constant a bit further down in the function

@WardBrian WardBrian merged commit 267722a into develop Jan 3, 2024
3 checks passed
@WardBrian WardBrian deleted the stansummary-segfault branch January 3, 2024 15:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants