Skip to content
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 nelder-mead sampler #346

Merged
merged 215 commits into from
May 13, 2024
Merged

Add nelder-mead sampler #346

merged 215 commits into from
May 13, 2024

Conversation

KanaiYuma-aist
Copy link
Collaborator

@KanaiYuma-aist KanaiYuma-aist commented Jan 9, 2024

Nelder-Mead Sampler と、対応したテストを追加しました。

Nelder-Mead Sampler の仕様

  • 基本的には現行aiaccelの _nelder_mead.py をベースとしています。
    • Vertex クラス、Store クラスは削除しました。
  • Sampler の引数は、パラメータの範囲設定の dict と初期点のランダムサーチに使う seed 値の int 、NelderMeadの頂点移動に用いるパラメータ coef の各パラメータ(r, e, ic, oc, s) のfloatとしています。
  • 探索パラメータを計算した際に、範囲外のパラメータが出力された時は、その座標の計算を行わずに(内部的にはinfとして扱い)次の探索パラメータの計算を行います。
  • 現状、並列化には対応していません。

テストについて

  • ユニットテストを tests/unit_tests 直下に、アルゴリズムテストを tests/sampler/nelder_mead 直下にそれぞれ追加しました。
    • ユニットテストのカバレッジは 96% となっています。
$ coverage report
Name                                           Stmts   Miss  Cover
------------------------------------------------------------------
aiaccel/__init__.py                                0      0   100%
aiaccel/hpo/__init__.py                            0      0   100%
aiaccel/hpo/samplers/__init__.py                   0      0   100%
aiaccel/hpo/samplers/nelder_mead_sampler.py      200      3    98%
tests/unit_tests/test_nelder_mead_sampler.py     394      0   100%
------------------------------------------------------------------
TOTAL                                            594      3    99%

  • アルゴリズムテストは results.csv から想定している計算結果を読み取り、 optuna.study() で探索を実行して、パラメータと計算結果を小数点以下第7位(assertAlmostEqual のデフォルト設定)まで一致しているかどうかを判定しています。

@KanaiYuma-aist KanaiYuma-aist marked this pull request as ready for review January 10, 2024 07:38
Copy link
Collaborator

@yoshipon yoshipon left a comment

Choose a reason for hiding this comment

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

PRありがとうございます.
全体的にAnyが多いのが気になりますが,Simplex等の入力はfloat32, 64等の数値型だと思うので,極力Anyを減らして貰ってもよいでしょうか?
特に | Any となっている部分は,型を付けていないのと同じになってしまうので,やむを得ない場合を除き,割けるべきだと思います.

mypy のチェックが厳しすぎる系の話であれば,そちらの設定を修正した方が良いと思うので,ミーティング等でご指摘下さい.

aiaccel/hpo/samplers/nelder_mead_sampler.py Outdated Show resolved Hide resolved
aiaccel/hpo/samplers/nelder_mead_sampler.py Outdated Show resolved Hide resolved
aiaccel/hpo/samplers/nelder_mead_sampler.py Outdated Show resolved Hide resolved
@KanaiYuma-aist
Copy link
Collaborator Author

KanaiYuma-aist commented Apr 22, 2024

sampler test をpytest に移行しました。
また、sub_sampler 機能の sampler test を追加しました。

bb24195

@KanaiYuma-aist
Copy link
Collaborator Author

KanaiYuma-aist commented Apr 22, 2024

開発者会議メモ

  • sub_sampler
    • sampler 内部で sub_sampler 用の study を呼んでいるが、これを sub_sampler の before_trial, sample_independent, after_trial を呼び出す形に改修する
  • テスト関連
    • クラスにする必要が無い箇所を修正する
    • fixture 関連は共通している部分のみとして、部分的に利用している箇所は関数化もしくはクラス化する

@KanaiYuma-aist
Copy link
Collaborator Author

@yoshipon
次回の開発者会議が3週間後(恐らく5/13)とかなので、上記が終わった後にやることがあればコメントください。
(sampler のドキュメント作成とか?)

@KanaiYuma-aist
Copy link
Collaborator Author

KanaiYuma-aist commented Apr 22, 2024

sub_sampler 用の study を sub_sampler の before_trial, sample_independent, after_trial に置き換える場合の懸念点

  • before_trial, sample_independent, after_trial の引数に study が含まれているが、sub_sampler の before_trial 等を実行する際の引数 study は(study(sampler=sub_sampler) ではなく) nelder_mead_sampler で用いている study(sampler=nelder_mead_sampler) で問題無いか?
    • sampler の実装次第?
    • TPESampler の場合は、過去に計算したパラメータと結果を参照しているのみだったので、特に問題無さそうだった。(むしろ nelder mead 側で計算した結果もTPEで参照出来てる?のでこちらの方が良いのかもしれない)

@KanaiYuma-aist
Copy link
Collaborator Author

KanaiYuma-aist commented Apr 23, 2024

sub_study を削除して、sub_sampler の before_trial, sample_independent, after_trial を呼び出す形に改修しました。
懸念->#346 (comment)

781c7a1

テストコード中のクラスにする必要のない箇所のクラス削除、部分的にしか利用していない fixture の削除を行いました。

f56f429

Copy link
Collaborator

@yoshipon yoshipon left a comment

Choose a reason for hiding this comment

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

修正ありがとうございます.何点かコメントさせて頂きました.
これらを修正頂いた段階で,一旦このPRはマージできればと思います.

よろしくお願いします.

tests/hpo/algorithms/test_nelder_mead_algorithm.py Outdated Show resolved Hide resolved
tests/hpo/algorithms/test_nelder_mead_algorithm.py Outdated Show resolved Hide resolved
aiaccel/hpo/samplers/nelder_mead_sampler.py Outdated Show resolved Hide resolved
aiaccel/hpo/samplers/nelder_mead_sampler.py Show resolved Hide resolved
aiaccel/hpo/samplers/nelder_mead_sampler.py Outdated Show resolved Hide resolved
aiaccel/hpo/samplers/nelder_mead_sampler.py Show resolved Hide resolved
aiaccel/hpo/samplers/nelder_mead_sampler.py Show resolved Hide resolved
Copy link
Collaborator

@yoshipon yoshipon left a comment

Choose a reason for hiding this comment

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

ありがとうございました!

@yoshipon yoshipon merged commit f67c995 into develop/v2 May 13, 2024
6 checks passed
@yoshipon yoshipon deleted the feature/add_nm_sampler branch May 13, 2024 05:42
aramoto99 added a commit that referenced this pull request May 14, 2024
* add nelder_mead_sampler.py

---------

Co-authored-by: Yoshiaki Bando <yoshipon@users.noreply.github.com>
yoshipon added a commit that referenced this pull request Aug 26, 2024
* Add nelder-mead sampler (#346)

* add nelder_mead_sampler.py

---------

Co-authored-by: Yoshiaki Bando <yoshipon@users.noreply.github.com>

* Add -e. (#371)

* Support for suggest_int in neldermead sampler. (#373)

* Support for suggest_int.

* Fix for ruff.

* Add Job dispatcher (#360)

* Update aiaccel/job

* fix lint error

* fix aiaccel/job/dispatcher.py

* wip

* Fix issues pointed out in review

* rename

* fix test

* fix for test

* fix for test

* fix for test

* fix for test

* Reflected code review feedback

* fix test

* fix test

* refactoring

* Run code formatter ruff

* refactoring

* Run code formatter ruff

* fix lint.yaml

* fix pypoject.toml

* fix mypy.ini

* fix mypy.ini

* fix mypy.ini

* fix mypy.ini

* fix mypy.ini

* Refactor abci jobs

* Update pyproject.toml

* adjusted to work in the ABCI environment.

* fix lint error

* fix test

* fix test

* Changed from unittest to pytest

* Incorporate revisions based on review feedback

* Add test items

* fix test

* fix test

* fix test

* remove __future__.annotations

* A bit simplify qstat_xml

* Simplify tests

---------

Co-authored-by: Yoshiaki Bando <yoshipon@users.noreply.github.com>

* Add ignore_missing_imports. (#376)

* Draft Implementation of CLI Command (#369)

* Update aiaccel/job

* fix lint error

* fix aiaccel/job/dispatcher.py

* wip

* Fix issues pointed out in review

* rename

* fix test

* fix for test

* fix for test

* fix for test

* fix for test

* Reflected code review feedback

* fix test

* fix test

* refactoring

* Run code formatter ruff

* refactoring

* Run code formatter ruff

* fix lint.yaml

* fix pypoject.toml

* fix mypy.ini

* fix mypy.ini

* fix mypy.ini

* fix mypy.ini

* fix mypy.ini

* Refactor abci jobs

* Update pyproject.toml

* adjusted to work in the ABCI environment.

* fix lint error

* fix test

* fix test

* Changed from unittest to pytest

* Incorporate revisions based on review feedback

* Add test items

* Add 'start.py'

* Fix code format

* update pyproject.toml

* Remove unnecessary items from config

* Add random seed option

* Refactor examples/start.py into aiaccel/apps/optimize.py

* fix lint errors and warnings

* remove apps/config

* fix typo

* change config.yaml format

* fix apps/optimizer

* fix HparamManager __init__

* fix HparamsManager

* Refactor Suggest class to use generics for improved type safety

* auto fix by ruff

* add optuna suggest wrapper

* format fix

* Update wrapper.py

---------

Co-authored-by: Yoshiaki Bando <yoshipon@users.noreply.github.com>

* Add nm docstring and move file (#381)

* Add docstring.

* Move nelder_mead_sampler.py.

* Fix path.

* Move test files.

* autoformat and fix mypy error

* Add v2 torch docstring   (#384)

* add docstring

* Update abci_environment.py

---------

Co-authored-by: Yoshiaki Bando <yoshipon@users.noreply.github.com>

---------

Co-authored-by: KanaiYuma-aist <105629713+KanaiYuma-aist@users.noreply.github.com>
Co-authored-by: Yoshiaki Bando <yoshipon@users.noreply.github.com>
aramoto99 added a commit that referenced this pull request Sep 2, 2024
* Add nelder-mead sampler (#346)

* add nelder_mead_sampler.py

---------

Co-authored-by: Yoshiaki Bando <yoshipon@users.noreply.github.com>

* Add -e. (#371)

* Support for suggest_int in neldermead sampler. (#373)

* Support for suggest_int.

* Fix for ruff.

* Add Job dispatcher (#360)

* Update aiaccel/job

* fix lint error

* fix aiaccel/job/dispatcher.py

* wip

* Fix issues pointed out in review

* rename

* fix test

* fix for test

* fix for test

* fix for test

* fix for test

* Reflected code review feedback

* fix test

* fix test

* refactoring

* Run code formatter ruff

* refactoring

* Run code formatter ruff

* fix lint.yaml

* fix pypoject.toml

* fix mypy.ini

* fix mypy.ini

* fix mypy.ini

* fix mypy.ini

* fix mypy.ini

* Refactor abci jobs

* Update pyproject.toml

* adjusted to work in the ABCI environment.

* fix lint error

* fix test

* fix test

* Changed from unittest to pytest

* Incorporate revisions based on review feedback

* Add test items

* fix test

* fix test

* fix test

* remove __future__.annotations

* A bit simplify qstat_xml

* Simplify tests

---------

Co-authored-by: Yoshiaki Bando <yoshipon@users.noreply.github.com>

* Add ignore_missing_imports. (#376)

* Draft Implementation of CLI Command (#369)

* Update aiaccel/job

* fix lint error

* fix aiaccel/job/dispatcher.py

* wip

* Fix issues pointed out in review

* rename

* fix test

* fix for test

* fix for test

* fix for test

* fix for test

* Reflected code review feedback

* fix test

* fix test

* refactoring

* Run code formatter ruff

* refactoring

* Run code formatter ruff

* fix lint.yaml

* fix pypoject.toml

* fix mypy.ini

* fix mypy.ini

* fix mypy.ini

* fix mypy.ini

* fix mypy.ini

* Refactor abci jobs

* Update pyproject.toml

* adjusted to work in the ABCI environment.

* fix lint error

* fix test

* fix test

* Changed from unittest to pytest

* Incorporate revisions based on review feedback

* Add test items

* Add 'start.py'

* Fix code format

* update pyproject.toml

* Remove unnecessary items from config

* Add random seed option

* Refactor examples/start.py into aiaccel/apps/optimize.py

* fix lint errors and warnings

* remove apps/config

* fix typo

* change config.yaml format

* fix apps/optimizer

* fix HparamManager __init__

* fix HparamsManager

* Refactor Suggest class to use generics for improved type safety

* auto fix by ruff

* add optuna suggest wrapper

* format fix

* Update wrapper.py

---------

Co-authored-by: Yoshiaki Bando <yoshipon@users.noreply.github.com>

* Add nm docstring and move file (#381)

* Add docstring.

* Move nelder_mead_sampler.py.

* Fix path.

* Move test files.

* autoformat and fix mypy error

* Add v2 torch docstring   (#384)

* add docstring

* Update abci_environment.py

---------

Co-authored-by: Yoshiaki Bando <yoshipon@users.noreply.github.com>

---------

Co-authored-by: KanaiYuma-aist <105629713+KanaiYuma-aist@users.noreply.github.com>
Co-authored-by: Yoshiaki Bando <yoshipon@users.noreply.github.com>
aramoto99 added a commit that referenced this pull request Sep 2, 2024
* Add nelder-mead sampler (#346)

* add nelder_mead_sampler.py

---------

Co-authored-by: Yoshiaki Bando <yoshipon@users.noreply.github.com>

* Add -e. (#371)

* Support for suggest_int in neldermead sampler. (#373)

* Support for suggest_int.

* Fix for ruff.

* Add Job dispatcher (#360)

* Update aiaccel/job

* fix lint error

* fix aiaccel/job/dispatcher.py

* wip

* Fix issues pointed out in review

* rename

* fix test

* fix for test

* fix for test

* fix for test

* fix for test

* Reflected code review feedback

* fix test

* fix test

* refactoring

* Run code formatter ruff

* refactoring

* Run code formatter ruff

* fix lint.yaml

* fix pypoject.toml

* fix mypy.ini

* fix mypy.ini

* fix mypy.ini

* fix mypy.ini

* fix mypy.ini

* Refactor abci jobs

* Update pyproject.toml

* adjusted to work in the ABCI environment.

* fix lint error

* fix test

* fix test

* Changed from unittest to pytest

* Incorporate revisions based on review feedback

* Add test items

* fix test

* fix test

* fix test

* remove __future__.annotations

* A bit simplify qstat_xml

* Simplify tests

---------

Co-authored-by: Yoshiaki Bando <yoshipon@users.noreply.github.com>

* Add ignore_missing_imports. (#376)

* Draft Implementation of CLI Command (#369)

* Update aiaccel/job

* fix lint error

* fix aiaccel/job/dispatcher.py

* wip

* Fix issues pointed out in review

* rename

* fix test

* fix for test

* fix for test

* fix for test

* fix for test

* Reflected code review feedback

* fix test

* fix test

* refactoring

* Run code formatter ruff

* refactoring

* Run code formatter ruff

* fix lint.yaml

* fix pypoject.toml

* fix mypy.ini

* fix mypy.ini

* fix mypy.ini

* fix mypy.ini

* fix mypy.ini

* Refactor abci jobs

* Update pyproject.toml

* adjusted to work in the ABCI environment.

* fix lint error

* fix test

* fix test

* Changed from unittest to pytest

* Incorporate revisions based on review feedback

* Add test items

* Add 'start.py'

* Fix code format

* update pyproject.toml

* Remove unnecessary items from config

* Add random seed option

* Refactor examples/start.py into aiaccel/apps/optimize.py

* fix lint errors and warnings

* remove apps/config

* fix typo

* change config.yaml format

* fix apps/optimizer

* fix HparamManager __init__

* fix HparamsManager

* Refactor Suggest class to use generics for improved type safety

* auto fix by ruff

* add optuna suggest wrapper

* format fix

* Update wrapper.py

---------

Co-authored-by: Yoshiaki Bando <yoshipon@users.noreply.github.com>

* Add nm docstring and move file (#381)

* Add docstring.

* Move nelder_mead_sampler.py.

* Fix path.

* Move test files.

* autoformat and fix mypy error

* Add v2 torch docstring   (#384)

* add docstring

* Update abci_environment.py

---------

Co-authored-by: Yoshiaki Bando <yoshipon@users.noreply.github.com>

---------

Co-authored-by: KanaiYuma-aist <105629713+KanaiYuma-aist@users.noreply.github.com>
Co-authored-by: Yoshiaki Bando <yoshipon@users.noreply.github.com>
yoshipon added a commit that referenced this pull request Sep 20, 2024
* Add torch goodies

* Add type annotations

* Add small things

* update for mypy

* Add several tests

* add test for hdf5_dataset.py

* Update workflows

* Add tests

* update workflows

* add dependencies

* update train.py

* add opt_lightning_module

* add opt_lightning_module

* Update error messages!

* Update hdf5_dataset to take grp_list as argument

* sort grp_list

* update v2 torch   (#383)

* Add nelder-mead sampler (#346)

* add nelder_mead_sampler.py

---------

Co-authored-by: Yoshiaki Bando <yoshipon@users.noreply.github.com>

* Add -e. (#371)

* Support for suggest_int in neldermead sampler. (#373)

* Support for suggest_int.

* Fix for ruff.

* Add Job dispatcher (#360)

* Update aiaccel/job

* fix lint error

* fix aiaccel/job/dispatcher.py

* wip

* Fix issues pointed out in review

* rename

* fix test

* fix for test

* fix for test

* fix for test

* fix for test

* Reflected code review feedback

* fix test

* fix test

* refactoring

* Run code formatter ruff

* refactoring

* Run code formatter ruff

* fix lint.yaml

* fix pypoject.toml

* fix mypy.ini

* fix mypy.ini

* fix mypy.ini

* fix mypy.ini

* fix mypy.ini

* Refactor abci jobs

* Update pyproject.toml

* adjusted to work in the ABCI environment.

* fix lint error

* fix test

* fix test

* Changed from unittest to pytest

* Incorporate revisions based on review feedback

* Add test items

* fix test

* fix test

* fix test

* remove __future__.annotations

* A bit simplify qstat_xml

* Simplify tests

---------

Co-authored-by: Yoshiaki Bando <yoshipon@users.noreply.github.com>

* Add ignore_missing_imports. (#376)

* Draft Implementation of CLI Command (#369)

* Update aiaccel/job

* fix lint error

* fix aiaccel/job/dispatcher.py

* wip

* Fix issues pointed out in review

* rename

* fix test

* fix for test

* fix for test

* fix for test

* fix for test

* Reflected code review feedback

* fix test

* fix test

* refactoring

* Run code formatter ruff

* refactoring

* Run code formatter ruff

* fix lint.yaml

* fix pypoject.toml

* fix mypy.ini

* fix mypy.ini

* fix mypy.ini

* fix mypy.ini

* fix mypy.ini

* Refactor abci jobs

* Update pyproject.toml

* adjusted to work in the ABCI environment.

* fix lint error

* fix test

* fix test

* Changed from unittest to pytest

* Incorporate revisions based on review feedback

* Add test items

* Add 'start.py'

* Fix code format

* update pyproject.toml

* Remove unnecessary items from config

* Add random seed option

* Refactor examples/start.py into aiaccel/apps/optimize.py

* fix lint errors and warnings

* remove apps/config

* fix typo

* change config.yaml format

* fix apps/optimizer

* fix HparamManager __init__

* fix HparamsManager

* Refactor Suggest class to use generics for improved type safety

* auto fix by ruff

* add optuna suggest wrapper

* format fix

* Update wrapper.py

---------

Co-authored-by: Yoshiaki Bando <yoshipon@users.noreply.github.com>

* Add nm docstring and move file (#381)

* Add docstring.

* Move nelder_mead_sampler.py.

* Fix path.

* Move test files.

* autoformat and fix mypy error

* Add v2 torch docstring   (#384)

* add docstring

* Update abci_environment.py

---------

Co-authored-by: Yoshiaki Bando <yoshipon@users.noreply.github.com>

---------

Co-authored-by: KanaiYuma-aist <105629713+KanaiYuma-aist@users.noreply.github.com>
Co-authored-by: Yoshiaki Bando <yoshipon@users.noreply.github.com>

* Add torch goodies

* Add type annotations

* Add small things

* update for mypy

* Add several tests

* add test for hdf5_dataset.py

* Update workflows

* Add tests

* update workflows

* add dependencies

* update train.py

* add opt_lightning_module

* Update error messages!

* add opt_lightning_module

* Update hdf5_dataset to take grp_list as argument

* sort grp_list

* update v2 torch   (#383)

* Add nelder-mead sampler (#346)

* add nelder_mead_sampler.py

---------

Co-authored-by: Yoshiaki Bando <yoshipon@users.noreply.github.com>

* Add -e. (#371)

* Support for suggest_int in neldermead sampler. (#373)

* Support for suggest_int.

* Fix for ruff.

* Add Job dispatcher (#360)

* Update aiaccel/job

* fix lint error

* fix aiaccel/job/dispatcher.py

* wip

* Fix issues pointed out in review

* rename

* fix test

* fix for test

* fix for test

* fix for test

* fix for test

* Reflected code review feedback

* fix test

* fix test

* refactoring

* Run code formatter ruff

* refactoring

* Run code formatter ruff

* fix lint.yaml

* fix pypoject.toml

* fix mypy.ini

* fix mypy.ini

* fix mypy.ini

* fix mypy.ini

* fix mypy.ini

* Refactor abci jobs

* Update pyproject.toml

* adjusted to work in the ABCI environment.

* fix lint error

* fix test

* fix test

* Changed from unittest to pytest

* Incorporate revisions based on review feedback

* Add test items

* fix test

* fix test

* fix test

* remove __future__.annotations

* A bit simplify qstat_xml

* Simplify tests

---------

Co-authored-by: Yoshiaki Bando <yoshipon@users.noreply.github.com>

* Add ignore_missing_imports. (#376)

* Draft Implementation of CLI Command (#369)

* Update aiaccel/job

* fix lint error

* fix aiaccel/job/dispatcher.py

* wip

* Fix issues pointed out in review

* rename

* fix test

* fix for test

* fix for test

* fix for test

* fix for test

* Reflected code review feedback

* fix test

* fix test

* refactoring

* Run code formatter ruff

* refactoring

* Run code formatter ruff

* fix lint.yaml

* fix pypoject.toml

* fix mypy.ini

* fix mypy.ini

* fix mypy.ini

* fix mypy.ini

* fix mypy.ini

* Refactor abci jobs

* Update pyproject.toml

* adjusted to work in the ABCI environment.

* fix lint error

* fix test

* fix test

* Changed from unittest to pytest

* Incorporate revisions based on review feedback

* Add test items

* Add 'start.py'

* Fix code format

* update pyproject.toml

* Remove unnecessary items from config

* Add random seed option

* Refactor examples/start.py into aiaccel/apps/optimize.py

* fix lint errors and warnings

* remove apps/config

* fix typo

* change config.yaml format

* fix apps/optimizer

* fix HparamManager __init__

* fix HparamsManager

* Refactor Suggest class to use generics for improved type safety

* auto fix by ruff

* add optuna suggest wrapper

* format fix

* Update wrapper.py

---------

Co-authored-by: Yoshiaki Bando <yoshipon@users.noreply.github.com>

* Add nm docstring and move file (#381)

* Add docstring.

* Move nelder_mead_sampler.py.

* Fix path.

* Move test files.

* autoformat and fix mypy error

* Add v2 torch docstring   (#384)

* add docstring

* Update abci_environment.py

---------

Co-authored-by: Yoshiaki Bando <yoshipon@users.noreply.github.com>

---------

Co-authored-by: KanaiYuma-aist <105629713+KanaiYuma-aist@users.noreply.github.com>
Co-authored-by: Yoshiaki Bando <yoshipon@users.noreply.github.com>

* fix confrict

* Fixed consistency in revision history

* Fixed consistency in revision history(2)

---------

Co-authored-by: Yoshiaki Bando <yoshipon@users.noreply.github.com>
Co-authored-by: Yoshiaki Bando <3883362-yoshipon@users.noreply.gitlab.com>
Co-authored-by: KanaiYuma-aist <105629713+KanaiYuma-aist@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants