Skip to content

Add BaseGASampler#5864

Merged
y0z merged 11 commits intooptuna:masterfrom
gen740:base_ga_sampler
Feb 13, 2025
Merged

Add BaseGASampler#5864
y0z merged 11 commits intooptuna:masterfrom
gen740:base_ga_sampler

Conversation

@gen740
Copy link
Copy Markdown
Member

@gen740 gen740 commented Dec 13, 2024

Motivation

In optuna GA (Genetic Algorithm) samplers are not easy to implement, this is because each sampler should handle generation id and caches correctly.

So for easy implementation. I implemented the abstract class of the GASampler BaseGASampler for general GA.

There are also some bugs in the current implementation.
The nsgaii sampler stopped with a random multiprocess error at this line.

Performance

I created a simple benchmark with the following simple objective function.

def objective(trial):
    x = trial.suggest_float("x", -10, 10)
    y = trial.suggest_float("y", -10, 10)
    return (x - 2) ** 2 + (y - 3) ** 2, (x + 2) ** 2 + (y + 3) ** 2

Run with in-memory storage and 3000 trials. Repeated 20 times. And the results are as follows

Current implementation This implementation
1.476 ± 0.016s 1.477 ± 0.008s

Description of the changes

  • Introduction of BaseGASampler.
  • Rewrite the NSGA-II sampler with BaseGASampler.
  • Add tests.

@gen740 gen740 marked this pull request as ready for review December 20, 2024 06:36
@HideakiImamura HideakiImamura self-assigned this Dec 20, 2024
@github-actions
Copy link
Copy Markdown
Contributor

This pull request has not seen any recent activity.

@github-actions github-actions bot added the stale Exempt from stale bot labeling. label Dec 29, 2024
@nabenabe0928 nabenabe0928 removed the stale Exempt from stale bot labeling. label Dec 30, 2024
@HideakiImamura
Copy link
Copy Markdown
Member

@y0z Could you review this PR?

@HideakiImamura
Copy link
Copy Markdown
Member

@porink0424 Could you review this PR?

@github-actions
Copy link
Copy Markdown
Contributor

This pull request has not seen any recent activity.

@github-actions github-actions bot added the stale Exempt from stale bot labeling. label Jan 13, 2025
@c-bata c-bata removed the stale Exempt from stale bot labeling. label Jan 14, 2025
@github-actions
Copy link
Copy Markdown
Contributor

This pull request has not seen any recent activity.

@github-actions github-actions bot added the stale Exempt from stale bot labeling. label Jan 21, 2025
Copy link
Copy Markdown
Member

@y0z y0z left a comment

Choose a reason for hiding this comment

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

I leave some comments on _base.py.

@y0z y0z removed the stale Exempt from stale bot labeling. label Jan 23, 2025
@nabenabe0928 nabenabe0928 added the code-fix Change that does not change the behavior, such as code refactoring. label Jan 23, 2025
return [study._storage.get_trial(trial_id) for trial_id in cached_parent_population]
else:
parent_population = self.select_parent(study, generation)
study._storage.set_study_system_attr(
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

TODO: Check race conditions

Copy link
Copy Markdown
Member

@porink0424 porink0424 left a comment

Choose a reason for hiding this comment

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

I've left a few comments, please take a look.

- `get_generation` -> `get_trial_generation`
- Remove "current" word from "current generation" because of ambiguity
- Use `get_trials` to preetch all the trials to avoid unnecessary
  execution of SQL queries
- Fix the test of BaseGASampler
Copy link
Copy Markdown
Member

@porink0424 porink0424 left a comment

Choose a reason for hiding this comment

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

LGTM!

@porink0424 porink0424 removed their assignment Feb 5, 2025
@github-actions
Copy link
Copy Markdown
Contributor

This pull request has not seen any recent activity.

@github-actions github-actions bot added the stale Exempt from stale bot labeling. label Feb 12, 2025
Copy link
Copy Markdown
Member

@y0z y0z left a comment

Choose a reason for hiding this comment

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

LGTM

@y0z y0z removed the stale Exempt from stale bot labeling. label Feb 13, 2025
@y0z y0z added this to the v4.3.0 milestone Feb 13, 2025
@y0z y0z merged commit e970196 into optuna:master Feb 13, 2025
@y0z y0z removed their assignment Feb 13, 2025
@gen740 gen740 deleted the base_ga_sampler branch February 14, 2025 05:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

code-fix Change that does not change the behavior, such as code refactoring.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants