question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Inconsistent error handling in `suggest_int` and `suggest_float`

See original GitHub issue

Expected 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:closed
  • Created 2 years ago
  • Comments:10 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
himktcommented, Jan 26, 2022

#3166 will fix the problem. (It has not been merged into the master branch yet)

0reactions
contramundum53commented, Jun 24, 2022

This issue has already been solved.

Read more comments on GitHub >

github_iconTop Results From Across the Web

CWE-544: Missing Standardized Error Handling Mechanism
If the application handles error messages individually, on a one-by-one basis, this is likely to result in inconsistent error handling. The causes of...
Read more >
optuna.trial.Trial — Optuna 3.0.4 documentation
A trial is a process of evaluating an objective function. This object is passed to an objective function and provides interfaces to get...
Read more >
Improper Error Handling - OWASP Foundation
Improper handling of errors can introduce a variety of security problems for a web site. The most common problem is when detailed internal...
Read more >
Error handling - Power Query | Microsoft Learn
An article on how to catch and handle errors in Power Query using the syntax try and otherwise.
Read more >
Better error handling in Golang: Theory and practical tips
How should a programming language treat errors? For example, a function that opens a file with a given name and reads it to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found