Skip to content

refactor: remove UltraNest and PySwarms, clean up search tests #1190

@Jammy2211

Description

@Jammy2211

Overview

Remove UltraNest and PySwarms search implementations from PyAutoFit to simplify the codebase. Both searches are preserved in the new autofit_workspace_developer repository with runnable examples. This also cleans up unit tests (adds Nautilus tests, expands abstract search coverage) and fixes pre-existing copy-paste bugs in Nautilus docstrings.

Plan

  • Archive UltraNest and PySwarms code to autofit_workspace_developer with examples
  • Remove source, imports, dependencies, configs, docs, citations, and tests from PyAutoFit
  • Fix Nautilus docstrings that incorrectly referenced UltraNest
  • Add Nautilus config test coverage (previously untested)
  • Expand abstract search test coverage
Detailed implementation plan

Affected Repositories

  • PyAutoFit (primary)
  • autofit_workspace_developer (new — archive)

Work Classification

Library

Branch Survey

Repository Current Branch Dirty?
./PyAutoFit feature/search-remove-ultranest-pyswarms changes staged
./autofit_workspace_developer main clean

Suggested branch: feature/search-remove-ultranest-pyswarms

Implementation Steps

  1. Created Jammy2211/autofit_workspace_developer with UltraNest and PySwarms source + examples
  2. Deleted autofit/non_linear/search/nest/ultranest/ and autofit/non_linear/search/mle/pyswarms/
  3. Removed imports from autofit/__init__.py
  4. Removed pyswarms==1.3.0 from dependencies and ultranest==4.3.2 from optional deps
  5. Removed config blocks from nest.yaml, mle.yaml, test configs, and visualize.yaml
  6. Removed from docs (searches.rst, search.rst cookbook, interpolate.rst, installation/overview.rst)
  7. Removed from citations (citations.md, citations.bib, citation.tex, paper.md, paper.bib)
  8. Fixed Nautilus copy-paste bugs (referenced "ultranest" instead of "nautilus")
  9. Updated CLAUDE.md, AGENTS.md, README files
  10. Added test_nautilus.py with 3 tests (config loading, identifier fields, test mode)
  11. Added 5 tests to test_abstract_search.py (config dicts, unique_tag, path_prefix, identifier fields)
  12. Verified: all 1205 tests pass, zero grep hits for ultranest/pyswarms

Key Files

  • autofit/__init__.py — removed 3 imports
  • pyproject.toml — removed 2 dependencies
  • autofit/config/non_linear/nest.yaml — removed UltraNest block
  • autofit/config/non_linear/mle.yaml — removed PySwarms blocks
  • docs/api/searches.rst, docs/cookbooks/search.rst — removed sections

Downstream cleanup needed (separate follow-up)

  • autofit_workspace — 32 files reference pyswarms/ultranest
  • autolens_workspace — 9 files
  • PyAutoGalaxy — 9 files (docs, citations)
  • PyAutoLens — 5 files (docs, citations)

Assessment: Future refactoring opportunities

After reviewing the non-linear search package, here are the key improvement areas for future phases:

  1. Issue Move search update to new class #1003 — Extract SearchUpdate class: perform_update and perform_visualization in abstract_search.py interact with many modules (saving samples, visualization, profiling, outputting results). Extracting to a SearchUpdate class would make each output task its own method.

  2. Issue Simplify Samples calculation via search #1002 — Simplify samples coupling: The samples_cls / samples_via_internal_from / samples_via_csv_from methods are tightly coupled. A factory in Samples that inspects search_internal type would decouple sample types from search types.

  3. Abstract search length (1353 lines): Composition and separation of concerns could significantly reduce this. Candidates for extraction: config loading boilerplate, multiprocessing pool management, path/output management.

  4. Config boilerplate: Every search constructor repeats self._config("parallel", "number_of_cores") pattern. This could be pushed into the base class.

  5. Missing integration tests: No tests actually run a search, even in test_mode. All existing tests only verify config loading. Lightweight end-to-end tests using test_mode would catch regressions in the _fitsamples_via_internal_from pipeline.

  6. Docstring quality: Copy-paste errors exist across searches (Nautilus had two UltraNest references, now fixed). A systematic audit would catch more.

Original Prompt

Click to expand starting prompt

The PyAutoFit non-linear search package allows us to perform modeling with a search.

A high level description of modeling is given in @autofit_workspace/scripts/overview/overview_1_the_basics.py

The full model API is given in the cookbook files @autofit_workspace/scripts/cookbooks/search.py
and their applicaiton in @autofit_workspace/scripts/cookbooks/analysis.py

Another guide is @autofit_workspace/scirpts/howtofit/chapter_1_introduction/tutorial_3_non_linear_search.py

The file @autofit_workspace/scirpts/howtofit/chapter_2_scientific_workflow shows many of the key outputs possible
with a search, which allows a user to inspect and judge results, which is a key feature of autofit.

Searches are defined in the source code mostly at @PyAutoFit/autofit/non_linear

There is a lot of scope to refactor and redesign this package, first, we can remove:

  • ultranest (PyAutoFit/autofit/non_linear/search/nest/ultranest)
  • pyswarms (PyAutoFit/autofit/non_linear/search/mle/pyswarms)

The following github describe some clean up and refactors:

#1003

#1002

First, after removing ultranest and pyswarms, can you review the unit tests, clean them up and add more test
coverage if you think it is needed? Then we can start to design the new API and implement it.

However, by remove, I dont want the code to be gone and lost forever. Can you
move their implmenetations to @autofit_workspace_developer,ensuring they can be run
with a test case locally. But such that most of the code which is a pain to keep ones head around
is in place.

The things I see that could be improved in this package are:

  • Look for unused functions and variables and remove them, to clean the code base and make it more concise.
  • Can the link between each search (e.g. samples_via_internal_from) and samples be improved or made more concise?
  • Attempts to make abstract_search a lot shorter by using composition and separation of concerns to move a lot
    of the functionality performed there into standalone packages and moduels. I Think there are ltos of sections
  • guilty of this. Do this by running against a simple test script in @autofit_workspace_test carefully.

However,can you give me your assessment oft he pckage and where you think.

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