Repository navigation
Description
Overview
AggregateCSV writes wrong numbers for three column kinds and hides a fourth failure. A latent's *_lower_3_sigma / *_upper_3_sigma columns carry the 1-sigma values (row.py reads latent_summary.values_at_sigma_1 inside values_at_sigma_3_kwargs); a MaxLogLikelihood model-parameter column is the median (max_likelihood_kwargs seeds from median_pdf_sample.kwargs); and Column.value swallows KeyError into None for all four value types, so a renamed latent or a typo is indistinguishable from a missing value. The test file asserts x == "a" or "b" (always truthy) eight times, so none of this was caught. The latent 3-sigma defect has already shipped into the June 2026 Euclid DR1 prelim catalogue (2990/2990 lens_mass.csv rows, 22815/22815 magnitudes.csv rows), and the silent None hid the euclid pipeline's stale latent. prefix from June to September.
Reproduced on the test fixture at main (6ea1dda): galaxies.lens.bulge.centre.latent gives lower_3_sigma == lower_1_sigma == 3.4319… while the fixture's latent_summary.json holds 1.6742… for 3-sigma; nope.missing yields {'': None} with no warning.
Plan
- Fix the two one-liners in
Row: 3-sigma latent bounds readvalues_at_sigma_3; max-likelihood kwargs seed frommax_log_likelihood_sample. - Make an unresolvable argument visible: one
logger.warningper column (not per row) when the argument matches neither the samples-summary nor the latent-summary keyspace, plus an opt-instrict=TrueonAggregateCSVthat raises instead. - Replace every tautological
== "a" or "b"assertion with an exact assertion against the fixture. - Add regression tests: latent 1-sigma and 3-sigma bounds differ; max-likelihood differs from median for a model parameter; an unresolvable argument warns once and raises under
strict=True. - Adjust the fixture so max-likelihood and median differ for a model parameter (they are currently identical, which is why the max_lh bug was invisible).
Detailed implementation plan
Affected Repositories
- PyAutoFit (primary, library)
Work Classification: Library
Worktree root: ~/Code/PyAutoLabs-wt/aggregate-csv-latent-sigma3/ (local-dev; this session is web-github and works on the session clone)
Branch Survey
| Repository | Current Branch | Dirty? |
|---|---|---|
| ./PyAutoFit | main (6ea1dda) | clean |
Remote branches: main, claude/slowest-ci-tests-s81dza, experiment/jax-vmap-jit-ordering — nothing touching the aggregator.
Suggested branch: feature/aggregate-csv-latent-sigma3 (this web session pushes claude/autofit-aggregate-csv-sigma3-x8twln)
Implementation Steps
-
autofit/aggregator/summary/aggregate_csv/row.pymax_likelihood_kwargs(line 64): seed fromsamples_summary.max_log_likelihood_sample.kwargsinstead ofmedian_pdf_sample.kwargs; fix its docstring (it says "median_pdf_sample").values_at_sigma_3_kwargs(line 102): readlatent_summary.values_at_sigma_3, notvalues_at_sigma_1.- Add a cached
known_paths(orresolves(path)) helper that returns the union of every key in the four kwargs dicts, so a column can ask "does this argument exist in either keyspace?" once.
-
autofit/aggregator/summary/aggregate_csv/column.py- Add a module
logger = logging.getLogger(__name__). Column.__init__gainsstrict: bool = Falseand a_warnedflag.Column.value: before the per-value-type lookups, ifself.pathis in none of the row's kwargs dicts: understrictraiseKeyError/ValueErrornaming the argument and listing a few nearby keys; otherwiselogger.warning(...)once (guard with_warned) and fall through to the existingNonefill. Keep the per-typeexcept KeyErrorso a value type absent for a real argument (e.g. novalues_at_sigma_3for a latent) still yieldsNonewithout noise.
- Add a module
-
autofit/aggregator/summary/aggregate_csv/__init__.pyAggregateCSV.__init__(self, aggregator, strict: bool = False);add_variablepassesstrict=self._stricttoColumn. Document both in the docstrings.
-
test_autofit/aggregator/summary_files/aggregate_summary/fit_{1,2}/files/samples_summary.json- Change
max_log_likelihood_sample.kwargs["galaxies.lens.bulge.centre.centre_0"]to a value distinct from the median (e.g.-1.5/-5.5) so the max_lh regression test is meaningful.
- Change
-
test_autofit/aggregator/summary_files/test_aggregate_csv.py- Replace the eight
== "a" or "b"assertions with exact per-row values from the fixture (test_add_column,test_use_max_log_likelihood,test_add_named_column,test_add_latent_column). - Add
test_latent_values_at_3_sigma:galaxies.lens.bulge.centre.latentwith[ValuesAt1Sigma, ValuesAt3Sigma]giveslower_3_sigma == "1.6742483855526449"andlower_1_sigma != lower_3_sigma. - Add
test_max_log_likelihood_differs_from_medianforcentre_0with[Median, MaxLogLikelihood]. - Add
test_unresolvable_argument_warns(caplog: exactly one warning across two rows, column value empty) andtest_unresolvable_argument_strict_raises(AggregateCSV(aggregator, strict=True)+pytest.raises). - Keep the fixture latent named
latent.value; the test that reads it should assert the exact values (1.0/2.0median,2.0/3.0max_lh) so the name is exercised, not assumed.
- Replace the eight
Key Files
autofit/aggregator/summary/aggregate_csv/row.py— the two wrong readsautofit/aggregator/summary/aggregate_csv/column.py— silentNone, new warning/strictautofit/aggregator/summary/aggregate_csv/__init__.py—AggregateCSV.stricttest_autofit/aggregator/summary_files/test_aggregate_csv.py— vacuous assertions, new regressionstest_autofit/aggregator/summary_files/aggregate_summary/fit_*/files/samples_summary.json— fixture
Testing
python -m pytest test_autofit/aggregator/ (fixture-driven, fast), then the full test_autofit/ suite before the PR.
Trade-offs / risks
- Public numbers change: any catalogue built with latent 3-sigma or
MaxLogLikelihoodcolumns must be regenerated (June DR1 prelim catalogue). strictis opt-in and the warning is per-column, so existing pipelines keep running with the same shape and one extra log line per bad argument.- Downstream (PyAutoLens
aggregatehelpers, euclid pipeline) only calladd_variable; theAggregateCSV.__init__signature grows a keyword with a default, so nothing breaks.
Original Prompt
Click to expand starting prompt
Source: PyAutoMind/draft/bug/autofit/aggregate_csv_latent_sigma3_and_silent_none.md
Type: bug · Target: PyAutoFit · Difficulty: medium · Autonomy: supervised · Priority: high · Filed: 2026-09-10
Witness: on the aggregate_csv test fixture a latent's *_lower_3_sigma differs from *_lower_1_sigma, a MaxLogLikelihood model-parameter column differs from its Median column, an argument matching neither keyspace emits exactly one warning and raises under strict=True, and no assertion of the form x == "a" or "b" remains in test_aggregate_csv.py.
Symptom
In PyAutoFit aggregate_csv, latent 3-sigma bounds silently carry the 1-sigma values, max-likelihood model-parameter columns are the median, unresolvable arguments are silent, and the tests are vacuous.
autofit/aggregator/summary/aggregate_csv/row.py:102values_at_sigma_3_kwargsreadslatent_summary.values_at_sigma_1(since 1a62a78, 2025-04-09), so every latent*_lower_3_sigma/*_upper_3_sigmacolumn equals its 1-sigma column: already shipped in the June 2026 DR1 prelim catalogue (2990/2990lens_mass.csvrows, 22815/22815magnitudes.csvrows) and reproduced on the 342398 rebuild 10/10, while the model-parameter control differs.row.py:64max_likelihood_kwargsseeds fromsamples_summary.median_pdf_sample.kwargsinstead ofmax_log_likelihood_sample.kwargs, so a MaxLogLikelihood model-parameter column is the median (the latent half atrow.py:68is correct).column.py:63-96Column.valuereturns None on KeyError for all four value types with no warning, so a renamed latent or a typo is indistinguishable from a missing value; this hid the euclid pipeline's stalelatent.prefix from June to September.test_autofit/aggregator/summary_files/test_aggregate_csv.pyassertsx == "a" or "b"(always truthy) about eight times, and its fixture latent is namedlatent.value, which made the prefix look sanctioned.
Do
- The two one-liners (1) and (2).
- A
logger.warningonce per column when an argument matches neither the samples-summary nor the latent-summary keyspace, plus an opt-instrict=TrueonAggregateCSVthat raises. - Replace the tautological assertions.
- Add regression tests that a latent's 1-sigma and 3-sigma bounds differ, that max-likelihood differs from the median, and that an unresolvable argument warns.
Release note
This changes published numbers: the June DR1 prelim catalogue's latent 3-sigma columns need regenerating.
Related: draft/bug/euclid/catalogue_latent_prefix_blank_columns.md (the stale latent. prefix this silence hid) and draft/bug/autolens/vis_lp_mge_stage_writes_no_latents.md (the vis_lp stage that writes no latents at all).
Activity
Jammy2211 commentedon Sep 10, 2026
Library PR Created
pending-release)test_autofit/2511 passed / 43 skipped serially; aggregator subtree 66 passed / 13 skipped; no== "a" or "b"assertion remains.AggregateCSV(strict=False)/Column(strict=False)added,Row.known_pathsadded; latent 3-sigma andMaxLogLikelihoodcolumns now hold what their names say; unresolvable arguments warn once per column. Row kwargs also tolerate a summary with no PDF.add_variable, and the new keyword defaults to the old shape. The euclid pipeline's catalogues need regenerating once released (numbers change), tracked bydraft/bug/euclid/catalogue_latent_prefix_blank_columns.md.Next:
/prmonce CI is green. Merge stays human.Generated by Claude Code
Jammy2211 commentedon Sep 10, 2026
Shipped
mainat68d43b0(pending-release; the fix reaches PyPI with the next release build).2fdec1b.*_3_sigmacolumns now readvalues_at_sigma_3;MaxLogLikelihoodcolumns now seed from the max-likelihood sample; an argument that resolves in neither the samples-summary nor the latent-summary keyspace warns once per column, andAggregateCSV(strict=True)raises. Row kwargs tolerate a summary with no PDF. The eight tautological assertions intest_aggregate_csv.pyare gone and regression tests cover each defect.PyAutoMind/draft/bug/euclid/catalogue_latent_prefix_blank_columns.md.Generated by Claude Code