Fix assertion failures escaping Fitness.call#1217
Merged
Conversation
Move instance_from_vector inside try/except FitException so that assertion failures on prior violation return resample_figure_of_merit instead of bubbling FitException up into the non-linear search. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This was referenced Apr 14, 2026
Collaborator
Author
|
Workspace PR: PyAutoLabs/autofit_workspace_test#7 |
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
Assertions added to models (e.g.
gaussian_0.centre > gaussian_1.centre) were broken for non-linear searches: when a sampled parameter vector violated an assertion,check_assertionsraisedFitException, but that exception escapedFitness.calland killed the search. The workspace test for assertions had been commented out with the note "Assertions broken by JAX development and need fixing one day."Root cause:
instance_from_vector(which triggerscheck_assertions) was called outside thetry/except FitExceptionblock inFitness.call. Moving it inside restores the intended behaviour — assertion failures returnresample_figure_of_meritso the sampler skips that point.Fixes #1215.
API Changes
None — internal changes only. The fix restores the originally-intended behaviour of
Fitness.callunder assertion failures.See full details below.
Test Plan
test_fitness_returns_resample_fom_on_assertion_failurecovers violating/satisfying vectorstest_assertion.pysuite passes (11 tests)test_autofitsuite passes (1217 tests)DynestyStaticsearch with assertion constraint runs end-to-end, all collected samples satisfy the constraintFull API Changes (for automation & release notes)
Removed
None.
Added
None (new test only, not public API).
Changed Behaviour
autofit.non_linear.fitness.Fitness.call—FitExceptionraised duringinstance_from_vector(i.e. assertion violation on prior values) is now caught and converts toresample_figure_of_merit, matching the behaviour already documented forFitExceptionraised fromlog_likelihood_function. Previously such exceptions escaped and aborted the search.Migration
None required.
Follow-up: JAX branch of
Fitness.callhas no exception handling (JAX tracing prevents conditional exceptions); tracked in issue #1216.🤖 Generated with Claude Code