Repository navigation
fix(gate): compare NumPy scalar measurements instead of abstaining - #795
Open
Abhishek-B-R wants to merge 1 commit into
Open
Abhishek-B-R wants to merge 1 commit into
Abhishek-B-R wants to merge 1 commit 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.
Contributor
[Medium impact] The PR appears safe to merge.
|
6 tasks done
This branch has not been deployed
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
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.