Overview
Profile and optimize the PyAutoGalaxy unit test suite to reduce total runtime by 25-35%. The source code is stable, so this only touches test code and test configuration. Follows the same approach proven on PyAutoFit (61s→41s).
Plan
- Remove redundant
visualize_before_fit() calls from aggregator test fixtures — these duplicate work already done by search.fit() and no aggregator test asserts on visualization outputs
- Disable FITS/CSV file output in test visualization config — real disk I/O that no test depends on
- Reduce interferometer simulate-and-fit grid sizes from 51×51 to 31×31 where assertions are grid-size-independent
Detailed implementation plan
Affected Repositories
Work Classification
Library
Branch Survey
| Repository |
Current Branch |
Dirty? |
| ./PyAutoGalaxy |
main |
minor (CLAUDE.md, docs, scrap.py) |
Suggested branch: feature/unit-test-profiling
Implementation Steps
-
Remove visualize_before_fit() line from 4 files:
test_autogalaxy/aggregator/conftest.py:51
test_autogalaxy/aggregator/ellipse/conftest.py:51
test_autogalaxy/aggregator/imaging/test_aggregator_fit_imaging.py:33
test_autogalaxy/aggregator/ellipse/test_aggregator_fit_ellipse.py:33
-
Disable FITS/CSV flags in test_autogalaxy/config/visualize.yaml:
fits_fit, fits_galaxy_images, fits_model_galaxy_images → false
fits_dirty_images → false
csv_reconstruction → false
-
Reduce grid sizes in test_autogalaxy/interferometer/test_simulate_and_fit_interferometer.py:
test__perfect_fit: 51×51→31×31 grid, 7→3 UV wavelengths, 7×7→5×5 mesh
test__linear_light_profiles_agree: 51×51→31×31 grid
-
Run full test suite to verify all 852 tests pass
Key Files
test_autogalaxy/aggregator/conftest.py — redundant viz call
test_autogalaxy/aggregator/ellipse/conftest.py — redundant viz call
test_autogalaxy/aggregator/imaging/test_aggregator_fit_imaging.py — redundant viz call
test_autogalaxy/aggregator/ellipse/test_aggregator_fit_ellipse.py — redundant viz call
test_autogalaxy/config/visualize.yaml — FITS/CSV output flags
test_autogalaxy/interferometer/test_simulate_and_fit_interferometer.py — grid sizes
Original Prompt
Click to expand starting prompt
Profile and speed up unit tests in @PyAutoGalaxy.
Goal
Reduce the test suite runtime by identifying and optimizing slow tests. The source code is stable, so safe changes to test parameters are acceptable — but prompt the user before changing any numerical assertion values.
Approach (proven on PyAutoFit)
- Profile: Run
pytest <test_dir> --durations=0 -q to get wall-clock times for all tests
- Identify: Find the top 30+ slowest tests and read their source to understand bottlenecks
- Categorize: Group by cause — large data arrays, excessive iterations/max_steps, expensive fixtures, real sampler initialization (Dynesty)
- Optimize (in order of impact):
- Reduce
n_obs, data array sizes, range(N) loop counts where tests use more data than needed for their assertion tolerances
- Reduce
max_steps, n_iters, maxcall values in EP/sampler tests that validate plumbing not convergence
- Reduce
number_of_steps in grid search fixtures to shrink the job count (e.g. 10->5 gives 25 jobs instead of 100)
- Adjust query/assertion values if data range changes (e.g. if range(100)->range(50), update assertions that referenced value 50 to value 25)
- Leave tests with inherent sampler initialization overhead (DynestyStatic with maxcall<=5) as-is
- Verify: Run full suite, confirm all tests pass, compare before/after total time
What NOT to change
- Don't change numerical reference values in assertions without user approval
- Don't change fixture scoping to module/session — this conflicts with function-scoped
set_config_path autouse fixtures
- Don't mock real sampler tests — they test actual sampling behavior
- Don't change
test_messages.py::test_normal_simplex — the slowness is numerical quadrature integration
Known pattern: FactorValue hash collision
If you encounter a KeyError: <GaussianPrior id=0> in AbstractJacobian.grad(), this is a known bug where FactorValue (id=0) hash-collides with a GaussianPrior that gets id=0. This was fixed in PyAutoFit PR #1182 — check that the fix is present in the installed autofit version.
Target
25-35% reduction in total test runtime. On PyAutoFit this took 61s -> 41s.
Overview
Profile and optimize the PyAutoGalaxy unit test suite to reduce total runtime by 25-35%. The source code is stable, so this only touches test code and test configuration. Follows the same approach proven on PyAutoFit (61s→41s).
Plan
visualize_before_fit()calls from aggregator test fixtures — these duplicate work already done bysearch.fit()and no aggregator test asserts on visualization outputsDetailed implementation plan
Affected Repositories
Work Classification
Library
Branch Survey
Suggested branch:
feature/unit-test-profilingImplementation Steps
Remove
visualize_before_fit()line from 4 files:test_autogalaxy/aggregator/conftest.py:51test_autogalaxy/aggregator/ellipse/conftest.py:51test_autogalaxy/aggregator/imaging/test_aggregator_fit_imaging.py:33test_autogalaxy/aggregator/ellipse/test_aggregator_fit_ellipse.py:33Disable FITS/CSV flags in
test_autogalaxy/config/visualize.yaml:fits_fit,fits_galaxy_images,fits_model_galaxy_images→ falsefits_dirty_images→ falsecsv_reconstruction→ falseReduce grid sizes in
test_autogalaxy/interferometer/test_simulate_and_fit_interferometer.py:test__perfect_fit: 51×51→31×31 grid, 7→3 UV wavelengths, 7×7→5×5 meshtest__linear_light_profiles_agree: 51×51→31×31 gridRun full test suite to verify all 852 tests pass
Key Files
test_autogalaxy/aggregator/conftest.py— redundant viz calltest_autogalaxy/aggregator/ellipse/conftest.py— redundant viz calltest_autogalaxy/aggregator/imaging/test_aggregator_fit_imaging.py— redundant viz calltest_autogalaxy/aggregator/ellipse/test_aggregator_fit_ellipse.py— redundant viz calltest_autogalaxy/config/visualize.yaml— FITS/CSV output flagstest_autogalaxy/interferometer/test_simulate_and_fit_interferometer.py— grid sizesOriginal Prompt
Click to expand starting prompt
Profile and speed up unit tests in @PyAutoGalaxy.
Goal
Reduce the test suite runtime by identifying and optimizing slow tests. The source code is stable, so safe changes to test parameters are acceptable — but prompt the user before changing any numerical assertion values.
Approach (proven on PyAutoFit)
pytest <test_dir> --durations=0 -qto get wall-clock times for all testsn_obs, data array sizes,range(N)loop counts where tests use more data than needed for their assertion tolerancesmax_steps,n_iters,maxcallvalues in EP/sampler tests that validate plumbing not convergencenumber_of_stepsin grid search fixtures to shrink the job count (e.g. 10->5 gives 25 jobs instead of 100)What NOT to change
set_config_pathautouse fixturestest_messages.py::test_normal_simplex— the slowness is numerical quadrature integrationKnown pattern: FactorValue hash collision
If you encounter a
KeyError: <GaussianPrior id=0>inAbstractJacobian.grad(), this is a known bug whereFactorValue(id=0) hash-collides with a GaussianPrior that gets id=0. This was fixed in PyAutoFit PR #1182 — check that the fix is present in the installed autofit version.Target
25-35% reduction in total test runtime. On PyAutoFit this took 61s -> 41s.