Skip to content

fix: Fix factor graph result splitting in grid searches #1789

Closed

Description

@Jammy2211

Overview

Use the fitted per-cell factor models to split the full samples and summary. Cover the shared-prior two-factor grid search and both factor results.

Approved plan

Reproduce on main and fix on feature/grid-factor-results. Run the regression checks below. Leave PRs open for maintainer review.

Original prompt

Development details and acceptance criteria

SearchGridSearch over a FactorGraphModel crashes in make_result

Type: bug
Target: autofit
Repos:

  • PyAutoFit
    Difficulty: small
    Autonomy: supervised
    Priority: normal
    Consequence: judge
    Witness: af.SearchGridSearch(...).fit(model=factor_graph.global_prior_model, analysis=factor_graph, grid_priors=[shared_prior_a, shared_prior_b]) over a two-factor graph sharing those priors completes under PYAUTO_TEST_MODE=1, and its best result indexes per factor (result.model[0], result.model[1]); a unit test in test_autofit/non_linear/grid/ covers it.

Symptom

Found by the shift worker on autolens_workspace#683 (SLaM simultaneous subhalo grid search), 2026-11-20.
Running a grid search over a factor graph crashes in the first cell:

autofit/non_linear/grid/grid_search/job.py:55 perform → search_instance.fit
autofit/graphical/declarative/collection.py:284 make_result → samples_summary.subsamples(model_factor.prior_model)
autofit/non_linear/samples/sample.py:138 subsample
KeyError: 'No path from () in sample'

reproduce before fixing: run autolens_workspace branch feature/slam-simultaneous-subhalo-grid-search
scripts/multi_dataset/features/slam/simultaneous.py under PYAUTO_TEST_MODE=1, or a minimal two-factor
Gaussian graph with a shared prior in a SearchGridSearch.

Cause

GridSearch.job_for_analysis_grid_priors_and_values maps the global model with
mapper_from_partial_prior_arguments, which replaces the grid priors with new per-cell priors.
FactorGraphModel.make_result then splits the samples by each original model_factor.prior_model.
That model still holds the replaced priors, so path_map_for_model → all_paths_for_prior returns ().

Fix (to plan)

  • Split by the per-factor sub-models of the model the search actually fitted (samples_summary.model[i]
    for a GlobalPriorModel-shaped collection) instead of the factor's original prior_model, or have the
    job rebuild the factor graph from the mapped model.
  • Unit test on a toy two-factor graph.
  • Then resume autolens_workspace#683.

Activity

  1. Jammy2211 commented on Nov 22, 2026

    @Jammy2211
    CollaboratorAuthor

    Open for maintainer review:

    The two-factor grid witness passes. The existing SLaM task can rerun its workspace witness after the library change lands.

  2. Jammy2211 commented on Nov 22, 2026

    @Jammy2211
    CollaboratorAuthor

    Shipped

    Factor results use the fitted grid-cell submodels for full samples and summaries. Two shared priors across four grid cells reproduced the old KeyError and now yield both child results. The full PyAutoFit suite passed 4,311 tests. The existing SLaM task can resume at its workspace witness.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions