Skip to content

Skip studies without finite observations in plot_edf - #6882

Merged
kAIto47802 merged 2 commits into
optuna:masterfrom
aswanth-07:fix/edf-empty-studies
Oct 7, 2026
Merged

kAIto47802 merged 2 commits into
optuna:masterfrom
aswanth-07:fix/edf-empty-studies

Conversation

@aswanth-07

@aswanth-07 aswanth-07 commented Oct 3, 2026 •

Copy link
Copy Markdown
Contributor

Motivation

Comparing a populated study with a study that has no completed finite observations produces a NaN EDF curve and RuntimeWarning: invalid value encountered in divide. With RuntimeWarnings treated as errors, both Plotly and Matplotlib plot_edf stop before producing the comparison.

For example:

import warnings
import optuna

completed = optuna.create_study()
completed.add_trials([optuna.create_trial(value=1.0), optuna.create_trial(value=3.0)])
pruned = optuna.create_study()
pruned.add_trial(optuna.create_trial(state=optuna.trial.TrialState.PRUNED))

with warnings.catch_warnings():
    warnings.simplefilter("error", RuntimeWarning)
    optuna.visualization.plot_edf([completed, pruned])

Description of the changes

Skip studies with no observations after the existing completed-trial and nonfinite-value filtering in _get_edf_info, which both backends use. An empty sample has no empirical distribution. Keep each remaining study name paired with its observations and retain the existing empty-plot return when none remain.

Add six regression cases across both backends: no trials, only pruned trials, and only nonfinite observations. They check the retained study name, axis, and exact empirical probabilities for observations [1.0, 3.0], then exercise the public plot function with strict RuntimeWarnings.

Clarify both public docstrings to state that only completed trials with finite target values contribute and that studies without such trials are omitted.

Existing users

Populated curves, their order, custom multiobjective targets, and partial nonfinite filtering remain unchanged. The comparison omits empty study entries instead of plotting undefined curves. This read-only plotting change does not write storage, change trials, or alter sampler settings.

Validation

  • All six regressions fail on pristine master at 5c8e50d with the division warning and pass with this change.
  • PYTEST_DISABLE_PLUGIN_AUTOLOAD=1 MPLBACKEND=Agg py -3.13 -m pytest tests/visualization_tests/test_edf.py tests/visualization_tests/test_utils.py -q -W error::RuntimeWarning: 72 passed. The 66 existing tests also pass on pristine upstream.
  • Repeated-call and unchanged-trial controls pass on both base and patch.
  • Ruff lint, formatting, and git diff --check pass.
  • py -3.13 -m mypy --follow-imports=silent optuna/visualization/_edf.py tests/visualization_tests/test_edf.py passes. The default import-following check reports three errors in unchanged _gp/optim_mixed.py and visualization/matplotlib/_rank.py on pristine upstream as well.

Validation used Python 3.13.3, NumPy 2.2.6, Plotly 6.9.0, and Matplotlib 3.10.3 on Windows. The full test matrix and documentation build were not run locally. All 15 CI checks passed on 36e6a50. After the docstring update in e9733ae, the 72 focused tests, Ruff lint and formatting, and diff checks pass locally; CI for the updated head is pending.

Checklist

  • I used an LLM while working on this PR.

@aswanth-07
aswanth-07 marked this pull request as ready for review October 3, 2026 06:21
@y0z y0z self-assigned this Oct 5, 2026
@y0z

y0z commented Oct 5, 2026

Copy link
Copy Markdown
Member

@kAIto47802 Could you review this PR?

@y0z y0z added the code-fix Change that does not change the behavior, such as code refactoring. label Oct 5, 2026

@y0z y0z left a comment

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.

Thank you for your contribution.

The changes look good. Please clarify that studies with no complete trials with finite target values are omitted in the docstring.

@aswanth-07

Copy link
Copy Markdown
Contributor Author

Updated both Plotly and Matplotlib docstrings in e9733ae to state that studies without complete trials with finite target values are omitted. The focused EDF and visualization utility suites pass (72 tests).

@y0z y0z left a comment

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.

LGTM

@y0z y0z removed their assignment Oct 5, 2026

@kAIto47802 kAIto47802 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM

@kAIto47802 kAIto47802 added this to the v5.1.0 milestone Oct 7, 2026
@kAIto47802
kAIto47802 merged commit d9b3528 into optuna:master Oct 7, 2026
14 checks passed
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.

3 participants