Skip to content

fix: LogUniform/Uniform NumPy log-prior returns NaN out-of-support (emcee crash) #1328

Description

@Jammy2211

Overview

Under release-fidelity validation (PyAutoHeart #27, run 28784914443), Emcee legs crash with ValueError: Probability function returned NaN. Root cause: LogUniformPrior's NumPy log-prior path returns -np.log(value) with no bounds-check, so when Emcee's stretch move proposes an out-of-support value (value <= 0) the log-prior is NaN, which propagates into the summed figure-of-merit and crashes Emcee. UniformPrior has the sibling gap (returns 0.0 unconditionally, not -inf, out-of-support). Both NumPy paths already have a correct JAX counterpart that returns -inf out-of-support — this fixes the NumPy paths to match.

Plan

  • Fix the producer. LogUniformPrior.log_prior_from_value (and UniformPrior for parity) NumPy path returns -inf outside [lower_limit, upper_limit], mirroring the already-correct JAX branch. Out-of-support log-prior is legitimately -inf (zero probability → Emcee rejects the move) — a correctness fix, not a masking guard.
  • Reproduce on clean main first, honouring the Pipeline name for meta data should retain own pipeline name if pipelines are added #27 clean-repro discipline; scope only reproducing scripts.
  • Do NOT add a defensive NaN-guard on the FoM in fitness.py — that would mask other producers; a NaN FoM from anything else should still fail loudly.
  • Split/park the non-reproducing autofit_workspace_test/database scripts to a follow-up (per PyAutoFit#1327 precedent).
Detailed implementation plan

Affected Repositories

  • PyAutoFit (primary)

Branch Survey

Repository Current Branch Dirty?
./PyAutoFit main clean

Suggested branch: bug/emcee-loguniform-nan

Implementation Steps

  1. Reproduce the NaN crash on clean main: a small Emcee run over a LogUniform-prior model where a walker exits support (or directly LogUniformPrior(...).log_prior_from_value(-1.0) → NaN).
  2. Fix autofit/mapper/prior/log_uniform.py:139-140: replace the unconditional -np.log(value) NumPy branch with a bounds-checked np.where-based form returning -inf outside [lower_limit, upper_limit], matching the JAX branch at lines 141-142; correct the docstring at lines 126-129.
  3. Fix autofit/mapper/prior/uniform.py:167 NumPy path: return -inf out-of-support instead of unconditional 0.0, matching its JAX branch (scalar-safe).
  4. Add tests in test_autofit/mapper/prior/ (+ Emcee integration in test_autofit/non_linear/search/mcmc/test_emcee.py): assert out-of-bounds LogUniformPrior/UniformPrior log-prior is -inf (not NaN/0.0), and a small Emcee run over a LogUniform model with out-of-support proposals completes without ValueError.
  5. Reproduce all 9 bundled scripts from clean output/; keep only reproducing ones in this PR; split non-reproducing database scripts to a parked follow-up.
  6. Validate: python -m pytest test_autofit/ green; rerun reproducing scripts from clean state.

Key Files

  • autofit/mapper/prior/log_uniform.py — NumPy log-prior missing bounds-check (primary defect, causes the NaN crash).
  • autofit/mapper/prior/uniform.py — sibling NumPy path returns 0.0 out-of-support (parity fix).
  • autofit/non_linear/fitness.py:239-248 — FoM = log_likelihood + Σ log_prior; NaN guard only covers likelihood, not the summed prior (context; deliberately not changed).
  • autofit/non_linear/search/mcmc/emcee/search.py:137-138fom_is_log_likelihood=False (context).

Context / Discipline

Original Prompt

Click to expand starting prompt

Scoped from PyAutoMind/bug/health_fixes/autofit_sampler_database.md to the reproducing Emcee bounded-prior NaN defect. Full prompt:

# Fix Autofit release sampler and database regressions

## Context

Release run `28784914443` failed two @autofit_workspace cookbooks and seven
@autofit_workspace_test scripts. The cookbook failures reproduce on current `main`:
Emcee proposes invalid LogUniform values and raises `ValueError: Probability function
returned NaN`. Database failures include empty aggregators, stale/mismatched scraped
search metadata, and changed likelihood assertions.

Primary library: @PyAutoFit.

## Scripts

- autofit_workspace/scripts/cookbooks/result.py
- autofit_workspace/scripts/cookbooks/samples.py
- autofit_workspace_test/scripts/database/directory/general.py
- autofit_workspace_test/scripts/database/directory/multi_analysis.py
- autofit_workspace_test/scripts/database/scrape/general.py
- autofit_workspace_test/scripts/database/scrape/grid_search.py
- autofit_workspace_test/scripts/database/scrape/multi_analysis.py
- autofit_workspace_test/scripts/database/scrape/sensitivity.py
- autofit_workspace_test/scripts/features/minimal_output.py

Scope note: this issue tracks only the reproducing Emcee bounded-prior NaN library defect. The database/minimal_output scripts are validated from clean output/; any that do not reproduce are split to a parked follow-up (stale-output false positives, per PyAutoFit#1327).

Reference: PyAutoHeart #27 (run 28784914443), health_fixes cluster.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions