fix: per-method recovery when stored samples fail model reconstruction (#1486) - #1504
Merged
Merged
Conversation
…#1486) `Samples.instances` and the shared `to_instance` decorator materialized stored samples with no `FitException` recovery, so results written before a model's constructor validation tightened raise from deep inside instance construction (PyAutoFit#1486; workspace half shipped as autogalaxy_workspace#210). - `to_instance` gains a per-method recovery policy: `max_log_posterior` falls back to the next valid stored sample (mirroring the #1466 `max_log_likelihood` guard via a shared helper); `from_sample_index` and the marginalized methods raise a typed `SamplesException` chained to the rejection, since they have no valid stored sample to substitute. - `Samples.instances` skips rejected stored samples with a warning, reusing `valid_sample_instance_pairs` (#1470). - The mode-1 rejected-final-sample hook and the updater's samples-save guard catch the new wrapped type. BREAKING: reconstruction failures from `to_instance`-decorated methods now surface as `SamplesException` instead of `ModelParameterException`. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This was referenced Aug 19, 2026
fix: database guide reads dataset info.json that no simulator writes
PyAutoLabs/autocti_workspace#20
Closed
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
Stored results written before a model's constructor validation tightened can hold samples the current model rejects via the narrow
FitExceptioncontract.Samples.instancesand the 15 methods sharing theto_instancedecorator materialized those samples with no recovery, raising from deep inside instance construction (#1486; the workspace half shipped as PyAutoLabs/autogalaxy_workspace#210).to_instancenow takes a per-method recovery policy:max_log_posteriorsubstitutes the highest-posterior valid stored sample (mirroring the #1466max_log_likelihoodguard, via a shared_instance_from_next_valid_samplehelper);from_sample_indexand the marginalized methods raise a typedSamplesExceptionchained to the rejection, since a marginalized vector has no stored sample to substitute.Samples.instancesskips rejected samples with a warning, reusingvalid_sample_instance_pairs(#1470).API Changes
Reconstruction failures from
to_instance-decorated methods (e.g.from_sample_index,median_pdf,values_at_sigma) now raiseautofit.exc.SamplesExceptioninstead of lettingModelParameterException(aValueError) escape; the original rejection is chained as__cause__.max_log_posteriorrecovers to the next valid stored sample instead of raising.Samples.instancesskips unreconstructable stored samples instead of raising, so it can be shorter thansample_list.See full details below.
Test Plan
pytest test_autofit— 2011 passed, 16 skipped (full suite, in the task worktree)instancesskips invalid samples;max_log_posteriornext-valid recovery and all-invalid failure;from_sample_indexandmedian_pdfraiseSamplesException; non-FitExceptionconstructor errors still propagate unwrappedFull API Changes (for automation & release notes)
Changed Behaviour
Samples.instances— skips stored samples the current model rejects viaFitException(warning logged) instead of raising; the list can be shorter thansample_list. Usevalid_sample_instance_pairswhen instances must stay paired with their samples/weights.Samples.max_log_posterior(as_instance=True)— when the stored best sample is rejected, recovers to the highest-posterior valid stored sample (warning logged) instead of raising; raisesSamplesExceptiononly when no stored sample is valid.to_instance-decorated methods (from_sample_index,median_pdf,values_at_sigma,values_at_upper_sigma,values_at_lower_sigma,errors_at_sigma,errors_at_upper_sigma,errors_at_lower_sigma,error_magnitudes_at_sigma,offset_values_via_input_values,SamplesSummary.median_pdf,SamplesInterface.max_log_likelihood) — aFitExceptionduring instance materialization now surfaces asautofit.exc.SamplesException(plainException) chained to the rejection, instead ofModelParameterException(aValueError). Theas_instance=Falseandas_dict=Truepaths are unchanged.to_instance— now a decorator factory taking arecoverpolicy: use@to_instance()or@to_instance(recover="next_valid"); bare@to_instanceno longer works (internal decorator; no downstream PyAuto repo imports it).Migration
try: samples.from_sample_index(i) except ValueError: ...try: samples.from_sample_index(i) except af.exc.SamplesException: ...Generated by the PyAutoLabs agent workflow.