Skip to content

fix: use valid_sample_instance_pairs in the aggregator samples guide - #210

Merged
Jammy2211 merged 1 commit into
mainfrom
feature/stored-sample-reconstruction-guard
Aug 17, 2026
Merged

Jammy2211 merged 1 commit into
mainfrom
feature/stored-sample-reconstruction-guard

Conversation

@Jammy2211

Copy link
Copy Markdown
Collaborator

Fixes the only red job in the nightly PyAutoHeart Workspace Smoke — run_notebooks (3.12, autogalaxy, guides), failing on every scheduled run since 2026-08-10 (runs 31356506626, 31992749671).

The failure

notebooks/guides/results/aggregator/samples.ipynb
  ModelParameterException: ell_comps must satisfy ell_comps[0]**2 + ell_comps[1]**2 < 1;
  got (0.9781300707301511, -0.23873992910981626), magnitude 1.0068441731558715

Cause

The derived-errors loop rebuilt an instance for every stored sample:

for sample in samples.sample_list:
    instance = sample.instance_for_model(model=samples.model, ignore_assertions=True)

ignore_assertions=True only suppresses af.Model assertions — it does not stop a downstream profile constructor from raising, despite its docstring reading "do not check that the instance is valid".

Such samples are legitimately stored. A FitException at fit time does not redraw: fitness.py returns resample_figure_of_merit (-1e99 for Nautilus) and the sampler still records the point. PyAutoGalaxy's validate_ell_comps guard (#566/#568, 2026-08-09/10) is also inert under a JAX trace, where convert.py clamps to 0.999 while the raw value is what gets stored. Measured on this guide's own fixture: 1–4 invalid samples per 300, present under the smoke env and a production-like JAX run.

Because the loop walks every sample, it fails deterministically rather than intermittently.

Fix

Use PyAutoFit's purpose-built valid_sample_instance_pairs (PyAutoLabs/PyAutoFit#1470) — which skips only points rejected via the narrow FitException contract while letting programming errors propagate. This is the same call autolens_workspace already uses in its copy of this guide, and that autofit/aggregator/base.py uses internally. That rollout covered autolens and stopped; this brings autogalaxy in line.

Also fixes a latent correctness bug: the old code passed weight_list=samples.weight_list alongside a per-sample axis_ratio_list, which misaligns the moment any sample is skipped. Pairing keeps them together. And it drops a bare except Exception: pass around af.marginalize, matching autolens.

No library dependency

valid_sample_instance_pairs is present in released autofit-2026.8.15.1 (verified by downloading and inspecting the wheel — the same one the smoke job installs), so this needs no library release and carries no pending-release label.

Verification

A/B against the same fixture, which contained 4 invalid samples out of 300:

arm result
pre-fix script exit 1 — ModelParameterException at line 451
this branch exit 0
regenerated notebook, executed exit 0

Run under the env PyAutoHands resolves from config/build/profile_smoke.yaml (PYAUTO_DISABLE_JAX=1, PYAUTO_SKIP_CHECKS=1; PYAUTO_TEST_MODE absent — released by this script's ENV: real_search).

Scripts Changed

  • scripts/guides/results/aggregator/samples.py — derived-errors loop → valid_sample_instance_pairs; weight list paired; silent except removed
  • notebooks/guides/results/aggregator/samples.ipynb — regenerated from the script via autohands/generate.py (not hand-edited)

Follow-ups (not in this PR)

🤖 Generated with Claude Code

https://claude.ai/code/session_01Gea6k3ZSink1T78jfxtxcr

The derived-errors loop rebuilt an instance for every stored sample via
Sample.instance_for_model(ignore_assertions=True). That flag only suppresses
af.Model assertions -- it does not stop a profile constructor raising, so any
stored sample with |ell_comps| >= 1 aborted the tutorial. Such samples are
legitimately stored: a FitException at fit time returns resample_figure_of_merit
(-1e99 for Nautilus) and the point is still recorded.

Use PyAutoFit's purpose-built valid_sample_instance_pairs (PyAutoFit#1470),
which skips only points rejected via the narrow FitException contract while
letting programming errors propagate -- the same call autolens_workspace and
autofit/aggregator/base.py already use.

Pairing each surviving sample with its instance also fixes a latent correctness
bug: the old code passed weight_list=samples.weight_list alongside a per-sample
axis_ratio_list, which misaligns as soon as any sample is skipped.

Also drops a bare "except Exception: pass" around af.marginalize, matching the
autolens_workspace version of this guide.

Refs PyAutoLabs/PyAutoFit#1486

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@Jammy2211
Jammy2211 merged commit 1b5005c into main Aug 17, 2026
6 checks passed
@Jammy2211
Jammy2211 deleted the feature/stored-sample-reconstruction-guard branch August 17, 2026 22:08
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