Add DerivativeCheckResult.assert_success - #78
Merged
Conversation
Ports AMICI's assert_gradient_check_success helper into fiddy so consumers can drop their local copy (#39). Raises an AssertionError with a human-readable, CI-log-friendly summary (failing direction IDs, a worst-first diff table with each direction's original index, and max abs/rel diff vs. tolerance) on failure, or on an unsuccessful finite- difference computation; no-op on success unless always_print=True. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
dweindl
marked this pull request as ready for review
August 7, 2026 13:39
dilpath
approved these changes
Aug 11, 2026
Comment on lines
+198
to
+210
| def test_assert_success_shows_all_failed_directions(): | ||
| point = np.full(40, 0.5) | ||
| result = _get_rosenbrock_check_result(point, rtol=0, atol=0) | ||
| assert not result.success | ||
|
|
||
| with pytest.raises(AssertionError) as error: | ||
| result.assert_success() | ||
|
|
||
| message = str(error.value) | ||
| failed_ids = result.df.index[~result.df["success"]] | ||
| assert len(failed_ids) == 40 | ||
| for direction_id in failed_ids: | ||
| assert direction_id in message |
Member
There was a problem hiding this comment.
This is not so interesting, I would slightly prefer a check that fails for a few specific parameters/directions and those are correctly reported
Co-authored-by: Dilan Pathirana <59329744+dilpath@users.noreply.github.com>
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
assert_gradient_check_successtest helper intofiddyasDerivativeCheckResult.assert_success(always_print=False).always_print=True); on failure raisesAssertionErrorwith a human-readable, CI-log-friendly summary: pass/fail counts, failing direction IDs, and a details table sorted by relative-difference severity (worst first) that also carries each direction's original index (so systematic patterns, e.g. "the first direction is always off", stay visible after the severity sort) and max abs/rel diff vs. tolerance.DerivativeCheckResultgainedatol/rtol/derivativefields (all optional, defaulted) populated byNumpyIsCloseDerivativeCheck, and.dfgainedatol_success/rtol_successcolumns when tolerances are known.Test plan
pytest tests/— all pass (one pre-existing, unrelated timing-based flake intest_function.py::test_cachereproduces onmaintoo and passes on rerun)pre-commit run --all-fileson changed files — cleanAssertionErrormessages for: a small failing case, a 40-direction failing case (confirms nothing is silently truncated), analways_print=Truesuccess case, and the "computation aborted" case🤖 Generated with Claude Code