Skip to content

Trial level suggest for same variable with different parameters give warning - #908

Merged
hvy merged 17 commits into
optuna:masterfrom
PhilipMay:trial_level_check
Feb 12, 2020
Merged

hvy merged 17 commits into
optuna:masterfrom
PhilipMay:trial_level_check

Conversation

@PhilipMay

@PhilipMay PhilipMay commented Feb 9, 2020 •

Copy link
Copy Markdown
Contributor

PR for #797
and fix for #867

PR is not completed yet.

  • more tests

@hvy
hvy self-requested a review February 10, 2020 06:15
@hvy hvy added the enhancement Change that does not break compatibility and not affect public interfaces, but improves performance. label Feb 10, 2020

@hvy hvy left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks a lot for this PR. I left some comments. Could you take a look?

Comment thread optuna/trial.py Resolved
Comment thread optuna/trial.py Resolved
Comment thread optuna/trial.py Resolved
Comment thread optuna/trial.py Resolved
@hvy hvy self-assigned this Feb 10, 2020
PhilipMay and others added 2 commits February 10, 2020 17:37
Co-Authored-By: Hiroyuki Vincent Yamazaki <hiroyuki.vincent.yamazaki@gmail.com>
@codecov-io

Copy link
Copy Markdown

Codecov Report

Merging #908 into master will increase coverage by 0.16%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #908      +/-   ##
==========================================
+ Coverage   90.21%   90.38%   +0.16%     
==========================================
  Files         108      110       +2     
  Lines        8936     9146     +210     
==========================================
+ Hits         8062     8267     +205     
- Misses        874      879       +5
Impacted Files Coverage Δ
optuna/trial.py 87.33% <100%> (+0.98%) ⬆️
tests/test_trial.py 99.24% <100%> (+0.12%) ⬆️
optuna/storages/rdb/storage.py 96.86% <0%> (-0.03%) ⬇️
optuna/integration/sklearn.py 75.6% <0%> (-0.02%) ⬇️
setup.py 0% <0%> (ø) ⬆️
tests/integration_tests/test_sklearn.py 100% <0%> (ø) ⬆️
optuna/exceptions.py 100% <0%> (ø) ⬆️
tests/integration_tests/test_xgboost.py 100% <0%> (ø) ⬆️
tests/test_experimental.py 93.02% <0%> (ø)
... and 12 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update c1b15be...bde3f44. Read the comment docs.

@PhilipMay

Copy link
Copy Markdown
Contributor Author

@hvy made all changes 👍

@PhilipMay
PhilipMay requested a review from hvy February 10, 2020 20:12

@hvy hvy left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@PhilipMay, thanks a lot for the quick fix. The changes LGTM so I'll merge this PR if there are no comments from the other maintainers.

I would by the way personally make the warning message a bit more verbose but that can be addressed later on. More precisely, include the actual search space definitions and maybe also the actual behavior that the search space is "ignored".

@hvy hvy added this to the v1.2.0 milestone Feb 12, 2020
@hvy
hvy merged commit 30af135 into optuna:master Feb 12, 2020
@sile

sile commented Feb 12, 2020

Copy link
Copy Markdown
Member

@PhilipMay

Thanks for the great PR! The code seems concise and efficient.

This is just an FYI and can be ignored, but I think that we might be able to implement Trial._check_distribution method in another way as follows:

    def _check_distribution(self, name, distribution):
        # type: (str, BaseDistribution) -> None

        old_distribution = self.distributions.get(name, distribution)
        if old_distribution != distribution:
            warnings.warn('Inconsistent parameter values for distribution {}! '
                          'This might be a configuration mistake.'
                          .format(name), RuntimeWarning)

Pros and cons of the above implementation:

  • Pros
    • It doesn't require an additional field, i.e., _distributions_in_trial field in this PR.
  • Cons
    • The invocation of Trial.distributions property incurs additional storage accesses.
      • If the storage backend is RDBStorage, it results in an increased number of SQL queries.
      • I believe that the additional cost would be negligible in practice, though.

@PhilipMay

Copy link
Copy Markdown
Contributor Author

Great. I am happy to help with this.
I will have a look into the 2 comments above.

@PhilipMay
PhilipMay deleted the trial_level_check branch February 16, 2020 20:50
@PhilipMay

PhilipMay commented Feb 16, 2020 •

Copy link
Copy Markdown
Contributor Author

@sile Your suggested change seems to work. I tested it.

    def _check_distribution(self, name, distribution):
        # type: (str, BaseDistribution) -> None

        old_distribution = self.distributions.get(name, distribution)
        if old_distribution != distribution:
            warnings.warn('Inconsistent parameter values for distribution {}! '
                          'This might be a configuration mistake.'
                          .format(name), RuntimeWarning)

What do you think? Should I change it? Your call.

@sile

sile commented Feb 17, 2020

Copy link
Copy Markdown
Member

@PhilipMay Thank you for checking my suggested code! Personally, I prefer simpler code, so it would be appreciated if you could create a PR to reflect the above change.

@PhilipMay

Copy link
Copy Markdown
Contributor Author

Created PR here: #937

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement Change that does not break compatibility and not affect public interfaces, but improves performance.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Trial suggest for same variable with different parameters should give error or raise exceptoion

4 participants