Inconsistent error handling in `suggest_int` and `suggest_float`
See original GitHub issueExpected behavior
More consistent error handling for suggest_int
and suggest_float
.
Reproducible examples (optional)
import optuna
# Suggest int. OK.
study = optuna.create_study()
trial = study.ask()
trial.suggest_int("x", 0, 10)
trial = study.ask()
trial.suggest_int("x", 0, 10, step=2) # OK.
# Suggest float. ValueError.
study = optuna.create_study()
trial = study.ask()
trial.suggest_float("x", 0, 10)
trial = study.ask()
trial.suggest_float("x", 0, 10, step=2) # ValueError: Cannot set different distribution kind to the same parameter name.
# Note: Similar behavior reproducible without the second `study.ask()`s.
Additional context (optional)
The inconsistency stem from historical reasons and in particular inconsistent distribution types and a consistency check based on these types https://github.com/optuna/optuna/blob/master/optuna/distributions.py#L521-L522. For instance, to suggest floats with steps you previously had to use suggest_discrete_uniform
, similarly for log suggest_loguniform
, until suggest_float
was introduced which covers both cases. Internally, suggest_float
simply calls suggest_discrete_uniform
, etc. and hence the associated distribution types become different depending on arguments. At the same time, this interface is not symmetric for suggest_int
. There is no suggest_discrete_int
or suggest_logint
.
To properly fix this issue, we probably have to rethink what distribution types to provide and make sure that samplers and other components depending on these distributions are aware.
Issue Analytics
- State:
- Created 2 years ago
- Comments:10 (4 by maintainers)
#3166 will fix the problem. (It has not been merged into the master branch yet)
This issue has already been solved.