Repository navigation
fix(samples): errors_at_sigma(as_instance=True) on a prior-valued model - #1578
Merged
Merged
Conversation
Model.instance_for_arguments constructed a Prior from (lower, upper) bounds pairs whenever a global model contains Model(af.GaussianPrior) (a HierarchicalFactor's distribution model), so errors_at_sigma and values_at_sigma with as_instance=True raised TypeError from NormalMessage's broadcast_arrays. A Prior's constructor only takes scalars, so a tuple argument can only be such a bounds pair: store it on a ModelInstance, as every other model class stores it, instead of building a message from it. Scalar vectors (median_pdf, max_log_likelihood) still construct the real prior. Three tests in test_autofit/graphical/global/test_errors_at_sigma_instance.py; the two tuple-valued ones fail without the fix. Closes #1577 (graphical-ep phase 1, finding D6 of autofit_workspace_test#91). Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01E2HKd5ZocDmTyZ544eVEh4
Collaborator
Author
|
Workspace PR: PyAutoLabs/autofit_workspace_test#99 Library-first: that workspace PR (docstring only, no code change) merges only after this one. |
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
Samples.errors_at_sigma(1.0)andvalues_at_sigma(1.0)(defaultas_instance=True) raisedTypeError: broadcast_arrays requires ndarray or scalar arguments, got <class 'tuple'>on any global model containing aModel(af.GaussianPrior)component — i.e. everyFactorGraphModel.global_prior_modelwith aHierarchicalFactor.Model.instance_for_argumentshanded the(lower, upper)bounds pairs to the Prior's constructor, which builds aNormalMessagefrom them.Fix (
autofit/mapper/prior_model/prior_model.py): when the model class is aPriorsubclass and any constructor argument is a tuple, return aModelInstanceholding the arguments (.mean == (lo, hi),.sigma == (lo, hi)) instead of constructing the prior. Scalar vectors (median_pdf,max_log_likelihood) are unchanged and still build the real prior. An explicit typed branch, not an exception guard.The alternative of returning a pair of instances was rejected: it would break the public tuple-attribute instance contract used by
autofit_workspace_test/scripts/graphical/ep_parity.py,simultaneous.pyand the workspace result tutorials.Finding D6 of the analytic Gaussian benchmark (autofit_workspace_test#91); umbrella PyAutoFit#1405; closes #1577. Workspace follow-up: remove the
as_instance=Falseworkaround fromautofit_workspace_test/scripts/graphical/analytic_autofit.py(ships after this PR merges).API Changes
Bug fix only — no signatures changed.
Samples.errors_at_sigma/values_at_sigmawithas_instance=Truenow return an instance on models with Prior-class components where they previously raised; the Prior-class component becomes aModelInstanceof bounds pairs.See full details below.
Test Plan
test_autofit/graphical/global/test_errors_at_sigma_instance.py:errors_at_sigmaandvalues_at_sigmainstances match theas_instance=Falsetuples throughprior_tuples_ordered_by_id(both fail without the fix);median_pdfstill yields a realaf.GaussianPriorpytest test_autofit -q: 2472 passed, 2 skipped (baseline 2469 + 3 new); graphical 278, messages 95analytic_gaussian.pyinfo lines byte-identical through the instance pathFull API Changes (for automation & release notes)
Changed Behaviour
Model.instance_for_arguments— for aPrior-subclass model whose constructor arguments contain a tuple (a bounds pair fromSamples.errors_at_sigma/values_at_sigma), returnsModelInstance(constructor_arguments)instead of constructing the prior (which raised). Scalar arguments unchanged.Generated by the PyAutoLabs agent workflow.
🤖 Generated with Claude Code
https://claude.ai/code/session_01E2HKd5ZocDmTyZ544eVEh4