Repository navigation
Description
Overview
AbstractSearch._fit_bypass_test_mode (autofit/non_linear/search/abstract_search.py:1091) is the sampler bypass used by PYAUTO_TEST_MODE=2 and =3. Its docstring promises it "writes all expected output files so that downstream code sees a complete result folder", and it does write samples, samples_summary and the .completed marker — but it never calls analysis.save_results / analysis.save_results_combined, which the normal path (start_resume_fit, lines 830-831) calls unconditionally.
Any script that defines a custom Analysis.save_results and reads its own output file back therefore fails under smoke. Heart workspace-smoke cloud run 34824535982 fails autofit_workspace overview/overview_2_scientific_workflow (.py and .ipynb) with FileNotFoundError: .../files/science_summary.json at overview_2_scientific_workflow.py:279. The gap predates the recent PyAutoFit commits — it was introduced with modes 2/3 in d41aa53e8.
Fixing it clears both autofit smoke failures with no workspace edit and no API change.
Plan
_fit_bypass_test_modecallsanalysis.save_resultsandanalysis.save_results_combinedafter building the result and beforepaths.completed(), matchingstart_resume_fit.- Add a unit test asserting a bypassed fit (mode 2 and mode 3) invokes both hooks with the result and paths.
- Verify the failing workspace script passes under
PYAUTO_TEST_MODE=2locally; no workspace edits. - Ship via
ship_library; downstream impact:autofit_workspaceoverview_2smoke goes green, no API change.
Detailed implementation plan
Work Classification
Library
Worktree root
~/Code/PyAutoLabs-wt/test-mode-bypass-save-results/
Affected Repositories
- PyAutoFit (primary — the only repo edited)
- autofit_workspace (downstream impact target, not edited — its
overview_2smoke is the witness)
Branch Survey
| Repository | Current Branch | Dirty? |
|---|---|---|
| ./PyAutoFit | main | clean |
| ./autofit_workspace | main | clean |
worktree_check_conflict test-mode-bypass-save-results PyAutoFit exits 0 (no conflict). No worktree or *bypass* branch exists, and no claim is registered on either repo.
Suggested branch: feature/test-mode-bypass-save-results
Implementation Steps
-
autofit/non_linear/search/abstract_search.py— in_fit_bypass_test_mode(def at line 1091), insert between themake_result(...)call ending at line 1204 andmodel.unfreeze()at line 1206:analysis.save_results(paths=self.paths, result=result) analysis.save_results_combined(paths=self.paths, result=result)
byte-identical to lines 830-831 in
start_resume_fit, same position relative tomake_result/model.unfreeze()/self.paths.completed(). Do not gate the new calls onskip_fit_output(): the normal path does not, and the smoke profile setsPYAUTO_SKIP_FIT_OUTPUT=1— gating them would reproduce the bug under exactly the conditions the fix targets. -
test_autofit/non_linear/search/test_abstract_search.py— addclass TestBypassCallsSaveResultsparametrised overPYAUTO_TEST_MODE"2"and"3", mirroringTestBypassWritesCompleted(line 379),TestBypassToleratesFitException(435) and the mode-parametrisedTestBypassToleratesAssertionTies(516). Pattern:monkeypatch.setenv("PYAUTO_TEST_MODE", mode),af.Model(af.m.MockClassx2),af.DynestyStatic(name=..., unique_tag=...), a localaf.m.MockAnalysissubclass (the_FitExceptionAnalysisidiom at 426) that recordspathsandresultfrom overriddensave_results/save_results_combined. Assert on the recorder, not on files (test config runsremove_files: true). -
Verify:
python3 -m pytest test_autofit/non_linear/search/test_abstract_search.py -k bypass -q, then the full suite (testpaths = ["test_autofit"]; CI runs pytest via PyAutoHeart's reusablelib-tests.yml), then the witness from theautofit_workspaceroot:PYAUTO_TEST_MODE=2 PYAUTO_SKIP_FIT_OUTPUT=1 PYAUTO_SKIP_VISUALIZATION=1 PYAUTO_SKIP_CHECKS=1 PYAUTO_DISABLE_JAX=1 JAX_ENABLE_X64=True NUMBA_CACHE_DIR=/tmp/numba_cache MPLCONFIGDIR=/tmp/matplotlib python3 scripts/overview/overview_2_scientific_workflow.py
and again with
PYAUTO_TEST_MODE=3.
Why this is safe
Analysis.save_results(autofit/non_linear/analysis/analysis.py:239) andsave_results_combined(:242) are bare no-ops; nothing gates them on test mode.save_results_combinedhas no override anywhere in the stack; its only references are the base def and the call sites at 831 and 1058.- Under mode 3 the stored parameter vector is a valid representative point, so
result.max_log_likelihood_instancereconstructs; the-1.0e99sentinel is only the likelihood value. - Downstream overrides (
PyAutoGalaxy/autogalaxy/analysis/analysis/dataset.py:157,PyAutoLens/autolens/analysis/analysis/dataset.py:170) are cheap JSON dumps already guarded per PyAutoFit fix: Result.instance falls back to a valid sample; persist samples before materialisation #1535.
Key Files
autofit/non_linear/search/abstract_search.py—_fit_bypass_test_mode(1091), insertion 1204→1206; referencestart_resume_fit823-835autofit/non_linear/analysis/analysis.py— base hooks 239 / 242test_autofit/non_linear/search/test_abstract_search.py— new test beside the bypass classesautofit/non_linear/mock/mock_analysis.py:18—MockAnalysis
Downstream impact
No API change. autofit_workspace overview/overview_2_scientific_workflow.{py,ipynb} go green in Heart workspace-smoke. Note overview_2 is absent from autofit_workspace/smoke_tests.txt, so the list-driven local smoke does not cover it; adding it is a separate workspace task.
Original Prompt
Click to expand starting prompt
Test-mode bypass never calls analysis.save_results, breaking scripts that read their own result files
Type: bug
Target: autofit
Repos:
- PyAutoFit
Themes: - test-mode
- workspace-smoke
Difficulty: easy
Autonomy: supervised
Priority: high
Status: draft
Consequence: judge
Witness:PYAUTO_TEST_MODE=2 python autofit_workspace/scripts/overview/overview_2_scientific_workflow.pycompletes and prints the science_summary it wrote; a PyAutoFit unit test asserts the bypass calls save_results / save_results_combined
Review-minutes: 10
Filed: 2026-09-14
User request (verbatim, 2026-09-14):
"""
can you fix the PyAutoHeart being red
"""
(follow-up after the RED cleared to YELLOW: "yes do next step" — file the PyAutoFit
bypass fix through start_dev, which also clears both autofit smoke failures.)
Context
Heart workspace-smoke cloud run 34824535982 (PyAutoHeart, workspace-smoke.yml,
PYAUTO_TEST_MODE=2) fails on autofit_workspace overview/overview_2_scientific_workflow
(.py and .ipynb) with
FileNotFoundError: .../files/science_summary.json
overview_2_scientific_workflow.py:279 print(search.paths.load_json("science_summary"))
The script defines Analysis.save_results to paths.save_json("science_summary", …)
and reads it back after the fit (autofit_workspace 424555d, 2026-09-09).
AbstractSearch._fit_bypass_test_mode (autofit/non_linear/search/abstract_search.py,
modes 2 and 3) writes samples + samples_summary, builds the result and calls
paths.completed(), but never calls analysis.save_results / save_results_combined,
unlike the normal path (start_resume_fit, ~line 829). Its docstring promises
"all expected output files so that downstream code sees a complete result folder".
Any workspace script that round-trips a custom save_results file therefore fails
under smoke. The gap predates the recent PyAutoFit commits (introduced with modes 2/3
in d41aa53).
Downstream save_results implementations (autogalaxy galaxies.json, autolens
tracer.json) are cheap JSON dumps already guarded against instance-build failures
(PyAutoFit #1535), so calling them from the bypass is safe in both modes.
Activity
Jammy2211 commentedon Sep 14, 2026
Library PR Created
PR: #1626 (
feature/test-mode-bypass-save-results, commit461ac836c, labelpending-release)_fit_bypass_test_modenow callsanalysis.save_resultsandanalysis.save_results_combinedbetweenmake_resultandpaths.completed(), matchingstart_resume_fitand ungated byskip_fit_output()— the smoke profile setsPYAUTO_SKIP_FIT_OUTPUT=1, so gating them would reproduce the bug under exactly the conditions the fix targets. Two source lines plus their comment, and a new parametrised test.Tests
pytest test_autofit/non_linear/search/test_abstract_search.py -k bypass→ 18 passed, 20 deselected.pytest test_autofit(full suite) → 2850 passed, 2 skipped, 255s.TestBypassCallsSaveResultsfails in both modes 2 and 3 — it is a real falsifier, not a passing bystander.Witness — the script Heart fails on, run from the canonical
autofit_workspaceroot with this branch'sautofitonPYTHONPATH(verified viaautofit.__file__), output cleared between runs so the.completedmarker could not shortcut the bypass:PyAutoFitmain,PYAUTO_TEST_MODE=2→ reproducesFileNotFoundError: .../files/science_summary.jsonatoverview_2_scientific_workflow.py:279.PYAUTO_TEST_MODE=2→ exit 0, line 279 prints the summary it wrote.PYAUTO_TEST_MODE=3→ exit 0, same print.Workspace impact: option (iii) — no workspace work needed. API Changes are
None — internal changes only. Threeautofit_workspacescripts define a customsave_results(overview/overview_2_scientific_workflow.py,cookbooks/analysis.py,cookbooks/result.py); onlyoverview_2round-trips its own file, which is why it is the only smoke failure. Expected Heart effect: bothautofitentries (.pyand.ipynb) go green in workspace-smoke, clearing 2 of the 3 workspace-validation failures in the current YELLOW (the third,autolens notebooks/imaging/slam.ipynb, is unrelated). Separate follow-up:overview_2is absent fromautofit_workspace/smoke_tests.txt, so only Heart's cloud run covers it.Readiness: Heart is YELLOW with no RED reasons, the same set acknowledged at approval and recorded as
heart-ack:on theactive.mdrow — workspace validation not passing (3 failed, cloud#34824535982); manifest drift x2; profiling drift x6; release validation incomplete.Next: merge stays human — run
/prmonce CI is green.🤖 Generated with Claude Code
https://claude.ai/code/session_01RbJGue5FwUPbxvCFKwXNam
Jammy2211 commentedon Sep 14, 2026
Shipped
Fixed in PyAutoFit#1626, merged as
559699fb1531ffe2205ae3b824bd29aadb39c145.AbstractSearch._fit_bypass_test_modenow callsanalysis.save_resultsandanalysis.save_results_combinedbetweenmake_resultandpaths.completed(),in the same position and with the same arguments as the normal path
(
start_resume_fit), and deliberately ungated byskip_fit_output()— thenormal path does not gate them, and the smoke profile that exposed the bug sets
PYAUTO_SKIP_FIT_OUTPUT=1.Two files, +72/-0:
autofit/non_linear/search/abstract_search.pyandtest_autofit/non_linear/search/test_abstract_search.py.Evidence
TestBypassCallsSaveResults, parametrised overPYAUTO_TEST_MODE"2"and"3"; with the source change stashed it fails in both modes (real falsifier).-k bypass→ 18 passed.autofit_workspaceroot: canonicalPyAutoFitmainreproducesFileNotFoundError: .../files/science_summary.jsonatoverview_2_scientific_workflow.py:279; this branch exits 0 and prints thescience_summaryit wrote under modes 2 and 3.unittest (3.12),unittest (3.13),unittest-nojax,docs-build.Workspace impact: none (option (iii)) — no API change, no workspace edit. Expected Heart effect: the two
autofit overview/overview_2_scientific_workflow.{py,ipynb}workspace-smoke failures clear.Note for a separate task:
overview_2is absent fromautofit_workspace/smoke_tests.txt, so only Heart's cloud run covers it.PyAutoFit is pending-release — merged is not published; a release build clears that.