Repository navigation
Description
Overview
When a script is smoke-tested under PYAUTO_TEST_MODE and then later run for real, AutoFit silently returns the cached test-mode result ("Fit Already Completed: skipping non-linear search") because the output path is identical between the two runs. The proper run never happens — symptom is every recovered σ on the supposedly-real run being exactly 0.
This was hit on the IC50 EP / graphical scripts. Current workaround is rm -rf output/<path-prefix>/ before the first proper run, which is runtime discipline contributors will forget. The structural fix is to namespace the test-mode output path so smoke and prod outputs are physically co-resident.
Plan
- Add a small helper in
autofit/non_linear/paths/abstract.pythat returns"test_mode"whenPYAUTO_TEST_MODEis set in the environment, elseNone. - Filter that segment into the path composition at every site that builds an output path from
conf.instance.output_path(three sites — see detailed plan). - Net effect: prod writes to
output/<prefix>/<name>/<id>/, test writes tooutput/test_mode/<prefix>/<name>/<id>/. Caches can no longer collide. - Add a PyAutoFit regression test that runs a search under
PYAUTO_TEST_MODE=2, then again with it unset, and asserts the second run re-fits. - Validation sweep:
/health_check+ per-workspace/smoke_testacross every workspace, includingic50_workspacewhere the bug was first hit.
Detailed implementation plan
Affected Repositories
- PyAutoFit (primary, code change)
- All workspaces (validation sweep only — no workspace edits): autofit_workspace, autogalaxy_workspace, autolens_workspace, autolens_workspace_test, autogalaxy_workspace_test, euclid_strong_lens_modeling_pipeline, ic50_workspace
Work Classification
Library (PyAutoFit) — single-repo code change with cross-workspace validation. No workspace code edits.
Branch Survey
| Repository | Current Branch | Dirty? |
|---|---|---|
| ./PyAutoFit | main | clean |
| ./PyAutoPrompt | main | clean (new prompt file untracked, expected) |
Suggested branch: feature/test-mode-output-path
Worktree root: ~/Code/PyAutoLabs-wt/test-mode-output-path/ (created by /start_library)
No conflicts: worktree_check_conflict test-mode-output-path PyAutoFit exits 0. The smoke-test-optimization entry in active.md touches PyAutoFit test_mode skip-guards but not the paths module, so the surface area doesn't overlap.
Implementation Steps
- Add the helper in
autofit/non_linear/paths/abstract.py, near the top of the module:def _test_mode_segment() -> Optional[str]: """Returns 'test_mode' when PYAUTO_TEST_MODE is set, else None.""" return "test_mode" if os.environ.get("PYAUTO_TEST_MODE") else None
- Patch the three composition sites to filter the segment in right after
conf.instance.output_path:autofit/non_linear/paths/abstract.py:239—output_pathproperty onAbstractPaths.autofit/non_linear/paths/directory.py:533—_make_path()onDirectoryPaths. (Note: this site already omitsunique_tagthat the property includes — pre-existing inconsistency, leave untouched.)autofit/database/__init__.py:60— read context first; patch only if it represents a search-output dir.
- Confirm
SubDirectoryPathsis covered for free — its_output_pathdelegates toself.parent.output_path, so the parent fix propagates. Verify by readingsub_directory_paths.py:31-79,123-128. - Add regression test in
test_autofit/non_linear/paths/test_paths.py:- Construct
DirectoryPaths(name=..., path_prefix=...)withPYAUTO_TEST_MODE=2set in the env, assert the resolvedoutput_pathcontainstest_modeas a path component. - Repeat with the env var unset, assert it does not.
- Use
monkeypatch.setenv/monkeypatch.delenvso the test is isolated.
- Construct
- Document the new path layout in the relevant docstring (the
AbstractPaths.__init__docstring already includes a worked example — add a one-paragraph note thatPYAUTO_TEST_MODEprependstest_mode/). - Run PyAutoFit unit suite — must be green.
- Cross-workspace validation sweep:
/health_check(fast-forward all repos, run library unit tests + workspace smoke).- Targeted
/smoke_testper workspace: autofit_workspace, autogalaxy_workspace, autolens_workspace, autolens_workspace_test, autogalaxy_workspace_test, euclid_strong_lens_modeling_pipeline, ic50_workspace.
- Manual cross-check on one or two scripts that already have output in
output/: run withPYAUTO_TEST_MODE=2, confirm the artefact lands underoutput/test_mode/..., then run unset and confirm the second invocation actually runs the sampler (no "Fit Already Completed").
Key Files
PyAutoFit/autofit/non_linear/paths/abstract.py— helper + property patch.PyAutoFit/autofit/non_linear/paths/directory.py—_make_path()patch.PyAutoFit/autofit/database/__init__.py— possibly patch, depends on context.PyAutoFit/test_autofit/non_linear/paths/test_paths.py— regression test.
Post-merge follow-up
Update memory feedback_autofit_cache_resume_pyauto_test_mode: the rm -rf workaround is obsolete once this ships.
Original Prompt
Click to expand starting prompt
PYAUTO_TEST_MODE should mutate the AutoFit output path
When a script is smoke-tested under PYAUTO_TEST_MODE and then later run for real, AutoFit silently returns the cached test-mode result ("Fit Already Completed: skipping non-linear search") because the output path is identical between the two runs. The proper run never happens — symptom is every recovered σ on the supposedly-real run being exactly 0.
This was hit on the IC50 EP / graphical scripts and the current workaround is "rm -rf output/<path-prefix>/ before the first proper run", which is runtime discipline that contributors will forget.
What I want
Make PYAUTO_TEST_MODE mutate the output path so smoke and prod outputs are physically co-resident and can't collide. The rm -rf workaround becomes unnecessary.
Where
Inject a test_mode/ segment at the root of the output tree when os.environ.get("PYAUTO_TEST_MODE") is set and truthy:
- prod:
output/<prefix>/<name>/<identifier>/ - test:
output/test_mode/<prefix>/<name>/<identifier>/
I prefer collecting all test-mode outputs under one tree (easy to gitignore or wipe wholesale) rather than splitting at the identifier level.
There are three places that compose paths from conf.instance.output_path — they all need the same treatment, so factor a shared helper rather than patching each site:
PyAutoFit/autofit/non_linear/paths/abstract.py:239—output_pathproperty onAbstractPaths.PyAutoFit/autofit/non_linear/paths/directory.py:533—_make_path()onDirectoryPaths, which reconstructs the path manually instead of using the property. (Aside: it omitsunique_tagwhile the property includes it — pre-existing inconsistency, don't fix here.)PyAutoFit/autofit/database/__init__.py:60— read the surrounding context before patching; may or may not need the segment depending on whether it represents a search-output dir.
SubDirectoryPaths overrides output_path in sub_directory_paths.py:74,123 but its _output_path delegates to self.parent.output_path, so it inherits the fix for free via the parent.
Suggested helper signature:
def _test_mode_segment() -> Optional[str]:
return "test_mode" if os.environ.get("PYAUTO_TEST_MODE") else NoneThen filter it into the path components at each of the three sites, right after conf.instance.output_path.
Validation
The code change is small; the cost is validation across every workspace, since the risk is a script that secretly relies on smoke and prod sharing the output path.
- PyAutoFit unit suite green.
- Add a regression test: run a search under
PYAUTO_TEST_MODE=2, then again withPYAUTO_TEST_MODEunset, and assert the second run re-fits (does not hit theis_completeshort-circuit). /health_checkfollowed by/smoke_teston every workspace:autofit_workspace,autogalaxy_workspace,autolens_workspace,autolens_workspace_test,autogalaxy_workspace_test,euclid_strong_lens_modeling_pipeline,ic50_workspace. ic50 is where the bug was first hit so it must be in the sweep.- Pick one or two scripts that already have output in
output/, run them with and withoutPYAUTO_TEST_MODE, and confirm the two land in distinct directories.
Out of scope
- Renaming smoke runs script-by-script (the whole point is the per-script rename is unnecessary).
- Touching the
is_completeshort-circuit — once paths differ, the existing logic is correct.
Once shipped
Update the feedback_autofit_cache_resume_pyauto_test_mode memory: the rm -rf workaround is obsolete.
Activity
Jammy2211 commentedon May 22, 2026
Smoke Test Results — 2026-05-22
Library PR: #1292
Native-habitat confirmation:
z_projects/ic50_workspace/scripts/ep_sim.pyexit 0 underPYAUTO_TEST_MODE=2, output landed atoutput/test_mode/ep_sim/...(notoutput/ep_sim/...). The path mutation fires correctly in the workspace where the original bug was hit.Failure summary
All 7 failures share one root cause and are confined to the two
_testworkspaces' aggregator scripts. Pattern:os.environ["PYAUTO_TEST_MODE"] = "1"inline (before importing autofit).output/test_mode/<db_name>/<hash>/.agg.add_directory(directory="<bare>/output/<db_name>/")— the bare path, missing the newtest_mode/segment.assert i == 2fails.This is real workspace-side migration work, not a library-side defect. The library is doing exactly what it was designed to do.
Affected aggregator scripts
autolens_workspace_test/scripts/aggregator/fit_imaging.pyautolens_workspace_test/scripts/aggregator/fit_interferometer.pyautolens_workspace_test/scripts/aggregator/tracer.pyautogalaxy_workspace_test/scripts/aggregator/galaxies.pyautogalaxy_workspace_test/scripts/aggregator/fit_imaging.pyautogalaxy_workspace_test/scripts/aggregator/fit_interferometer.pyautogalaxy_workspace_test/scripts/aggregator/ellipse.pyLikely fix: make the scripts read the result directory via the paths machinery (
paths.output_path) rather than reconstructing the bare path. To be designed in/start_workspace.Status
Library PR holds until the 7 aggregator scripts are migrated. Status moved to
library-shipped, workspace-pendingin active.md. Next step:/start_workspace.Jammy2211 commentedon May 22, 2026
Shipped — 2026-05-22
PRs
Summary
PYAUTO_TEST_MODEnow namespaces AutoFit output paths underoutput/test_mode/...via a_test_mode_segment()helper threaded through three composition sites (AbstractPaths.output_path,DirectoryPaths._make_path, andopen_databasefor relative filenames). Smoke and prod runs are now physically co-resident — therm -rf output/<path-prefix>/workaround is no longer needed. PyAutoFit unit suite stayed green (1408 passed). Cross-workspace validation sweep surfaced 7 aggregator integration scripts in the two_testworkspaces that hardcodedPYAUTO_TEST_MODE=1inline and reconstructedresult_pathfromconf.instance.output_path; those were migrated to include thetest_mode/segment alongside the library change.Session Notes
output_pathproperty patch would cover everything.DirectoryPaths._make_path()reconstructs the path manually instead of using the property, andautofit.database.open_database()joins ontoconf.instance.output_pathdirectly when the filename is relative. The shared_test_mode_segment()helper avoids drift but each site needs its own injection.Aggregator.from_database(filename=db_path)in the aggregator scripts passes an absolute path, which bypasses the segment injection inopen_database. The fit's search-output directory gets the segment; the SQLite file lives at the bare root. The migration in the workspace PRs reflects that asymmetry.z_projects/ic50_workspace/scripts/ep_sim.py(where the bug was first hit) runs cleanly underPYAUTO_TEST_MODE=2and writes tooutput/test_mode/ep_sim/.... Therm -rf output/ep_sim/cleanup inprofile_ep_sim.pystill works (it just deletes an empty bare path) — worth removing in a future cleanup pass but not load-bearing.feedback_autofit_cache_resume_pyauto_test_modeupdated: therm -rfworkaround is obsolete; the new guidance is to include"test_mode"as a segment in any manual path composition that reads back search outputs.