Skip to content

Implement NSGA-III using BaseGASampler#6219

Merged
gen740 merged 2 commits intooptuna:masterfrom
y0z:feature/basega_nsgaiii
Aug 1, 2025
Merged

Implement NSGA-III using BaseGASampler#6219
gen740 merged 2 commits intooptuna:masterfrom
y0z:feature/basega_nsgaiii

Conversation

@y0z
Copy link
Copy Markdown
Member

@y0z y0z commented Jul 25, 2025

Motivation & Description of the changes

This PR implements NSGAIII using BaseGASampler as in #5864.
This change reduces code duplication. It also eliminates some unintuitive internal differences between NSGA-II and NSGA-III.
For example, in Optuna v4.4, _GENERATION_KEY is not defined in NSGA-III, as shown below, but it is now defined.

>>> import optuna
>>> optuna.samplers.NSGAIISampler._GENERATION_KEY
'NSGAIISampler:generation'
>>> optuna.samplers.NSGAIIISampler._GENERATION_KEY
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: type object 'NSGAIIISampler' has no attribute '_GENERATION_KEY'
>>>

@y0z y0z added the code-fix Change that does not change the behavior, such as code refactoring. label Jul 25, 2025
@nabenabe0928 nabenabe0928 changed the title Implement NSGAIII using BaseGASampler Implement NSGA-III using `BaseGASampler Jul 26, 2025
@nabenabe0928 nabenabe0928 changed the title Implement NSGA-III using `BaseGASampler Implement NSGA-III using BaseGASampler Jul 26, 2025
@nabenabe0928 nabenabe0928 added this to the v4.5.0 milestone Jul 26, 2025
Copy link
Copy Markdown
Contributor

@nabenabe0928 nabenabe0928 left a comment

Choose a reason for hiding this comment

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

I compared the changes in this PR with the following:

LGTM:)

@c-bata
Copy link
Copy Markdown
Member

c-bata commented Jul 28, 2025

@gen740 Could you review this PR?

Copy link
Copy Markdown
Member

@gen740 gen740 left a comment

Choose a reason for hiding this comment

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

I confirmed that this PR returns identical results as in the master branch using the following code.

import optuna
from optuna.samplers import NSGAIIISampler


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


study = optuna.create_study(
    directions=["minimize", "minimize"],
    sampler=NSGAIIISampler(seed=42),
)

study.optimize(objective, n_trials=30)

LGTM!

@gen740 gen740 merged commit d49e8b1 into optuna:master Aug 1, 2025
15 checks passed
@y0z y0z deleted the feature/basega_nsgaiii branch August 1, 2025 08:00
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.

4 participants