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 missing __init__.py
files
#1367
Conversation
tests/multi_objective/test_trial.py:25: error: Unsupported operand types for + ("float" and "None")
tests/multi_objective/test_trial.py:25: error: Unsupported operand types for + ("float" and "str")
tests/multi_objective/test_trial.py:25: note: Right operand is of type "Union[None, bool, int, float, str]"
tests/multi_objective/test_trial.py:35: error: Argument 1 to "report" of "MultiObjectiveTrial" has incompatible type "Tuple[int, int, int]"; expected "Tuple[float]"
tests/multi_objective/test_trial.py:36: error: Argument 1 to "report" of "MultiObjectiveTrial" has incompatible type "Tuple[int, int, int]"; expected "Tuple[float]"
tests/multi_objective/test_trial.py:150: error: Value expression in dictionary comprehension has incompatible type "Optional[float]"; expected type "float"
tests/multi_objective/samplers_tests/test_nsga2.py:41: error: Argument "population_size" to "NSGAIIMultiObjectiveSampler" has incompatible type "float"; expected "int"
optuna/storages/rdb/alembic/env.py:32: error: Function is missing a return type annotation
optuna/storages/rdb/alembic/env.py:32: note: Use "-> None" if function does not return a value
optuna/storages/rdb/alembic/env.py:51: error: Function is missing a return type annotation
optuna/storages/rdb/alembic/env.py:51: note: Use "-> None" if function does not return a value
tests/multi_objective/test_study.py:131: error: Incompatible return value type (got "Tuple[float, float]", expected "List[float]")
Found 9 errors in 4 files (checked 171 source files) |
It seems the type annotation of optuna/optuna/multi_objective/trial.py Line 111 in e7afd40
|
Good catch! We should address the failures in the same PR. Taking a brief look through the errors, they mostly seem straight forward to address (e.g. by introducing assertions). Do you want to do that here? I otherwise suggest we split up this PR into multiple parts. |
Thank you for finding the missing type check. I think What do you think? |
@hvy Got it. I'll fix all the errors in this PR. @toshihikoyanase If so, I'll make |
p0 = trial.suggest_float("p0", -10, 10) | ||
p1 = trial.suggest_uniform("p1", 3, 5) | ||
p2 = trial.suggest_loguniform("p2", 0.00001, 0.1) | ||
p3 = trial.suggest_discrete_uniform("p3", 100, 200, q=5) | ||
p4 = trial.suggest_int("p4", -20, -15) | ||
p5 = trial.suggest_categorical("p5", [7, 1, 100]) | ||
p5 = cast(int, trial.suggest_categorical("p5", [7, 1, 100])) |
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.
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 is just an idea. It'd be nice if we could infer the return type of suggest_categorical
in a generic way like "return int if int list given" instead of returning Union
of several python primitive types because this enforces users to cast
a suggested value to resolve type errors when they use Optuna with a type-checking tool like mypy
.
The tests in |
@harupy I found similar issues in other PRs (e.g., https://circleci.com/gh/optuna/optuna/45221?utm_campaign=vcs-integration-link&utm_medium=referral&utm_source=github-build-link) and daily CI (https://github.com/optuna/optuna/actions/runs/136123282). I'm sorry but I'm under investigation. |
Codecov Report
@@ Coverage Diff @@
## master #1367 +/- ##
==========================================
+ Coverage 87.92% 88.06% +0.14%
==========================================
Files 98 97 -1
Lines 7376 7297 -79
==========================================
- Hits 6485 6426 -59
+ Misses 891 871 -20
Continue to review full report at Codecov.
|
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.
Why don't we allow both tuples and lists (sequence) giving the user some flexibility in how to design their objective functions? It's cumbersome having to convert lists to tuples. This is not a strong opinion though.
That makes sense. I'll fix the type annotaions. |
@hvy I have fixed the type annotations to use |
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.
Sorry for the delayed response, and thanks for fixing the details. LGTM!
@toshihikoyanase could you cont. for the second approval? |
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. Thank you for your contribution!
@hvy Thank you for letting me know.
Motivation
mypy
ignores directories that don't contain__init__.py
.Description of the changes
Add
__init__.py
files.I ran the test below to make sure all the directories contain
__init__.py