Skip to content

Restore infeasible trial markers in plot_contour matrices - #6934

Merged
kAIto47802 merged 2 commits into
optuna:masterfrom
vicmcorrea:fix/contour-infeasible-matrix
Oct 30, 2026
Merged

kAIto47802 merged 2 commits into
optuna:masterfrom
vicmcorrea:fix/contour-infeasible-matrix

Conversation

@vicmcorrea

Copy link
Copy Markdown
Contributor

Motivation

For constrained studies with three or more parameters, plot_contour omits the gray markers for infeasible trials. The same observations appear when plotting two parameters. The subplot helper already returns the infeasible scatter, but the matrix branch adds only the contour and feasible scatter.

Description of the changes

  • Add the existing infeasible scatter to each off-diagonal matrix subplot.
  • Add a public-API regression checking feasible and infeasible coordinates and subplot placement in two- and three-parameter figures.

Blast radius

Only Plotly contour-matrix assembly changes. Each off-diagonal panel gains a scatter trace, including an empty trace for all-feasible data, so positional figure.data indexes change. Contour values, axis and colorbar settings, stored trials, optimization, the two-parameter path, and Matplotlib behavior remain unchanged.

Validation

  • On unchanged master, the new two-parameter regression passes and the three-parameter case fails because the infeasible scatter is absent. Both pass with this fix.
  • All 83 contour tests pass on Python 3.10, 3.12, and 3.15.
  • Ruff lint and format checks, mypy on both changed files, and git diff --check pass.

The contour suite retains its existing Matplotlib open-figure warning. The full repository suite and browser rendering were not run locally.

Checklist

  • I used an LLM while working on this PR.

@c-bata

c-bata commented Oct 26, 2026

Copy link
Copy Markdown
Member

Could you add a minimal reproducible example (code and the resulting plot) showing the missing infeasible markers in a contour matrix? Please clarify which panels change; a before-and-after plot would help.

@vicmcorrea

Copy link
Copy Markdown
Contributor Author

hey @c-bata , I reproduced this with a small random forest study under a model-size limit.

here's a smaller repro.

import optuna


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_constraint("x <= y", x - y)
    return x + y + z


study = optuna.create_study()
for x, y, z in [(0, 0, 0), (0.75, 0.25, 0.75), (0, 1, 1), (1, 1, 0)]:
    study.enqueue_trial({"x": x, "y": y, "z": z})
study.optimize(objective, n_trials=4)

figure = optuna.visualization.plot_contour(study, params=["x", "y", "z"])
figure.update_layout(width=900, height=900)
figure.show()

The fix adds the gray marker to all six off-diagonal panels, the two-parameter plot, contours and diagonal panels stay the same.

image

here's a cropped panel from the model-size study. five trials fit the 256 KiB budget and seven exceeded it. the fix restores those seven over-budget trial markers.

image

@c-bata

c-bata commented Oct 27, 2026

Copy link
Copy Markdown
Member

@yen-0 @kAIto47802 Could you review this PR?

@yen-0 yen-0 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. The fix restores infeasible-trial markers in every off-diagonal contour-matrix panel, and the regression test verifies behavior.

@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 merged commit 8c615f0 into optuna:master Oct 30, 2026
12 checks passed
@y0z y0z added this to the v5.1.0 milestone Nov 12, 2026
@y0z y0z added the enhancement Change that does not break compatibility and not affect public interfaces, but improves performance. label Nov 12, 2026
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.

5 participants