Skip to content

Fix assertion failures escaping Fitness.call#1217

Merged
Jammy2211 merged 1 commit intomainfrom
feature/assertions-fix
Apr 14, 2026
Merged

Fix assertion failures escaping Fitness.call#1217
Jammy2211 merged 1 commit intomainfrom
feature/assertions-fix

Conversation

@Jammy2211
Copy link
Copy Markdown
Collaborator

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_assertions raised FitException, but that exception escaped Fitness.call and 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 triggers check_assertions) was called outside the try/except FitException block in Fitness.call. Moving it inside restores the intended behaviour — assertion failures return resample_figure_of_merit so the sampler skips that point.

Fixes #1215.

API Changes

None — internal changes only. The fix restores the originally-intended behaviour of Fitness.call under assertion failures.
See full details below.

Test Plan

  • New regression test test_fitness_returns_resample_fom_on_assertion_failure covers violating/satisfying vectors
  • Existing test_assertion.py suite passes (11 tests)
  • Full test_autofit suite passes (1217 tests)
  • Live DynestyStatic search with assertion constraint runs end-to-end, all collected samples satisfy the constraint
Full API Changes (for automation & release notes)

Removed

None.

Added

None (new test only, not public API).

Changed Behaviour

  • autofit.non_linear.fitness.Fitness.callFitException raised during instance_from_vector (i.e. assertion violation on prior values) is now caught and converts to resample_figure_of_merit, matching the behaviour already documented for FitException raised from log_likelihood_function. Previously such exceptions escaped and aborted the search.

Migration

None required.

Follow-up: JAX branch of Fitness.call has no exception handling (JAX tracing prevents conditional exceptions); tracked in issue #1216.

🤖 Generated with Claude Code

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>
@Jammy2211
Copy link
Copy Markdown
Collaborator Author

Workspace PR: PyAutoLabs/autofit_workspace_test#7

@Jammy2211 Jammy2211 merged commit 5ac44a0 into main Apr 14, 2026
2 checks passed
@Jammy2211 Jammy2211 deleted the feature/assertions-fix branch April 14, 2026 21:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pending-release Pending next release build

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix: restore broken PyAutoFit assertions

1 participant