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

Suppress warnings from numpy in hypervolume computation #5432

Merged
merged 15 commits into from May 21, 2024

Conversation

eukaryo
Copy link
Collaborator

@eukaryo eukaryo commented May 8, 2024

Motivation

I want to reduce warning RuntimeWarning: invalid value encountered in subtract in unittests.
Related to issue #3815 .

Description of the changes

I applied with np.errstate(invalid='ignore'): to minimum extent necessary and suppressed warnings.

Copy link
Collaborator

@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.

Thank you for the PR, I left a minor comment!

optuna/_hypervolume/hssp.py Outdated Show resolved Hide resolved
optuna/_hypervolume/hssp.py Outdated Show resolved Hide resolved
eukaryo and others added 2 commits May 8, 2024 10:55
Co-authored-by: Shuhei Watanabe <47781922+nabenabe0928@users.noreply.github.com>
Co-authored-by: Shuhei Watanabe <47781922+nabenabe0928@users.noreply.github.com>
@nabenabe0928
Copy link
Collaborator

In fact, this PR relates to the following issue's comment:

Namely, we should probably return inf instead of nan for inf - inf.

@eukaryo
Copy link
Collaborator Author

eukaryo commented May 8, 2024

I added guards that immediately returns if reference_points has non-finite value(s). I kept with np.errstate(invalid='ignore'): clauses because trials can have non-finite value(s).

Anyway, I think issue #5374 will be resolved by PR #5435 .

optuna/_hypervolume/utils.py Outdated Show resolved Hide resolved
optuna/_hypervolume/hssp.py Outdated Show resolved Hide resolved
Copy link
Collaborator

@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.

Thank you for the changes, I left a minor comment!

optuna/_hypervolume/hssp.py Outdated Show resolved Hide resolved
Co-authored-by: Shuhei Watanabe <47781922+nabenabe0928@users.noreply.github.com>
Copy link
Collaborator

@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.

Thank you for the change and the update in the unittest, LGTM!

assert not np.any(reference_point - rank_i_loss_vals <= 0)
if not np.isfinite(reference_point).all():
return rank_i_indices[:subset_size]
diff_of_loss_vals_and_ref_point = reference_point - rank_i_loss_vals
Copy link
Collaborator

Choose a reason for hiding this comment

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

Btw, can we revert here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I think the current defensive code is better for when _solve_hssp_on_unique_loss_vals is called from other code in the future.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ok, then let's keep the current code!

@nabenabe0928
Copy link
Collaborator

@not522
Could you review this PR?

@not522
Copy link
Member

not522 commented May 20, 2024

Could you remove filterwarnings from test_hssp.py? I think that they are no longer needed.

Copy link
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

@not522 not522 added the enhancement Change that does not break compatibility and not affect public interfaces, but improves performance. label May 21, 2024
@not522 not522 added this to the v4.0.0 milestone May 21, 2024
@not522 not522 merged commit 3aac18f into optuna:master May 21, 2024
14 checks passed
@eukaryo eukaryo deleted the suppress-numpy-invalid branch May 23, 2024 03:30
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

3 participants