-
-
Notifications
You must be signed in to change notification settings - Fork 971
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Move default logic of get_trial_id_from_study_id_trial_number()
method to BaseStorage.
#3910
Move default logic of get_trial_id_from_study_id_trial_number()
method to BaseStorage.
#3910
Conversation
get_trial_id_from_study_id_trial_number()
method to BaseStorage.
This pull request has not seen any recent activity. |
584b18b
to
ce674ac
Compare
Codecov Report
@@ Coverage Diff @@
## master #3910 +/- ##
==========================================
- Coverage 90.58% 90.55% -0.03%
==========================================
Files 167 167
Lines 13113 13110 -3
==========================================
- Hits 11878 11872 -6
- Misses 1235 1238 +3
📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
@wattlebirdaz Could you review this PR since hvy-san will take a vacation. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the pull request. LGTM.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR! I think this PR is generally a good direction, but I left some concerns and questions. PTAL.
tests/study_tests/test_study.py
Outdated
def test_tell_storage_not_implemented_trial_number() -> None: | ||
with StorageSupplier("inmemory") as storage: | ||
|
||
with patch.object( | ||
storage, | ||
"get_trial_id_from_study_id_trial_number", | ||
side_effect=NotImplementedError, | ||
): | ||
study = create_study(storage=storage) | ||
|
||
study.tell(study.ask(), 1.0) | ||
|
||
# Storage missing implementation for method required to map trial numbers back to | ||
# trial IDs. | ||
with pytest.warns(UserWarning): | ||
study.tell(study.ask().number, 1.0) | ||
|
||
with pytest.raises(ValueError): | ||
study.tell(study.ask().number + 1, 1.0) | ||
study = create_study(storage=storage) | ||
study.tell(study.ask(), 1.0) | ||
study.tell(study.ask().number, 1.0) | ||
|
||
with pytest.raises(ValueError): | ||
study.tell(study.ask().number + 1, 1.0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With this, InMemoryStorage.get_trial_id_from_study_id_trial_number
is tested instead of BaseStorage.get_trial_id_from_study_id_trial_number
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I cannot think of a way to easily test InMemoryStorage.get_trial_id_from_study_id_trial_number
(except for mocking all the abstract methods of InMemoryStorage
), but do you come up with a good way...?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch! It is a difficult problem how to test concrete methods in an abstract base class. I thought it would be better to just remove this test case since this test case should not be written in test_study.py
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems that get_trial_id_from_study_id_trial_number()
is enough tested at:
optuna/tests/storages_tests/test_storages.py
Lines 1070 to 1096 in 2c09c5d
@pytest.mark.parametrize("storage_mode", STORAGE_MODES) | |
def test_get_trial_id_from_study_id_trial_number(storage_mode: str) -> None: | |
with StorageSupplier(storage_mode) as storage: | |
with pytest.raises(KeyError): # Matching study does not exist. | |
storage.get_trial_id_from_study_id_trial_number(study_id=0, trial_number=0) | |
study_id = storage.create_new_study() | |
with pytest.raises(KeyError): # Matching trial does not exist. | |
storage.get_trial_id_from_study_id_trial_number(study_id, trial_number=0) | |
trial_id = storage.create_new_trial(study_id) | |
assert trial_id == storage.get_trial_id_from_study_id_trial_number( | |
study_id, trial_number=0 | |
) | |
# Trial IDs are globally unique within a storage but numbers are only unique within a | |
# study. Create a second study within the same storage. | |
study_id = storage.create_new_study() | |
trial_id = storage.create_new_trial(study_id) | |
assert trial_id == storage.get_trial_id_from_study_id_trial_number( | |
study_id, trial_number=0 | |
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree that this test should not be located in test_study.py
.
Still, I feel the default logic of BaseStorage.get_trial_id_from_study_id_trial_number
should be tested somewhere (not tested in test_get_trial_id_from_study_id_trial_number
because all the concrete class override the method). We should probably discuss how to test default implementations in BaseStorage
as another issue.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So, let me merge this PR first. If you have any opinions, please leave a comment!
This pull request has not seen any recent activity. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the update! LGTM. Please comment if you have any opinion on the point I mentioned.
Thank you for your thorough review! |
Motivation
Follow-up #3909. Please see the description of #3909.
Description of the changes
Implement default logic of
get_trial_id_from_study_id_trial_number
in BaseStorage.