Increase test coverage of storage tests for single worker cases.#1191
Increase test coverage of storage tests for single worker cases.#1191toshihikoyanase merged 57 commits intooptuna:masterfrom
Conversation
78043d7 to
280c4fb
Compare
…-storage-spec # Conflicts: # tests/storages_tests/test_storages.py
|
Multi-study support will be addressed in #1228 instead of this PR. |
# Conflicts: # optuna/storages/in_memory.py # tests/integration_tests/test_chainermn.py # tests/storages_tests/test_storages.py
| system_attrs={}, | ||
| n_trials=0, | ||
| datetime_start=datetime.now(), | ||
| datetime_start=None, |
There was a problem hiding this comment.
comment: In InMemoryStorage and RDBStorage, the datetime_start is not the time the study created but the time the first trial in the study started.
| if trial.state.is_finished(): | ||
| self._update_cache(trial_id) |
There was a problem hiding this comment.
These two lines are necessary to manage StudySummaries appropriately.
| @@ -119,135 +110,6 @@ def test_set_default_engine_kwargs_for_mysql_with_other_rdb(): | |||
| assert "pool_pre_ping" not in engine_kwargs | |||
|
|
|||
|
|
|||
There was a problem hiding this comment.
comment: Logic tests for RDB storage are merged into tests/storage_tests/test_storages.py.
Codecov Report
@@ Coverage Diff @@
## master #1191 +/- ##
=========================================
Coverage ? 86.28%
=========================================
Files ? 92
Lines ? 6781
Branches ? 0
=========================================
Hits ? 5851
Misses ? 930
Partials ? 0
Continue to review full report at Codecov.
|
sile
left a comment
There was a problem hiding this comment.
LGTM but I left minor suggestions to make the style of the source code comments align to the Optuna coding convention.
Co-authored-by: Takeru Ohta <phjgt308@gmail.com>
|
|
||
| if trial_id not in self._trial_id_to_study_id_and_number: | ||
| raise ValueError("No trial with trial_id {} exists.".format(trial_id)) | ||
| raise KeyError("No trial with trial_id {} exists.".format(trial_id)) |
There was a problem hiding this comment.
[Comment] The trial_id is an internal attribute, but I think it is reasonable to use it here because this KeyError is not usually raised by user-code problems.
toshihikoyanase
left a comment
There was a problem hiding this comment.
Thank you for improving the storage tests. It basically looks good to me.
I have small suggestions and a few questions.
| def _check_trial_equality(output: FrozenTrial, expected: FrozenTrial) -> None: | ||
| assert output._trial_id == expected._trial_id | ||
| assert output.state == expected.state | ||
| assert output.value == expected.value | ||
| assert output.datetime_start == expected.datetime_start | ||
| assert output.datetime_complete == expected.datetime_complete | ||
| assert output.user_attrs == expected.user_attrs | ||
| assert output.system_attrs == expected.system_attrs | ||
| assert output.intermediate_values == expected.intermediate_values |
There was a problem hiding this comment.
assert output == expected is insufficient even if FrozenTrial has the __eq__ method?
There was a problem hiding this comment.
It seems I have misunderstood somethin, and I replaced them with __eq__.
There was a problem hiding this comment.
I found that for CategoricalDistribution, json_to_distribution(distribution_to_json(dist)) != dist in general and I'll create a PR to add an appropriate eq method to CategoricalDistribution.
There was a problem hiding this comment.
I'll create a PR to add an appropriate eq method to CategoricalDistribution.
Good catch! Thank you.
Co-authored-by: Toshihiko Yanase <toshihiko.yanase@gmail.com>
Co-authored-by: Toshihiko Yanase <toshihiko.yanase@gmail.com>
toshihikoyanase
left a comment
There was a problem hiding this comment.
LGTM! Thank you for improving the storage tests.
By the way, how about creating issue on the issue on CategoricalDistribution.__eq__ if it takes time to create a PR?
Motivation
Many storage features/specs are not tested. This low test coverage is a direct cause of the inconsistent implementations among storages. This PR aims to increase the test coverage and, at the same time, remove found bugs/inconsistent behaviors. This PR inevitably relies on #1175 and #1176. While we should test specs related to multi-worker settings, it will make this PR too complicated and it will be separated into another PR.
Description of the changes
The following space will be used to list all fixed/modified behaviors of storage implementations.
Some behaviors which need discussion, but not tackled in this PR.