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 a caching mechanism to make NSGAIIMultiObjectiveSampler faster. #1257

Merged
merged 4 commits into from Jul 2, 2020

Conversation

sile
Copy link
Member

@sile sile commented May 19, 2020

The current implementation of NSGAIIMultiObjectiveSampler is unnecessarily slow because it calculates the latest population from scratch each time when the relative_sample method is called.
This PR makes it faster by storing caches of populations to the study system attributes and eliminating the need of the redundant recalculation.

TODO

  • Benchmark

@sile sile added the enhancement Change that does not break compatibility and not affect public interfaces, but improves performance. label May 19, 2020
@sile sile added this to the v1.5.0 milestone May 19, 2020
@sile sile changed the title Add a caching mechanism to make NSGAIIMultiObjectiveSampler faster. [WIP] Add a caching mechanism to make NSGAIIMultiObjectiveSampler faster. May 19, 2020
@codecov-commenter
Copy link

codecov-commenter commented May 19, 2020

Codecov Report

Merging #1257 into master will increase coverage by 0.16%.
The diff coverage is 92.68%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1257      +/-   ##
==========================================
+ Coverage   88.00%   88.16%   +0.16%     
==========================================
  Files          97       98       +1     
  Lines        7301     7410     +109     
==========================================
+ Hits         6425     6533     +108     
- Misses        876      877       +1     
Impacted Files Coverage Δ
optuna/multi_objective/samplers/_nsga2.py 97.05% <92.10%> (-2.26%) ⬇️
optuna/multi_objective/study.py 97.47% <100.00%> (+0.13%) ⬆️
optuna/structs.py 51.45% <0.00%> (-3.50%) ⬇️
optuna/integration/__init__.py 60.41% <0.00%> (-1.29%) ⬇️
optuna/samplers/_cmaes.py 75.67% <0.00%> (-0.26%) ⬇️
optuna/multi_objective/trial.py 91.21% <0.00%> (-0.06%) ⬇️
optuna/dashboard.py 60.64% <0.00%> (ø)
optuna/_experimental.py 100.00% <0.00%> (ø)
optuna/samplers/_random.py 86.27% <0.00%> (ø)
optuna/integration/skopt.py 90.83% <0.00%> (ø)
... and 13 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 99788db...cd5d04f. Read the comment docs.

@sile
Copy link
Member Author

sile commented May 19, 2020

Benchmark Result

Elapsed time

zdt1-7553fd1fa688b1a8d73d925f8faa1da4770c81ecbb7c365b25a19e120a9e072a

Optimization Performance

The results are exactly the same before and after applying this PR.

Commands

$ pip3 install --user git+https://github.com/optuna/optuna@9b3eccfc1a
$ kurobako solver --name 'NSGA-II@master' command python3 nsga2.py > solver-master.json
$ kurobako studies --problems $(kurobako problem zdt 1) --solvers $(cat solver-master.json) --repeats 1 --budget 1000 --seed 0 | kurobako run > result-master.json

$ pip3 install --user git+https://github.com/sile/optuna@aa8b578
$ kurobako solver --name 'NSGA-II@pr1257' command python3 nsga2.py > solver-pr1257.json
$ kurobako studies --problems $(kurobako problem zdt 1) --solvers $(cat solver-pr1257.json) --repeats 1 --budget 1000 --seed 0 | kurobako run > result-pr1257.json

$ cat result-*.json | kurobako plot curve --metric solver-elapsed-time
$ cat result-*.json | kurobako plot pareto-front --ymin 1 --ymax 7 

@sile sile changed the title [WIP] Add a caching mechanism to make NSGAIIMultiObjectiveSampler faster. Add a caching mechanism to make NSGAIIMultiObjectiveSampler faster. May 19, 2020
@toshihikoyanase toshihikoyanase modified the milestones: v1.5.0, v2.0.0 May 29, 2020
@github-actions
Copy link
Contributor

This pull request has not seen any recent activity.

@github-actions github-actions bot added the stale Exempt from stale bot labeling. label Jun 14, 2020
@ytsmiling ytsmiling self-requested a review June 24, 2020 03:50
Copy link
Member

@ytsmiling ytsmiling 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 creating this PR. The speed-up is impressive and the contest looks almost LGTM except for one concern.

optuna/multi_objective/samplers/_nsga2.py Outdated Show resolved Hide resolved
Co-authored-by: Yusuke Tsuzuku <ytsmiling@users.noreply.github.com>
@sile sile removed the stale Exempt from stale bot labeling. label Jun 24, 2020
@sile
Copy link
Member Author

sile commented Jun 29, 2020

Fixed the CI failure. PTAL 🙇 > @ytsmiling

Copy link
Member

@ytsmiling ytsmiling left a comment

Choose a reason for hiding this comment

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

LGTM!

@ytsmiling ytsmiling merged commit 943fd25 into optuna:master Jul 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Change that does not break compatibility and not affect public interfaces, but improves performance.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants