Repository navigation
fix(gate): compare NumPy scalar measurements instead of abstaining - #795
Abhishek-B-R wants to merge 3 commits into
Conversation
evaluate_gate only compared values that were int or float instances. np.int64 and np.float32 are neither, so a check that returned a count straight from NumPy made its gate abstain: the episode got a gate-unevaluated tag and no verdict, and a critical check never quarantined it. The catalog already stores those scalars as their Python values, so the gate now reads them the same way before comparing.
[Medium impact] This PR appears safe to merge.
|
kstonekuan
left a comment
There was a problem hiding this comment.
Could you limit the conversion to numeric scalars and cover a date or duration in the regression test? I verified that both np.datetime64(99, "ns") and np.timedelta64(99, "ns") now produce a failing threshold verdict where the gate used to abstain.
np.datetime64 and np.timedelta64 are NumPy scalars too, so the first version turned them into ints and compared them against the threshold instead of abstaining. timedelta64 even subclasses np.integer, so it is excluded by name. The regression test now covers both.
Dismissed because a newer commit was pushed; Greptile will re-review the current head.
|
@kstonekuan Done in 07d15ee. The conversion now only applies to |
kstonekuan
left a comment
There was a problem hiding this comment.
Could you cover np.longdouble too? On Linux x86-64, np.longdouble(99).item() stays a NumPy scalar, so a gate with AT_MOST 50 still abstains.
np.longdouble(...).item() returns a NumPy scalar rather than a Python float, so a longdouble measurement still made the gate abstain. Convert with int()/float() instead, and cover np.longdouble in the regression test.
Dismissed because a newer commit was pushed; Greptile will re-review the current head.
|
@kstonekuan Covered in b7e1e00. as_python_number now converts with int() / float() instead of .item(), since np.longdouble(99).item() stays a NumPy scalar where long double is wider than a C double (Linux x86-64). The regression test adds np.longdouble(99) to the values that must compare, so AT_MOST 50 now gives a failing verdict for it instead of abstaining; the bool/datetime64/timedelta64 abstain cases are unchanged. |
Summary
A gate now compares NumPy scalar measurements. Before, a check that returned
np.int64ornp.float32(whatnp.count_nonzero,.sum()on an int array, or any float32 array reduction gives you) made its gate abstain, so a critical check never quarantined the episode however bad the number was.Why
evaluate_gatekeeps a matched value only if it is anint | floatinstance.np.int64andnp.float32are not subclasses of either (onlynp.float64is), so they fell into the "not a real number" branch. The catalog boundary already converts NumPy scalars with.item()(#126), andWeightedValuedoes the same (#647), but the gate runs on the rawCheckResultbefore the catalog sees it.Repro:
On main the run reports
measured,quarantine_tags == []and tagsgate-unevaluated:value. With this change it reportsfailedandquarantined:counts_frames, the same as for99or99.0.The fix converts
np.genericvalues with.item()before the existing checks, looking NumPy up insys.modulesthe waystatistics.pydoes sosteps.pystays NumPy free.np.bool_becomesbooland still abstains, asTruedoes today.Validation
test_numpy_scalar_measurements_compare_like_python_numbersintests/test_gates.py: fails on main (GateAbstained(unevaluated_patterns=('value',)) == GateDecided(verdict=False)), passes with the fix.uv run pytest -q tests/test_gates.py tests/test_checks.py tests/test_statistics.py: 167 passed.uv run pytest -q -n 4: 2595 passed, 49 skipped, 3 failed. The 3 aretests/test_cli.py::test_the_module_form_*, which fail the same way on main in my macOS environment and do not touch this code.uv run ruff check,uv run ruff format --check,uv run ty check: clean.Checklist
uv run ruff check --fix,uv run ruff format, anduv run ty check.Open in [code]smith · Need help on this PR? Tag
@codesmith-botwith what you need.Note
Medium Risk
Changes quality-gating behavior for checks that emit NumPy scalars—correct for critical quarantine but could newly fail episodes that previously abstained; scope is limited to
evaluate_gatewith targeted tests.Overview
Gate evaluation now treats NumPy integer and floating scalars (e.g.
np.int64,np.float32from reductions likenp.count_nonzero) like plain Python numbers by calling.item()before threshold checks. Previously those values failedisinstance(..., int | float), so gates abstained and critical checks did not quarantine even when the measurement clearly failed.NumPy is resolved via
sys.modulessosteps.pystays NumPy-free;np.timedelta64and other non-numeric scalars are still left alone so gates abstain as before.A new gate test covers direct
evaluate_gatecalls and an end-to-end critical check that returnsnp.int64(99)against an AT_MOST 50 threshold, expecting FAILED and quarantine.Reviewed by Cursor Bugbot for commit 07d15ee. Bugbot is set up for automated code reviews on this repo. Configure here.