Repository navigation
Serialize non-primitive strategy parameters defensively - #101
Merged
Merged
Conversation
_strategy_parameters() assumed every non-primitive strategy field could be converted with float(), so a PolicyStrategy holding a neural-network model (or any other non-numeric object) as a field crashed run_benchmark() at result-serialization time. Following the fix suggested in #99: primitives and None pass through, lists/tuples/dicts serialize recursively, scalar arrays keep the historical float() conversion, and anything else falls back to repr(). strategy_parameters therefore always stays JSON-native and serialization never fails a completed run. Co-Authored-By: Claude Fable 5 <noreply@anthropic.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
Closes #99.
_strategy_parameters()inbenchmark/runner/_run_benchmark.pyassumed every non-primitive strategy field could be converted withfloat(), so aPolicyStrategyholding a neural-network model (PyTorch/Flax/etc.) as a field crashedrun_benchmark()at result-serialization time — after the benchmark had already run.Following the fix suggested in the issue, a new
_serialize_parameter()helper serializes defensively:bool/int/float/str) andNonepass through unchangedlist/tuple/dictserialize recursivelyfloat()conversion (backward compatible)repr()— serialization can never fail a completed run (hence the deliberate broadexcept:__float__on arbitrary objects can raise anything)strategy_parameterstherefore always stays JSON-native. Multi-element arrays serialize as theirrepr()string, not nested lists — lossless array serialization would be a deliberate follow-up, not part of this fix.Tests
Two regression tests in
tests/test_benchmark_result_schema.pydrive a fake neural-net object throughrun_benchmark()as aPolicyStrategyfield, asserting the repr fallback, pass-through, recursion, and float paths, plus a fulljson.dumpsround-trip of the resultingBenchmarkResult.Full suite: 663 passed, 1 skipped.
Note: CI arrives with #100 — merge that first, then update this branch so it gets a CI run before merging.
🤖 Generated with Claude Code