fix: LogUniform NumPy log-prior returns -inf for value<=0 (emcee NaN crash)#1329
Merged
Conversation
…crash) Emcee's stretch move proposes physical values that can go non-positive for a LogUniform parameter. The NumPy log_prior_from_value path computed -np.log(value), which is NaN for value<=0; the NaN propagated into the summed figure-of-merit (fom = log_likelihood + sum(log_prior)) and crashed the search with "ValueError: Probability function returned NaN". Return -inf (zero density -> the proposed move is rejected) for value<=0, using the double-where pattern so no log of a non-positive value is evaluated (avoiding a NumPy RuntimeWarning). Positive values are unchanged: the NumPy path stays unnormalised and unbounded, returning -log(value). The JAX path is untouched. Surfaced by PyAutoHeart #27 release-fidelity validation (run 28784914443). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes an Emcee crash caused by LogUniformPrior.log_prior_from_value returning NaN on the NumPy path when proposed values are non-positive, by safely returning -inf instead (zero density → rejected move) without ever evaluating log on invalid inputs.
Changes:
- Update
LogUniformPrior.log_prior_from_value(..., xp=np)to return-infforvalue <= 0using a safe “doublewhere” pattern to avoid NumPyRuntimeWarnings. - Add a regression test ensuring non-positive values return
-infand that no “invalid value in log” warning is emitted; confirm positive-value behaviour is unchanged.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
autofit/mapper/prior/log_uniform.py |
Makes NumPy log-prior robust to non-positive proposals by returning -inf without evaluating invalid logs. |
test_autofit/mapper/prior/test_prior.py |
Adds regression coverage for the non-positive case and verifies warning-free evaluation plus unchanged positive behaviour. |
This was referenced Jul 8, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Emcee's stretch move proposes physical values that can go non-positive for a
LogUniform-priored parameter.LogUniformPrior.log_prior_from_valuecomputed-np.log(value)on the NumPy path, which isNaNforvalue <= 0; thatNaNpropagated into the summed figure-of-merit (
fom = log_likelihood + Σ log_prior,fitness.py) and crashed the search withValueError: Probability function returned NaN.This returns
-inf(zero density → the proposed move is rejected) forvalue <= 0, using the "double where" pattern so nologof a non-positive valueis ever evaluated (avoiding a NumPy
RuntimeWarning). Positive values areunchanged — the NumPy path stays unnormalised and unbounded, returning
-log(value); the JAX path is untouched.Surfaced by PyAutoHeart #27 release-fidelity validation (run 28784914443); fixes
the
autofit_workspacecookbook legs that failed with the emcee NaN crash.Closes #1328.
API Changes
Behaviour-only:
LogUniformPrior.log_prior_from_value(value)now returns-inf(was
NaN/+inf) forvalue <= 0on the NumPy path. No signatures, symbols, ordefaults change; positive-value behaviour is identical. The only direct callers are
the
autofit_workspace_testprior parity/regression gates(
jax_assertions/priors_xp_dispatch.py,prior_correctness/emcee_gaussian_bias_check.py),which exercise only positive, in-bounds values and are unaffected.
See full details below.
Test Plan
python -m pytest test_autofit/mapper/prior/ test_autofit/non_linear/(918 + 250 pass)test__log_prior_from_value__non_positive_returns_neg_infLogUniformmodel completes without "Probability function returned NaN"Full API Changes (for automation & release notes)
Changed Behaviour
autofit.LogUniformPrior.log_prior_from_value(value)— NumPy path returns-infforvalue <= 0(previouslyNaNfrom-logof a non-positive value,+infatvalue == 0). Positive values unchanged (-log(value), unnormalised/unbounded). JAX path unchanged.Migration
🤖 Generated with Claude Code