Skip to content

fix(autofit): resolve sample parameter-path KeyError under release profile #1327

Description

@Jammy2211

Overview

Nine workspace scripts fail under the release-fidelity profile (PyAutoHeart run 28784914443, issue PyAutoHeart#27) with a KeyError raised in autofit/non_linear/samples/sample.py::parameter_lists_for_paths: a loaded sample's stored kwargs keys no longer align with the current model's paths. This is a high-severity, ecosystem-scope runtime regression whose fix belongs in the PyAutoFit resolution contract — not in the user-facing workspace scripts.

Plan

  • Reproduce the KeyError on clean main for a representative subset (single, multi-analysis, chained, list-profile, multi-dataset) to confirm the cluster is still live.
  • Trace model-path construction vs. stored sample kwargs through Sample / Samples / result-loading to classify the mismatch (path alias, collection/list index, or genuinely retired stored-key format).
  • Fix the PyAutoFit path-resolution contract so valid current-model paths resolve against stored samples; a single general fix, split into more than one PR only if sub-causes diverge.
  • Add focused regression tests in test_autofit/non_linear/samples/test_samples.py covering the represented path categories.
  • Ship the PyAutoFit PR (pending-release); a separate Phase 2 re-validates the 9 scripts under the release profile and edits only scripts using a genuinely retired API.
Detailed implementation plan

Affected Repositories

  • PyAutoFit (primary — library fix)
  • autogalaxy_workspace, autolens_workspace (downstream verification only, Phase 2)

Branch Survey

Repository Current Branch Dirty?
./PyAutoFit main clean
./autogalaxy_workspace main dirty (generated outputs; irrelevant to library phase)
./autolens_workspace main dirty (generated outputs; irrelevant to library phase)

Suggested branch: feature/samples-parameter-paths
Worktree: ~/Code/PyAutoLabs-wt/samples-parameter-paths/

Implementation Steps

  1. Reproduce on clean main under the release profile for 1–2 representative scripts (via the vitals faculty) — confirm the KeyError still fires before fixing.
  2. Root-cause in autofit/non_linear/samples/sample.py: parameter_lists_for_paths (line 104), is_path_kwargs (line 119), subsample (line 130); and how Samples builds all_paths / all_names and how directory/database loading repopulates kwargs.
  3. Fix at the resolution boundary so valid current-model paths resolve against stored sample kwargs. Do not catch/mask the error or weaken workspace scripts.
  4. Add regression tests in test_autofit/non_linear/samples/test_samples.py covering single, multi-analysis, chained, list-profile, and multi-dataset path shapes.
  5. Run python -m pytest test_autofit/; note any public-API change for downstream consumers.

Key Files

  • autofit/non_linear/samples/sample.py — the KeyError locus and path/kwargs resolution.
  • autofit/non_linear/samples/* (Samples container + directory/database loaders) — where stored kwargs are repopulated.
  • test_autofit/non_linear/samples/test_samples.py — regression coverage.

Fix locus / guardrails (from the Bug Agent BugDecision)

  • severity=high · scope=ecosystem · type=runtime-error · owner=autofit
  • Fix locus: library source (general fix) — resolving the contract clears the whole class.
  • Strategy: split-into-phases (prefer small shippable PRs); workflow: combined (library ships first).
  • Do NOT edit workspace scripts to mask it (no injected env-vars / hard-coded paths / os.environ mutation / silent guards).
  • Validate via the vitals faculty after patching (lib-tests, then workspace/integration), targeting pyauto-heart GREEN/YELLOW before ship.

Original Prompt

Click to expand starting prompt

Fix release result/sample parameter-path regressions

Context

PyAutoHeart release validation run 28784914443 exposed a family of workspace
failures. Against current main, nine scripts converge on
PyAutoFit/autofit/non_linear/samples/sample.py::parameter_lists_for_paths
raising KeyError for model paths that no longer match stored sample kwargs.

Primary repository: @PyAutoFit. Downstream verification repositories:
@autogalaxy_workspace and @autolens_workspace.

Scripts

  • autogalaxy_workspace/scripts/imaging/features/pixelization/galaxy_reconstruction.py
  • autogalaxy_workspace/scripts/imaging/features/shapelets/modeling.py
  • autogalaxy_workspace/scripts/multi/features/imaging_and_interferometer/modeling.py
  • autolens_workspace/scripts/group/features/advanced/mass_stellar_dark/chaining.py
  • autolens_workspace/scripts/guides/modeling/advanced/hierarchical.py
  • autolens_workspace/scripts/imaging/features/advanced/shapelets/modeling.py
  • autolens_workspace/scripts/interferometer/features/subhalo/detect/start_here.py
  • autolens_workspace/scripts/interferometer/features/extra_galaxies/slam.py
  • autolens_workspace/scripts/multi/features/imaging_and_interferometer/modeling.py

Required work

  1. Reproduce from clean task worktrees with the release profile and current library
    sources; distinguish stale cached output from newly written samples.
  2. Trace model path construction, stored kwargs, path aliases, and collection/list
    indices through Samples, Sample, and result loading.
  3. Fix the owning PyAutoFit contract if valid current-model paths cannot resolve.
    Do not weaken workspace scripts or silently ignore missing parameters.
  4. Add focused PyAutoFit regression tests covering single, multi-analysis, chained,
    list-profile, and multi-dataset paths represented above.
  5. Run PyAutoFit pytest, then rerun all nine scripts under their release profiles.

Preserve tutorial prose and make workspace edits only where a script genuinely uses a
retired API rather than exposing a library defect.


🤖 Filed via /bug → Bug Agent → /start_dev. Source: PyAutoHeart#27 release-fidelity validation.

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