Skip to content

Ask and tell interface tutorial#2422

Merged
Crissman merged 17 commits intooptuna:masterfrom
nzw0301:add_ask-and-tell_tutorial
Mar 17, 2021
Merged

Ask and tell interface tutorial#2422
Crissman merged 17 commits intooptuna:masterfrom
nzw0301:add_ask-and-tell_tutorial

Conversation

@nzw0301
Copy link
Copy Markdown
Member

@nzw0301 nzw0301 commented Feb 27, 2021

Motivation

Optuna has introduced an awesome interface called ask and tell. This pr aims to give a tutorial for the interface.

Description of the changes

  • Write the tutorial covering the following three features of ask-and-tell
    • Apply optuna to an existing optimization problem with minimum modifications
    • Define and Run
    • Batch Optimization
  • Mention the tutorial in ask and tell methods. (Thanks @crcrpar for your suggestions!)

@nzw0301
Copy link
Copy Markdown
Member Author

nzw0301 commented Feb 27, 2021

By the way, does formats.sh check the tutorial? I needed to run black tutorial/ on my local machine...

@codecov-io
Copy link
Copy Markdown

codecov-io commented Feb 27, 2021

Codecov Report

Merging #2422 (a28591a) into master (30f58b5) will decrease coverage by 0.07%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2422      +/-   ##
==========================================
- Coverage   91.44%   91.36%   -0.08%     
==========================================
  Files         134      135       +1     
  Lines       11270    11307      +37     
==========================================
+ Hits        10306    10331      +25     
- Misses        964      976      +12     
Impacted Files Coverage Δ
optuna/study.py 96.13% <ø> (ø)
optuna/integration/pytorch_lightning.py 83.33% <0.00%> (-4.17%) ⬇️
optuna/integration/allennlp.py 88.11% <0.00%> (-1.00%) ⬇️
optuna/importance/_fanova/_tree.py 99.45% <0.00%> (-0.01%) ⬇️
optuna/integration/botorch.py 97.75% <0.00%> (ø)
optuna/storages/_rdb/models.py 99.59% <0.00%> (ø)
optuna/samplers/_search_space.py 100.00% <0.00%> (ø)
optuna/storages/_cached_storage.py 97.06% <0.00%> (ø)
optuna/samplers/_tpe/parzen_estimator.py 100.00% <0.00%> (ø)
... and 9 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 30f58b5...a28591a. Read the comment docs.

Copy link
Copy Markdown
Contributor

@crcrpar crcrpar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your great work.

I think it's better to refer to this tutorial from ask and tell methods.

What's your take?

@nzw0301
Copy link
Copy Markdown
Member Author

nzw0301 commented Feb 28, 2021

@crcrpar Absolutely!

@keisuke-umezawa
Copy link
Copy Markdown
Member

@hvy could you also review it?

@nzw0301
Copy link
Copy Markdown
Member Author

nzw0301 commented Feb 28, 2021

I'll update the PR as suggested by @crcrpar in a few days; refer to the tutorial from ask and tell methods.

Cheers,

@hvy
Copy link
Copy Markdown
Member

hvy commented Mar 1, 2021

Just for the record, this is a tracking issue for ask and tell related changes #2177

@crcrpar crcrpar added document Documentation related. sprint-20210227 PR from the online sprint event Feb 27, 2021. labels Mar 1, 2021
@nzw0301 nzw0301 force-pushed the add_ask-and-tell_tutorial branch from 8c38403 to eeb6800 Compare March 1, 2021 05:53
@nzw0301 nzw0301 force-pushed the add_ask-and-tell_tutorial branch from eeb6800 to 5340398 Compare March 1, 2021 05:56
@g-votte g-votte assigned Crissman and unassigned hvy Mar 1, 2021
Copy link
Copy Markdown
Contributor

@crcrpar crcrpar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Basically okay. I'm not quite happy with my suggestions thus comments and it's up to you and other reviewers.


.. _Apply-optuna-to-an-existing-optimization-problem-with-minimum-modifications:

----------------------------------------------------------------------------
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit-picking this line isn't necessary. But I like this because this line makes the structure clearer while editing.

Suggested change
----------------------------------------------------------------------------
----------------------------------------------------------------------------

Comment thread tutorial/20_recipes/009_ask_and_tell.py Outdated
Comment thread tutorial/20_recipes/009_ask_and_tell.py Outdated
Comment on lines +63 to +69
# A drawback of this traditional interface is less flexibility.
# If ``objective`` requires an additional argument for ``objective``,
# you need to define your customized class for the objective as in
# `this FAQ section <../../faq.html#how-to-define-objective-functions-that-have-own-arguments>`_.
# That will make the codebase more complicated.
# The ask-and-tell interface provides a more flexible syntax to optimize hyperparameters.
# The following example of ask-and-tell interface is equivalent to the previous code block.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do prefer a shorter description, but let @Crissman decide.

The following is my suggestion and not a strong suggestion.

Suggested change
# A drawback of this traditional interface is less flexibility.
# If ``objective`` requires an additional argument for ``objective``,
# you need to define your customized class for the objective as in
# `this FAQ section <../../faq.html#how-to-define-objective-functions-that-have-own-arguments>`_.
# That will make the codebase more complicated.
# The ask-and-tell interface provides a more flexible syntax to optimize hyperparameters.
# The following example of ask-and-tell interface is equivalent to the previous code block.
# This interface is not flexible enough.
# For example, if ``objective`` requires additional arguments other than ``trial``,
# you need to define a class as in
# `How to define objective functions that have own arguments? <../../faq.html#how-to-define-objective-functions-that-have-own-arguments>`_.
# The ask-and-tell interface provides a more flexible syntax to optimize hyperparameters.
# The following example is equivalent to the previous code block.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aside from changing that first line to explain why ask/tell is not always superior, I like @crcrpar 's shorter description. 🙇‍♂️

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry but I don't understand your comment enough. Do you mean it's better to leave the first line "A drawback of this traditional interface is less flexibility." as is and replace the other line with my suggestion?

Comment thread tutorial/20_recipes/009_ask_and_tell.py Outdated
Comment thread tutorial/20_recipes/009_ask_and_tell.py Outdated
Comment thread tutorial/20_recipes/009_ask_and_tell.py Outdated
nzw0301 and others added 4 commits March 5, 2021 22:01
Co-authored-by: Masaki Kozuki <masaki.kozuki.2014@gmail.com>
Co-authored-by: Masaki Kozuki <masaki.kozuki.2014@gmail.com>
Co-authored-by: Masaki Kozuki <masaki.kozuki.2014@gmail.com>
Co-authored-by: Masaki Kozuki <masaki.kozuki.2014@gmail.com>
Copy link
Copy Markdown
Contributor

@Crissman Crissman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good tutorial. Thanks!

Comment thread tutorial/20_recipes/009_ask_and_tell.py Outdated
Comment thread tutorial/20_recipes/009_ask_and_tell.py Outdated
Comment on lines +63 to +69
# A drawback of this traditional interface is less flexibility.
# If ``objective`` requires an additional argument for ``objective``,
# you need to define your customized class for the objective as in
# `this FAQ section <../../faq.html#how-to-define-objective-functions-that-have-own-arguments>`_.
# That will make the codebase more complicated.
# The ask-and-tell interface provides a more flexible syntax to optimize hyperparameters.
# The following example of ask-and-tell interface is equivalent to the previous code block.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aside from changing that first line to explain why ask/tell is not always superior, I like @crcrpar 's shorter description. 🙇‍♂️

Comment thread tutorial/20_recipes/009_ask_and_tell.py Outdated
Comment thread tutorial/20_recipes/009_ask_and_tell.py Outdated
Comment thread tutorial/20_recipes/009_ask_and_tell.py Outdated
Comment thread tutorial/20_recipes/009_ask_and_tell.py Outdated
Comment thread tutorial/20_recipes/009_ask_and_tell.py Outdated
Comment thread tutorial/20_recipes/009_ask_and_tell.py Outdated
Comment thread tutorial/20_recipes/009_ask_and_tell.py Outdated
Comment thread tutorial/20_recipes/009_ask_and_tell.py Outdated
Copy link
Copy Markdown
Contributor

@Crissman Crissman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The separate examples structure is looking good! Let's sell the tutorial more in the API doc.

Comment thread optuna/study.py Outdated
Comment thread optuna/study.py Outdated
nzw0301 and others added 2 commits March 15, 2021 14:35
Co-authored-by: Crissman Loomis <crissman@preferred.jp>
Co-authored-by: Crissman Loomis <crissman@preferred.jp>
Copy link
Copy Markdown
Contributor

@Crissman Crissman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@Crissman Crissman merged commit 4891377 into optuna:master Mar 17, 2021
@Crissman Crissman added this to the v2.6.1 milestone Mar 17, 2021
@nzw0301 nzw0301 deleted the add_ask-and-tell_tutorial branch March 17, 2021 05:21
@nzw0301
Copy link
Copy Markdown
Member Author

nzw0301 commented Mar 17, 2021

Thank you for your long reviews! I'm happy to learn this interface!

@toshihikoyanase toshihikoyanase modified the milestones: v2.6.1, v2.7.0 Apr 2, 2021
@hvy hvy mentioned this pull request May 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

document Documentation related. sprint-20210227 PR from the online sprint event Feb 27, 2021.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants