Skip to content
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

Add cached extra study property #217

Merged
merged 6 commits into from
Apr 24, 2022

Conversation

yoshinobc
Copy link
Contributor

Contributor License Agreement

This repository (optuna-dashboard) and Goptuna share common code.
This pull request may therefore be ported to Goptuna.
Make sure that you understand the consequences concerning licenses and check the box below if you accept the term before creating this pull request.

  • I agree this patch may be ported to Goptuna by other Goptuna contributors.

Reference Issues/PRs

What does this implement/fix? Explain your changes.

Motivation

Eliminate unnecessary calculations when retrieving cached study properties.

Description of the changes

  • Add call to get_chached_extra_study_property method in _app.py
  • Integration of _search_space.py and _intermediate_values.py. Update both information in a single update.

Comment on lines 55 to 56
if self.has_intermediate_values:
return
Copy link
Member

@c-bata c-bata Apr 24, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Even if self.has_intermediate_values is True, we need to continue for-loop to update the search space cache.

@@ -65,11 +72,15 @@ def update(self, trials: List[FrozenTrial]) -> None:
if trial.state not in states_of_interest:
continue

if len(trial.intermediate_values) > 0:
Copy link
Member

@c-bata c-bata Apr 24, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nits] How about changing here like following to reduce a bit of computation since we don't need to update self.has_intermediate_values if it's already True?

Deleted

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you very much.
When self.has_intermediate_values is True , there is no need to run L76, so
Isn't this place if not self.has_intermediate_values and len(trial.intermediate_values) > 0:

Copy link
Member

@c-bata c-bata Apr 24, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, sorry. You are completely correct 🙏

Comment on lines 118 to 177
def test_no_intermediate_value(self) -> None:
intermediate_values = [
{},
{},
]
trials = [
create_trial(
state=TrialState.COMPLETE,
value=0,
distributions={"x0": UniformDistribution(low=0, high=10)},
intermediate_values=iv,
params={"x0": 0.5},
)
for iv in intermediate_values
]
cached_extra_study_property = _CachedExtraStudyProperty()
cached_extra_study_property.update(trials)
self.assertFalse(cached_extra_study_property.has_intermediate_values)

def test_some_trials_has_no_intermediate_value(self) -> None:
intermediate_values = [
{0: 0.3, 1: 1.2},
{},
{0: 0.3, 1: 1.2},
]
trials = [
create_trial(
state=TrialState.COMPLETE,
value=0,
distributions={"x0": UniformDistribution(low=0, high=10)},
intermediate_values=iv,
params={"x0": 0.5},
)
for iv in intermediate_values
]
cached_extra_study_property = _CachedExtraStudyProperty()
cached_extra_study_property.update(trials)
self.assertTrue(cached_extra_study_property.has_intermediate_values)

def test_all_trials_has_intermediate_value(self) -> None:
intermediate_values = [{0: 0.3, 1: 1.2}, {0: 0.3, 1: 1.2}]
trials = [
create_trial(
state=TrialState.COMPLETE,
value=0,
distributions={"x0": UniformDistribution(low=0, high=10)},
intermediate_values=iv,
params={"x0": 0.5},
)
for iv in intermediate_values
]
cached_extra_study_property = _CachedExtraStudyProperty()
cached_extra_study_property.update(trials)
self.assertTrue(cached_extra_study_property.has_intermediate_values)

def test_no_trials(self) -> None:
trials = []
cached_extra_study_property = _CachedExtraStudyProperty()
cached_extra_study_property.update(trials)
self.assertFalse(cached_extra_study_property.has_intermediate_values)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about splitting these test cases into another TestCase class? This test class looks somewhat large. These logics are defined in the same class (_CachedExtraStudyProperty) though.

Copy link
Member

@c-bata c-bata left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @yoshinobc.
Thank you for your pull request!

You changes looks almost good after solving lint errors and my suggestions.

Copy link
Member

@c-bata c-bata left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM after passed all CI tests!

@c-bata c-bata merged commit 24c5c6f into optuna:main Apr 24, 2022
@c-bata
Copy link
Member

c-bata commented Apr 24, 2022

Merged! Thank you for your contribution 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants