fix(csv): preserve TuplePrior on af.Model built from tuple-param rows#429
Merged
Conversation
galaxy_af_models_from_csv_tables previously did af.Model(cls, **params),
which for tuple-valued params (e.g. centre=(0.3, 0.5)) bypassed PyAutoFit's
TuplePrior auto-create path and stored `centre` as a raw tuple attribute.
Later `.centre_0 = GaussianPrior(...)` overrides then created ghost direct
attributes alongside the raw tuple, so at sample time the constructor was
called as `Point(centre=(0.3, 0.5), centre_0=..., centre_1=...)` and
raised `TypeError: Point.__init__() got an unexpected keyword argument
'centre_0'`.
Build af.Model(cls) first (which triggers the TuplePrior auto-create
branch in PyAutoFit for tuple-defaulted ctor args), then setattr each
tuple param component-wise. Scalar params unchanged. Later prior
overrides on `.centre_0`/`.centre_1` now delegate into the auto-created
TuplePrior instead of producing ghost direct attributes.
Unblocks autolens_workspace/scripts/cluster/{start_here,modeling}.py.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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.
Summary
galaxy_af_models_from_csv_tablespreviously built each profile'saf.Modelwith
af.Model(cls, **params). For tuple-valued params (e.g.centre=(0.3, 0.5))this bypassed PyAutoFit's
TuplePriorauto-create path (inautofit/mapper/prior_model/prior_model.py:144-156the tuple branch only firesfor defaults, not kwargs) and stored
centreas a raw tuple attribute. Lateroverrides like
model.centre_0 = af.GaussianPrior(...)then created ghostdirect attributes alongside the raw tuple, because
PriorModel.__setattr__falls through to
super().__setattr__when no matchingTuplePrioris found.At sample time,
_instance_for_argumentscalledPoint(centre=(0.3, 0.5), centre_0=..., centre_1=...)and the search crashedwith
TypeError: Point.__init__() got an unexpected keyword argument 'centre_0'.The fix builds
af.Model(cls)with no kwargs first — this triggers theauto-create-
TuplePriorbranch for tuple-defaulted ctor args — and then setseach tuple param component-wise via
setattr(model, f"{name}_{i}", component).Scalar params are unchanged. Later prior overrides on
.centre_0/.centre_1now delegate correctly into the existing
TuplePrior.Unblocks
autolens_workspace/scripts/cluster/start_here.pyandautolens_workspace/scripts/cluster/modeling.py, which crashed on every runafter the recent cluster-CSV API adoption.
API Changes
None — internal change to the construction logic inside
galaxy_af_models_from_csv_tables. Existing callers that don't overridetuple-component priors after construction see no behaviour difference; callers
that do (the cluster modeling scripts) now succeed instead of raising
TypeErrorat sample time.See full details below.
Test Plan
pytest test_autogalaxy/galaxy/test_galaxy_model_csv.py -v— 10/10 pass, including new regression testtest__af_models__tuple_param_supports_prior_overridethat exercises the failing pattern end-to-end (CSV →af.Model→centre_0/1GaussianPrior override →instance_from_unit_vector)PYAUTO_TEST_MODE=2 PYAUTO_SKIP_FIT_OUTPUT=1 PYAUTO_SKIP_VISUALIZATION=1 PYAUTO_SKIP_CHECKS=1 PYAUTO_SMALL_DATASETS=1 PYAUTO_FAST_PLOTS=1 python autolens_workspace/scripts/cluster/start_here.py— runs to completionPYAUTO_TEST_MODE=2 ... python autolens_workspace/scripts/cluster/modeling.py— runs to completionFull API Changes (for automation & release notes)
Removed
None.
Added
None.
Changed Behaviour
galaxy_af_models_from_csv_tables(*tables)— the returnedaf.Modelinstances now carry aTuplePriorfor tuple-valued attributes (e.g.centre) rather than a rawtuple. Readingmodel.centreis unchanged for downstream consumers (the TuplePrior resolves to a tuple at instance construction);_0/_1component overrides such asmodel.centre_0 = af.GaussianPrior(...)now delegate into theTuplePriorinstead of creating ghost direct attributes alongside the raw tuple.Migration
No migration required. The previously-broken
.centre_0 = prior/.centre_1 = prioroverride pattern on a CSV-built model now works as the cluster scripts expect.🤖 Generated with Claude Code