Repository: optuna/optuna

Issue:
Update CLI tutorial
The current CLI tutorial uses deprecated features. https://optuna.readthedocs.io/en/v2.10.0/tutorial/20_recipes/004_cli.html

New features of CLI have been introduced into master. I recommend rewriting the tutorial using the ask-and-tell interface.


Discussion:
This issue has not seen any recent activity.
This issue was closed automatically because it had not seen any recent activity. If you want to discuss it, you can reopen it freely.
Reopening as this is still an issue.
@hppRC is now working on this topic. 👍 
This issue has not seen any recent activity.
This issue has not seen any recent activity.
Hi @hppRC, please feel free to tell me if I can help you. :pray:
I talked with @hppRC and we decide to free the assignment. If someone is interested in writing a new tutorial, please feel free to comment here!
Hi, @himkt I would love to write the tutorial. Can you please give me some tips that can help me out with getting started!
Thank you for your interest @divyanshugit!

The current tutorial show the usage of `optuna create_study` and `optuna study optimize`. But `optuna study optimize` was deprecated in v2.2.0 and Optuna provides other CLI command such as `optuna ask` and `optuna tell`. We want to update our CLI tutorial to use `ask-and-tell` interface. And I think it's good starting point to rewrite the tutorial with CLI `ask-and-tell`.
This issue has not seen any recent activity.

Resolving patch:
diff --git a/optuna/cli.py b/optuna/cli.py
--- a/optuna/cli.py
+++ b/optuna/cli.py
@@ -847,7 +847,7 @@ def get_parser(self, prog_name: str) -> ArgumentParser:
             "--skip-if-finished",
             default=False,
             action="store_true",
-            help="If specified, tell is skipped without any error when the trial is already"
+            help="If specified, tell is skipped without any error when the trial is already "
             "finished.",
         )
         return parser
diff --git a/tutorial/20_recipes/004_cli.py b/tutorial/20_recipes/004_cli.py
--- a/tutorial/20_recipes/004_cli.py
+++ b/tutorial/20_recipes/004_cli.py
@@ -42,33 +42,36 @@ def objective(trial):
     print("Best value: {} (params: {})\n".format(study.best_value, study.best_params))
 
 ###################################################################################################
-# However, we can reduce boilerplate codes by using our ``optuna`` command.
-# Let us assume that ``foo.py`` contains only the following code.
-
-
-def objective(trial):
-    x = trial.suggest_float("x", -10, 10)
-    return (x - 2) ** 2
-
-
-###################################################################################################
+# However, if we cannot write ``objective`` explicitly in Python code such as developing a new
+# drug in a lab, an interactive way is suitable.
+# In Optuna CLI, :ref:`ask_and_tell` style commands provide such an interactive and flexible interface.
+#
+# Let us assume we minimize the objective value depending on a parameter ``x`` in :math:`[-10, 10]`
+# and objective value is calculated via some experiments by hand.
 # Even so, we can invoke the optimization as follows.
-# (Don't care about ``--storage sqlite:///example.db`` for now, which is described in :ref:`rdb`.)
+# Don't care about ``--storage sqlite:///example.db`` for now, which is described in :ref:`rdb`.
 #
 # .. code-block:: bash
 #
-#     $ cat foo.py
-#     def objective(trial):
-#         x = trial.suggest_float('x', -10, 10)
-#         return (x - 2) ** 2
-#
 #     $ STUDY_NAME=`optuna create-study --storage sqlite:///example.db`
-#     $ optuna study optimize foo.py objective --n-trials=100 --storage sqlite:///example.db --study-name $STUDY_NAME
-#     [I 2018-05-09 10:40:25,196] Finished a trial resulted in value: 54.353767789264026. Current best value is 54.353767789264026 with parameters: {'x': -5.372500782588228}.
-#     [I 2018-05-09 10:40:25,197] Finished a trial resulted in value: 15.784266965526376. Current best value is 15.784266965526376 with parameters: {'x': 5.972941852774387}.
-#     ...
-#     [I 2018-05-09 10:40:26,204] Finished a trial resulted in value: 14.704254135013741. Current best value is 2.280758099793617e-06 with parameters: {'x': 1.9984897821018828}.
+#     $ optuna ask --storage sqlite:///example.db --study-name $STUDY_NAME --sampler TPESampler \
+#          --search-space '{"x": {"name": "FloatDistribution", "attributes": {"step": null, "low": -10.0, "high": 10.0, "log": false}}}'
+#
+#
+#     [I 2022-08-20 06:08:53,158] Asked trial 0 with parameters {'x': 2.512238141966016}.
+#     {"number": 0, "params": {"x": 2.512238141966016}}
+#
+# The argument of ``--search-space`` option can be generated by using
+# :func:`optuna.distributions.distribution_to_json`, for example,
+# ``optuna.distributions.distribution_to_json(optuna.distributions.FloatDistribution(-10, 10))``.
+# Please refer to :class:`optuna.distributions.FloatDistribution` and
+# :class:`optuna.distributions.IntDistribution` for detailed explanations of their arguments.
+#
+# After conducting an experiment using the suggested parameter in the lab,
+# we store the result to Optuna's study as follows:
+#
+# .. code-block:: bash
+#
+#     $ optuna tell --storage sqlite:///example.db --study-name $STUDY_NAME --trial-number 0 --values 0.7 --state complete
+#     [I 2022-08-20 06:22:50,888] Told trial 0 with values [0.7] and state TrialState.COMPLETE.
 #
-# Please note that ``foo.py`` only contains the definition of the objective function.
-# By giving the script file name and the method name of objective function to
-# ``optuna study optimize`` command, we can invoke the optimization.


Test patch: