Skip to content

Fix TPESampler with multivariate and constant_liar#6505

Merged
c-bata merged 1 commit intooptuna:masterfrom
not522:fix-multivariate-constant_liar
Mar 11, 2026
Merged

Fix TPESampler with multivariate and constant_liar#6505
c-bata merged 1 commit intooptuna:masterfrom
not522:fix-multivariate-constant_liar

Conversation

@not522
Copy link
Copy Markdown
Member

@not522 not522 commented Mar 11, 2026

Motivation

Combining TPESampler's multivariate and constant_liar can sometimes cause the constant_liar to function improperly during batch optimization.
#6189 fixed the bug that reappeared in #6265, so this PR addresses that issue.

import matplotlib.pyplot as plt
import optuna

N_TRIAL = 50
N_BATCH = 10

multivariate = True
constant_liar = True
sampler = optuna.samplers.TPESampler(
    seed=42,
    multivariate=multivariate,
    constant_liar=constant_liar,
)
study = optuna.create_study(sampler=sampler)

for i in range(0, N_TRIAL, N_BATCH):
    trials = []
    for j in range(N_BATCH):
        trials.append(study.ask())
    X = [trial.suggest_float("x", -10, 10) for trial in trials]
    Y = [trial.suggest_float("y", -10, 10) for trial in trials]
    for j in range(N_BATCH):
        study.tell(trials[j], X[j] ** 2 + Y[j] ** 2)

    # Skip first random sampling.
    if i > 0:
        plt.plot(X, Y, ".")
plt.xlim(-10, 10)
plt.ylim(-10, 10)
plt.savefig(f"{multivariate}-{constant_liar}.png")
plt.clf()
  • master
True-True
  • PR
True-True

Description of the changes

Revert #6265.

Speed Benchmark

This PR increases storage access and degrades speed. Ideally, this access could be avoided, but making changes to the Study class would be required, which I haven't done in this PR.

import optuna

def objective(trial: optuna.Trial) -> float:
    x = trial.suggest_float("x", -100, 100)
    y = trial.suggest_int("y", -100, 100)
    return x**2 + y**2

sampler = optuna.samplers.TPESampler(seed=42, multivariate=True, constant_liar=True)
study = optuna.create_study(sampler=sampler, storage="sqlite:///tmp.db")
study.optimize(objective, n_trials=1000)
master PR
9.939s 10.882s

@not522 not522 added this to the v4.8.0 milestone Mar 11, 2026
@c-bata c-bata assigned c-bata and y0z Mar 11, 2026
@c-bata
Copy link
Copy Markdown
Member

c-bata commented Mar 11, 2026

@y0z Could you review this PR?

@c-bata c-bata added the bug Issue/PR about behavior that is broken. Not for typos/examples/CI/test but for Optuna itself. label Mar 11, 2026
Copy link
Copy Markdown
Member

@y0z y0z left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Copy Markdown
Member

@c-bata c-bata left a comment

Choose a reason for hiding this comment

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

Good catch. LGTM!

@c-bata c-bata merged commit 274f5b9 into optuna:master Mar 11, 2026
14 checks passed
@not522 not522 deleted the fix-multivariate-constant_liar branch March 11, 2026 07:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Issue/PR about behavior that is broken. Not for typos/examples/CI/test but for Optuna itself.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants