Skip to content

feat: results-library phase 0b — honest reads - #1737

Merged
Jammy2211 merged 1 commit into
mainfrom
feature/results-library-p0b-honest-reads
Oct 29, 2026
Merged

Jammy2211 merged 1 commit into
mainfrom
feature/results-library-p0b-honest-reads

Conversation

@Jammy2211

@Jammy2211 Jammy2211 commented Oct 29, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Results-library phase 0, PR 0b of 2 (#1734), stacked on PR 0a. Makes the aggregator and AggregateCSV report problems instead of hiding them:

  • one corrupt or damaged result zip no longer aborts a whole Aggregator.from_directory scan; it is collected in agg.errors (or raised with on_error="raise")
  • an aggregator that finds nothing logs a warning naming the directory and filters
  • the aggregator logs instead of printing
  • AggregateCSV is strict by default (unknown columns raise), the header is the union of all rows, saves are atomic, labels can be joined by key, and save() reports columns that are blank for every row
  • regression tests for Row sigma-1 / sigma-3 / max_lh on an asymmetric latent PDF; the inverted post_fit_output docstring is fixed

Merge order: after PR 0a (this PR's base is the 0a branch; GitHub retargets it to main when 0a merges).

API Changes

AggregateCSV now defaults to strict=True, and from_directory now defaults to on_error="skip". Both are behaviour changes; see Migration. New: agg.errors, on_error=, add_label_column(..., key=), and save() returns the blank columns. Aggregator messages move from stdout to logging.
See full details below.

Downstream to check: the euclid_strong_lens_modeling_pipeline catalogue scripts (catalogue/scripts/{lens_mass,lens_sersic,source_sersic,magnitudes,astrometric_offsets}.py, workflow/csv_make.py) call af.AggregateCSV(aggregator=...) without strict= and pass positional label lists. If a variable path is missing for some fits, or a label list's length differs from the aggregator, they will now raise instead of writing blanks. Confirmed: one euclid pipeline test fails on this branch for exactly that reason. Passing strict=False explicitly in those scripts works with both the released and this PyAutoFit, so that euclid change can merge first. Resolved: PyAutoLabs/euclid_strong_lens_modeling_pipeline#112 (explicit strict=False, merged first; euclid tests 352/352 against this branch).

Test Plan

  • test_autofit/aggregator/summary_files/test_honest_reads.py (new, 17 tests): one corrupt zip → len(agg.errors) == 1 (with and without unzip_temporary), on_error="raise" raises; a damaged member is collected; empty aggregator warns; nothing printed to stdout; unknown column raises and writes no file; union header; a save interrupted mid-write leaves the old CSV byte-identical; blank columns reported; label joins by key and by search id; asymmetric-latent Row sigma-1/sigma-3/max_lh
  • Full test_autofit suite: 3,969 passed, 2 skipped, 1 xfailed
  • Smoke: pyauto-heart smoke autofit autolens_test euclid: 56 passed, 0 failed
  • euclid_strong_lens_modeling_pipeline tests/: 351 passed, 1 failed — test_catalogue_missing_assets.py::test_bundle_reaches_later_stages_with_missing_assets: source_sersic asks for galaxies.source.bulge.centre.centre_0 on fits without it, which now raises KeyError under the strict default (see Downstream to check)
Full API Changes (for automation & release notes)

Added

  • Aggregator.from_directory(..., on_error="skip" | "raise") and Aggregator.errors — list of (path, exception); carried through add_directory, filter and slicing
  • unzip_directory(directory, on_error="raise") returns its error list
  • AggregateCSV.add_label_column(name, values: list | dict, key=None) — a dict is joined by key(search_output), defaulting to the search id
  • AggregateCSV.save() returns the columns blank in every row and logs them as a warning

Changed behaviour

  • AggregateCSV(strict=True) is the default: an unknown variable column raises KeyError; a dict label with no value for a search raises KeyError; a positional label list of the wrong length raises ValueError
  • from_directory defaults to on_error="skip"; previously a corrupt zip always raised BadZipFile. Under "raise", BadZipFile / EOFError / zlib.error are raised as BadZipFile naming the original error
  • CSV header = union of all rows' keys in first-seen order (was the first row's keys)
  • save() writes atomically
  • aggregator prints → logging (empty result, incomplete-excluded counts and skipped zips are warnings)
  • the "Removing all files except for .zip file" log line only appears when remove_files is set

Migration

  • Keep the old "warn and leave blank" CSV behaviour: af.AggregateCSV(aggregator, strict=False)
  • Keep fail-fast loading: Aggregator.from_directory(path, on_error="raise")
  • Scripts that parsed aggregator stdout should read logging instead

Refs #1734

🤖 Generated with Claude Code

- Aggregator.from_directory(..., on_error="skip"|"raise"): an unreadable zip
  (BadZipFile, or EOFError / zlib.error from a damaged member) is skipped, logged
  and recorded in agg.errors as (path, exception) instead of failing the whole
  scan; a partial extraction is removed. unzip_directory gains the same on_error
  and returns its errors; add_directory, filter and slicing carry errors along.
- An empty aggregator logs a warning naming the directory and filters; every
  print in the aggregator is now logging.
- AggregateCSV: strict=True by default; header is the union of every row's
  columns; rows are built before the file is opened and written via open_atomic,
  so a failed or interrupted save leaves the previous CSV whole; save() reports
  (logs and returns) columns blank in every row; add_label_column joins a dict
  of labels by key (search id, or key=callable), and under strict a positional
  list must match the aggregator's length.
- Row regression test on an asymmetric latent PDF (median, max_lh, 1-sigma and
  3-sigma bounds all distinct).
- post_fit_output docstring states the zip is always written and the folder is
  removed only under remove_files; the "Removing all files" log is conditional.

Refs #1734

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Jammy2211 Jammy2211 added the pending-release PR queued for the next release build label Oct 29, 2026
Base automatically changed from feature/results-library-p0-integrity to main October 29, 2026 21:23
@Jammy2211
Jammy2211 merged commit 4bb7080 into main Oct 29, 2026
5 checks passed
@Jammy2211
Jammy2211 deleted the feature/results-library-p0b-honest-reads branch October 29, 2026 21:35
@pyautolabs-bot pyautolabs-bot Bot removed the pending-release PR queued for the next release build label Nov 1, 2026
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