Skip to content

refactor: drop output metadata file; aggregator keys on files/search.json #1582

Closed

Description

@Jammy2211

Overview

Every DirectoryPaths.save_all writes a two-line metadata file (name=…, non_linear_search=…) into each search output folder. A 2026-09-08 survey found it has one load-bearing consumer: Aggregator.from_directory uses "metadata" in filenames as the sentinel that a directory is a search output. files/search.json is already written unconditionally by the same save_all, so the sentinel can move there at no run-time or aggregation cost. Resume keys entirely on .completed, so in-flight runs are unaffected. This task stops writing metadata, keys discovery on files/search.json (still accepting legacy metadata folders), and derives the non_linear_search filter attribute from search.json.

Plan

  • Aggregator discovers a search output when <root>/files/search.json exists; legacy folders carrying only metadata still aggregate.
  • SearchOutput stops parsing metadata; non_linear_search becomes a property read from search.json's class_path.
  • Delete _save_metadata and its call; fix the skip-fit-output comment that references the file.
  • Remove the four metadata test fixtures; update the zip round-trip assertion; add discovery and filter tests.
  • Update the two mock-result writers and the profiling harness (autofit_workspace_test, autolens_workspace_developer) to stop appending metadata and to key on unique_tag instead of the injected dataset_name.
Detailed implementation plan

Affected Repositories

  • PyAutoFit (primary)
  • autofit_workspace_test
  • autolens_workspace_developer

Branch Survey

Repository Current Branch Dirty?
./PyAutoFit main clean
./autofit_workspace_test main clean
./autolens_workspace_developer main clean

worktree_check_conflict fires: PyAutoFit and autofit_workspace_test are claimed by traced-assertions-on-jax-path (#1581). Its file set (autofit/mapper/prior/arithmetic/assertion.py, autofit/mapper/prior_model/{abstract,constraint}.py, autofit/non_linear/fitness.py + tests) is disjoint from this task, so this task runs in its own parallel worktree (recorded as parallel-claim: in active.md).

Suggested branch: feature/aggregator-search-json-sentinel

Implementation Steps

PyAutoFit:

  1. autofit/aggregator/aggregator.py (from_directory → scan, ~L195): replace if "metadata" in filenames: with a helper _is_search_output(root, dirs, filenames) = ("files" in dirs and (Path(root)/"files"/"search.json").exists()) or "metadata" in filenames. The "files" in dirs guard keeps the check at the search root so os.walk never hands the files/ directory itself to SearchOutput. .is_grid_search handling unchanged.
  2. autofit/aggregator/search_output.py (SearchOutput.__init__ ~L216–225, __str__/__repr__ ~L430): remove the metadata read into __dict__/self.text. Add @property non_linear_search returning class_path.rsplit(".", 1)[-1].lower() from files/search.json (no search instantiation), matching what _save_metadata wrote so existing filters keep their values. Replace __str__/__repr__ with a description built from self.directory.
  3. autofit/non_linear/paths/directory.py: delete _save_metadata (~L472–481) and its call at the end of save_all (~L384). Verify no override in sub_directory_paths.py / database.py / null.py.
  4. autofit/non_linear/search/abstract_search.py (~L573–576): rewrite the skip-fit-output comment to name files/search.json + identifier files as what aggregator discovery needs.
  5. Tests: git rm test_autofit/aggregator/{search_output,search_output_derived,summary_files/aggregate_summary/fit_1,summary_files/aggregate_summary/fit_2}/metadata; test_from_directory.py:37 asserts files/search.json survives the zip round-trip; new tests: folder with only files/search.json is discovered, folder with files/ but no search.json is not, files/ itself is never returned, legacy metadata-only folder is discovered, agg.query(agg.non_linear_search == "dynestystatic") matches the search_output fixture and "emcee" matches search_output_derived. Grep test_autofit for _save_metadata, "metadata", .text and fix remaining hits. Check the 70-byte search_output_derived/metadata for keys a test relies on via __dict__ injection.

Workspace side (after the library PR is open):
6. autofit_workspace_test/scripts/profiling/aggregator/mock_results.py: drop the metadata append in stamp_results (~L183–184); unique_tag already carries the dataset name in search.json. Update docstrings (L86, L95–96, L170).
7. autofit_workspace_test/scripts/profiling/aggregator/profile_aggregator.py: agg.dataset_name == … → agg.unique_tag == …; output_to_folder(name="dataset_name") → name="unique_tag" for AggregateImages and AggregateFITS. Keep the query_dataset_name timing key if any results README/dashboard parses it (grep first).
8. autolens_workspace_developer/aggregator_profiling/mock_lens_results.py: same as step 6 (~L126–127; docstrings L14–15, L82, L94–95); apply the unique_tag substitution to any sibling profiling script that queries dataset_name.

Key Files

  • PyAutoFit/autofit/aggregator/aggregator.py — directory-walk sentinel
  • PyAutoFit/autofit/aggregator/search_output.py — SearchOutput metadata parse, non_linear_search, __str__
  • PyAutoFit/autofit/non_linear/paths/directory.py — _save_metadata writer
  • PyAutoFit/autofit/non_linear/search/abstract_search.py — skip-fit-output comment
  • PyAutoFit/test_autofit/aggregator/ — fixtures and from-directory tests
  • autofit_workspace_test/scripts/profiling/aggregator/{mock_results,profile_aggregator}.py
  • autolens_workspace_developer/aggregator_profiling/mock_lens_results.py

Verification

  • pytest test_autofit -q green in the worktree.
  • Tiny test-mode fit from the worktree: output folder has no metadata; af.Aggregator.from_directory(output) returns it; agg.query(agg.non_linear_search == "<search>") matches.
  • Legacy: from_directory on an existing pre-change output folder returns the same count.
  • Resume: delete metadata from an incomplete output folder and re-run; the fit resumes.

Original Prompt

Click to expand starting prompt

Remove the output-folder metadata file; aggregator discovers searches via files/search.json

Type: refactor
Target: PyAutoFit
Repos:

  • PyAutoFit
  • autofit_workspace_test
  • autolens_workspace_developer
    Difficulty: small
    Autonomy: supervised
    Priority: medium
    Status: formalised
    Witness: no search output folder written by DirectoryPaths.save_all contains a metadata file; Aggregator.from_directory on a fresh run (and on a legacy folder that still carries metadata) returns the same search outputs as before; agg.filter(agg.non_linear_search == ...) still works, sourced from search.json; resume of a run whose metadata file has been deleted is unaffected; full PyAutoFit test suite green.
    Unattended: ready
    Filed: 2026-09-08

Original request (verbatim):

Is the "metadata" file that is output to the output folder of all autofit /
autolens runs still required? Is there any way we could remove it or would
this disrupt on going runs

Would using search.json impact run time in a meaningful way? If not then
that is the solution

lets go, use search.json and remove metadata

Findings (2026-09-08 survey):

  • Sole writer: DirectoryPaths._save_metadata (autofit/non_linear/paths/directory.py),
    called last in save_all. Two key=value lines: name=, non_linear_search=.
    Appends, so resumed runs duplicate the block.
  • Sole sentinel: Aggregator.from_directory (autofit/aggregator/aggregator.py)
    treats a directory as a search output iff "metadata" in filenames. The
    database scrape and MCP tools inherit this by iterating the aggregator.
  • SearchOutput.__init__ (autofit/aggregator/search_output.py) parses it
    into self.__dict__; name is shadowed by the property reading
    search.json, so only non_linear_search survives as a filter attribute.
    Absence is already swallowed (FileNotFoundError passed).
  • Resume keys entirely on .completed; nothing on that path reads metadata.
  • files/search.json is written unconditionally by the same save_all
    (including the skip-fit-output branch), so switching costs no I/O.
  • Trap: search.json lives one level down in files/; the sentinel must be
    checked from the search root ("files" in dirs + exists), not by name match
    in filenames, or os.walk would hand SearchOutput the files/ dir.
  • Mock writers to update: autofit_workspace_test/scripts/profiling/aggregator/mock_results.py,
    autolens_workspace_developer/aggregator_profiling/mock_lens_results.py.
  • Test fixtures under test_autofit/aggregator/ carry metadata files;
    test_from_directory.py asserts one survives a zip round-trip.

Activity

  1. Jammy2211 commented on Sep 8, 2026

    @Jammy2211
    CollaboratorAuthor

    Library PR created: #1585 (2477 passed, 2 skipped; end-to-end fit writes no metadata, aggregator discovers via files/search.json).

    Workspace follow-ups, behind the library-first gate:

    Resume is unaffected: nothing on the .completed path reads the file, so in-flight runs carry on and legacy output folders still aggregate.

  2. Jammy2211 commented on Sep 8, 2026

    @Jammy2211
    CollaboratorAuthor

    Shipped

    Resume is unaffected (keyed on .completed); in-flight runs and existing output folders keep aggregating. The library change is pending release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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