Repository navigation
Description
Overview
A model where one parameter is an arithmetic combination of priors shared by two components (e.g. stars.mass = (1 - f) * m, halo.mass = f * m) evaluates correctly, but search.fit dies before sampling: paths.save_all writing model.json raises TypeError: Object of type UniformPrior is not JSON serializable. Found 2026-11-16 in the stars_dm_slope science project.
Reproduced on main @ 3ba1e6c: json.dumps(model.dict()) raises the TypeError; the offending path is …mass.left.left.prior. That is the NegativePrior that 1 - f builds.
Plan
ModifiedPrior.dict(NegativePrior,AbsolutePrior,Log, …) serialises its operand only when it is anAbstractPriorModel; a plainPrioris aModelObjectbut not anAbstractPriorModel, so the raw prior object is written. CheckModelObject, asCompoundPrior.dictalready does.- Past that,
search.fithits a second error on the same path:ModifiedPrior.clsreturnsself.prior.cls, which a plainPriorlacks (AttributeErrorfromsuperscripts/prior_class_dict). Returnfloatfor a plain prior, asCompoundPriordoes. CompoundPrior.dictdoes not save its operand attribute names (found by frame inspection, e.g.self,m). They are part of the model identifier, so a reloaded compound model gets a different identifier. Saveleft_name/right_nameand restore them infrom_dict. Dicts without them still load.- Unit tests: build a two-component model sharing compound priors, write it to JSON, reload it, and check the prior count, the identifier and the instance values; serialise a
NegativePriorof a plain prior; load an old-format dict.
effective level: supervised; merge mode: auto-merge on green if the Witness passes after a merge slot
Tier: glance (declared). In this shift the task ends at PR-open; the close-out session runs the witness.
Detailed plan
Work Classification: Library (PyAutoFit only)
Worktree root: ~/Code/PyAutoLabs-wt/compound-prior-model-json/
Branch: feature/compound-prior-model-json
Files:
autofit/mapper/prior/arithmetic/compound.py:ModifiedPrior.dictisinstance check →ModelObject;ModifiedPrior.cls→floatfor a non-model prior;CompoundPrior.dictaddsleft_name/right_name;CompoundPrior.from_dictcalls the new_set_operand_names.test_autofit/serialise/test_compound_model.py(new).test_autofit/serialise/test_sum_prior.pyandtest_assertions.py: their exact-dict fixtures now pop the two name keys, since the frame-inspected names depend on the call stack.
Witness: a model with a compound prior shared by two components writes model.json, reloads to an equal model, and search.fit starts without a TypeError.
Out of scope (follow-ups):
Prior.from_dictgives priors fresh ids in load order, so any model whose priors were created out of path order reloads with a different parameter order. This happens with or without compound priors; samples load by path name, so the aggregator is unaffected.retrieve_nameframe-walking makes compound operand names, and so identifiers, depend on the call stack.
Activity
Jammy2211 commentedon Nov 18, 2026
Library PR open: #1783, ended at PR-open (shift 2026-11-18-pm, supervised, labelled
decision-taken).The PR fixes four defects on the
search.fit→model.jsonpath:ModifiedPrior.dictwrote a rawPriorinstead of its dict.ModifiedPrior.clsfailed for a plain prior.CompoundPrioroperand names were not saved, so the identifier changed on reload."modified"had no autonerves parser, somodel.sigma = -fsilently reloaded as the default prior.Gate:
Workspace impact: (iii) none. No public names changed and no workspace scripts need edits. The serialised compound-prior dict only gains two keys.
Follow-ups, out of scope and pre-existing, are listed in the PR: prior-id reorder on load, and call-stack-dependent operand names.
Jammy2211 commentedon Nov 18, 2026
Shipped: #1783 merged 2026-11-18T17:40Z (merge 45e8cd3) by human /prm after shift 2026-11-18-pm (unattended merge refused for the decision-taken label). Compound-prior models now write model.json and reload with the same identifier. Pending release (PyAutoFit is in the published set).