Skip to content

fix: Result.instance falls back to a valid sample; persist samples before materialisation (#1535) - #1536

Merged
Jammy2211 merged 1 commit into
mainfrom
feature/result-instance-fallback
Aug 28, 2026
Merged

fix: Result.instance falls back to a valid sample; persist samples before materialisation (#1535)#1536
Jammy2211 merged 1 commit into
mainfrom
feature/result-instance-fallback

Conversation

@Jammy2211

Copy link
Copy Markdown
Collaborator

Summary

A completed fit whose stored maximum-likelihood vector is rejected by the current model (e.g. a gradient lane that settled at ell_comps outside the unit disk — finite under JAX tracing, ModelParameterException on the host) used to die inside analysis.save_results and lose its samples.csv and .completed marker. Six 2–4 h A100 Phase 8B arms were lost this way (PyAutoLabs/autolens_profiling#182).

Two changes: Result.instance degrades to the next-valid recovering path that #1486 added on Samples, and SearchUpdater._save_samples writes the samples and summary before attempting to materialise the instance, so a rejected best point can never cost a run its data. The reordering is also what lets the weight-threshold prune run (#1487).

Closes #1535. Fixes #1487.

API Changes

No public API removed or renamed. Behavioural changes only:

  • Result.instance no longer raises SamplesException when the samples-summary vector is rejected; it logs a WARNING and returns Samples.max_log_likelihood() (highest-likelihood sample the model still accepts), cached on the result. Returns None only when no samples are available to fall back on. SamplesSummary.instance itself still raises (it holds one sample and has nothing to substitute).
  • SearchUpdater._save_samples now always writes samples.csv (weight-thresholded) and samples_summary.json; on a rejected best point it returns instance=None and the caller skips only latents / visualization / profiling. The 4th return value is now the pruned samples_save.
    See full details below.

Test Plan

  • pytest test_autofit -q — 2251 passed, 3 skipped
  • New tests: test_result.py::TestResultInstanceRejectedBestPoint (4), test_updater.py (3: both writers called with instance=None; zero-weight row pruned; real DirectoryPaths run writes samples.csv + samples_summary.json)
  • Control: the 7 new tests fail against the previous source
  • After merge: HPCPullPyAuto on RAL so the pending Phase 8B arms (jobs 341874/341875) write normally
Full API Changes (for automation & release notes)

Removed

  • none

Added

  • AbstractResult._recovered_instance (private cache) — the fallback instance, computed once.

Migration

  • No user code changes. Code that relied on Result.instance raising SamplesException for a rejected best point must now check the WARNING log or call result.samples_summary.instance directly.

Generated by the PyAutoLabs agent workflow.

@Jammy2211 Jammy2211 added the pending-release PR queued for the next release build label Aug 27, 2026
@Jammy2211
Jammy2211 merged commit cbd3006 into main Aug 28, 2026
4 checks passed
@Jammy2211
Jammy2211 deleted the feature/result-instance-fallback branch August 28, 2026 00:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pending-release PR queued for the next release build

Projects

None yet

1 participant