Skip to content

Make bypass test mode write a complete on-disk result#1192

Merged
Jammy2211 merged 1 commit intomain_buildfrom
feature/bypass-mode-save-and-log-evidence-stub
Apr 10, 2026
Merged

Make bypass test mode write a complete on-disk result#1192
Jammy2211 merged 1 commit intomain_buildfrom
feature/bypass-mode-save-and-log-evidence-stub

Conversation

@Jammy2211
Copy link
Copy Markdown
Collaborator

Summary

Three tightly-coupled bugs in PYAUTOFIT_TEST_MODE=2 (bypass mode) were causing the post-API-drift mega-run cluster of NoneType arithmetic errors on log_evidence and the database scrape test's IndexError.

All three ship together because they share the same root cause — bypass mode was supposed to produce a fully-populated result folder, but its implementation was incomplete:

  • SamplesPDF.log_evidence returned None unconditionally
  • _fit_bypass_test_mode never called save_samples or save_samples_summary (despite its docstring)
  • fit() skipped pre_fit_output in bypass mode, which meant the metadata file used by the aggregator to discover search directories was never written

After this PR, autofit features/search_grid_search.py, autolens imaging/features/advanced/subhalo/detect/start_here.py, and autofit_workspace_test database/scrape/grid_search.py all pass end-to-end in bypass mode.

API Changes

  • SamplesPDF.log_evidence now returns samples_info.get("log_evidence") instead of None.
  • Bypass test mode now writes metadata, samples.csv, and samples_summary.json to the output folder. No public signatures changed; this only affects what files exist on disk after a bypass-mode run.

See full details below.

Test Plan

  • PyAutoFit unit tests: test_autofit/non_linear/search + test_autofit/non_linear/samples — 65 passed
  • Full PyAutoFit test suite — 1205 passed
  • 27-script workspace smoke test suite across all four workspaces — all passed
  • The three originally-failing scripts wiped-and-rerun in bypass mode — all exit 0
Full API Changes (for automation & release notes)

Changed Behaviour

  • autofit.non_linear.samples.pdf.SamplesPDF.log_evidence — now returns self.samples_info.get("log_evidence") instead of hardcoded None. Only affects pure SamplesPDF instances; SamplesNest and SamplesMCMC override and are unchanged.
  • autofit.non_linear.search.abstract_search.NonLinearSearch._fit_bypass_test_mode — now stubs log_evidence in samples_info (set to the single evaluated log_likelihood) and calls self.paths.save_samples_summary(...) and self.paths.save_samples(...) so downstream readers see a complete result folder.
  • autofit.non_linear.search.abstract_search.NonLinearSearch.fit — when test_mode_level() >= 2, now calls self.paths.save_all(...) instead of only _save_model_info. This writes the metadata file that the aggregator uses to discover search directories. Still skips analysis.save_attributes and visualize_before_fit to keep bypass mode cheap.

Migration

No migration needed for library consumers. If you have custom code that relied on SamplesPDF.log_evidence being None, replace with an explicit check against samples_info.

🤖 Generated with Claude Code

Three things were broken for `PYAUTOFIT_TEST_MODE=2` (bypass mode):

1. `SamplesPDF.log_evidence` hard-coded `return None`, so any downstream
   arithmetic on the log evidence (grid search comparisons, subhalo
   Bayesian model comparison, scraped-aggregator assertions) crashed
   with `NoneType - float`. Now it returns `samples_info.get("log_evidence")`
   — matching the pattern already used by `SamplesNest`.

2. `_fit_bypass_test_mode` never persisted samples or the samples
   summary to disk even though its docstring claimed to write "all
   expected output files". Downstream code that reads from the output
   folder (database scrape, `paths.load_samples_summary`) saw a
   half-populated directory. Now calls `save_samples_summary` and
   `save_samples`; both are no-ops on `NullPaths` and safe on
   `DatabasePaths`, so all path modes remain correct.

3. `fit()` skipped `pre_fit_output` in bypass mode and only wrote
   `model.info`, omitting the `metadata` file that the aggregator uses
   to discover search directories. Now calls the full `save_all`
   (lightweight JSON dumps only — still skips the expensive
   `analysis.save_attributes` / `visualize_before_fit` steps).

Together these make `autofit search_grid_search`, `autolens subhalo
detect`, and `autofit_workspace_test database/scrape/grid_search` work
end-to-end in bypass mode.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@Jammy2211 Jammy2211 merged commit dae5a94 into main_build Apr 10, 2026
1 check passed
@Jammy2211 Jammy2211 deleted the feature/bypass-mode-save-and-log-evidence-stub branch April 10, 2026 17:04
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.

1 participant