Retry probabilistic subsampling after failure #676
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description of proposed changes
Probabilistic subsampling can randomly fail to select any samples when the requested number of maximum samples is very small. To minimize the chances of this edge case (that also happens to affect our Travis CI tests), this PR places the probabilistic subsampling inside a loop that checks for non-zero list of selected samples and retries subsampling a fixed number of times before giving up.
With 10 maximum retries, subsampling never fails under the conditions we use in our CI test (10 groups, 5 max sequences) when tested 10,000,000 times. The resulting probability of failure is low enough that this change should resolve our flaky CI test and also prevent most users from ever encountering the same error in their own analyses.
Note that this change should not affect most people under most conditions and will mostly make Augur development more sane.
Related issue(s)
Fixes #674
Testing
I confirmed the selected maximum number of retry attempts with the following code. This code tries to recreate the effect of running augur filter 10,000,000 times to see if subsampling ever fails under the conditions used by our CI test.