-
-
Notifications
You must be signed in to change notification settings - Fork 985
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 tests for CmaEsSampler
#4233
Conversation
Codecov Report
@@ Coverage Diff @@
## master #4233 +/- ##
==========================================
+ Coverage 89.94% 89.95% +0.01%
==========================================
Files 169 170 +1
Lines 13274 13279 +5
==========================================
+ Hits 11939 11945 +6
+ Misses 1335 1334 -1
📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
7239fb6
to
f730924
Compare
f730924
to
300f250
Compare
@gen740 @contramundum53 Could you review this PR if you have time? |
465db6d
to
944a24b
Compare
def objective(trial: optuna.Trial) -> float: | ||
x1 = trial.suggest_float("x1", -10, 10, step=1) | ||
x2 = trial.suggest_float("x2", -10, 10) | ||
return x1**2 + x2**2 |
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.
This objective function appears so many times, how about defining this function on the top of this test?
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.
@gen740 Thank you for your review!
I understand your motivation. Obviously, this is not optimal in DRY mind. It's a matter of preference, but reusing the same objective function in multiple test cases often made unit tests non-readable. (e.g. prepare_study_with_trials
function, which is used in visualization tests, contains a lot of implicit specifications and lots of unit tests depends on it. See https://github.com/optuna/optuna/pulls?q=is%3Apr+author%3Ac-bata+prepare_study_with_trials for details.)
So if it's a not your strong opinion, I suggest keeping this function not DRY. What do you think?
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 see. Indeed, reusing an objective function is sometimes hard to read...
I think that's fine to define for each test.
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.
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.
LGTM!
@contramundum53 Please merge this PR since this PR has two approvals. |
Motivation
Follow-up #4184.
Let me this PR ready for review after merged #4184.
Description of the changes
Add test cases to verify that
CmaEsSampler
restores the correct optimizer and updates the distribution with the correct solution trials.