From 9c33faaa84fc7076d297f3be751e7f3189f9b755 Mon Sep 17 00:00:00 2001 From: outbreak_kp <112833146+jot-s-bindra@users.noreply.github.com> Date: Fri, 20 Oct 2023 10:00:14 +0530 Subject: [PATCH 01/12] Fixed future annotation in typing.py (#5054) Co-authored-by: Vaibhav --- optuna/_typing.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/optuna/_typing.py b/optuna/_typing.py index 350af8cc514..fe8ebbb3642 100644 --- a/optuna/_typing.py +++ b/optuna/_typing.py @@ -1,3 +1,5 @@ +from __future__ import annotations + from typing import Mapping from typing import Sequence from typing import Union @@ -13,5 +15,4 @@ None, ] - __all__ = ["JSONSerializable"] From 1a5c19e76d45312f7ad21d0360909984548f4d86 Mon Sep 17 00:00:00 2001 From: Vaibhav101203 <128999000+Vaibhav101203@users.noreply.github.com> Date: Fri, 20 Oct 2023 10:14:18 +0530 Subject: [PATCH 02/12] fixed future annotations in _hypervolume_history.py (#5057) --- optuna/visualization/matplotlib/_hypervolume_history.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/optuna/visualization/matplotlib/_hypervolume_history.py b/optuna/visualization/matplotlib/_hypervolume_history.py index fc347abb733..b6ebdbca95a 100644 --- a/optuna/visualization/matplotlib/_hypervolume_history.py +++ b/optuna/visualization/matplotlib/_hypervolume_history.py @@ -1,6 +1,6 @@ from __future__ import annotations -from typing import Sequence +from collections.abc import Sequence import numpy as np From 2171633400ebad5a7722da3649acc4f5d9232992 Mon Sep 17 00:00:00 2001 From: Vaibhav101203 <128999000+Vaibhav101203@users.noreply.github.com> Date: Fri, 20 Oct 2023 10:15:22 +0530 Subject: [PATCH 03/12] Fixed future annotations to edf python file (#5056) --- optuna/visualization/matplotlib/_edf.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/optuna/visualization/matplotlib/_edf.py b/optuna/visualization/matplotlib/_edf.py index ee138b91498..3625dbbe707 100644 --- a/optuna/visualization/matplotlib/_edf.py +++ b/optuna/visualization/matplotlib/_edf.py @@ -1,7 +1,7 @@ from __future__ import annotations -from typing import Callable -from typing import Sequence +from collections.abc import Callable +from collections.abc import Sequence from optuna._experimental import experimental_func from optuna.logging import get_logger From 3b40ae0dcf3163c7fb0ac63c74e3370e51a61716 Mon Sep 17 00:00:00 2001 From: nabenabe0928 Date: Fri, 6 Oct 2023 07:12:59 +0200 Subject: [PATCH 04/12] Add the table of dependencies in each integration module --- dependency-description.md | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 dependency-description.md diff --git a/dependency-description.md b/dependency-description.md new file mode 100644 index 00000000000..89dfa69748f --- /dev/null +++ b/dependency-description.md @@ -0,0 +1,28 @@ + +| Integration | Dependencies | +|:--:|:--:| +|[AllenNLP](https://github.com/optuna/optuna/tree/master/optuna/integration/allennlp) | allennlp, torch, psutil, _jsonnet | +| [BoTorch](https://github.com/optuna/optuna/blob/master/optuna/integration/botorch.py) | botorch, gpytorch, torch | +| [Catalyst](https://github.com/optuna/optuna/blob/master/optuna/integration/catalyst.py) | catalyst | +| [CatBoost](https://github.com/optuna/optuna/blob/master/optuna/integration/catboost.py) | catboost | +| [ChainerMN](https://github.com/optuna/optuna/blob/master/optuna/integration/chainermn.py)| chainermn | +| [Chainer](https://github.com/optuna/optuna/blob/master/optuna/integration/chainer.py)| chainer | +| [pycma](https://github.com/optuna/optuna/blob/master/optuna/integration/cma.py)| cma | +| [Dask](https://github.com/optuna/optuna/blob/master/optuna/integration/dask.py)| distributed | +| FastAI ([v1](https://github.com/optuna/optuna/blob/master/optuna/integration/fastaiv1.py), [v2](https://github.com/optuna/optuna/blob/master/optuna/integration/fastaiv2.py)) | fastai | +| [Keras](https://github.com/optuna/optuna/blob/master/optuna/integration/keras.py)| keras | +| [LightGBM](https://github.com/optuna/optuna/blob/master/optuna/integration/lightgbm.py)| lightgbm, sklearn | +| [MLflow](https://github.com/optuna/optuna/blob/master/optuna/integration/mlflow.py)| mlflow | +| [MXNet](https://github.com/optuna/optuna/blob/master/optuna/integration/mxnet.py)| mxnet | +| PyTorch ([Distributed](https://github.com/optuna/optuna/blob/master/optuna/integration/pytorch_distributed.py))| torch | +| PyTorch ([Ignite](https://github.com/optuna/optuna/blob/master/optuna/integration/pytorch_ignite.py))| pytorch-ignite | +| PyTorch ([Lightning](https://github.com/optuna/optuna/blob/master/optuna/integration/pytorch_lightning.py))| pytorch-lightning | +| [SHAP](https://github.com/optuna/optuna/blob/master/optuna/integration/shap.py)| scikit-learn, shap | +| [Scikit-learn](https://github.com/optuna/optuna/blob/master/optuna/integration/sklearn.py)| pandas, scipy, scikit-learn | +| [Scikit-optimize](https://github.com/optuna/optuna/blob/master/optuna/integration/skopt.py)| scikit-optimize | +| [SKorch](https://github.com/optuna/optuna/blob/master/optuna/integration/skorch.py)| skorch | +| [TensorBoard](https://github.com/optuna/optuna/blob/master/optuna/integration/tensorboard.py)| tensorboard, tensorflow | +| [TensorFlow](https://github.com/optuna/optuna/blob/master/optuna/integration/tensorflow.py)| tensorflow, tensorflow-estimator | +| [TensorFlow + Keras](https://github.com/optuna/optuna/blob/master/optuna/integration/tfkeras.py)| tensorflow | +| [Weights & Biases](https://github.com/optuna/optuna/blob/master/optuna/integration/wandb.py)| wandb | +| [XGBoost](https://github.com/optuna/optuna/blob/master/optuna/integration/xgboost.py)| xgboost | From 6dce23c609948c153799713af35e845d5f20b4b2 Mon Sep 17 00:00:00 2001 From: nabenabe0928 Date: Fri, 6 Oct 2023 07:20:22 +0200 Subject: [PATCH 05/12] Fix _jsonnet to jsonnet and modify the alignment --- dependency-description.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dependency-description.md b/dependency-description.md index 89dfa69748f..e4f8f92d9c4 100644 --- a/dependency-description.md +++ b/dependency-description.md @@ -1,7 +1,7 @@ | Integration | Dependencies | -|:--:|:--:| -|[AllenNLP](https://github.com/optuna/optuna/tree/master/optuna/integration/allennlp) | allennlp, torch, psutil, _jsonnet | +|:--|:--| +|[AllenNLP](https://github.com/optuna/optuna/tree/master/optuna/integration/allennlp) | allennlp, torch, psutil, jsonnet | | [BoTorch](https://github.com/optuna/optuna/blob/master/optuna/integration/botorch.py) | botorch, gpytorch, torch | | [Catalyst](https://github.com/optuna/optuna/blob/master/optuna/integration/catalyst.py) | catalyst | | [CatBoost](https://github.com/optuna/optuna/blob/master/optuna/integration/catboost.py) | catboost | From e411146f6c50784b70fcffcbce265f10f6a6ca29 Mon Sep 17 00:00:00 2001 From: nabenabe0928 Date: Tue, 10 Oct 2023 08:28:30 +0200 Subject: [PATCH 06/12] Add the table to the specified doc by c-bata --- dependency-description.md | 28 ------------- docs/source/reference/integration.rst | 59 +++++++++++++++++++++++++++ 2 files changed, 59 insertions(+), 28 deletions(-) delete mode 100644 dependency-description.md diff --git a/dependency-description.md b/dependency-description.md deleted file mode 100644 index e4f8f92d9c4..00000000000 --- a/dependency-description.md +++ /dev/null @@ -1,28 +0,0 @@ - -| Integration | Dependencies | -|:--|:--| -|[AllenNLP](https://github.com/optuna/optuna/tree/master/optuna/integration/allennlp) | allennlp, torch, psutil, jsonnet | -| [BoTorch](https://github.com/optuna/optuna/blob/master/optuna/integration/botorch.py) | botorch, gpytorch, torch | -| [Catalyst](https://github.com/optuna/optuna/blob/master/optuna/integration/catalyst.py) | catalyst | -| [CatBoost](https://github.com/optuna/optuna/blob/master/optuna/integration/catboost.py) | catboost | -| [ChainerMN](https://github.com/optuna/optuna/blob/master/optuna/integration/chainermn.py)| chainermn | -| [Chainer](https://github.com/optuna/optuna/blob/master/optuna/integration/chainer.py)| chainer | -| [pycma](https://github.com/optuna/optuna/blob/master/optuna/integration/cma.py)| cma | -| [Dask](https://github.com/optuna/optuna/blob/master/optuna/integration/dask.py)| distributed | -| FastAI ([v1](https://github.com/optuna/optuna/blob/master/optuna/integration/fastaiv1.py), [v2](https://github.com/optuna/optuna/blob/master/optuna/integration/fastaiv2.py)) | fastai | -| [Keras](https://github.com/optuna/optuna/blob/master/optuna/integration/keras.py)| keras | -| [LightGBM](https://github.com/optuna/optuna/blob/master/optuna/integration/lightgbm.py)| lightgbm, sklearn | -| [MLflow](https://github.com/optuna/optuna/blob/master/optuna/integration/mlflow.py)| mlflow | -| [MXNet](https://github.com/optuna/optuna/blob/master/optuna/integration/mxnet.py)| mxnet | -| PyTorch ([Distributed](https://github.com/optuna/optuna/blob/master/optuna/integration/pytorch_distributed.py))| torch | -| PyTorch ([Ignite](https://github.com/optuna/optuna/blob/master/optuna/integration/pytorch_ignite.py))| pytorch-ignite | -| PyTorch ([Lightning](https://github.com/optuna/optuna/blob/master/optuna/integration/pytorch_lightning.py))| pytorch-lightning | -| [SHAP](https://github.com/optuna/optuna/blob/master/optuna/integration/shap.py)| scikit-learn, shap | -| [Scikit-learn](https://github.com/optuna/optuna/blob/master/optuna/integration/sklearn.py)| pandas, scipy, scikit-learn | -| [Scikit-optimize](https://github.com/optuna/optuna/blob/master/optuna/integration/skopt.py)| scikit-optimize | -| [SKorch](https://github.com/optuna/optuna/blob/master/optuna/integration/skorch.py)| skorch | -| [TensorBoard](https://github.com/optuna/optuna/blob/master/optuna/integration/tensorboard.py)| tensorboard, tensorflow | -| [TensorFlow](https://github.com/optuna/optuna/blob/master/optuna/integration/tensorflow.py)| tensorflow, tensorflow-estimator | -| [TensorFlow + Keras](https://github.com/optuna/optuna/blob/master/optuna/integration/tfkeras.py)| tensorflow | -| [Weights & Biases](https://github.com/optuna/optuna/blob/master/optuna/integration/wandb.py)| wandb | -| [XGBoost](https://github.com/optuna/optuna/blob/master/optuna/integration/xgboost.py)| xgboost | diff --git a/docs/source/reference/integration.rst b/docs/source/reference/integration.rst index 044a83baf95..0860bba252c 100644 --- a/docs/source/reference/integration.rst +++ b/docs/source/reference/integration.rst @@ -148,3 +148,62 @@ XGBoost :nosignatures: optuna.integration.XGBoostPruningCallback + +Dependencies of each integration +================================ + +We summarize the necessary dependencies for each integration. + ++-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+------------------------------------+ +| Integration | Dependencies | ++===================================================================================================================================================================================+====================================+ +| `AllenNLP `_ | allennlp, torch, psutil, jsonnet | ++-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+------------------------------------+ +| `BoTorch `_ | botorch, gpytorch, torch | ++-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+------------------------------------+ +| `Catalyst `_ | catalyst | ++-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+------------------------------------+ +| `CatBoost `_ | catboost | ++-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+------------------------------------+ +| `ChainerMN `_ | chainermn | ++-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+------------------------------------+ +| `Chainer `_ | chainer | ++-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+------------------------------------+ +| `pycma `_ | cma | ++-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+------------------------------------+ +| `Dask `_ | distributed | ++-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+------------------------------------+ +| FastAI (`v1 `_, `v2 `_) | fastai | ++-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+------------------------------------+ +| `Keras `_ | keras | ++-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+------------------------------------+ +| `LightGBM `_ | lightgbm, sklearn | ++-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+------------------------------------+ +| `MLflow `_ | mlflow | ++-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+------------------------------------+ +| `MXNet `_ | mxnet | ++-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+------------------------------------+ +| PyTorch `Distributed `_ | torch | ++-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+------------------------------------+ +| PyTorch (`Ignite `_) | pytorch-ignite | ++-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+------------------------------------+ +| PyTorch (`Lightning `_) | pytorch-lightning | ++-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+------------------------------------+ +| `SHAP `_ | scikit-learn, shap | ++-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+------------------------------------+ +| `Scikit-learn `_ | pandas, scipy, scikit-learn | ++-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+------------------------------------+ +| `Scikit-optimize `_ | scikit-optimize | ++-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+------------------------------------+ +| `SKorch `_ | skorch | ++-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+------------------------------------+ +| `TensorBoard `_ | tensorboard, tensorflow | ++-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+------------------------------------+ +| `TensorFlow `_ | tensorflow, tensorflow-estimator | ++-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+------------------------------------+ +| `TensorFlow + Keras `_ | tensorflow | ++-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+------------------------------------+ +| `Weights & Biases `_ | wandb | ++-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+------------------------------------+ +| `XGBoost `_ | xgboost | ++-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+------------------------------------+ From 23ec20b892eac86f5ccbd45fdc14a81535446f18 Mon Sep 17 00:00:00 2001 From: nabenabe0928 Date: Wed, 11 Oct 2023 09:50:14 +0200 Subject: [PATCH 07/12] Address the comment by not522 --- docs/source/reference/integration.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/source/reference/integration.rst b/docs/source/reference/integration.rst index 0860bba252c..4c4cc258c95 100644 --- a/docs/source/reference/integration.rst +++ b/docs/source/reference/integration.rst @@ -150,7 +150,7 @@ XGBoost optuna.integration.XGBoostPruningCallback Dependencies of each integration -================================ +-------------------------------- We summarize the necessary dependencies for each integration. From f4b5d2be9f1a0669ec6631688f131e9f5e45b77f Mon Sep 17 00:00:00 2001 From: nabenabe0928 Date: Thu, 12 Oct 2023 04:54:49 +0200 Subject: [PATCH 08/12] Change sklearn --> scikit-learn --- docs/source/reference/integration.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/source/reference/integration.rst b/docs/source/reference/integration.rst index 4c4cc258c95..25f1c66ed62 100644 --- a/docs/source/reference/integration.rst +++ b/docs/source/reference/integration.rst @@ -177,7 +177,7 @@ We summarize the necessary dependencies for each integration. +-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+------------------------------------+ | `Keras `_ | keras | +-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+------------------------------------+ -| `LightGBM `_ | lightgbm, sklearn | +| `LightGBM `_ | lightgbm, scikit-learn | +-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+------------------------------------+ | `MLflow `_ | mlflow | +-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+------------------------------------+ From 9d9567c1ac15f9393e8ecaa0cbf5f4e50c6b2f41 Mon Sep 17 00:00:00 2001 From: nabenabe0928 Date: Thu, 12 Oct 2023 06:21:30 +0200 Subject: [PATCH 09/12] Address the comment by not522 --- docs/source/reference/integration.rst | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/docs/source/reference/integration.rst b/docs/source/reference/integration.rst index 25f1c66ed62..20e6450fa46 100644 --- a/docs/source/reference/integration.rst +++ b/docs/source/reference/integration.rst @@ -177,7 +177,9 @@ We summarize the necessary dependencies for each integration. +-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+------------------------------------+ | `Keras `_ | keras | +-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+------------------------------------+ -| `LightGBM `_ | lightgbm, scikit-learn | +| `LightGBMTuner `_ | lightgbm, scikit-learn | ++-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+------------------------------------+ +| `LightGBMPruningCallback `_ | lightgbm | +-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+------------------------------------+ | `MLflow `_ | mlflow | +-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+------------------------------------+ From 21f53d5305bff6b9d152ab94dbc9043c38363486 Mon Sep 17 00:00:00 2001 From: Alain Anghelidi <38346044+aanghelidi@users.noreply.github.com> Date: Fri, 20 Oct 2023 08:14:10 +0200 Subject: [PATCH 10/12] Fix `Any` with `float` in `_TreeNode.children` (#5040) * fix: `Any` with `float` in `_TreeNode.children` Fix typing of `_TreeNode.children` in `_brute_force.py` the following changes has been applied to keep type hinting consistent: * Change `Optional[Dict[Any, "_TreeNode"]]` to `Optional[Dict[float, "_TreeNode"]]` * Change **search_space** in `expand` to `Iterable[float]` * Change **params_and_search_spaces** in `add_path` to `Iterable[float]` Resolves: #5034 * fix: correct remaining type hints to internal representation --- optuna/samplers/_brute_force.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/optuna/samplers/_brute_force.py b/optuna/samplers/_brute_force.py index a4320ac7583..7d06733076d 100644 --- a/optuna/samplers/_brute_force.py +++ b/optuna/samplers/_brute_force.py @@ -33,9 +33,9 @@ class _TreeNode: # 3. Normal node. It has a param_name and non-empty children. param_name: Optional[str] = None - children: Optional[Dict[Any, "_TreeNode"]] = None + children: Optional[Dict[float, "_TreeNode"]] = None - def expand(self, param_name: Optional[str], search_space: Iterable[Any]) -> None: + def expand(self, param_name: Optional[str], search_space: Iterable[float]) -> None: # If the node is unexpanded, expand it. # Otherwise, check if the node is compatible with the given search space. if self.children is None: @@ -54,7 +54,7 @@ def set_leaf(self) -> None: self.expand(None, []) def add_path( - self, params_and_search_spaces: Iterable[Tuple[str, Iterable[Any], Any]] + self, params_and_search_spaces: Iterable[Tuple[str, Iterable[float], float]] ) -> Optional["_TreeNode"]: # Add a path (i.e. a list of suggested parameters in one trial) to the tree. current_node = self @@ -74,7 +74,7 @@ def count_unexpanded(self) -> int: else sum(child.count_unexpanded() for child in self.children.values()) ) - def sample_child(self, rng: np.random.RandomState) -> Any: + def sample_child(self, rng: np.random.RandomState) -> float: assert self.children is not None # Sample an unexpanded node in the subtree uniformly, and return the first # parameter value in the path to the node. @@ -240,7 +240,7 @@ def after_trial( study.stop() -def _enumerate_candidates(param_distribution: BaseDistribution) -> Sequence[Any]: +def _enumerate_candidates(param_distribution: BaseDistribution) -> Sequence[float]: if isinstance(param_distribution, FloatDistribution): if param_distribution.step is None: raise ValueError( From 1a0994ebab15c9c962de3cdf6f7b099cbdd7ba41 Mon Sep 17 00:00:00 2001 From: outbreak_kp <112833146+jot-s-bindra@users.noreply.github.com> Date: Fri, 20 Oct 2023 11:46:28 +0530 Subject: [PATCH 11/12] Added future annotations to callback and terminator files inside terminator folder (#5055) Co-authored-by: Vaibhav --- optuna/terminator/callback.py | 2 ++ optuna/terminator/terminator.py | 2 ++ 2 files changed, 4 insertions(+) diff --git a/optuna/terminator/callback.py b/optuna/terminator/callback.py index 74c484d0e84..dc75f23aa45 100644 --- a/optuna/terminator/callback.py +++ b/optuna/terminator/callback.py @@ -1,3 +1,5 @@ +from __future__ import annotations + from typing import Optional from optuna._experimental import experimental_class diff --git a/optuna/terminator/terminator.py b/optuna/terminator/terminator.py index 4970fd2661b..7536079f0df 100644 --- a/optuna/terminator/terminator.py +++ b/optuna/terminator/terminator.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import abc from typing import Optional From 5e5c498ebf94b51c866ee3f74d479ec24b9155b4 Mon Sep 17 00:00:00 2001 From: Shinichi Hemmi <50256998+Alnusjaponica@users.noreply.github.com> Date: Sat, 21 Oct 2023 09:22:03 +0900 Subject: [PATCH 12/12] Update link to reference --- optuna/integration/fastaiv1.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/optuna/integration/fastaiv1.py b/optuna/integration/fastaiv1.py index d9d988c9c4d..878f8991b8a 100644 --- a/optuna/integration/fastaiv1.py +++ b/optuna/integration/fastaiv1.py @@ -50,7 +50,7 @@ class FastAIV1PruningCallback(TrackerCallback): Args: learn: - `fastai.basic_train.Learner `_. + `fastai.basic_train.Learner `_. trial: A :class:`~optuna.trial.Trial` corresponding to the current evaluation of the objective function.