Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1061 +/- ##
=======================================
Coverage 66.24% 66.24%
=======================================
Files 89 89
Lines 17064 17064
Branches 2642 2642
=======================================
Hits 11304 11304
Misses 5021 5021
Partials 739 739
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
61d5159 to
4071122
Compare
|
I thought we had fixed this already... |
|
My apologies @ColmTalbot I may have missed your MR that fixed it. If that is the case, please do close this |
|
Agreed on the call we would backport this to 2.7.x |
4071122 to
7f3e429
Compare
There was a problem hiding this comment.
Pull request overview
Fixes a TypeError in PriorDict.sample_subset_constrained when constrained sampling is invoked with size=None or size=1, which occurs in sampler parameter verification paths (e.g., dynesty).
Changes:
- Ensure the constraint validity indicator can be converted to an
intby squeezing 1-element numpy arrays to a 0-d scalar before counting valid samples.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| if size is None or size == 1: | ||
| while True: | ||
| sample = self.sample_subset(keys=keys, size=size) | ||
| is_valid = self.evaluate_constraints(sample) | ||
| n_tested_samples += 1 | ||
| n_valid_samples += int(is_valid) | ||
| n_valid_samples += int(np.squeeze(is_valid)) | ||
| check_efficiency(n_tested_samples, n_valid_samples) | ||
| if is_valid: | ||
| return sample |
Issue
GitHub #1047
sample_subset_constrainedraised aTypeErrorwhen sampling withsize=Noneorsize=1:Root Cause
evaluate_constraintsreturns a numpy array vianp.ones_like. When sampling a single point, this is a 1-element array rather than a scalar. The subsequentint(is_valid)call on line 464 fails becauseint()only accepts 0-dimensional arrays.Fix
Wrap
is_validwithnp.squeezebefore converting toint, reducing the 1-element array to a 0-d scalar: