Skip to content

fix: aggregate_csv latent 3-sigma = 1-sigma, max_lh = median, silent None #1597

Closed

Description

@Jammy2211

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 read values_at_sigma_3; max-likelihood kwargs seed from max_log_likelihood_sample.
  • Make an unresolvable argument visible: one logger.warning per column (not per row) when the argument matches neither the samples-summary nor the latent-summary keyspace, plus an opt-in strict=True on AggregateCSV that 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

  1. autofit/aggregator/summary/aggregate_csv/row.py

    • max_likelihood_kwargs (line 64): seed from samples_summary.max_log_likelihood_sample.kwargs instead of median_pdf_sample.kwargs; fix its docstring (it says "median_pdf_sample").
    • values_at_sigma_3_kwargs (line 102): read latent_summary.values_at_sigma_3, not values_at_sigma_1.
    • Add a cached known_paths (or resolves(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.
  2. autofit/aggregator/summary/aggregate_csv/column.py

    • Add a module logger = logging.getLogger(__name__).
    • Column.__init__ gains strict: bool = False and a _warned flag.
    • Column.value: before the per-value-type lookups, if self.path is in none of the row's kwargs dicts: under strict raise KeyError/ValueError naming the argument and listing a few nearby keys; otherwise logger.warning(...) once (guard with _warned) and fall through to the existing None fill. Keep the per-type except KeyError so a value type absent for a real argument (e.g. no values_at_sigma_3 for a latent) still yields None without noise.
  3. autofit/aggregator/summary/aggregate_csv/__init__.py

    • AggregateCSV.__init__(self, aggregator, strict: bool = False); add_variable passes strict=self._strict to Column. Document both in the docstrings.
  4. 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.
  5. 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.latent with [ValuesAt1Sigma, ValuesAt3Sigma] gives lower_3_sigma == "1.6742483855526449" and lower_1_sigma != lower_3_sigma.
    • Add test_max_log_likelihood_differs_from_median for centre_0 with [Median, MaxLogLikelihood].
    • Add test_unresolvable_argument_warns (caplog: exactly one warning across two rows, column value empty) and test_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.0 median, 2.0/3.0 max_lh) so the name is exercised, not assumed.

Key Files

  • autofit/aggregator/summary/aggregate_csv/row.py — the two wrong reads
  • autofit/aggregator/summary/aggregate_csv/column.py — silent None, new warning/strict
  • autofit/aggregator/summary/aggregate_csv/__init__.py — AggregateCSV.strict
  • test_autofit/aggregator/summary_files/test_aggregate_csv.py — vacuous assertions, new regressions
  • test_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 MaxLogLikelihood columns must be regenerated (June DR1 prelim catalogue).
  • strict is 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 aggregate helpers, euclid pipeline) only call add_variable; the AggregateCSV.__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.

  1. autofit/aggregator/summary/aggregate_csv/row.py:102 values_at_sigma_3_kwargs reads latent_summary.values_at_sigma_1 (since 1a62a78, 2025-04-09), so every latent *_lower_3_sigma / *_upper_3_sigma column equals its 1-sigma column: already shipped in the June 2026 DR1 prelim catalogue (2990/2990 lens_mass.csv rows, 22815/22815 magnitudes.csv rows) and reproduced on the 342398 rebuild 10/10, while the model-parameter control differs.
  2. row.py:64 max_likelihood_kwargs seeds from samples_summary.median_pdf_sample.kwargs instead of max_log_likelihood_sample.kwargs, so a MaxLogLikelihood model-parameter column is the median (the latent half at row.py:68 is correct).
  3. column.py:63-96 Column.value returns 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 stale latent. prefix from June to September.
  4. test_autofit/aggregator/summary_files/test_aggregate_csv.py asserts x == "a" or "b" (always truthy) about eight times, and its fixture latent is named latent.value, which made the prefix look sanctioned.

Do

  1. The two one-liners (1) and (2).
  2. A logger.warning once per column when an argument matches neither the samples-summary nor the latent-summary keyspace, plus an opt-in strict=True on AggregateCSV that raises.
  3. Replace the tautological assertions.
  4. 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

  1. Jammy2211 commented on Sep 10, 2026

    @Jammy2211
    CollaboratorAuthor

    Library PR Created

    • PR: fix(aggregate_csv): latent 3-sigma bounds, max_lh seed, warn on unresolvable argument #1598 (pending-release)
    • Gate: test_autofit/ 2511 passed / 43 skipped serially; aggregator subtree 66 passed / 13 skipped; no == "a" or "b" assertion remains.
    • API: AggregateCSV(strict=False) / Column(strict=False) added, Row.known_paths added; latent 3-sigma and MaxLogLikelihood columns now hold what their names say; unresolvable arguments warn once per column. Row kwargs also tolerate a summary with no PDF.
    • Workspace impact: (iii) none expected — downstream callers only use add_variable, and the new keyword defaults to the old shape. The euclid pipeline's catalogues need regenerating once released (numbers change), tracked by draft/bug/euclid/catalogue_latent_prefix_blank_columns.md.

    Next: /prm once CI is green. Merge stays human.


    Generated by Claude Code

  2. Jammy2211 commented on Sep 10, 2026

    @Jammy2211
    CollaboratorAuthor

    Shipped

    • PR: fix(aggregate_csv): latent 3-sigma bounds, max_lh seed, warn on unresolvable argument #1598 — merged into main at 68d43b0 (pending-release; the fix reaches PyPI with the next release build).
    • CI: unittest 3.12, unittest 3.13, unittest-nojax and docs-build all green on 2fdec1b.
    • Summary: latent *_3_sigma columns now read values_at_sigma_3; MaxLogLikelihood columns 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, and AggregateCSV(strict=True) raises. Row kwargs tolerate a summary with no PDF. The eight tautological assertions in test_aggregate_csv.py are gone and regression tests cover each defect.
    • Follow-up: catalogues built with latent 3-sigma or max-likelihood columns (the June DR1 prelim) must be regenerated once the release ships — tracked by PyAutoMind/draft/bug/euclid/catalogue_latent_prefix_blank_columns.md.

    Generated by Claude Code

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