Repository navigation
BUG: accept roundoff-sized overshoot in Function.compose - #1222
Gui-FernandesBR wants to merge 5 commits into
Conversation
Inner values that differ from the outer domain by floating-point noise (e.g. -1e-17 instead of 0) made compose raise a spurious ValueError. Values outside the domain by at most 1e-9 of the domain size are now clipped to it; larger overshoots still raise as before. Fixing it in compose covers every caller, not only the tank code. Related to #1209. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XDW575d9C9zpS7Z1v2KXVq
Function.compose now absorbs roundoff-sized overshoot itself, so the tank helper that clipped any amount at six call sites is redundant. The helper tests moved to the Function tests; the exact-depletion tank test stays and fails if compose reverts to the strict check. Related to #1209. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XDW575d9C9zpS7Z1v2KXVq
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XDW575d9C9zpS7Z1v2KXVq
Codecov Report✅ All modified and coverable lines are covered by tests.
Additional details and impacted files@@ Coverage Diff @@
## develop #1222 +/- ##
===========================================
- Coverage 91.71% 86.58% -5.14%
===========================================
Files 131 131
Lines 18248 18252 +4
===========================================
- Hits 16737 15803 -934
- Misses 1511 2449 +938 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
CharlesXmf
left a comment
There was a problem hiding this comment.
I checked this against Function.compose and the old _compose_clipped helper.
Moving the roundoff clip into the array–array path of compose is the right place for it, and the new tests in tests/unit/mathutils/test_function.py cover the important cases: both sides of the domain, a relative tolerance that depends on domain size, overshoots that should still raise, extrapolate=True leaving values unclipped, and callable sources still deferring to the existing no-bounds-check path. Keeping test_mass_flow_rate_tank_exact_depletion is also the right regression check for #1166.
Two notes:
-
The old
_compose_clippedhelper clipped any overshoot to the domain and then composed, so a physically large over/underfill would still produce a height at the tank edge and rely on the Tank volume/height checks for a specific error. After this change, an overshoot larger than1e-9 * (x_final - x_initial)raisesValueErrorinsidecompose(“must be within the domain”) before those Tank checks run. For the exact-depletion / roundoff case this is what you want; for a true overfill the failure mode is stricter and the message is less Tank-specific. That looks like an improvement to me, but it is worth being explicit about if callers were depending on the old silent clip. -
tolerance = 1e-9 * (self.x_final - self.x_initial)is zero if the domain is a single point, and is negative ifx_final < x_initial. Array-sourced Functions are normally sorted, so this may not come up, but a zero-width domain would still reject a-1e-17overshoot. Usingabs(self.x_final - self.x_initial)(or a small absolute floor) would make that case safer.
I did not run the tests here.
CharlesXmf
left a comment
There was a problem hiding this comment.
Moving the tank-only clip helper into Function.compose is the right place for this, and the tests cover the important edges: both sides of the domain, a tolerance that scales with domain size, a hard reject beyond the 1e-9 relative window, and extrapolate=True still not clipping. Leaving the exact-depletion tank test as a regression for the original failure is good.
One assumption this inherits from the existing bounds check: x_initial / x_final are x_array[0] / x_array[-1], and they are treated as a low-to-high interval. tolerance = 1e-9 * (self.x_final - self.x_initial) and np.clip(..., self.x_initial, self.x_final) would go the wrong way on a decreasing array-valued domain. If compose is only used with increasing domains (as _from_sorted_arrays suggests), this is fine; otherwise abs(...) and min/max would be safer.
The 1e-9 relative overshoot is now the default of a tol parameter, as suggested in review. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XDW575eTpLt8NEpXTiDNqw
|
@CharlesXmf on the overfill note: On the domain direction: array sources are sorted ascending on construction and |
The tank checks accept an error of up to 1e-6 m³ in the volumes and 1e-4 m in the heights, but Function.compose only accepted 1e-9 of the domain. An input between the two passed the tank checks and then stopped at the domain error of compose, in all four tank types. The six compose calls now pass the tolerance of the tank checks, so a larger error is still reported by the tank as underfilled or overfilled. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
|
I pushed a small commit here (74fc106) The tank checks accept up to 1e-6 m³ of error in the volumes and 1e-4 m in the heights, but Now the six |
Related to #1209
Related to #1166
Covers the #1166 part of the Motors item of the v1.14.0 checklist, as decided in #1194.
Function.composenow accepts inner values outside the domain by at most 1e-9 of the domain size and clips them to it; larger overshoots still raise the sameValueError, andextrapolate=Trueis unchanged. With that, the tanks use plaincomposeand_compose_clippedis removed; the exact-depletion tank test still reproduces the original failure without the fix.🤖 Generated with Claude Code
https://claude.ai/code/session_01XDW575d9C9zpS7Z1v2KXVq