Skip to content

Improve performance of plot_hypervolume_history#6115

Merged
HideakiImamura merged 1 commit intooptuna:masterfrom
shmurai:perf-hypervolume_history_info
Jun 4, 2025
Merged

Improve performance of plot_hypervolume_history#6115
HideakiImamura merged 1 commit intooptuna:masterfrom
shmurai:perf-hypervolume_history_info

Conversation

@shmurai
Copy link
Copy Markdown
Contributor

@shmurai shmurai commented May 31, 2025

Motivation

Current implementation of _get_hypervolume_history_info calls _dominates many times. If we normalize values first and perform checks equivalent to _dominates on ndarrays, its performance will be improved

Description of the changes

_get_hypervolume_history_info no longer keeps best_trials. Instead it maintains best_trials_values_normalized as ndarrray, for which checks like _dominates can be efficiently performed.

@not522 not522 self-assigned this May 31, 2025
@not522 not522 added sprint-20250531 PR from the online sprint event May 31, 2025. enhancement Change that does not break compatibility and not affect public interfaces, but improves performance. labels May 31, 2025
@not522 not522 changed the title Improve performance of hypervolume_history_info Improve performance of plot_hypervolume_history May 31, 2025
@HideakiImamura HideakiImamura self-assigned this May 31, 2025
Copy link
Copy Markdown
Member

@not522 not522 left a comment

Choose a reason for hiding this comment

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

LGTM!

@HideakiImamura
Copy link
Copy Markdown
Member

HideakiImamura commented May 31, 2025

I tried the following code, but I see the performance worsened. Am I misunderstanding something?

I misunderstood. I'm so sorry.

  • Code
import optuna
import time

optuna.logging.set_verbosity(optuna.logging.WARNING)


def test_pr6115_with_constraints():
    def objective(trial):
        x = trial.suggest_float("x", 0, 1)
        y = trial.suggest_float("y", 0, 1)
        z = trial.suggest_float("z", 0, 1)
        trial.set_user_attr("constraints", [x ** 2 + y ** 2 + z ** 2 - 1])
        return x, y, z

    def constraints_func(trial):
        return trial.user_attrs["constraints"]

    sampler = optuna.samplers.NSGAIISampler(seed=42, constraints_func=constraints_func)
    study = optuna.create_study(directions=["maximize", "maximize", "maximize"], sampler=sampler)

    study.optimize(objective, n_trials=10000)

    reference_point=[0, 0, 0]
    start = time.time()
    fig = optuna.visualization.plot_hypervolume_history(study, reference_point)
    end = time.time()
    print(f"Time taken for hypervolume plot: {end - start} seconds")


if __name__ == "__main__":
    test_pr6115_with_constraints()
  • The master
> python work/test-pr6115.py 
...
Time taken for hypervolume plot: 10.530152320861816 seconds
  • This PR
> python work/test-pr6115.py 
...
Time taken for hypervolume plot: 2.809957504272461 seconds

@not522 not522 removed their assignment Jun 2, 2025
Copy link
Copy Markdown
Member

@HideakiImamura HideakiImamura left a comment

Choose a reason for hiding this comment

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

LGTM!

@HideakiImamura HideakiImamura merged commit 44bb2d3 into optuna:master Jun 4, 2025
16 checks passed
@y0z y0z added this to the v4.4.0 milestone Jun 4, 2025
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. sprint-20250531 PR from the online sprint event May 31, 2025.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants