Skip to content

feat: add sampler bypass modes to PYAUTOFIT_TEST_MODE #1179

@Jammy2211

Description

@Jammy2211

Overview

PYAUTOFIT_TEST_MODE=1 reduces sampler iterations but still instantiates and runs the sampler, which takes noticeable time for smoke tests. This adds two new bypass modes (levels 2 and 3) that skip the sampler entirely while still producing the full output folder structure, enabling much faster integration/smoke testing.

Plan

  • Add PYAUTOFIT_TEST_MODE=2: bypass sampler, call likelihood once (verifies likelihood function works)
  • Add PYAUTOFIT_TEST_MODE=3: bypass sampler and skip likelihood (maximum speed)
  • Keep PYAUTOFIT_TEST_MODE=1 unchanged (existing behavior)
  • Add centralized is_test_mode() / test_mode_level() helpers to replace scattered env var checks
  • Update downstream repos (PyAutoArray, PyAutoGalaxy, PyAutoLens) to use the new helper
Detailed implementation plan

Affected Repositories

  • rhayes777/PyAutoFit (primary)
  • Jammy2211/PyAutoArray
  • Jammy2211/PyAutoGalaxy
  • Jammy2211/PyAutoLens

Work Classification

Library

Branch Survey

Repository Current Branch Dirty?
./PyAutoFit main_build clean
./PyAutoArray main clean (untracked only)
./PyAutoGalaxy main clean (untracked only)
./PyAutoLens main clean

Suggested branch: feature/test-mode-bypass

Implementation Steps

  1. Create PyAutoFit/autofit/non_linear/test_mode.py with test_mode_level() and is_test_mode() helpers
  2. Add _fit_bypass_test_mode() and _build_fake_samples() to AbstractSearch in abstract_search.py
  3. Modify start_resume_fit() to route to bypass when mode >= 2
  4. Guard post_fit_output() for None search_internal
  5. Replace all os.environ.get("PYAUTOFIT_TEST_MODE") == "1" checks with is_test_mode() across all 4 repos
  6. Run timing comparison with modes 1, 2, 3 on model_fit.py

Key Files

  • PyAutoFit/autofit/non_linear/search/abstract_search.py — main bypass logic
  • PyAutoFit/autofit/non_linear/samples/sample.py — Sample class
  • PyAutoFit/autofit/non_linear/samples/pdf.py — SamplesPDF constructor
  • PyAutoFit/autofit/non_linear/initializer.py — existing test mode reference
  • PyAutoFit/autofit/non_linear/test_mode.py — new utility module

Original Prompt

Click to expand starting prompt

PYAUTOFIT_TEST_MODE is used to make integration scripts run faster, and it does the following:

  • Makes the sampler use only 50 samples if its Nautilus, or for other samples some other value that reduces run time.
  • Disables all visualization so images are not output for speed up.
  • Disables some other features to speed things up.

The problem is that running Nautilus with PYAUTOFIT_TEST_MODE=1 still takes some time and means integration testing, especially smoke tests, still has some time to run.

In test mode, can you run the file @autolens_workspace_test/scripts/imaging/model_fit.py and do an assessment if whether there is a way we can have test mode run but in a way which does not require Nautilus itself to be run. The truth is we just want the output folder state to be output as if its run so that we can use test mode for testing.

One part of behaviour we do want is currently test mode does call the likelihood function, and thus it does make sure that the likelihood function can be called correct in these scripts. This will be where some run time is lost, but it is important to make sure the likelihood function can be called correctly in test mode.

Can you investigate the behaviour for two cases, where the likelihood function is called when you try to bypass and nautilus and one where its not called at all. Compare their runtimes, we may make it so test mode can do either and we customize tests to use one or the other depending on the test.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions