Make positional args to kwargs in suggest_int#5044
Make positional args to kwargs in suggest_int#5044HideakiImamura merged 11 commits intooptuna:masterfrom
Conversation
2dc92a4 to
25d7a0a
Compare
|
I have a question. |
25d7a0a to
29b63da
Compare
Codecov Report
@@ Coverage Diff @@
## master #5044 +/- ##
==========================================
+ Coverage 89.40% 89.42% +0.01%
==========================================
Files 203 205 +2
Lines 15055 15135 +80
==========================================
+ Hits 13460 13534 +74
- Misses 1595 1601 +6
... and 17 files with indirect coverage changes 📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
|
@not522 @HideakiImamura Could you review this PR? |
HideakiImamura
left a comment
There was a problem hiding this comment.
Thanks for the PR. Basically, LGTM. I have two minor comments. PTAL.
By the way, as you mentioned, this PR does not force anything on the users as it is a change aimed at continuing support for the older API. However, this change is a milestone for the future. It is expected that the older API will no longer be supported in a future major version, and by making these changes in the code, it becomes easier for us to keep motivation.
There was a problem hiding this comment.
The multi_objective module is deprecated, so you should not have to add tests on this module.
There was a problem hiding this comment.
Just to make sure, but did you mean "do not have to" or "discouraging" (In other words, should I remove it)?
There was a problem hiding this comment.
I mean I discourage to fix the deprecated module.
There was a problem hiding this comment.
The multi_objective module is deprecated, so you should not have to fix this module.
| from optuna.distributions import CategoricalChoiceType | ||
|
|
||
|
|
||
| _SUGGEST_INT_POSITIONAL_ARGS = ["self", "name", "low", "high", "step", "log"] |
There was a problem hiding this comment.
Could you make only step and log positional? Currently convert_positional_args does not support partial conversion, but you can use inspect.signature to achieve this.
There was a problem hiding this comment.
Hi sorry for the late response:(
The variable name was actually misleading because these are "previous" positional arguments, but not the current positional arguments.
Plus, since all the arguments in suggest_int were positional arguments before this PR, I would like to simply change the variable name and let the convert_positional_args stay as it does.
If necessary, I can also make another PR for this.
How do you like it? (@not522)
There was a problem hiding this comment.
Oh, I'm sorry, it's my mistake. I wanted to say "make only step and log keyword-only".
There was a problem hiding this comment.
Certainly!
Then I will change the code so that inappropriate args usages will be warned!
|
@nabenabe0928 The checks CI fails. Could you fix them? |
Done! |
not522
left a comment
There was a problem hiding this comment.
I found unnecessary warnings, for example, suggest_int("x", 0, 9) outputs FutureWarning. I think that the check for the length in converter_wrapper is not correct.
56fe8a9 to
070cc61
Compare
Now I changed so that the |
optuna/_convert_positional_args.py
Outdated
| f"{func.__name__}(): Please give all values as keyword arguments." | ||
| f"{func.__name__}() got {kwargs_expected} as positional arguments " | ||
| "but they were expected to be given as keyword arguments." | ||
| " See https://github.com/optuna/optuna/issues/3324 for details.", |
There was a problem hiding this comment.
It's almost LGTM. How about removing this line because this error is not only related to #3324?
There was a problem hiding this comment.
Right, because of the last change, #3324 does not relate to this line anymore. (while it still makes sense to use kwargs only, the future warning for it is not the default Python design, so I removed it and stick to your suggestion.)
Motivation
As
suggest_floathas*beforestepsandlogso that users need to pass them askwargs, I applied the same tosuggest_int.Description of the changes
I made the following changes:
suggest_int(name, low, high, step, log)intosuggest_int(name, low, high, *, step, log)to strengthen the future safety, andsuggest_intwithconvert_positional_argsfor now to avoid breaking changes.