Repository navigation
Conversation
The JSON encoder wrote DataFrames with pandas' default double_precision of 10 decimal places, so a metric mean/SEM below ~5e-11 was stored as 0.0 and larger values lost digits on save_to_json_file / load_from_json_file. Use pandas' maximum of 15.
Apply the same double_precision=15 to the SQA Data encoder and add a SQL round trip test; extend the JSON test with a 3.456789e-9 value.
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
object_to_jsonserialises everypd.DataFrame(theDataof each trial) withobj.to_json(). pandas' defaultdouble_precisionis 10 decimal places, so a metric mean or SEM between about 1e-15 and 5e-11 is written as0.0, and larger values silently lose digits (for example 3.456789e-9 reloads as 3.5e-9), onsave_to_json_file/load_from_json_file.Encoder.data_to_sqahas the sameto_json()call for SQL storage.A lossless fix is already proposed in #1750 ("Store floats exactly in Pandas DataFrames"), which changes the stored format and has been idle since 2023. This PR is a small stopgap that keeps the current format and decoder.
Repro (Ax main, pandas 3.1.2):
main:
[['loss', 1.23456789e-12, 3.3e-13]]then[['loss', 0.0, 0.0]].With this change the reloaded values are 1.235e-12 / 3.3e-13 (15 decimal places, pandas' maximum), instead of 0.0.
Change
ax/storage/json_store/encoder.pyandax/storage/sqa_store/encoder.py(data_json):to_json(double_precision=15). The stored format is unchanged, so older files still decode. 15 decimals is pandas' upper limit, so this stays lossy: about half of random floats round trip bit-exactly (0.3% at 10 decimals), values around 1e-12 keep 3 to 4 digits, and values of order 1e-9 and above are exact in the cases I tried. It no longer zeroes values above 1e-15.Test plan
JSONStoreTest.test_encode_decode_data_keeps_small_metric_values(means 1.23e-12, 3.456789e-9, SEM 3.3e-13) andSQAStoreTest.test_data_round_trip_keeps_small_metric_values(data_to_sqa/data_from_sqa).0.0 != 1.23456789e-12).pytest ax/storage/json_store: 59 passed.pytest ax/storage/sqa_store: 134 passed, 1 skipped, 1 failed (test_save_experiment_with_surrogate_as_model_kwarg; the installed botorch lacksfmin_l_bfgs_b_batched, same failure without this change).The implementation and tests were written with AI assistance.