Add float precision tests for storages#6040
Merged
nabenabe0928 merged 12 commits intooptuna:masterfrom Jun 4, 2025
Merged
Conversation
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.
Motivation
To prevent float precision loss on the storage layer, this PR adds tests for float values.
Related to: #3227 #3327
Description of the changes
Adding precision tests on
test_storages.pyandtest_with_server.py.Overview of the implementation for the float precision
In the storage layer, the following methods must keep precision of values.
set_trial_state_valuesset_trial_intermediate_valueset_trial_paramset_study_user_attrset_study_system_attrset_trial_user_attrset_trial_system_attrNote: Outside of the storage layer,
to_internal_repr/to_external_reprof distributions must also keep precision. These are tested intest_distributions.py.These methods handle the following floats:
set_trial_state_valuesset_trial_intermediate_valueset_trial_paramFloatDistribution)CategoricalDistribution)set_study_user_attr/set_study_system_attr/set_trial_user_attr/set_trial_system_attrStorage classes
Note: We assume that there is no precision issues in the encoded JSON string https://docs.python.org/3.13/library/json.html#implementation-limitations.
InMemoryStorageAll values are stored as Python variables so there are no precision issues.
JournalStorageIt dumps all the values into JSON strings and saves them.
RDBStorageAll
sqlalchemy.Floatspecify double-precision.Note: MySQL cannot handle infinities.
set_trial_state_valuessqlalchemy.FloatandTrialValueType.set_trial_intermediate_valuesqlalchemy.FloatandTrialIntermediateValueType.set_trial_paramFloatDistributionsqlalchemy.Float.CategoricalDistributionsqlalchemy.Floatinstead of values of them.set_study_user_attr/set_study_system_attr/set_trial_user_attr/set_trial_system_attrGrpcStorageProxyThe precision of values are specified in
api.proto.set_trial_state_valuesset_trial_intermediate_valueset_trial_paramFloatDistributionCategoricalDistributionset_study_user_attr/set_study_system_attr/set_trial_user_attr/set_trial_system_attr