Repository navigation
fix: use valid_sample_instance_pairs in the aggregator samples guide - #210
Merged
Merged
Conversation
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>
2 tasks done
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes the only red job in the nightly
PyAutoHeartWorkspace Smoke —run_notebooks (3.12, autogalaxy, guides), failing on every scheduled run since 2026-08-10 (runs31356506626,31992749671).The failure
Cause
The derived-errors loop rebuilt an instance for every stored sample:
ignore_assertions=Trueonly suppressesaf.Modelassertions — 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
FitExceptionat fit time does not redraw:fitness.pyreturnsresample_figure_of_merit(-1e99for Nautilus) and the sampler still records the point. PyAutoGalaxy'svalidate_ell_compsguard (#566/#568, 2026-08-09/10) is also inert under a JAX trace, whereconvert.pyclamps to0.999while 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 narrowFitExceptioncontract while letting programming errors propagate. This is the same callautolens_workspacealready uses in its copy of this guide, and thatautofit/aggregator/base.pyuses 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_listalongside a per-sampleaxis_ratio_list, which misaligns the moment any sample is skipped. Pairing keeps them together. And it drops a bareexcept Exception: passaroundaf.marginalize, matching autolens.No library dependency
valid_sample_instance_pairsis present in releasedautofit-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 nopending-releaselabel.Verification
A/B against the same fixture, which contained 4 invalid samples out of 300:
ModelParameterExceptionat line 451Run under the env
PyAutoHandsresolves fromconfig/build/profile_smoke.yaml(PYAUTO_DISABLE_JAX=1,PYAUTO_SKIP_CHECKS=1;PYAUTO_TEST_MODEabsent — released by this script'sENV: real_search).Scripts Changed
scripts/guides/results/aggregator/samples.py— derived-errors loop →valid_sample_instance_pairs; weight list paired; silentexceptremovednotebooks/guides/results/aggregator/samples.ipynb— regenerated from the script viaautohands/generate.py(not hand-edited)Follow-ups (not in this PR)
Samples.instancesand theto_instancedecorator (from_sample_index,max_log_posterior, the marginalized methods) have the same unguarded materialization.from_sample_indexappears across autolens, autogalaxy, autofit, autocti and HowToFit.0.0, so a working prune would remove them at source.autocti_workspace(2 sites),autofit_workspaceandHowToFit— fragile but not currently failing, since those fit models with no constructor guards.🤖 Generated with Claude Code
https://claude.ai/code/session_01Gea6k3ZSink1T78jfxtxcr