Skip to content

Add PYAUTOFIT_TEST_MODE levels 2 and 3 to bypass sampler#1180

Merged
Jammy2211 merged 1 commit intomain_buildfrom
feature/test-mode-bypass
Apr 6, 2026
Merged

Add PYAUTOFIT_TEST_MODE levels 2 and 3 to bypass sampler#1180
Jammy2211 merged 1 commit intomain_buildfrom
feature/test-mode-bypass

Conversation

@Jammy2211
Copy link
Copy Markdown
Collaborator

Summary

Adds two new test mode levels that bypass the sampler entirely, enabling much faster integration/smoke testing. Level 2 calls the likelihood function once (to verify it works), level 3 skips everything for maximum speed. Both produce the full output folder structure so downstream code works unchanged.

Also centralizes all scattered os.environ.get("PYAUTOFIT_TEST_MODE") checks into a shared test_mode.py module and improves log messages to describe each level's behavior.

Timing on model_fit.py: mode 1 ~71s → mode 2 ~37s → mode 3 ~32s.

Closes #1179

API Changes

Added autofit.non_linear.test_mode module with is_test_mode() and test_mode_level() public helpers. Existing PYAUTOFIT_TEST_MODE=1 behavior is unchanged. New levels 2 and 3 are opt-in via the same environment variable.
See full details below.

Test Plan

  • PyAutoFit unit tests: 1198 passed
  • PyAutoArray unit tests: 739 passed
  • PyAutoGalaxy unit tests: 852 passed
  • PyAutoLens unit tests: 286 passed
  • Smoke tests with mode 2 and 3: no new failures
Full API Changes (for automation & release notes)

Added

  • autofit.non_linear.test_mode.test_mode_level() — returns current test mode level (0-3)
  • autofit.non_linear.test_mode.is_test_mode() — returns True if any test mode is active
  • AbstractSearch._fit_bypass_test_mode(model, analysis, call_likelihood) — internal method to bypass sampler in modes 2/3
  • AbstractSearch._build_fake_samples(model, parameter_vector, log_likelihood) — internal method to build minimal Sample objects for bypass mode
  • PYAUTOFIT_TEST_MODE=2 — bypass sampler, call likelihood once
  • PYAUTOFIT_TEST_MODE=3 — bypass sampler and likelihood entirely

Changed Behaviour

  • All internal os.environ.get("PYAUTOFIT_TEST_MODE") == "1" checks replaced with is_test_mode() which returns True for levels 1, 2, and 3
  • Test mode log messages now describe each level's specific behavior

Migration

  • No migration needed — existing PYAUTOFIT_TEST_MODE=1 behavior is unchanged
  • Downstream repos should import from autofit.non_linear.test_mode import is_test_mode instead of checking the env var directly

🤖 Generated with Claude Code

Level 2 skips the sampler but calls the likelihood function once to
verify it works. Level 3 skips both sampler and likelihood for maximum
speed. Both produce the full output folder structure for downstream
compatibility.

Also centralizes scattered os.environ test mode checks into a shared
test_mode.py module with is_test_mode() and test_mode_level() helpers,
and improves log messages to describe each level's behavior.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@Jammy2211 Jammy2211 merged commit 818624d into main_build Apr 6, 2026
1 check passed
@Jammy2211 Jammy2211 deleted the feature/test-mode-bypass branch April 6, 2026 12:30
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